|
@@ -1,27 +1,17 @@
|
|
"use strict";
|
|
"use strict";
|
|
import axios from "axios";
|
|
import axios from "axios";
|
|
-import store from '@/store'
|
|
|
|
-import { ElMessage } from 'element-plus'
|
|
|
|
|
|
+import { Toast } from 'vant';
|
|
import CryptoJS from './crypto'
|
|
import CryptoJS from './crypto'
|
|
-import {webLogin} from '@/utils/webLogin'
|
|
|
|
-
|
|
|
|
-// 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;
|
|
|
|
-// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
|
|
|
|
|
|
let config = {
|
|
let config = {
|
|
baseURL: import.meta.env.VITE_APP_API_URL,
|
|
baseURL: import.meta.env.VITE_APP_API_URL,
|
|
- timeout: 10*60 * 1000, // Timeout
|
|
|
|
- // withCredentials: true, // Check cross-site Access-Control
|
|
|
|
|
|
+ timeout: 60 * 1000, // Timeout
|
|
};
|
|
};
|
|
|
|
|
|
const _axios = axios.create(config);
|
|
const _axios = axios.create(config);
|
|
|
|
|
|
_axios.interceptors.request.use(
|
|
_axios.interceptors.request.use(
|
|
function (config) {
|
|
function (config) {
|
|
- // Do something before request is sent
|
|
|
|
- config.headers.Authorization=store.state.token
|
|
|
|
return config;
|
|
return config;
|
|
},
|
|
},
|
|
function (error) {
|
|
function (error) {
|
|
@@ -33,25 +23,11 @@ _axios.interceptors.request.use(
|
|
// Add a response interceptor
|
|
// Add a response interceptor
|
|
_axios.interceptors.response.use(
|
|
_axios.interceptors.response.use(
|
|
function (response) {
|
|
function (response) {
|
|
- // Do something with response data
|
|
|
|
- let data
|
|
|
|
- if(import.meta.env.MODE==='production'){
|
|
|
|
- data=JSON.parse(CryptoJS.Des3Decrypt(response.data));//解密
|
|
|
|
- }else{
|
|
|
|
- data=response.data
|
|
|
|
- }
|
|
|
|
- if(data.code===401){//token失效
|
|
|
|
- console.log('请重新登录')
|
|
|
|
- console.log('miniprogram:',window.__wxjs_environment)
|
|
|
|
- if(window.__wxjs_environment === 'miniprogram'){
|
|
|
|
- // 如果在小程序中 则回跳到小程序首页进行更新token 再带回到项目中
|
|
|
|
- wx.miniProgram.switchTab({url: '/pages/report/report'})
|
|
|
|
- }else{
|
|
|
|
- webLogin()
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if(data.code!==200&&data.code!==403&&data.code!==4001&&data.code!==401){
|
|
|
|
- ElMessage.error(data.msg)
|
|
|
|
|
|
+ const data=JSON.parse(CryptoJS.Des3Decrypt(response.data));//解密
|
|
|
|
+ // const data = response.data;
|
|
|
|
+
|
|
|
|
+ if(data.Ret === 403) {
|
|
|
|
+ Toast(data.Msg)
|
|
}
|
|
}
|
|
return data;
|
|
return data;
|
|
},
|
|
},
|
|
@@ -67,7 +43,7 @@ _axios.interceptors.response.use(
|
|
* @params get请求参数
|
|
* @params get请求参数
|
|
*/
|
|
*/
|
|
export const get = (url, params) => {
|
|
export const get = (url, params) => {
|
|
- return _axios.get(url, { params });
|
|
|
|
|
|
+ return _axios.get(url, { params })
|
|
};
|
|
};
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -75,6 +51,6 @@ export const get = (url, params) => {
|
|
* @url 请求地址
|
|
* @url 请求地址
|
|
* @params post请求参数
|
|
* @params post请求参数
|
|
*/
|
|
*/
|
|
-export const post = (url, params) => {
|
|
|
|
- return _axios.post(url, params);
|
|
|
|
|
|
+export const post = (url,params) => {
|
|
|
|
+ return _axios.post(url, params)
|
|
};
|
|
};
|