refactor(store):BUG 524 530 重构 signOut 逻辑
- 移除了 state 中的冗余代码 -优化了 signOut mutation 的逻辑结构 - 使用 Promise 处理异步操作,提高了代码可读性 - 简化了登录页面 URL 的拼接方式
This commit is contained in:
@@ -8,24 +8,17 @@ import extra from "../config.json"
|
||||
Vue.use(Vuex)
|
||||
|
||||
export default new Vuex.Store({
|
||||
state: {
|
||||
},
|
||||
state: {},
|
||||
mutations: {
|
||||
signOut(state, flag) {
|
||||
const base = extra.base || ""
|
||||
if (flag) {
|
||||
state.user.token = null;
|
||||
state.user.info = {}
|
||||
new Promise(resolve => {
|
||||
flag ? resolve() : axios.delete('/auth/token/logout').then(resolve)
|
||||
}).then(() => {
|
||||
localStorage.removeItem("vuex");
|
||||
sessionStorage.clear();
|
||||
location.href = base + '/login' + location.hash;
|
||||
} else {
|
||||
axios.delete('/auth/token/logout').then(() => {
|
||||
state.user.token = null;
|
||||
sessionStorage.clear();
|
||||
state.user.info = {}
|
||||
location.href = base + '/login';
|
||||
});
|
||||
}
|
||||
location.href = [base, '/login', location.hash].join('');
|
||||
})
|
||||
},
|
||||
},
|
||||
getters: {
|
||||
|
||||
Reference in New Issue
Block a user