From c988aa1944acb6a4e9372249b2ae0cc12bf455e4 Mon Sep 17 00:00:00 2001 From: wangxiang <1827945911@qq.com> Date: Sat, 16 Apr 2022 20:29:30 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=9F=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kicc-ui/src/store/modules/app.ts | 10 +++++----- kicc-ui/src/store/modules/locale.ts | 13 ++++--------- kicc-ui/src/store/modules/lock.ts | 13 ++++++++----- kicc-ui/src/store/modules/multipleTab.ts | 20 ++++++++++---------- kicc-ui/src/store/modules/user.ts | 8 ++++---- 5 files changed, 31 insertions(+), 33 deletions(-) diff --git a/kicc-ui/src/store/modules/app.ts b/kicc-ui/src/store/modules/app.ts index 6947476a..7293dc8e 100644 --- a/kicc-ui/src/store/modules/app.ts +++ b/kicc-ui/src/store/modules/app.ts @@ -29,7 +29,7 @@ interface AppState { pageLoading: boolean; // 项目配置 projectConfig: ProjectConfig | null; - // 当窗口收缩时,记住一些状态,在窗口恢复时恢复这些状态 + // 当窗口收缩时,记住一些状态,在窗口恢复时恢复这些状态 beforeMiniInfo: BeforeMiniState; } @@ -37,7 +37,7 @@ let timeId: TimeoutHandle; export const useAppStore = defineStore({ id: 'app', state: (): AppState => ({ - darkMode: undefined, + darkMode: localStorage.getItem(APP_DARK_MODE_KEY_), pageLoading: false, projectConfig: Persistent.getLocal(PROJ_CFG_KEY), beforeMiniInfo: {}, @@ -47,7 +47,7 @@ export const useAppStore = defineStore({ return this.pageLoading; }, getDarkMode(): 'light' | 'dark' | string { - return this.darkMode || localStorage.getItem(APP_DARK_MODE_KEY_) || darkMode; + return this.darkMode || darkMode; }, getBeforeMiniInfo(): BeforeMiniState { return this.beforeMiniInfo; @@ -98,8 +98,8 @@ export const useAppStore = defineStore({ this.setPageLoading(loading); clearTimeout(timeId); } - }, - }, + } + } }); // 需要在设置之外使用 diff --git a/kicc-ui/src/store/modules/locale.ts b/kicc-ui/src/store/modules/locale.ts index a48044e8..318d7ae1 100644 --- a/kicc-ui/src/store/modules/locale.ts +++ b/kicc-ui/src/store/modules/locale.ts @@ -41,16 +41,11 @@ export const useLocaleStore = defineStore({ this.localInfo = { ...this.localInfo, ...info }; ls.set(LOCALE_KEY, this.localInfo); }, - /** - * 初始化多语言信息并从本地缓存加载现有配置 - */ + /** 初始化多语言信息并从本地缓存加载现有配置 */ initLocale() { - this.setLocaleInfo({ - ...localeSetting, - ...this.localInfo, - }); - }, - }, + this.setLocaleInfo({ ...localeSetting, ...this.localInfo }); + } + } }); // 需要在设置之外使用 diff --git a/kicc-ui/src/store/modules/lock.ts b/kicc-ui/src/store/modules/lock.ts index ba0f8271..a255c7ff 100644 --- a/kicc-ui/src/store/modules/lock.ts +++ b/kicc-ui/src/store/modules/lock.ts @@ -26,20 +26,25 @@ export const useLockStore = defineStore({ }, }, actions: { + /** 设置锁屏 */ setLockInfo(info: LockInfo) { this.lockInfo = Object.assign({}, this.lockInfo, info); Persistent.setLocal(LOCK_INFO_KEY, this.lockInfo, true); }, + /** 还原锁屏数据 */ resetLockInfo() { Persistent.removeLocal(LOCK_INFO_KEY, true); this.lockInfo = null; }, + /** 解锁锁屏 */ async unLock(password?: string) { const userStore = useUserStore(); + // 浏览器存在当前锁屏信息缓存,直接比对当前用户密码 if (this.lockInfo?.pwd === password) { this.resetLockInfo(); return true; } + // 浏览器缓存已经清空,需要重新登录验证当前用户密码 const tryLogin = async () => { try { const username = userStore.getUserInfo.userName; @@ -51,15 +56,13 @@ export const useLockStore = defineStore({ realKey: '', code: '', }); - if (res) { - this.resetLockInfo(); - } + if (res) this.resetLockInfo(); return res; } catch (error) { return false; } }; return await tryLogin(); - }, - }, + } + } }); diff --git a/kicc-ui/src/store/modules/multipleTab.ts b/kicc-ui/src/store/modules/multipleTab.ts index 2c8b802b..7ad33dfa 100644 --- a/kicc-ui/src/store/modules/multipleTab.ts +++ b/kicc-ui/src/store/modules/multipleTab.ts @@ -125,7 +125,7 @@ export const useMultipleTabStore = defineStore({ this.tabList.splice(updateIndex, 1, curTab); // 添加选项卡 } else this.tabList.push(route); - this.updateCacheTab(); + await this.updateCacheTab(); cacheTab && Persistent.setLocal(MULTIPLE_TABS_KEY, this.tabList); }, /** 关闭标签页 */ @@ -173,7 +173,7 @@ export const useMultipleTabStore = defineStore({ /** 标签新增与删除回调处理,用于关闭标签页 */ async closeTabByKey(key: string, router: Router) { const index = this.tabList.findIndex((item) => (item.fullPath || item.path) === key); - index !== -1 && this.closeTab(this.tabList[index], router); + index !== -1 && await this.closeTab(this.tabList[index], router); }, /** 对选项卡进行排序 */ async sortTabs(oldIndex: number, newIndex: number) { @@ -192,9 +192,9 @@ export const useMultipleTabStore = defineStore({ const affix = item?.meta?.affix ?? false; if (!affix) pathList.push(item.fullPath); } - this.bulkCloseTabs(pathList); + await this.bulkCloseTabs(pathList); } - this.updateCacheTab(); + await this.updateCacheTab(); handleGotoPage(router); }, /** 关闭左侧标签并跳转 */ @@ -207,9 +207,9 @@ export const useMultipleTabStore = defineStore({ const affix = item?.meta?.affix ?? false; if (!affix) pathList.push(item.fullPath); } - this.bulkCloseTabs(pathList); + await this.bulkCloseTabs(pathList); } - this.updateCacheTab(); + await this.updateCacheTab(); handleGotoPage(router); }, /** 关闭全部标签并跳转 */ @@ -230,8 +230,8 @@ export const useMultipleTabStore = defineStore({ if (!affix) pathList.push(closeItem.fullPath); } } - this.bulkCloseTabs(pathList); - this.updateCacheTab(); + await this.bulkCloseTabs(pathList); + await this.updateCacheTab(); handleGotoPage(router); }, /** 批量关闭标签页 */ @@ -254,8 +254,8 @@ export const useMultipleTabStore = defineStore({ findTab.path = fullPath; await this.updateCacheTab(); } - }, - }, + } + } }); // 需要在设置之外使用 diff --git a/kicc-ui/src/store/modules/user.ts b/kicc-ui/src/store/modules/user.ts index df50ce07..d080e413 100644 --- a/kicc-ui/src/store/modules/user.ts +++ b/kicc-ui/src/store/modules/user.ts @@ -144,7 +144,7 @@ export const useUserStore = defineStore({ this.setAccessToken(''); this.setRefreshToken(''); this.setSessionTimeout(false); - goLogin && router.push(PageEnum.BASE_LOGIN); + goLogin && await router.push(PageEnum.BASE_LOGIN); }, /** 退出前确认 */ confirmLoginOut() { @@ -156,10 +156,10 @@ export const useUserStore = defineStore({ content: t('sys.app.logoutMessage'), onOk: async () => { await this.logout(true); - }, + } }); - }, - }, + } + } }); // 需要在设置之外使用