|
@@ -1,7 +1,28 @@
|
|
|
"use strict";
|
|
|
import axios from "axios";
|
|
|
-import CryptoJS from '@/utils/crypto'
|
|
|
-import { Toast } from 'tdesign-mobile-vue';
|
|
|
+import CryptoJS from "@/utils/crypto";
|
|
|
+import { Toast } from "tdesign-mobile-vue";
|
|
|
+
|
|
|
+function handleNoToken() {
|
|
|
+ const url = location.search; //获取url携带的参数
|
|
|
+ let urlParams = new Object();
|
|
|
+ if (url.indexOf("?") != -1) {
|
|
|
+ let str = url.substr(1);
|
|
|
+ let strs = str.split("&");
|
|
|
+ for (let i = 0; i < strs.length; i++) {
|
|
|
+ urlParams[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 目前只有报告详情所以写死回跳地址吧
|
|
|
+ const redirectUrl=urlParams.reportid?encodeURIComponent(`/pages-report/reportDetail/index?id=${urlParams.reportid}`):''
|
|
|
+ console.log('408 回跳地址:',redirectUrl);
|
|
|
+ setTimeout(() => {
|
|
|
+ wx.miniProgram.navigateTo({
|
|
|
+ url: `/pages/user/refreshToken?redirectUrl=${redirectUrl}`,
|
|
|
+ });
|
|
|
+ }, 1000);
|
|
|
+}
|
|
|
+
|
|
|
// Full config: https://github.com/axios/axios#request-config
|
|
|
// axios.defaults.baseURL = process.env.baseURL || process.env.apiUrl || '';
|
|
|
// axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
|
|
@@ -12,7 +33,7 @@ let LOADING;
|
|
|
|
|
|
let config = {
|
|
|
baseURL: import.meta.env.VITE_APP_API_URL,
|
|
|
- timeout: 10*60 * 1000, // Timeout
|
|
|
+ timeout: 10 * 60 * 1000, // Timeout
|
|
|
// withCredentials: true, // Check cross-site Access-Control
|
|
|
};
|
|
|
|
|
@@ -23,19 +44,18 @@ _axios.interceptors.request.use(
|
|
|
// Do something before request is sent
|
|
|
|
|
|
// 设置loading
|
|
|
- if (LOADINGCOUNT === 0) {
|
|
|
- LOADING = Toast({
|
|
|
- message: "loading...",
|
|
|
- duration: 0,
|
|
|
- theme:'loading',
|
|
|
- preventScrollThrough:true
|
|
|
- });
|
|
|
- }
|
|
|
- LOADINGCOUNT++;
|
|
|
-
|
|
|
+ if (LOADINGCOUNT === 0) {
|
|
|
+ LOADING = Toast({
|
|
|
+ message: "loading...",
|
|
|
+ duration: 0,
|
|
|
+ theme: "loading",
|
|
|
+ preventScrollThrough: true,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ LOADINGCOUNT++;
|
|
|
|
|
|
- let auth = localStorage.getItem('token')
|
|
|
- if(auth) {
|
|
|
+ let auth = localStorage.getItem("token");
|
|
|
+ if (auth) {
|
|
|
config.headers.Authorization = auth;
|
|
|
}
|
|
|
// config.headers.Authorization=localStorage.getItem('token')||''
|
|
@@ -57,34 +77,34 @@ _axios.interceptors.response.use(
|
|
|
LOADING.clear();
|
|
|
}
|
|
|
|
|
|
- let data
|
|
|
- if(import.meta.env.MODE==='production'){
|
|
|
- data=JSON.parse(CryptoJS.Des3Decrypt(response.data,import.meta.env.VITE_APP_RESPONSE_DES_KEY));//解密
|
|
|
- }else{
|
|
|
- data=response.data
|
|
|
+ let data;
|
|
|
+ if (import.meta.env.MODE === "production") {
|
|
|
+ data = JSON.parse(CryptoJS.Des3Decrypt(response.data, import.meta.env.VITE_APP_RESPONSE_DES_KEY)); //解密
|
|
|
+ } else {
|
|
|
+ data = response.data;
|
|
|
}
|
|
|
-
|
|
|
|
|
|
- if(response.status!==200){
|
|
|
+ if (response.status !== 200) {
|
|
|
setTimeout(() => {
|
|
|
- Toast('网络异常')
|
|
|
+ Toast("网络异常");
|
|
|
}, 100);
|
|
|
}
|
|
|
|
|
|
- if(!data){
|
|
|
+ if (!data) {
|
|
|
setTimeout(() => {
|
|
|
- Toast('服务器开了个小差')
|
|
|
+ Toast("服务器开了个小差");
|
|
|
}, 100);
|
|
|
}
|
|
|
- if(data.Ret===408){//token失效
|
|
|
- Toast(data.Msg)
|
|
|
+ if (data.Ret === 408) {
|
|
|
+ //token失效
|
|
|
setTimeout(() => {
|
|
|
- wx.miniProgram.switchTab({url:'/pages/user/index'})
|
|
|
- }, 1000);
|
|
|
+ Toast(data.Msg);
|
|
|
+ }, 100);
|
|
|
+ handleNoToken();
|
|
|
}
|
|
|
- if(data.Ret===403){
|
|
|
+ if (data.Ret === 403) {
|
|
|
setTimeout(() => {
|
|
|
- Toast(data.Msg||'网络异常')
|
|
|
+ Toast(data.Msg || "网络异常");
|
|
|
}, 100);
|
|
|
}
|
|
|
|
|
@@ -92,7 +112,7 @@ _axios.interceptors.response.use(
|
|
|
},
|
|
|
function (error) {
|
|
|
console.log(error);
|
|
|
- Toast(error.message)
|
|
|
+ Toast(error.message);
|
|
|
// Do something with response error
|
|
|
return Promise.reject(error);
|
|
|
}
|