|
@@ -1,16 +1,16 @@
|
|
|
import uni from '@/utils/uniHooks';
|
|
|
import { getUTMSource } from '@/utils/utils';
|
|
|
import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
|
-import {md} from '@/utils/common'
|
|
|
+import { md } from '@/utils/common'
|
|
|
// import { Message } from 'element-ui';
|
|
|
// import { jumpLogin } from '@/utils';
|
|
|
// import { Loading } from 'element-ui';
|
|
|
// import { ElLoadingComponent } from 'element-ui/types/loading';
|
|
|
// import vm from "@/main";
|
|
|
-import { Toast, Dialog } from 'vant';
|
|
|
+import { Toast, Dialog, Switch } from 'vant';
|
|
|
// import vue from 'vue';
|
|
|
import store from '@/store';
|
|
|
-import {backLbsHome, getsTheCurrentTopic} from "@/utils";
|
|
|
+import { backLbsHome, getsTheCurrentTopic, toLogin } from "@/utils";
|
|
|
import kipTheme from '@/kui/theme/theme'
|
|
|
// import { v4 as uuidv4 } from 'uuid';
|
|
|
// import { wxToLoginCallback } from '@/utils/index.js'
|
|
@@ -105,20 +105,33 @@ function XUser(config) {
|
|
|
// isLogin: store.state?.member?.vipcode ? true : false
|
|
|
isLogin: store.state?.isLogin === 'haveLoggedIn'
|
|
|
};
|
|
|
- if(!params.isLogin) {
|
|
|
+ if (!params.isLogin) {
|
|
|
delete params.vipCode
|
|
|
delete params.userId
|
|
|
delete params.phoneNumber
|
|
|
}
|
|
|
- if(params.isLogin && (!params.vipCode || !params.userId) && config.url.indexOf('/parking-lots/') < -1) {
|
|
|
+ if (params.isLogin && (!params.vipCode || !params.userId) && config.url.indexOf('/parking-lots/') < -1) {
|
|
|
throw {
|
|
|
response: {
|
|
|
data: {
|
|
|
- code:'BAD_USER_INFO'
|
|
|
+ code: 'BAD_USER_INFO'
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
+ // 如果 token 存在, 但是没有 vipCode 或者 userId
|
|
|
+ const kipAccessToken =uni.getStorageSync('kipAccessToken')
|
|
|
+ if (kipAccessToken && (!params.vipCode || !params.userId) && config.url.indexOf('/parking-lots/') < -1) {
|
|
|
+ throw {
|
|
|
+ response: {
|
|
|
+ data: {
|
|
|
+ message: '当前登录失效,请重新登录',
|
|
|
+ code: 'BAD_USER_INFO_2'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
// params = {"userId": "8aaa809d835ba76d018378bc57180006","sourceType": "WECHAT","phoneNumber": "18521563898","projectId": "paroject1","buildingId": "QHKC-P1","brandId":"8a84853b7c91ac5b017c962dab55030e","cid": "oIUfO5XAVleJ88z13i1_08DCKIhQ","vipCode":"KERRY100200040","lbsId":"8aaa81cb7c836c6b017c83e46b110001"}
|
|
|
if (/orders-and-prepay|calculate-discount|unlicensed-car-check-in|unlicensed-car-checkout|paper-coupon/g.test(config.url)) {
|
|
|
params.buildingId = window.localStorage.getItem('buildingId');
|
|
@@ -127,7 +140,7 @@ function XUser(config) {
|
|
|
Object.keys(params).forEach(key => {
|
|
|
const value = params[key]
|
|
|
// 对特殊字段,不做过滤处理
|
|
|
- if ( value || key === 'isLogin') {
|
|
|
+ if (value || key === 'isLogin') {
|
|
|
newParams[key] = value
|
|
|
}
|
|
|
})
|
|
@@ -135,10 +148,10 @@ function XUser(config) {
|
|
|
}
|
|
|
function getSign(config) {
|
|
|
let params = {}
|
|
|
- if(config.method === 'get' && config?.params) {
|
|
|
+ if (config.method === 'get' && config?.params) {
|
|
|
params = config.params
|
|
|
}
|
|
|
- if(config.method === 'post' && config?.data) {
|
|
|
+ if (config.method === 'post' && config?.data) {
|
|
|
params = config.data
|
|
|
}
|
|
|
const newHeader = md(params, true)
|
|
@@ -182,14 +195,29 @@ export const createAxiosByinterceptors = (config) => {
|
|
|
instance.interceptors.response.use(
|
|
|
function (response) {
|
|
|
// 对响应数据做点什么
|
|
|
- console.log('response:', response);
|
|
|
+ // console.log('response:', response);
|
|
|
const { loading = true } = response.config;
|
|
|
if (loading) cancelLoading();
|
|
|
- const { code, data, message, langMessage } = response.data;
|
|
|
- console.log('success response', response);
|
|
|
- const codeList = ['010902']
|
|
|
+ const { code, data, message = '', langMessage = '' } = response.data;
|
|
|
+ // console.log('success response', response);
|
|
|
+ const codeList = ['010902', '300000', '500001', '500000']
|
|
|
if (codeList.indexOf(code) > -1) {
|
|
|
uni.showToast({ title: langMessage || message, duration: 3000, icon: 'fail' });
|
|
|
+ // console.log('193193193193193193', '193');
|
|
|
+ setTimeout(() => {
|
|
|
+ switch (code) {
|
|
|
+ case '300000':
|
|
|
+ toLogin()
|
|
|
+ break
|
|
|
+ case '500001':
|
|
|
+ toLogin()
|
|
|
+ break
|
|
|
+ case '500000':
|
|
|
+ toLogin()
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }, 1500)
|
|
|
+ console.log('206206206206206206206', '206');
|
|
|
}
|
|
|
// TODO: 临时注释
|
|
|
// Promise.reject(response.data)
|
|
@@ -215,8 +243,8 @@ export const createAxiosByinterceptors = (config) => {
|
|
|
}
|
|
|
}
|
|
|
// 错误信息提示
|
|
|
- const { code, langMessage, message,status } = error.response.data;
|
|
|
- const codeList = ['INTERNAL_SERVER_ERROR', 'VALIDATION_FAILED', 'CAR_HAS_PLATE', "NOT_FOUND", "LOCAL_PARK_ERROR", "LOCK_OCCUPIED", "REMOTE_CALL_FAIL", 'PLEASE_SCAN_QRCODE', 'SUBIN_CAR_IN_DEVICE_EXCEPTION', 'COUPON_UNAVAILABLE', 'COUPON_SELECTION_FAILED' ]; // 默认处理的错误code
|
|
|
+ const { code, langMessage = '', message = '', status } = error.response.data;
|
|
|
+ const codeList = ['INTERNAL_SERVER_ERROR', 'VALIDATION_FAILED', 'CAR_HAS_PLATE', "NOT_FOUND", "LOCAL_PARK_ERROR", "LOCK_OCCUPIED", "REMOTE_CALL_FAIL", 'PLEASE_SCAN_QRCODE', 'SUBIN_CAR_IN_DEVICE_EXCEPTION', 'COUPON_UNAVAILABLE', 'COUPON_SELECTION_FAILED']; // 默认处理的错误code
|
|
|
if (codeList.indexOf(code) > -1) {
|
|
|
uni.showToast({ title: langMessage || message, duration: 3000, icon: 'fail' });
|
|
|
}
|
|
@@ -224,7 +252,14 @@ export const createAxiosByinterceptors = (config) => {
|
|
|
if (['BAD_USER_INFO'].indexOf(code) > -1) {
|
|
|
backLbsHome()
|
|
|
}
|
|
|
- if ( status === 500 ) {
|
|
|
+ // 如果必填参数校验失败的话
|
|
|
+ if (['BAD_USER_INFO_2'].indexOf(code) > -1) {
|
|
|
+ uni.showToast({ title: langMessage || message, duration: 3000, icon: 'fail' });
|
|
|
+ setTimeout(() => {
|
|
|
+ toLogin()
|
|
|
+ }, 1500)
|
|
|
+ }
|
|
|
+ if (status === 500) {
|
|
|
uni.showToast({ title: error.response.data.error, duration: 3000, icon: 'fail' });
|
|
|
}
|
|
|
// Message.error(error?.response?.data?.message || '服务端异常');
|