refactor(store):BUG 524 530 重构 signOut 逻辑

- 移除了 state 中的冗余代码
-优化了 signOut mutation 的逻辑结构
- 使用 Promise 处理异步操作,提高了代码可读性
- 简化了登录页面 URL 的拼接方式
This commit is contained in:
aixianling
2025-01-08 16:22:44 +08:00
parent cfc8f3c8e0
commit 6bb4802f15

View File

@@ -8,24 +8,17 @@ import extra from "../config.json"
Vue.use(Vuex) Vue.use(Vuex)
export default new Vuex.Store({ export default new Vuex.Store({
state: { state: {},
},
mutations: { mutations: {
signOut(state, flag) { signOut(state, flag) {
const base = extra.base || "" const base = extra.base || ""
if (flag) { new Promise(resolve => {
state.user.token = null; flag ? resolve() : axios.delete('/auth/token/logout').then(resolve)
state.user.info = {} }).then(() => {
localStorage.removeItem("vuex");
sessionStorage.clear(); sessionStorage.clear();
location.href = base + '/login' + location.hash; location.href = [base, '/login', location.hash].join('');
} else { })
axios.delete('/auth/token/logout').then(() => {
state.user.token = null;
sessionStorage.clear();
state.user.info = {}
location.href = base + '/login';
});
}
}, },
}, },
getters: { getters: {