Commit ef82a71b by 胡悦

Merge branch 'v1.0.1' of http://192.168.3.233:8090/glsx/gl_tape into v1.0.1

2 parents d4763275 c68080c6
import http from '../request/http' import http from "../request/http";
module.exports = { module.exports = {
search(data) { search(data) {
return http.post({ return http.post({
method: 'scrm.api.carlife.weapp.homeSearch.search', method: "scrm.api.carlife.weapp.homeSearch.search",
pageSize: 10, pageSize: 10,
...data, ...data,
}) });
}, },
findSoureList(data) { findSoureList(data) {
return http.post({ return http.post({
method: 'dj.api.smartcarlife.recepiton.soure.findSoureList', method: 'dj.api.smartcarlife.recepiton.soure.findSoureList',
...data, ...data,
}) })
}
}
\ No newline at end of file \ No newline at end of file
},
getToken(data) {
return http.post({
method: "dj.api.mindworkplate.badge.getToken",
projectName: "mindworkplate",
sessionId: "2ae39c60-60c9-4096-901a-68da57068cd9",
});
},
};
import http from '../request/http' import http from '../request/http'
module.exports = { module.exports = {
getSmsCode (data) { /**获取短信 */
getSmsCode (data = {}) {
data.projectName = 'boutique' data.projectName = 'boutique'
return http.fetch('dj.api.smartcarlife.sms.get.code', data) return http.fetch('dj.api.smartcarlife.sms.get.code', data)
}, },
/**手机验证码登录 */
smsLogin (data = {}) {
data.projectName = 'boutique'
data.source = 'MINIAPP'
data.productCode = 'PC00c2'
return http.fetch('dj.api.smartcarlife.sms.login', data)
},
/**获取当前登录账号能查看的园区店列表 */
getYQList () {
return http.fetch('dj.api.smartcarlife.serviceMerchant.curYqList')
},
} }
\ No newline at end of file \ No newline at end of file
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
<image <image
:src="imagePath" :src="imagePath"
:mode="mode" :mode="mode"
:webp="webp||isWebp"
lazy-load
/> />
</template> </template>
...@@ -22,7 +20,6 @@ export default { ...@@ -22,7 +20,6 @@ export default {
type: null, type: null,
default: '' default: ''
}, },
webp: Boolean
}, },
name: 'GlsxImage', name: 'GlsxImage',
data () { data () {
...@@ -53,4 +50,9 @@ export default { ...@@ -53,4 +50,9 @@ export default {
</script> </script>
<style scoped lang='scss'> <style scoped lang='scss'>
image{
width: 100%;
height: 100%;
vertical-align: top;
}
</style> </style>
\ No newline at end of file \ No newline at end of file
import Vue from 'vue' // import Vue from 'vue'
const componentsFiles = require.context(`./`, true, /.vue$/) // const componentsFiles = require.context(`./`, true, /.vue$/)
componentsFiles.keys().forEach(path => { // componentsFiles.keys().forEach(path => {
const component = componentsFiles(path).default // const component = componentsFiles(path).default
Vue.component(component.name, component) // // Vue.component(component.name, component)
}) // })
\ No newline at end of file \ No newline at end of file
module.exports = { module.exports = {
// 请求域名 格式:https://xxx.xxx.com // 请求域名 格式:https://xxx.xxx.com
HTTP_REQUEST_URL: 'http://127.0.0.1:8000/api', HTTP_REQUEST_URL: "http://127.0.0.1:8000/api",
// 阿里云oss域名 格式:https://xxx.oss-cn-xxx.aliyuncs.com // 阿里云oss域名 格式:https://xxx.oss-cn-xxx.aliyuncs.com
OSS_DOMAIN: '', OSS_DOMAIN: "https://glsk-oss.oss-cn-shenzhen.aliyuncs.com",
// 文件直传到阿里云oss时需用到
ACCESSKEYID: '',
ACCESSKEYSECRET: '',
// 与后端约定的token字段名 // 文件直传到阿里云oss时需用到
TOKEN_NAME: 'Authorization' ACCESSKEYID: "LTAI5tCRcCUgd7bt1J7JY596",
} ACCESSKEYSECRET: "kJos9mgylkR5ztosnDt8Asrc3ulgqy",
BUKET_NAME: "glsk-oss",
FOLDER: "quality/",
// 与后端约定的token字段名
TOKEN_NAME: "glsk-oss",
};
const target = ['ip', 'dev', 'uat', 'prod', 'preRelease'] const target = ["ip", "dev", "uat", "prod", "preRelease"];
const index = 2 const index = 2;
/** /**
* *
0本地 0本地
...@@ -12,109 +12,109 @@ const secretKey = { ...@@ -12,109 +12,109 @@ const secretKey = {
ip: {}, ip: {},
dev: { dev: {
sso: { sso: {
appKey: '8b31ae1009ccb0f96130ca4bd90e3d89', appKey: "8b31ae1009ccb0f96130ca4bd90e3d89",
secret: '02d60f17ae714872845d2aa9d3b087e109ccb0f96130ca4b' secret: "02d60f17ae714872845d2aa9d3b087e109ccb0f96130ca4b",
} },
}, },
uat: { uat: {
sso: { sso: {
appKey: '8b31ae1009ccb0f96130ca4bd90e3d89', appKey: "8b31ae1009ccb0f96130ca4bd90e3d89",
secret: '02d60f17ae714872845d2aa9d3b087e109ccb0f96130ca4b' secret: "02d60f17ae714872845d2aa9d3b087e109ccb0f96130ca4b",
} },
}, },
prod: { prod: {
sso: { sso: {
appKey: '8b31ae1009ccb0f96130ca4bd90e3d89', appKey: "8b31ae1009ccb0f96130ca4bd90e3d89",
secret: '02d60f17ae714872845d2aa9d3b087e109ccb0f96130ca4b' secret: "02d60f17ae714872845d2aa9d3b087e109ccb0f96130ca4b",
} },
}, },
preRelease: { preRelease: {
sso: { sso: {
appKey: '8b31ae1009ccb0f96130ca4bd90e3d89', appKey: "8b31ae1009ccb0f96130ca4bd90e3d89",
secret: '02d60f17ae714872845d2aa9d3b087e109ccb0f96130ca4b' secret: "02d60f17ae714872845d2aa9d3b087e109ccb0f96130ca4b",
} },
} },
}[target[index]] }[target[index]];
const domain = { const domain = {
// ip: 'http://192.168.2.94:8558', // ip: 'http://192.168.2.94:8558',
// ip: 'http://192.168.2.3:8315', // ip: 'http://192.168.2.3:8315',
ip: 'http://192.168.1.170:8315', ip: "http://192.168.1.170:8315",
/**登录: 192.168.2.3:8315 /**登录: 192.168.2.3:8315
商城: 192.168.2.3:8558 */ 商城: 192.168.2.3:8558 */
dev: 'https://scrm.dev.glsx.com.cn', dev: "https://scrm.dev.glsx.com.cn",
uat: 'https://scrm.test.glsx.com.cn', uat: "https://scrm.test.glsx.com.cn",
preRelease: 'https://scrm.beta.glsx.com.cn', preRelease: "https://scrm.beta.glsx.com.cn",
prod: 'https://scrm.glsx.com.cn' prod: "https://scrm.glsx.com.cn",
}[target[index]] }[target[index]];
const djDomain = { const djDomain = {
ip: 'http://192.168.2.59:8292', ip: "http://192.168.2.59:8292",
// ip: 'http://192.168.2.80:8558', // ip: 'http://192.168.2.80:8558',
dev: 'https://dj.dev.glsx.com.cn', dev: "https://dj.dev.glsx.com.cn",
beta: 'https://dj.beta.glsx.com.cn', //预发布 appid: wx9f91c1ec493eb425 beta: "https://dj.beta.glsx.com.cn", //预发布 appid: wx9f91c1ec493eb425
uat: 'https://dj.test.glsx.com.cn', //测试 appid: wxe10067a63c1856ac uat: "https://dj.test.glsx.com.cn", //测试 appid: wxe10067a63c1856ac
prod: 'https://dj.glsx.com.cn', prod: "https://dj.glsx.com.cn",
pet: 'https://cdptest.glsx.com.cn' //压测 appid: wx7ce755e425603084 pet: "https://cdptest.glsx.com.cn", //压测 appid: wx7ce755e425603084
}[target[index]] }[target[index]];
const merchantDomain = { const merchantDomain = {
ip: 'http://rop-merchant.dev.glsx.com.cn', ip: "http://rop-merchant.dev.glsx.com.cn",
dev: 'http://rop-merchant.dev.glsx.com.cn', dev: "http://rop-merchant.dev.glsx.com.cn",
beta: 'https://rop-merchant.beta.glsx.com.cn', beta: "https://rop-merchant.beta.glsx.com.cn",
uat: 'https://rop-merchant.test.glsx.com.cn', uat: "https://rop-merchant.test.glsx.com.cn",
prod: 'https://commodity.glsx.com.cn', prod: "https://commodity.glsx.com.cn",
pet: '' pet: "",
}[target[index]] }[target[index]];
const djSecretKey = { const djSecretKey = {
ip: { ip: {},
},
dev: { dev: {
appKey: '48e5e13229b82c1b4e6e8c96151f0637', appKey: "48e5e13229b82c1b4e6e8c96151f0637",
secret: 'c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b', secret: "c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b",
}, },
uat: { uat: {
appKey: '48e5e13229b82c1b4e6e8c96151f0637', appKey: "48e5e13229b82c1b4e6e8c96151f0637",
secret: 'c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b', secret: "c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b",
}, },
beta: { beta: {
appKey: 'd7ffc3346fc9a45bccaaa35300d59022', appKey: "d7ffc3346fc9a45bccaaa35300d59022",
secret: '4bc07f8868374c49a4661d603377e3106fc9a45bccaaa353', secret: "4bc07f8868374c49a4661d603377e3106fc9a45bccaaa353",
}, },
prod: { prod: {
appKey: 'd7ffc3346fc9a45bccaaa35300d59022', appKey: "d7ffc3346fc9a45bccaaa35300d59022",
secret: '4bc07f8868374c49a4661d603377e3106fc9a45bccaaa353' secret: "4bc07f8868374c49a4661d603377e3106fc9a45bccaaa353",
}, },
pet: { pet: {
appKey: 'd7ffc3346fc9a45bccaaa35300d59022', appKey: "d7ffc3346fc9a45bccaaa35300d59022",
secret: '4bc07f8868374c49a4661d603377e3106fc9a45bccaaa353' secret: "4bc07f8868374c49a4661d603377e3106fc9a45bccaaa353",
} },
}[target[index]] }[target[index]];
const pathEnum = { const pathEnum = {
sso: '/rop-scrm-sso/', sso: "/rop-scrm-sso/",
shopmall: '/rop-scrm-shopmall/', shopmall: "/rop-scrm-shopmall/",
coupon: '/rop-scrm-coupon/', coupon: "/rop-scrm-coupon/",
carlife: '/rop-scrm-carlife/', carlife: "/rop-scrm-carlife/",
live: '/rop-scrm-live/', live: "/rop-scrm-live/",
equity: '/rop-scrm-equity/', equity: "/rop-scrm-equity/",
entmicro: '/rop-scrm-entmicro/', entmicro: "/rop-scrm-entmicro/",
wechat: '/rop-scrm-wechat/', wechat: "/rop-scrm-wechat/",
boutiquecoupon: '/rop-scrm-boutiquecoupon/', boutiquecoupon: "/rop-scrm-boutiquecoupon/",
material: '/rop-scrm-marketing/', //素材 material: "/rop-scrm-marketing/", //素材
sop: '/rop-scrm-sop/', sop: "/rop-scrm-sop/",
customercollect: '/rop-scrm-bigdatautil/', customercollect: "/rop-scrm-bigdatautil/",
drac: '/rop-scrm-entmicro/', mindworkplate: "/rop-dj-smartcarlife/",
busassistant: '/rop-scrm-busassistant/', drac: "/rop-scrm-entmicro/",
boutique: '/rop-dj-car-boutique/' busassistant: "/rop-scrm-busassistant/",
} boutique: "/rop-dj-car-boutique/",
};
const CONFIG_ENV_MAP = { const CONFIG_ENV_MAP = {
1: 'develop', 1: "develop",
2: 'test', 2: "test",
3: 'production', 3: "production",
4: 'beta' 4: "beta",
} };
module.exports = { module.exports = {
index, index,
domain, domain,
...@@ -123,5 +123,5 @@ module.exports = { ...@@ -123,5 +123,5 @@ module.exports = {
env: CONFIG_ENV_MAP[index], env: CONFIG_ENV_MAP[index],
djDomain, djDomain,
merchantDomain, merchantDomain,
djSecretKey djSecretKey,
} };
...@@ -4,7 +4,8 @@ import config from '@/config.js' ...@@ -4,7 +4,8 @@ import config from '@/config.js'
import store from '@/store'; import store from '@/store';
import api from './api/index' import api from './api/index'
import { Storage } from './utils/cache/index' import { Storage } from './utils/cache/index'
import 'components' import GlsxImage from './components/GlsxImage'
Vue.component('GlsxImage', GlsxImage)
uni.$api = api uni.$api = api
uni.$storage = new Storage() uni.$storage = new Storage()
Vue.config.productionTip = false Vue.config.productionTip = false
......
/*
* @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2024-04-08 11:28:48
* @LastEditors: 前端 qianduan01@didihu.com.cn
* @LastEditTime: 2024-04-08 13:47:00
* @FilePath: \gl_tape\mixin\click.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
const recorderManager = uni.getRecorderManager();
export default {
data() {
return {
timer: null,
times: 0,
timeout: 10 * 60,
reaction: 10,
};
},
onShow() {
window.addEventListener("devicemotion", this.handleDeviceMotion);
},
onHide() {
window.removeEventListener("devicemotion", this.handleDeviceMotion);
},
created() {
recorderManager.start();
this.initTime();
document.addEventListener("visibilitychange", this.handleVisibilityChange);
},
methods: {
handleDeviceMotion(event) {
let acceleration = event.accelerationIncludingGravity;
let brightness =
Math.abs(acceleration.x) +
Math.abs(acceleration.y) +
Math.abs(acceleration.z);
if (brightness < 10) {
// 假设<10的值代表屏幕可能变暗了
console.log("屏幕可能熄灭了");
// 在这里执行你需要的操作
}
},
//监听点击事件
initTime() {
this.timer = setInterval(() => {
this.times++;
console.log(this.times);
if (this.times >= this.timeout) {
this.showToast();
}
if (this.times >= this.reaction + this.timeout) {
this.handleEnd();
}
}, 1000);
},
handleTouchStart() {
this.times = 0;
},
},
handleVisibilityChange() {
if (document.visibilityState === "hidden") {
// 屏幕被关闭
console.log("Screen closed");
}
},
beforeCreate() {
clearInterval(this.timer);
this.timer = null;
},
};
...@@ -12,7 +12,17 @@ ...@@ -12,7 +12,17 @@
maxlength="11" maxlength="11"
/> />
<template v-if="mobile"> <template v-if="mobile">
<text class="icon" @click="mobile = ''">X</text> <view
class="icon"
@click="mobile = ''"
>
<icon
type="clear"
size="16"
color="#000"
>
</icon>
</view>
</template> </template>
</view> </view>
<view class="input"> <view class="input">
...@@ -23,15 +33,31 @@ ...@@ -23,15 +33,31 @@
maxlength="4" maxlength="4"
/> />
<template v-if="code"> <template v-if="code">
<text class="icon" @click="code = ''">X</text> <view
class="icon"
@click="code = ''"
>
<icon
type="clear"
size="16"
color="#000"
>
</icon>
</view>
</template> </template>
<!-- :class="['code-btn', { 'code-disabled': count }]" -->
<view <view
:class="['code-btn', { 'code-disabled': count }]"
@click="getSmsCode" @click="getSmsCode"
>{{ count ? `重新发送(${count}s)` : '获取验证码' }}</view >{{ count ? `重新发送(${count}s)` : '获取验证码' }}</view>
>
</view> </view>
<button class="btn" :disabled="!mobile || !code">登录</button> <button
class="btn"
:disabled="!mobile || !code"
@click="login"
>
登录
</button>
</view> </view>
</view> </view>
</template> </template>
...@@ -39,28 +65,27 @@ ...@@ -39,28 +65,27 @@
<script> <script>
const phoneRex = /^[1]([3-9])[0-9]{9}$/; const phoneRex = /^[1]([3-9])[0-9]{9}$/;
export default { export default {
data() { data () {
return { return {
mobile: '', mobile: '15626599738',
code: '', code: '8888',
count: '', count: '',
}; };
}, },
onLoad(options) { onLoad (options) {
uni.hideLoading();
}, },
methods: { methods: {
/**获取验证码 */ /**获取验证码 */
async getSmsCode() { async getSmsCode () {
const { mobile, count } = this; const { mobile, count } = this;
try { try {
if (!mobile) throw '请输入手机号'; if (!mobile) throw '请输入手机号';
if (!phoneRex.test(mobile)) throw '请输入正确的手机号'; if (!phoneRex.test(mobile)) throw '请输入正确的手机号';
if (count) throw '验证码发送过于频繁,请稍后在试'; if (count) throw '验证码发送过于频繁,请稍后在试';
this.countDown(60); this.countDown(60);
uni.showLoading() uni.showLoading();
const { code, message } = await uni.$api.userApi.getSmsCode({mobile}); const { code, message } = await uni.$api.userApi.getSmsCode({ mobile });
uni.hideLoading() uni.hideLoading();
if (code == '0') { if (code == '0') {
uni.showToast({ uni.showToast({
title: '验证码已发送', title: '验证码已发送',
...@@ -69,15 +94,15 @@ export default { ...@@ -69,15 +94,15 @@ export default {
this.countDown(60); this.countDown(60);
} else throw message || '发送验证码失败'; } else throw message || '发送验证码失败';
} catch (error) { } catch (error) {
uni.hideLoading() uni.hideLoading();
uni.showToast({ uni.showToast({
title: error, title: error,
icon: 'none', icon: 'none',
}) });
} }
}, },
/**验证码倒计时 */ /**验证码倒计时 */
countDown(countDown) { countDown (countDown) {
if (countDown) this.count = countDown; if (countDown) this.count = countDown;
setTimeout(() => { setTimeout(() => {
let { count } = this; let { count } = this;
...@@ -86,18 +111,117 @@ export default { ...@@ -86,18 +111,117 @@ export default {
else this.count = null; else this.count = null;
}, 1e3); }, 1e3);
}, },
async login () {
const { mobile, code: smsCode } = this;
try {
uni.showLoading();
const { code, data, message } = await uni.$api.userApi.smsLogin({
mobile,
code: smsCode,
noSignIn: false,
});
console.log(code, data, message);
uni.hideLoading();
if (code == 0) {
let {
loginUserInfoList,
sessionId,
noSignInUuid,
needSelectAccount,
} = data;
if (loginUserInfoList.length) {
const loginUserObj =
loginUserInfoList.filter(
(val) =>
val.subLoginUser && Object.keys(val.subLoginUser)?.length
)[0] || {};
uni.$storage.set('sessionId', sessionId);
console.log(loginUserObj)
// getYQList();
// noSignInUuid ? setNoSignInUuid(noSignInUuid) : rmNoSignInUuid();
// 记录登录信息 已选园区店、4s店和场景
if (!needSelectAccount && Object.keys(loginUserObj)?.length && loginUserObj?.shopMerchantId && !((loginUserObj?.sceneType ?? '') === '')) {
this.getYqMerchantSceneConfig(loginUserObj, 0);
} else if (!needSelectAccount && Object.keys(loginUserObj)?.length && loginUserObj?.shopMerchantId && (loginUserObj?.sceneType ?? '') === '') {
// 已选园区店、4s店
this.getYqMerchantSceneConfig(loginUserObj, 1);
} else if (!needSelectAccount) {
// 仅选择园区店
this.getYqMerchantSceneConfig(loginUserObj, 2);
} else {
// 未记录到登录信息
this.getAccountLoginList(loginUserInfoList);
}
} else wx.$router.reLaunch('pages.nothing');
} else
uni.showModal({
title: '温馨提示',
content: message,
showCancel: false,
confirmText: '知道了',
confirmColor: '#347BFF',
});
} catch (error) {
uni.hideLoading();
uni.showToast({
title: error,
icon: 'none',
});
}
},
async getYqMerchantSceneConfig (loginUserObj, num) {
// let checkAgreeClient = await this.checkAgreeClient(loginUserObj)
// if (!checkAgreeClient) return wx.$router.go('pages.accountItems')
// num 0已选园区店、4s店和场景 1已选园区店、4s店 2仅选择园区店
let pageUrl = ['pages.loading', 'pages.sceneIndex', 'pages.merchantList']
let { shopMerchantId, shopMerchantName } = loginUserObj
wx.$util.setUserInfo(loginUserObj)
if (num == 2) {
this.get4SStoreList(loginUserObj, pageUrl[num])
} else {
// 兼容除精品升级外场景 已选门店数据
wx.$util.setUserInfo({
...wx.$util.getUserInfo(),
default4SStoreInfo: {
merchantId: shopMerchantId,
merchantName: shopMerchantName
},
default4SStoreInfo_crowdFunding: {
merchantId: shopMerchantId,
merchantName: shopMerchantName
},
default4SStoreInfo_newCarConversion: {
merchantId: shopMerchantId,
merchantName: shopMerchantName
}
})
if (num == 0) wx.$router.reLaunch(pageUrl[num])
else wx.$router.go(pageUrl[num])
this.setData({ jumpPageFlag: false })
}
},
// 获取登录账号下园区店列表
getAccountLoginList (loginUserInfoList) {
if (loginUserInfoList?.length == 1) this.getYqMerchantSceneConfig(loginUserInfoList[0], 2)
else wx.$router.go('pages.accountItems')
},
}, },
}; };
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.a{
width: 500px;
height: 200px;
}
.bg { .bg {
position: fixed; position: fixed;
width: 100%; width: 100%;
height: 100%; height: 100%;
left: 0; left: 0;
top: 0; top: 0;
background-image: url('https://img02.glsx.com.cn/weapp/resource/app-tape/login/bg.png'); background-image: url("https://img02.glsx.com.cn/weapp/resource/app-tape/login/bg.png");
background-size: 100% 100%; background-size: 100% 100%;
} }
.login { .login {
...@@ -124,7 +248,7 @@ export default { ...@@ -124,7 +248,7 @@ export default {
border-radius: 56rpx; border-radius: 56rpx;
margin-bottom: 40rpx; margin-bottom: 40rpx;
box-sizing: border-box; box-sizing: border-box;
padding: 0 40rpx; padding-left: 40rpx;
display: flex; display: flex;
align-items: center; align-items: center;
input { input {
...@@ -135,6 +259,10 @@ export default { ...@@ -135,6 +259,10 @@ export default {
.icon { .icon {
margin-left: auto; margin-left: auto;
flex-shrink: 0; flex-shrink: 0;
display: flex;
align-items: center;
padding: 0 40rpx;
height: 100%;
} }
.code-btn { .code-btn {
font-weight: 500; font-weight: 500;
...@@ -142,6 +270,7 @@ export default { ...@@ -142,6 +270,7 @@ export default {
color: #2c66f7; color: #2c66f7;
flex-shrink: 0; flex-shrink: 0;
border: none; border: none;
margin-right: 40rpx;
} }
.code-disabled { .code-disabled {
color: #9b9b9e; color: #9b9b9e;
...@@ -160,7 +289,7 @@ export default { ...@@ -160,7 +289,7 @@ export default {
color: #ffffff; color: #ffffff;
} }
.btn[disabled]:not([type]), .btn[disabled]:not([type]),
.btn[disabled][type='default'] { .btn[disabled][type="default"] {
background: #c9c9c9 !important; background: #c9c9c9 !important;
} }
} }
......
...@@ -2,7 +2,9 @@ import config from '@/config.js' ...@@ -2,7 +2,9 @@ import config from '@/config.js'
// 在h5端上传涉及到跨域,需在阿里云上配置跨域规则才能正常使用 // 在h5端上传涉及到跨域,需在阿里云上配置跨域规则才能正常使用
module.exports = { module.exports = {
uploadImageUrl: config.OSS_DOMAIN + '/', // 默认存在根目录后面要跟个'/' (在你当前小程序的后台的uploadFile 合法域名也要配上这个域名) bucketName: config.BUKET_NAME,
folder: config.FOLDER,
uploadUrl: config.OSS_DOMAIN + '/', // 默认存在根目录后面要跟个'/' (在你当前小程序的后台的uploadFile 合法域名也要配上这个域名)
AccessKeySecret: config.ACCESSKEYSECRET, // AccessKeySecret 去你的阿里云上控制台上找 AccessKeySecret: config.ACCESSKEYSECRET, // AccessKeySecret 去你的阿里云上控制台上找
OSSAccessKeyId: config.ACCESSKEYID, // AccessKeyId 去你的阿里云上控制台上找 OSSAccessKeyId: config.ACCESSKEYID, // AccessKeyId 去你的阿里云上控制台上找
timeout: 87600 // 这个是上传文件时Policy的失效时间 timeout: 87600 // 这个是上传文件时Policy的失效时间
......
This diff could not be displayed because it is too large.
/*
* @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2024-04-07 17:09:51
* @LastEditors: 前端 qianduan01@didihu.com.cn
* @LastEditTime: 2024-04-08 10:53:29
* @FilePath: \gl_tape\utils\ossUploadFile\uploadFile.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
// base64,Hmac,Sha1,Crypto 相关算法 // base64,Hmac,Sha1,Crypto 相关算法
import config from './config.js'; import config from "./config.js";
import base64 from './base64.js'; import base64 from "./base64.js";
import Hmac from './hmac.js'; import Hmac from "./hmac.js";
import Sha1 from './sha1.js'; import Sha1 from "./sha1.js";
import Crypto from './crypto.js'; import Crypto from "./crypto.js";
/** /**
* 上传文件到阿里云oss * 上传文件到阿里云oss
* @param {string} filePath 图片的本地资源路径 * @param {string} filePath 图片的本地资源路径
* @param {string} dir 表示要传到哪个目录下 * @param {string} dir 表示要传到哪个目录下
* @return 完整的图片地址 * @return 完整的图片地址
*/ */
const uploadFile = function(filePath, dir) { const uploadFile = function (filePath) {
return new Promise((resolve, reject) => { return new Promise(async (resolve, reject) => {
if (!filePath || filePath.length < 9) { if (!filePath || filePath.length < 9) {
uni.showModal({ uni.showModal({
title: '图片错误', title: "文件错误",
content: '请重试', content: "请重试",
showCancel: false, showCancel: false,
}) });
reject('图片错误'); reject("文件错误");
} }
// 获取上传的文件类型
console.log('上传图片中...'); let fileTypeIndex = filePath.lastIndexOf("/");
let fileType = filePath.substring(fileTypeIndex + 1);
// #ifdef H5 let aliyunFileKey = config.folder + fileType;
// 图片名字 可以自行定义 const aliyunServerURL = config.uploadUrl; // OSS地址
let aliyunFileKey = dir + '.png'; const accessid = config.OSSAccessKeyId;
// #endif const policyBase64 = getPolicyBase64();
const { signature, securityToken, lsaccessKeyId } = await getSignature(
// #ifndef H5 policyBase64
// 获取上传的文件类型 ); // 获取签名
let fileTypeIndex = filePath.lastIndexOf('.');
let fileType = filePath.substring(fileTypeIndex);
let aliyunFileKey = dir + fileType;
// #endif
const aliyunServerURL = config.uploadImageUrl; // OSS地址,需要https
const accessid = config.OSSAccessKeyId;
const policyBase64 = getPolicyBase64();
const signature = getSignature(policyBase64); // 获取签名
uni.uploadFile({ uni.uploadFile({
url: aliyunServerURL, // 开发者服务器url url: aliyunServerURL, // 开发者服务器url
filePath: filePath, // 要上传文件资源的路径 filePath: filePath, // 要上传文件资源的路径
name: 'file', // 必须填file name: "file", // 必须填file
formData: { formData: {
'key': aliyunFileKey, key: aliyunFileKey,
'policy': policyBase64, policy: policyBase64,
'OSSAccessKeyId': accessid, OSSAccessKeyId: lsaccessKeyId,
'success_action_status': '200', // 让服务端返回200, 不然默认会返回204 success_action_status: "200", // 让服务端返回200, 不然默认会返回204
'signature': signature, signature: signature,
}, "x-oss-security-token": securityToken, // 使用STS签名时必传。
success: function(res) { },
if (res.statusCode != 200) { success: function (res) {
reject(new Error('上传错误:' + JSON.stringify(res))); console.log(res, 444);
} if (res.statusCode != 200) {
resolve(aliyunServerURL + aliyunFileKey); reject(new Error("上传错误:" + JSON.stringify(res)));
}, }
fail: function(err) { resolve(aliyunServerURL + aliyunFileKey);
err.domainName = aliyunServerURL; },
reject(err); fail: function (err) {
}, err.domainName = aliyunServerURL;
}) reject(err);
}); },
} });
});
};
const getPolicyBase64 = function() { const getPolicyBase64 = function () {
let date = new Date(); let date = new Date();
date.setHours(date.getHours() + config.timeout); date.setHours(date.getHours() + config.timeout);
let srcT = date.toISOString(); let srcT = date.toISOString();
const policyText = { const policyText = {
"expiration": '2099-01-01T12:00:00.000Z', //设置该Policy的失效时间,超过这个失效时间之后,就没有办法通过这个policy上传文件了 expiration: srcT, //设置该Policy的失效时间,超过这个失效时间之后,就没有办法通过这个policy上传文件了
"conditions": [ conditions: [
["content-length-range", 0, 5242880] // 设置上传文件的大小限制(5m) ["content-length-range", 0, 1024 * 1024 * 1024], // 设置上传文件的大小限制(5m)
] ],
}; };
const policyBase64 = base64.encode(JSON.stringify(policyText)); const policyBase64 = base64.encode(JSON.stringify(policyText));
return policyBase64; return policyBase64;
} };
// 生成签名 // 生成签名
const getSignature = function(policyBase64) { const getSignature = function (policyBase64) {
const accesskey = config.AccessKeySecret; return new Promise(async (reslove) => {
const bytes = Crypto.HMAC(Crypto.SHA1, policyBase64, accesskey, { const result = uni.$api.commonApi.getToken({}).then((res) => {
asBytes: true const { lsaccessKeySecret, securityToken, lsaccessKeyId } = res;
}); const bytes = Crypto.HmacSHA1(policyBase64, lsaccessKeySecret);
const signature = Crypto.util.bytesToBase64(bytes); const signature = Crypto.enc.Base64.stringify(bytes);
return signature; reslove({
} signature,
securityToken,
lsaccessKeyId,
});
});
// const result = await uni.request({
// url: 'https://dj.test.glsx.com.cn/rop-dj-smartcarlife/router',
// data: {
// method: 'dj.api.mindworkplate.badge.getToken',
// appKey: '48e5e13229b82c1b4e6e8c96151f0637',
// timestamp: '1712487472621',
// v: '1.0.0',
// format: 'json',
// locale: 'zh_CN',
// sessionId: '98152bee-7533-41ed-bc94-60310f2df6f0',
// sign: '238CE46892F88BBAD035BAEA73E27AC7C080F340'
// },
// success(res) {
// const {
// lsaccessKeySecret,
// securityToken,
// lsaccessKeyId
// } = res.data.data;
// const bytes = Crypto.HmacSHA1(policyBase64, lsaccessKeySecret);
// const signature = Crypto.enc.Base64.stringify(bytes);
// reslove({
// signature,
// securityToken,
// lsaccessKeyId
// })
// }
// })
});
};
module.exports = uploadFile; module.exports = uploadFile;
import defaultStorage from './storage';
export default defaultStorage;
\ No newline at end of file \ No newline at end of file
export default {
// 设置永久缓存
set(key, value) {
uni.setStorageSync(key, value);
},
// 获取永久缓存
get(key) {
return uni.getStorageSync(key);
},
// 移除永久缓存
remove(key) {
uni.removeStorageSync(key);
},
// 移除全部永久缓存
clear() {
uni.clearStorageSync();
},
};
\ No newline at end of file \ No newline at end of file
export const setToken = (data) => {
uni.setStorageSync('token', data);
};
export const getToken = () => uni.getStorageSync('token');
export const removeToken = () => {
uni.removeStorageSync('token');
};
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!