From 6bb4802f15abb1869729acbe777c97e5ddfc7a15 Mon Sep 17 00:00:00 2001 From: aixianling Date: Wed, 8 Jan 2025 16:22:44 +0800 Subject: [PATCH] =?UTF-8?q?refactor(store):BUG=20524=20530=20=20=E9=87=8D?= =?UTF-8?q?=E6=9E=84=20signOut=20=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除了 state 中的冗余代码 -优化了 signOut mutation 的逻辑结构 - 使用 Promise 处理异步操作,提高了代码可读性 - 简化了登录页面 URL 的拼接方式 --- src/utils/store.js | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/utils/store.js b/src/utils/store.js index 3ba2ce9f..85f2cb25 100644 --- a/src/utils/store.js +++ b/src/utils/store.js @@ -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: {