This commit is contained in:
X1627315083
2024-06-17 14:10:25 +08:00
parent 2e03f8445e
commit 2cd1637153
4 changed files with 11 additions and 27 deletions

View File

@@ -9,4 +9,4 @@ VUE_APP_BASE_URL = 'https://develop.api.aida.com.hk'
# 佩佩 # 佩佩
# VUE_APP_BASE_URL = 'http://192.168.1.7:5567' # VUE_APP_BASE_URL = 'http://192.168.1.7:5567'
# 海波 # 海波
# VUE_APP_BASE_URL = 'http://192.168.1.9:5567' VUE_APP_BASE_URL = 'http://192.168.1.9:5567'

View File

@@ -37,7 +37,7 @@ const userHabit : Module<UserHabit,RootState> = {
MalePosition:[], MalePosition:[],
Position:[], Position:[],
systemUser:{ systemUser:{
value : 0 value : -1
}, },
}, },

View File

@@ -13,7 +13,7 @@ axios.defaults.headers.post["Content-Type"] = "application/json";
axios.defaults.headers.post['lang'] = 'en'; //配置语言请求头 axios.defaults.headers.post['lang'] = 'en'; //配置语言请求头
axios.defaults.withCredentials = true; //跨域携带cookie axios.defaults.withCredentials = true; //跨域携带cookie
import { message } from 'ant-design-vue'; import { message } from 'ant-design-vue';
import store from '@/store';
// if(process.env.NODE_ENV == "development"){ // if(process.env.NODE_ENV == "development"){
// axios.defaults.baseURL = ""; //配置接口地址 // axios.defaults.baseURL = ""; //配置接口地址
// }else{ // }else{
@@ -34,21 +34,19 @@ let httpIp = process.env.NODE_ENV == 'development' ? "" : "";
axios.defaults.baseURL = process.env.VUE_APP_BASE_URL; //配置接口地址 axios.defaults.baseURL = process.env.VUE_APP_BASE_URL; //配置接口地址
// 创建取消令牌 // 创建取消令牌
let cancelList = [] const CancelToken = axios.CancelToken;
const source = CancelToken.source();
// console.log(process.env.VUE_APP_BASE_URL); // console.log(process.env.VUE_APP_BASE_URL);
//POST传参序列化(添加请求拦截器) //POST传参序列化(添加请求拦截器)
axios.interceptors.request.use((config) => { axios.interceptors.request.use((config) => {
//在发送请求之前做某件事 //在发送请求之前做某件事
// config.cancelToken = source.token
if(config.method === 'post' || config.method === 'put' || config.method === 'delete'){ if(config.method === 'post' || config.method === 'put' || config.method === 'delete'){
// config.data = qs.stringify(config.data); // config.data = qs.stringify(config.data);
// config.data = JSON.stringify(config.data); // config.data = JSON.stringify(config.data);
} }
// config['cancelToken'] = axios.CancelToken(function(c){
// cancel.push(c)
// })
// config.headers.Authorization = 'Bearer-eyJhbGciOiJIUzUxMiJ9.eyJqdGkiOiIyIiwic3ViIjoie1wiaWRcIjoyLFwidXNlcm5hbWVcIjpcImxpcnNcIn0iLCJpYXQiOjE2NjU3NDEwODcsImlzcyI6IkRXSiIsImF1dGhvcml0aWVzIjoiW10iLCJleHAiOjE2NzQzODEwODd9.ShM9R_NNFD7oo1OvxrEgg7PFeWinOuAKkuInUCMQupp66s64Hhv8tN0Wwr83nIN4rHPqtn95wmd4msWcvaFYJA'; // config.headers.Authorization = 'Bearer-eyJhbGciOiJIUzUxMiJ9.eyJqdGkiOiIyIiwic3ViIjoie1wiaWRcIjoyLFwidXNlcm5hbWVcIjpcImxpcnNcIn0iLCJpYXQiOjE2NjU3NDEwODcsImlzcyI6IkRXSiIsImF1dGhvcml0aWVzIjoiW10iLCJleHAiOjE2NzQzODEwODd9.ShM9R_NNFD7oo1OvxrEgg7PFeWinOuAKkuInUCMQupp66s64Hhv8tN0Wwr83nIN4rHPqtn95wmd4msWcvaFYJA';
config.headers.Authorization = getCookie('token'); config.headers.Authorization = getCookie('token');
return config; return config;
},(error) =>{ },(error) =>{
return Promise.reject(error); return Promise.reject(error);
@@ -88,39 +86,25 @@ axios.interceptors.response.use((res) =>{
return Promise.reject(res.data); return Promise.reject(res.data);
} }
} }
removeCancelToken(res.config.cancelToken);
}, function(error) { }, function(error) {
if(error?.response?.status === 401 && router.currentRoute._value.name != 'setIdentification'){//如果是记录浏览器页面就不跳转login if(error?.response?.status === 401 && router.currentRoute._value.name != 'setIdentification'){//如果是记录浏览器页面就不跳转login
if(!isLoginTime){ if(!isLoginTime){
isLoginTime = true isLoginTime = true
router.replace('/') router.replace('/')
message.warning('请登陆后重试~') message.warning('请登陆后重试~')
cancelAllRequests()
clonAllCookie() clonAllCookie()
store.commit('clearSystemUser')
setTimeout(()=>[ setTimeout(()=>[
isLoginTime = false isLoginTime = false
],2000) ],2000)
} }
// source.cancel('取消后续接口调用');
return Promise.reject() return Promise.reject()
} }
let data_new = error?.response?.data let data_new = error?.response?.data
// message.error(data_new?.errMsg || 'Error: server exception') // message.error(data_new?.errMsg || 'Error: server exception')
return Promise.reject(data_new); return Promise.reject(data_new);
}); });
function removeCancelToken(cancelTokenToRemove) {
const index = cancelList.findIndex(source => source.token === cancelTokenToRemove);
if (index !== -1) {
cancelList.splice(index, 1);
}
}
function cancelAllRequests() {
// cancelList.forEach(source => {
// console.log(123123,source);
// source('123');
// });
}
export const Https = { export const Https = {
httpUrls: { httpUrls: {
interfaceUrl: '', interfaceUrl: '',

View File

@@ -97,14 +97,14 @@ export default defineComponent({
let logout = ()=>{ let logout = ()=>{
let userInfo = JSON.parse(getCookie("userInfo")); let userInfo = JSON.parse(getCookie("userInfo"));
let data = { let data = {
userId: userInfo.userId, userId: userInfo?.userId,
}; };
let isTest = getCookie('isTest') store.commit('clearSystemUser')
if(!data.userId) return
// console.log(getCookie("token")); // console.log(getCookie("token"));
Https.axiosPost(Https.httpUrls.accountLogout, data).then((rv) => { Https.axiosPost(Https.httpUrls.accountLogout, data).then((rv) => {
// WriteCookie("token"); // WriteCookie("token");
}); });
store.commit('clearSystemUser')
} }
return { return {
systemUser, systemUser,