From de43d8b30bd30434cd15c514aee0d2d4fd4c8fca Mon Sep 17 00:00:00 2001 From: xingyuv Date: Fri, 24 Mar 2023 23:35:47 +0800 Subject: [PATCH] perf: respect the writing style of pinia getters --- src/store/modules/app.ts | 20 ++++++++++---------- src/store/modules/dict.ts | 10 +++++----- src/store/modules/errorLog.ts | 8 ++++---- src/store/modules/locale.ts | 8 ++++---- src/store/modules/lock.ts | 4 ++-- src/store/modules/multipleTab.ts | 12 ++++++------ src/store/modules/permission.ts | 20 ++++++++++---------- src/store/modules/user.ts | 24 ++++++++++++------------ 8 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/store/modules/app.ts b/src/store/modules/app.ts index 2f75864..c45a1f9 100644 --- a/src/store/modules/app.ts +++ b/src/store/modules/app.ts @@ -31,19 +31,19 @@ export const useAppStore = defineStore('app', { componentSize: 'middle' }), getters: { - getPageLoading(): boolean { - return this.pageLoading + getPageLoading(state): boolean { + return state.pageLoading }, - getDarkMode(): 'light' | 'dark' | string { - return this.darkMode || localStorage.getItem(APP_DARK_MODE_KEY_) || darkMode + getDarkMode(state): 'light' | 'dark' | string { + return state.darkMode || localStorage.getItem(APP_DARK_MODE_KEY_) || darkMode }, - getBeforeMiniInfo(): BeforeMiniState { - return this.beforeMiniInfo + getBeforeMiniInfo(state): BeforeMiniState { + return state.beforeMiniInfo }, - getProjectConfig(): ProjectConfig { - return this.projectConfig || ({} as ProjectConfig) + getProjectConfig(state): ProjectConfig { + return state.projectConfig || ({} as ProjectConfig) }, getHeaderSetting(): HeaderSetting { @@ -58,8 +58,8 @@ export const useAppStore = defineStore('app', { getMultiTabsSetting(): MultiTabsSetting { return this.getProjectConfig.multiTabsSetting }, - getComponentSize(): AppSizeType | undefined { - return this.componentSize + getComponentSize(state): AppSizeType | undefined { + return state.componentSize } }, actions: { diff --git a/src/store/modules/dict.ts b/src/store/modules/dict.ts index 1b06d7b..69f2643 100644 --- a/src/store/modules/dict.ts +++ b/src/store/modules/dict.ts @@ -17,15 +17,15 @@ export const useDictStore = defineStore({ isSetDict: false }), getters: { - getDictMap(): Recordable { + getDictMap(state): Recordable { const dictMap = ls.get(DICT_KEY) if (dictMap) { - this.dictMap = dictMap + state.dictMap = dictMap } - return this.dictMap + return state.dictMap }, - getIsSetDict(): boolean { - return this.isSetDict + getIsSetDict(state): boolean { + return state.isSetDict } }, actions: { diff --git a/src/store/modules/errorLog.ts b/src/store/modules/errorLog.ts index f9f2b44..a17a3b6 100644 --- a/src/store/modules/errorLog.ts +++ b/src/store/modules/errorLog.ts @@ -19,11 +19,11 @@ export const useErrorLogStore = defineStore('app-error-log', { errorLogListCount: 0 }), getters: { - getErrorLogInfoList(): ErrorLogInfo[] { - return this.errorLogInfoList || [] + getErrorLogInfoList(state): ErrorLogInfo[] { + return state.errorLogInfoList || [] }, - getErrorLogListCount(): number { - return this.errorLogListCount + getErrorLogListCount(state): number { + return state.errorLogListCount } }, actions: { diff --git a/src/store/modules/locale.ts b/src/store/modules/locale.ts index 392b333..f067dfe 100644 --- a/src/store/modules/locale.ts +++ b/src/store/modules/locale.ts @@ -20,11 +20,11 @@ export const useLocaleStore = defineStore('app-locale', { localInfo: lsLocaleSetting }), getters: { - getShowPicker(): boolean { - return !!this.localInfo?.showPicker + getShowPicker(state): boolean { + return !!state.localInfo?.showPicker }, - getLocale(): LocaleType { - return this.localInfo?.locale ?? 'zh_CN' + getLocale(state): LocaleType { + return state.localInfo?.locale ?? 'zh_CN' } }, actions: { diff --git a/src/store/modules/lock.ts b/src/store/modules/lock.ts index 0cb0199..996e7f9 100644 --- a/src/store/modules/lock.ts +++ b/src/store/modules/lock.ts @@ -15,8 +15,8 @@ export const useLockStore = defineStore('app-lock', { lockInfo: Persistent.getLocal(LOCK_INFO_KEY) }), getters: { - getLockInfo(): Nullable { - return this.lockInfo + getLockInfo(state): Nullable { + return state.lockInfo } }, actions: { diff --git a/src/store/modules/multipleTab.ts b/src/store/modules/multipleTab.ts index 7b1134e..a96b8da 100644 --- a/src/store/modules/multipleTab.ts +++ b/src/store/modules/multipleTab.ts @@ -46,14 +46,14 @@ export const useMultipleTabStore = defineStore('app-multiple-tab', { lastDragEndIndex: 0 }), getters: { - getTabList(): RouteLocationNormalized[] { - return this.tabList + getTabList(state): RouteLocationNormalized[] { + return state.tabList }, - getCachedTabList(): string[] { - return Array.from(this.cacheTabList) + getCachedTabList(state): string[] { + return Array.from(state.cacheTabList) }, - getLastDragEndIndex(): number { - return this.lastDragEndIndex + getLastDragEndIndex(state): number { + return state.lastDragEndIndex } }, actions: { diff --git a/src/store/modules/permission.ts b/src/store/modules/permission.ts index 0bb37f1..c37b125 100644 --- a/src/store/modules/permission.ts +++ b/src/store/modules/permission.ts @@ -54,20 +54,20 @@ export const usePermissionStore = defineStore('app-permission', { frontMenuList: [] }), getters: { - getPermCodeList(): string[] | number[] { - return this.permCodeList + getPermCodeList(state): string[] | number[] { + return state.permCodeList }, - getBackMenuList(): Menu[] { - return this.backMenuList + getBackMenuList(state): Menu[] { + return state.backMenuList }, - getFrontMenuList(): Menu[] { - return this.frontMenuList + getFrontMenuList(state): Menu[] { + return state.frontMenuList }, - getLastBuildMenuTime(): number { - return this.lastBuildMenuTime + getLastBuildMenuTime(state): number { + return state.lastBuildMenuTime }, - getIsDynamicAddedRoute(): boolean { - return this.isDynamicAddedRoute + getIsDynamicAddedRoute(state): boolean { + return state.isDynamicAddedRoute } }, actions: { diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index ee500ca..e782e3f 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -42,23 +42,23 @@ export const useUserStore = defineStore('app-user', { lastUpdateTime: 0 }), getters: { - getUserInfo(): GetUserInfoModel { - return this.userInfo || getAuthCache(USER_INFO_KEY) || {} + getUserInfo(state): GetUserInfoModel { + return state.userInfo || getAuthCache(USER_INFO_KEY) || {} }, - getAccessToken(): string { - return this.accessToken || getAuthCache(ACCESS_TOKEN_KEY) + getAccessToken(state): string { + return state.accessToken || getAuthCache(ACCESS_TOKEN_KEY) }, - getRefreshToken(): string { - return this.refreshToken || getAuthCache(REFRESH_TOKEN_KEY) + getRefreshToken(state): string { + return state.refreshToken || getAuthCache(REFRESH_TOKEN_KEY) }, - getRoleList(): RoleEnum[] { - return this.roleList.length > 0 ? this.roleList : getAuthCache(ROLES_KEY) + getRoleList(state): RoleEnum[] { + return state.roleList.length > 0 ? state.roleList : getAuthCache(ROLES_KEY) }, - getSessionTimeout(): boolean { - return !!this.sessionTimeout + getSessionTimeout(state): boolean { + return !!state.sessionTimeout }, - getLastUpdateTime(): number { - return this.lastUpdateTime + getLastUpdateTime(state): number { + return state.lastUpdateTime } }, actions: {