1232
This commit is contained in:
+34
-16
@@ -1,8 +1,20 @@
|
||||
import { Encrypt, Decrypt } from '@/js_sdk/cainiao-crypto/cainiao-crypto.js'
|
||||
|
||||
const install = (Vue, vm) => {
|
||||
let redirecting99 = false
|
||||
const lylawPost = (url, params = {}) => {
|
||||
console.log('[接口请求]', url, JSON.stringify(params))
|
||||
const handleInvalidAuth = (body) => {
|
||||
if (body && (body.code === -99 || body.code === '-99')) {
|
||||
uni.setStorageSync('authorizationGift', '')
|
||||
uni.$emit('authorizationExpired')
|
||||
if (!redirecting99) {
|
||||
redirecting99 = true
|
||||
setTimeout(() => { redirecting99 = false }, 1500)
|
||||
uni.switchTab({ url: '/pages/index/index' })
|
||||
}
|
||||
}
|
||||
}
|
||||
return Vue.prototype.$u.post(url, { request: Encrypt(JSON.stringify(params)) }).then(res => {
|
||||
if (res && res.Data) {
|
||||
if (res.Data === 'VFXeGhPbmE9mfQeg2iiwdA==') {
|
||||
@@ -11,26 +23,32 @@ const install = (Vue, vm) => {
|
||||
try { res.Data = JSON.parse(Decrypt(res.Data)) } catch (e) {}
|
||||
}
|
||||
}
|
||||
if (res && res.Data && res.Data.authorization) {
|
||||
uni.setStorageSync('authorizationGift', res.Data.authorization)
|
||||
}
|
||||
handleInvalidAuth(res)
|
||||
return res
|
||||
}).catch(err => {
|
||||
handleInvalidAuth(err && err.data ? err.data : err)
|
||||
return Promise.reject(err)
|
||||
})
|
||||
}
|
||||
Vue.prototype.$u.api = {
|
||||
getWxOpenId: (code) => lylawPost('/lylaw/api/lylaw/getWxOpenId', { code }),
|
||||
wxOpenidLogin: (data) => lylawPost('/lylaw/api/lylaw/wxOpenidLogin', data),
|
||||
sendSms: (phone) => lylawPost('/lylaw/api/lylaw/sendAliSms', { phone }),
|
||||
userRegist: (data) => lylawPost('/lylaw/api/lylaw/userRegist', data),
|
||||
queryWenjuanQA: (data) => lylawPost('/lylaw/api/lylaw/queryWenjuanQA', data),
|
||||
submitQA: (data) => lylawPost('/lylaw/api/lylaw/submitQA', data),
|
||||
getWenjuanPhb: (data) => lylawPost('/lylaw/api/lylaw/getWenjuanPhb', data),
|
||||
getChouJiangResult: (data) => lylawPost('/lylaw/api/lylaw/getChouJiangResult', data),
|
||||
addScore: (data) => lylawPost('/lylaw/api/lylaw/addScore', data),
|
||||
getUserHisResultList: (data) => lylawPost('/lylaw/api/lylaw/getUserHisResultList', data),
|
||||
getUserHisResultDetail: (data) => lylawPost('/lylaw/api/lylaw/getUserHisResultDetail', data),
|
||||
getWenjuanWinDetailList: (data) => lylawPost('/lylaw/api/lylaw/getWenjuanWinDetailList', data),
|
||||
getExchangePrize: (data) => lylawPost('/lylaw/api/lylaw/getExchangePrize', data),
|
||||
exchangePrize: (data) => lylawPost('/lylaw/api/lylaw/exchangePrize', data),
|
||||
getUserResult: (data) => lylawPost('/lylaw/api/lylaw/getUserResult', data)
|
||||
|
||||
getWxOpenId: (code) => lylawPost('/lylaw/api/hnlylaw/getWxOpenId', { code }),
|
||||
wxOpenidLogin: (data) => lylawPost('/lylaw/api/hnlylaw/wxOpenidLogin', data),
|
||||
sendSms: (phone) => lylawPost('/lylaw/api/hnlylaw/sendAliSms', { phone }),
|
||||
userRegist: (data) => lylawPost('/lylaw/api/hnlylaw/userRegist', data),
|
||||
queryWenjuanQA: (data) => lylawPost('/lylaw/api/hnlylaw/queryWenjuanQA', data),
|
||||
submitQA: (data) => lylawPost('/lylaw/api/hnlylaw/submitQA', data),
|
||||
getWenjuanPhb: (data) => lylawPost('/lylaw/api/hnlylaw/getWenjuanPhb', data),
|
||||
getChouJiangResult: (data) => lylawPost('/lylaw/api/hnlylaw/getChouJiangResult', data),
|
||||
addScore: (data) => lylawPost('/lylaw/api/hnlylaw/addScore', data),
|
||||
getUserHisResultList: (data) => lylawPost('/lylaw/api/hnlylaw/getUserHisResultList', data),
|
||||
getUserHistResultDetail: (data) => lylawPost('/lylaw/api/hnlylaw/getUserHistResultDetail', data),
|
||||
getWenjuanWinDetailList: (data) => lylawPost('/lylaw/api/hnlylaw/getWenjuanWinDetailList', data),
|
||||
getExchangePrize: (data) => lylawPost('/lylaw/api/hnlylaw/getExchangePrize', data),
|
||||
exchangePrize: (data) => lylawPost('/lylaw/api/hnlylaw/exchangePrize', data),
|
||||
getUserResult: (data) => lylawPost('/lylaw/api/hnlylaw/getUserResult', data)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,8 @@ const install = (Vue, vm) => {
|
||||
// config.header.token = getApp().globalData.username;
|
||||
|
||||
// 方式四,如果token放在了Storage本地存储中,拦截是每次请求都执行的,所以哪怕您重新登录修改了Storage,下一次的请求将会是最新值
|
||||
const token = uni.getStorageSync('tokenGift');
|
||||
config.header.Authorization = 'Bearer '+token;
|
||||
const auth = uni.getStorageSync('authorizationGift');
|
||||
if (auth) config.header.Authorization = auth;
|
||||
|
||||
return config;
|
||||
}
|
||||
@@ -41,10 +41,6 @@ const install = (Vue, vm) => {
|
||||
|
||||
// 如果把originalData设置为了true,这里return回什么,this.$u.post的then回调中就会得到什么
|
||||
return res;
|
||||
}else if(res.errcode==-99){
|
||||
uni.navigateTo({
|
||||
url:'/pages/index/login'
|
||||
})
|
||||
}else {
|
||||
|
||||
// uni.showToast({
|
||||
|
||||
Reference in New Issue
Block a user