Commit e681d845 authored by 沈翠玲's avatar 沈翠玲

登录问题处理

parent dfa18029
...@@ -46,6 +46,14 @@ export const useUserStore = defineStore({ ...@@ -46,6 +46,14 @@ export const useUserStore = defineStore({
this.isTenant = false; this.isTenant = false;
this.tenant = null; this.tenant = null;
}, },
async logoutPass() {
const socketStore = useSocketStore();
socketStore.closeWs();
this.token = '';
this.userInfo = null;
this.isTenant = false;
this.tenant = null;
},
}, },
persist: piniaPersistConfig('admin-user'), persist: piniaPersistConfig('admin-user'),
}); });
...@@ -136,7 +136,9 @@ const useSocketStore = defineStore('socket', { ...@@ -136,7 +136,9 @@ const useSocketStore = defineStore('socket', {
this.handClose = true; this.handClose = true;
this.clearTimer(); this.clearTimer();
console.log('ws', this.ws); console.log('ws', this.ws);
if (this.ws && this.ws.close) {
this.ws.close(); this.ws.close();
}
}, },
}, },
}); });
......
...@@ -78,8 +78,9 @@ class RequestClient { ...@@ -78,8 +78,9 @@ class RequestClient {
axiosCanceler.removePending(config); axiosCanceler.removePending(config);
const userStore = useUserStore(); const userStore = useUserStore();
if (data.code === 500 && data.message.includes('token')) { if (data.code === 500 && data.message.includes('token')) {
userStore.setToken(''); // if (data.code === 200) {
router.replace(LOGIN_URL); userStore.logoutPass();
window.location.href = LOGIN_URL
ElMessage({ ElMessage({
message: '登录失效,请重新登录', message: '登录失效,请重新登录',
type: 'error', type: 'error',
...@@ -89,8 +90,8 @@ class RequestClient { ...@@ -89,8 +90,8 @@ class RequestClient {
} }
// 登录失效 // 登录失效
if (data.code === 404) { if (data.code === 404) {
userStore.setToken(''); userStore.logoutPass();
router.replace(LOGIN_URL); window.location.href = LOGIN_URL
ElMessage({ ElMessage({
message: '登录失效,请重新登录', message: '登录失效,请重新登录',
type: 'error', type: 'error',
......
...@@ -115,8 +115,10 @@ ...@@ -115,8 +115,10 @@
keepAliveStore.setKeepAliveName([]); keepAliveStore.setKeepAliveName([]);
// 4.跳转到首页 // 4.跳转到首页
setTimeout(() => {
router.push(HOME_URL); router.push(HOME_URL);
loginLoading.value = false; loginLoading.value = false;
}, 1000)
}; };
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment