From c120686faefc81cb786591b8f853d7849140ed12 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Wed, 22 Dec 2021 21:13:25 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=B8=85=E9=99=A4=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/assets/js/pages/login.vue | 8 +++++--- resources/assets/js/pages/manage.vue | 7 ++++++- resources/assets/js/store/actions.js | 30 +++++++++++++++++++++------- resources/assets/js/store/state.js | 8 -------- 4 files changed, 34 insertions(+), 19 deletions(-) diff --git a/resources/assets/js/pages/login.vue b/resources/assets/js/pages/login.vue index cd263bf7..db3cb1ce 100644 --- a/resources/assets/js/pages/login.vue +++ b/resources/assets/js/pages/login.vue @@ -143,9 +143,11 @@ export default { }, }).then(({data}) => { this.loadIng--; - this.$store.state.method.clearLocal(); - this.$store.dispatch("saveUserInfo", data); - this.goNext(); + this.$store.dispatch("handleClearCache", data).then(() => { + this.goNext(); + }).catch(() => { + this.goNext(); + }); }).catch(({data, msg}) => { this.loadIng--; $A.noticeError(msg); diff --git a/resources/assets/js/pages/manage.vue b/resources/assets/js/pages/manage.vue index e44faa1b..2dc217dd 100644 --- a/resources/assets/js/pages/manage.vue +++ b/resources/assets/js/pages/manage.vue @@ -425,7 +425,12 @@ export default { this.archivedProjectShow = true; return; case 'clearCache': - this.$store.dispatch("clearCache"); + this.$store.dispatch("handleClearCache", null).then(() => { + this.$store.state.method.setStorage("clearCache", $A.randomString(6)) + window.location.reload() + }).catch(() => { + window.location.reload() + }); return; case 'signout': $A.modalConfirm({ diff --git a/resources/assets/js/store/actions.js b/resources/assets/js/store/actions.js index 7c168898..0bf4543f 100644 --- a/resources/assets/js/store/actions.js +++ b/resources/assets/js/store/actions.js @@ -1,4 +1,5 @@ import {Store} from 'le5le-store'; +import state from "./state"; export default { /** @@ -371,8 +372,7 @@ export default { * @param dispatch */ logout({state, dispatch}) { - state.method.clearLocal(); - dispatch("saveUserInfo", {}).then(() => { + dispatch("handleClearCache", {}).then(() => { const from = ["/", "/login"].includes(window.location.pathname) ? "" : encodeURIComponent(window.location.href); $A.goForward({name: 'login', query: from ? {from: from} : {}}, true); }); @@ -382,12 +382,28 @@ export default { * 清除缓存 * @param state * @param dispatch + * @param userInfo + * @returns {Promise} */ - clearCache({state, dispatch}) { - state.method.clearLocal(); - state.method.setStorage("clearCache", $A.randomString(6)) - dispatch("saveUserInfo", state.userInfo); - window.location.reload() + handleClearCache({state, dispatch}, userInfo) { + return new Promise(function (resolve, reject) { + try { + window.localStorage.clear(); + // + state.cacheUserBasic = []; + state.cacheDialogs = state.dialogs = []; + state.cacheProjects = state.projects = []; + state.cacheColumns = state.columns = []; + state.cacheTasks = state.tasks = state.taskSubs = []; + // + state.method.setStorage("cacheTablePanel", state.cacheTablePanel); + dispatch("saveUserInfo", state.method.isJson(userInfo) ? userInfo : state.userInfo); + // + resolve() + } catch (e) { + reject(e) + } + }); }, /** *****************************************************************************************/ diff --git a/resources/assets/js/store/state.js b/resources/assets/js/store/state.js index 01a64edd..174802ee 100644 --- a/resources/assets/js/store/state.js +++ b/resources/assets/js/store/state.js @@ -197,14 +197,6 @@ const method = { } }, - clearLocal() { - try { - window.localStorage.clear(); - } catch (e) { - // - } - }, - runNum(str, fixed) { let _s = Number(str); if (_s + "" === "NaN") {