58 lines
2.4 KiB
JavaScript
58 lines
2.4 KiB
JavaScript
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==') {
|
|
res.Data = null
|
|
} else {
|
|
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/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)
|
|
};
|
|
}
|
|
|
|
export default {
|
|
install
|
|
}
|