diff --git a/.env.dev b/.env.dev index d5d9d7c0..7d4cc729 100644 --- a/.env.dev +++ b/.env.dev @@ -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.9:5567' +VUE_APP_BASE_URL = 'http://192.168.1.9:5567' diff --git a/src/store/userHabit/userHabit.ts b/src/store/userHabit/userHabit.ts index 984e3ff1..b7a56e44 100644 --- a/src/store/userHabit/userHabit.ts +++ b/src/store/userHabit/userHabit.ts @@ -37,7 +37,7 @@ const userHabit : Module = { MalePosition:[], Position:[], systemUser:{ - value : 0 + value : -1 }, }, diff --git a/src/tool/https.js b/src/tool/https.js index b9c9641f..fcc730b2 100644 --- a/src/tool/https.js +++ b/src/tool/https.js @@ -13,7 +13,7 @@ axios.defaults.headers.post["Content-Type"] = "application/json"; axios.defaults.headers.post['lang'] = 'en'; //配置语言请求头 axios.defaults.withCredentials = true; //跨域携带cookie import { message } from 'ant-design-vue'; - +import store from '@/store'; // if(process.env.NODE_ENV == "development"){ // axios.defaults.baseURL = ""; //配置接口地址 // }else{ @@ -34,21 +34,19 @@ let httpIp = process.env.NODE_ENV == 'development' ? "" : ""; 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); //POST传参序列化(添加请求拦截器) axios.interceptors.request.use((config) => { //在发送请求之前做某件事 + // config.cancelToken = source.token if(config.method === 'post' || config.method === 'put' || config.method === 'delete'){ // config.data = qs.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 = getCookie('token'); - return config; },(error) =>{ return Promise.reject(error); @@ -88,39 +86,25 @@ axios.interceptors.response.use((res) =>{ return Promise.reject(res.data); } } - removeCancelToken(res.config.cancelToken); - }, function(error) { if(error?.response?.status === 401 && router.currentRoute._value.name != 'setIdentification'){//如果是记录浏览器页面就不跳转login if(!isLoginTime){ isLoginTime = true router.replace('/') message.warning('请登陆后重试~') - cancelAllRequests() clonAllCookie() + store.commit('clearSystemUser') setTimeout(()=>[ isLoginTime = false ],2000) } - + // source.cancel('取消后续接口调用'); return Promise.reject() } let data_new = error?.response?.data // message.error(data_new?.errMsg || 'Error: server exception') 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 = { httpUrls: { interfaceUrl: '', diff --git a/src/views/HomeRecommend.vue b/src/views/HomeRecommend.vue index dd4e66bc..1c946e59 100644 --- a/src/views/HomeRecommend.vue +++ b/src/views/HomeRecommend.vue @@ -97,14 +97,14 @@ export default defineComponent({ let logout = ()=>{ let userInfo = JSON.parse(getCookie("userInfo")); let data = { - userId: userInfo.userId, + userId: userInfo?.userId, }; - let isTest = getCookie('isTest') + store.commit('clearSystemUser') + if(!data.userId) return // console.log(getCookie("token")); Https.axiosPost(Https.httpUrls.accountLogout, data).then((rv) => { // WriteCookie("token"); }); - store.commit('clearSystemUser') } return { systemUser,