Commit 15567e478c0f274b0f8f0a7410ea5cb636bacc3d
1 parent
f6cef108
fix: improve persistent cache logic
Showing
14 changed files
with
68 additions
and
45 deletions
package.json
... | ... | @@ -76,7 +76,7 @@ |
76 | 76 | "conventional-changelog-cli": "^2.1.1", |
77 | 77 | "cross-env": "^7.0.3", |
78 | 78 | "dotenv": "^8.2.0", |
79 | - "eslint": "^7.20.0", | |
79 | + "eslint": "^7.21.0", | |
80 | 80 | "eslint-config-prettier": "^8.1.0", |
81 | 81 | "eslint-plugin-prettier": "^3.3.1", |
82 | 82 | "eslint-plugin-vue": "^7.6.0", |
... | ... | @@ -106,7 +106,7 @@ |
106 | 106 | "vite-plugin-pwa": "^0.5.5", |
107 | 107 | "vite-plugin-style-import": "^0.7.5", |
108 | 108 | "vite-plugin-theme": "^0.4.8", |
109 | - "vite-plugin-windicss": "0.6.0", | |
109 | + "vite-plugin-windicss": "0.6.2", | |
110 | 110 | "vue-eslint-parser": "^7.5.0", |
111 | 111 | "yargs": "^16.2.0" |
112 | 112 | }, | ... | ... |
src/components/Menu/src/BasicMenu.vue
... | ... | @@ -110,7 +110,7 @@ |
110 | 110 | listenerLastChangeTab((route) => { |
111 | 111 | if (route.name === REDIRECT_NAME) return; |
112 | 112 | handleMenuChange(route); |
113 | - currentActiveMenu.value = route.meta?.currentActiveMenu; | |
113 | + currentActiveMenu.value = route.meta?.currentActiveMenu as string; | |
114 | 114 | |
115 | 115 | if (unref(currentActiveMenu)) { |
116 | 116 | menuState.selectedKeys = [unref(currentActiveMenu)]; | ... | ... |
src/hooks/web/useFullContent.ts
src/layouts/default/menu/useLayoutMenu.ts
... | ... | @@ -41,7 +41,7 @@ export function useSplitMenu(splitType: Ref<MenuSplitTyeEnum>) { |
41 | 41 | if (unref(splitNotLeft) || unref(getIsMobile)) return; |
42 | 42 | |
43 | 43 | const { meta } = unref(currentRoute); |
44 | - const currentActiveMenu = meta.currentActiveMenu; | |
44 | + const currentActiveMenu = meta.currentActiveMenu as string; | |
45 | 45 | let parentPath = await getCurrentParentPath(path); |
46 | 46 | if (!parentPath) { |
47 | 47 | parentPath = await getCurrentParentPath(currentActiveMenu); | ... | ... |
src/logics/initAppConfig.ts
1 | 1 | /** |
2 | 2 | * Application configuration |
3 | 3 | */ |
4 | +import type { ProjectConfig } from '/#/config'; | |
4 | 5 | |
6 | +import { PROJ_CFG_KEY } from '/@/enums/cacheEnum'; | |
5 | 7 | import projectSetting from '/@/settings/projectSetting'; |
6 | 8 | |
7 | 9 | import { updateHeaderBgColor, updateSidebarBgColor } from '/@/logics/theme/updateBackground'; |
... | ... | @@ -15,9 +17,13 @@ import { localeStore } from '/@/store/modules/locale'; |
15 | 17 | import { getCommonStoragePrefix, getStorageShortName } from '/@/utils/env'; |
16 | 18 | |
17 | 19 | import { primaryColor } from '../../build/config/themeConfig'; |
20 | +import { Persistent } from '/@/utils/cache/persistent'; | |
21 | +import { deepMerge } from '/@/utils'; | |
18 | 22 | |
19 | 23 | // Initial project configuration |
20 | 24 | export function initAppConfigStore() { |
25 | + let projCfg: ProjectConfig = Persistent.getLocal(PROJ_CFG_KEY) as ProjectConfig; | |
26 | + projCfg = deepMerge(projectSetting, projCfg || {}); | |
21 | 27 | try { |
22 | 28 | const { |
23 | 29 | colorWeak, |
... | ... | @@ -25,7 +31,7 @@ export function initAppConfigStore() { |
25 | 31 | themeColor, |
26 | 32 | headerSetting: { bgColor: headerBgColor } = {}, |
27 | 33 | menuSetting: { bgColor } = {}, |
28 | - } = projectSetting; | |
34 | + } = projCfg; | |
29 | 35 | if (themeColor && themeColor !== primaryColor) { |
30 | 36 | changeTheme(themeColor); |
31 | 37 | } |
... | ... | @@ -36,7 +42,7 @@ export function initAppConfigStore() { |
36 | 42 | } catch (error) { |
37 | 43 | console.log(error); |
38 | 44 | } |
39 | - appStore.commitProjectConfigState(projectSetting); | |
45 | + appStore.commitProjectConfigState(projCfg); | |
40 | 46 | localeStore.initLocale(); |
41 | 47 | |
42 | 48 | setTimeout(() => { | ... | ... |
src/settings/projectSetting.ts
... | ... | @@ -22,7 +22,7 @@ const setting: ProjectConfig = { |
22 | 22 | permissionMode: PermissionModeEnum.ROLE, |
23 | 23 | |
24 | 24 | // Permission-related cache is stored in sessionStorage or localStorage |
25 | - permissionCacheType: CacheTypeEnum.LOCAL, | |
25 | + permissionCacheType: CacheTypeEnum.SESSION, | |
26 | 26 | |
27 | 27 | // color |
28 | 28 | themeColor: primaryColor, | ... | ... |
src/store/modules/error.ts
... | ... | @@ -22,7 +22,7 @@ export interface ErrorState { |
22 | 22 | errorListCountState: number; |
23 | 23 | } |
24 | 24 | |
25 | -const NAME = 'error'; | |
25 | +const NAME = 'app-error'; | |
26 | 26 | hotModuleUnregisterModule(NAME); |
27 | 27 | @Module({ dynamic: true, namespaced: true, store, name: NAME }) |
28 | 28 | class Error extends VuexModule implements ErrorState { | ... | ... |
src/store/modules/locale.ts
... | ... | @@ -13,7 +13,7 @@ const ls = createLocalStorage(); |
13 | 13 | |
14 | 14 | const lsSetting = (ls.get(LOCALE_KEY) || localeSetting) as LocaleSetting; |
15 | 15 | |
16 | -const NAME = 'locale'; | |
16 | +const NAME = 'app-locale'; | |
17 | 17 | hotModuleUnregisterModule(NAME); |
18 | 18 | @Module({ dynamic: true, namespaced: true, store, name: NAME }) |
19 | 19 | class Locale extends VuexModule { | ... | ... |
src/store/modules/lock.ts
src/store/modules/permission.ts
... | ... | @@ -22,7 +22,7 @@ import { useI18n } from '/@/hooks/web/useI18n'; |
22 | 22 | import { ERROR_LOG_ROUTE, PAGE_NOT_FOUND_ROUTE } from '/@/router/constant'; |
23 | 23 | |
24 | 24 | const { createMessage } = useMessage(); |
25 | -const NAME = 'permission'; | |
25 | +const NAME = 'app-permission'; | |
26 | 26 | hotModuleUnregisterModule(NAME); |
27 | 27 | @Module({ dynamic: true, namespaced: true, store, name: NAME }) |
28 | 28 | class Permission extends VuexModule { | ... | ... |
src/store/modules/tab.ts
... | ... | @@ -14,7 +14,7 @@ import { getRoute } from '/@/router/helper/routeHelper'; |
14 | 14 | import { useGo, useRedo } from '/@/hooks/web/usePage'; |
15 | 15 | import { cloneDeep } from 'lodash-es'; |
16 | 16 | |
17 | -const NAME = 'tab'; | |
17 | +const NAME = 'app-tab'; | |
18 | 18 | |
19 | 19 | hotModuleUnregisterModule(NAME); |
20 | 20 | ... | ... |
src/store/modules/user.ts
... | ... | @@ -25,16 +25,22 @@ import projectSetting from '/@/settings/projectSetting'; |
25 | 25 | |
26 | 26 | export type UserInfo = Omit<GetUserInfoByUserIdModel, 'roles'>; |
27 | 27 | |
28 | -const NAME = 'user'; | |
28 | +const { permissionCacheType } = projectSetting; | |
29 | +const isLocal = permissionCacheType === CacheTypeEnum.LOCAL; | |
30 | + | |
31 | +const NAME = 'app-user'; | |
29 | 32 | hotModuleUnregisterModule(NAME); |
30 | 33 | |
31 | 34 | function getCache<T>(key: BasicKeys) { |
32 | - const { permissionCacheType } = projectSetting; | |
33 | - const fn = | |
34 | - permissionCacheType === CacheTypeEnum.LOCAL ? Persistent.getLocal : Persistent.getSession; | |
35 | + const fn = isLocal ? Persistent.getLocal : Persistent.getSession; | |
35 | 36 | return fn(key) as T; |
36 | 37 | } |
37 | 38 | |
39 | +function setCache(key: BasicKeys, value) { | |
40 | + const fn = isLocal ? Persistent.setLocal : Persistent.setSession; | |
41 | + return fn(key, value); | |
42 | +} | |
43 | + | |
38 | 44 | @Module({ namespaced: true, name: NAME, dynamic: true, store }) |
39 | 45 | class User extends VuexModule { |
40 | 46 | // user info |
... | ... | @@ -68,19 +74,19 @@ class User extends VuexModule { |
68 | 74 | @Mutation |
69 | 75 | commitUserInfoState(info: UserInfo): void { |
70 | 76 | this.userInfoState = info; |
71 | - Persistent.setLocal(USER_INFO_KEY, info); | |
77 | + setCache(USER_INFO_KEY, info); | |
72 | 78 | } |
73 | 79 | |
74 | 80 | @Mutation |
75 | 81 | commitRoleListState(roleList: RoleEnum[]): void { |
76 | 82 | this.roleListState = roleList; |
77 | - Persistent.setLocal(ROLES_KEY, roleList); | |
83 | + setCache(ROLES_KEY, roleList); | |
78 | 84 | } |
79 | 85 | |
80 | 86 | @Mutation |
81 | 87 | commitTokenState(info: string): void { |
82 | 88 | this.tokenState = info; |
83 | - Persistent.setLocal(TOKEN_KEY, info); | |
89 | + setCache(TOKEN_KEY, info); | |
84 | 90 | } |
85 | 91 | |
86 | 92 | /** | ... | ... |
src/utils/cache/persistent.ts
1 | +import type { UserInfo } from '/@/store/modules/user'; | |
2 | +import type { LockInfo } from '/@/store/modules/lock'; | |
3 | +import { ProjectConfig } from '/#/config'; | |
4 | + | |
1 | 5 | import { createLocalStorage, createSessionStorage } from '/@/utils/cache'; |
2 | 6 | import { Memory } from './memory'; |
3 | 7 | import { |
... | ... | @@ -14,10 +18,10 @@ import { toRaw } from 'vue'; |
14 | 18 | |
15 | 19 | interface BasicStore { |
16 | 20 | [TOKEN_KEY]: string | number | null | undefined; |
17 | - [USER_INFO_KEY]: Recordable; | |
18 | - [ROLES_KEY]: Recordable; | |
19 | - [LOCK_INFO_KEY]: Recordable; | |
20 | - [PROJ_CFG_KEY]: Recordable; | |
21 | + [USER_INFO_KEY]: UserInfo; | |
22 | + [ROLES_KEY]: string[]; | |
23 | + [LOCK_INFO_KEY]: LockInfo; | |
24 | + [PROJ_CFG_KEY]: ProjectConfig; | |
21 | 25 | } |
22 | 26 | |
23 | 27 | type LocalStore = BasicStore; |
... | ... | @@ -36,7 +40,7 @@ const sessionMemory = new Memory(DEFAULT_CACHE_TIME); |
36 | 40 | |
37 | 41 | function initPersistentMemory() { |
38 | 42 | const localCache = ls.get(APP_LOCAL_CACHE_KEY); |
39 | - const sessionCache = ls.get(APP_SESSION_CACHE_KEY); | |
43 | + const sessionCache = ss.get(APP_SESSION_CACHE_KEY); | |
40 | 44 | localCache && localMemory.resetCache(localCache); |
41 | 45 | sessionCache && sessionMemory.resetCache(sessionCache); |
42 | 46 | } |
... | ... | @@ -65,7 +69,7 @@ export class Persistent { |
65 | 69 | |
66 | 70 | static setSession(key: SessionKeys, value: SessionStore[SessionKeys], immediate = false): void { |
67 | 71 | sessionMemory.set(key, toRaw(value)); |
68 | - immediate && ss.set(APP_SESSION_CACHE_KEY, localMemory); | |
72 | + immediate && ss.set(APP_SESSION_CACHE_KEY, sessionMemory); | |
69 | 73 | } |
70 | 74 | |
71 | 75 | static removeSession(key: SessionKeys): void { | ... | ... |
yarn.lock
... | ... | @@ -1057,10 +1057,10 @@ |
1057 | 1057 | resolved "https://registry.npmjs.org/@ctrl/tinycolor/-/tinycolor-3.3.3.tgz#980487763bc7c9238d6d88d1ac0dee2d4df3df68" |
1058 | 1058 | integrity sha512-v75yutF4BDMv9weDQVM+K5XEfjiODhugSV729pnoxtBDO61ij2CsDnQa4N4E9xGaH3/FX5ASZjnajljT2F71tA== |
1059 | 1059 | |
1060 | -"@eslint/eslintrc@^0.3.0": | |
1061 | - version "0.3.0" | |
1062 | - resolved "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.3.0.tgz#d736d6963d7003b6514e6324bec9c602ac340318" | |
1063 | - integrity sha512-1JTKgrOKAHVivSvOYw+sJOunkBjUOvjqWk1DPja7ZFhIS2mX/4EgTT8M7eTK9jrKhL/FvXXEbQwIs3pg1xp3dg== | |
1060 | +"@eslint/eslintrc@^0.4.0": | |
1061 | + version "0.4.0" | |
1062 | + resolved "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.4.0.tgz#99cc0a0584d72f1df38b900fb062ba995f395547" | |
1063 | + integrity sha512-2ZPCc+uNbjV5ERJr+aKSPRwZgKd2z11x0EgLvb1PURmUrn9QNRXFqje0Ldq454PfAVyaJYyrDvvIKSFP4NnBog== | |
1064 | 1064 | dependencies: |
1065 | 1065 | ajv "^6.12.4" |
1066 | 1066 | debug "^4.1.1" |
... | ... | @@ -1069,7 +1069,6 @@ |
1069 | 1069 | ignore "^4.0.6" |
1070 | 1070 | import-fresh "^3.2.1" |
1071 | 1071 | js-yaml "^3.13.1" |
1072 | - lodash "^4.17.20" | |
1073 | 1072 | minimatch "^3.0.4" |
1074 | 1073 | strip-json-comments "^3.1.1" |
1075 | 1074 | |
... | ... | @@ -1718,10 +1717,10 @@ |
1718 | 1717 | dependencies: |
1719 | 1718 | vue-demi latest |
1720 | 1719 | |
1721 | -"@windicss/plugin-utils@0.6.0": | |
1722 | - version "0.6.0" | |
1723 | - resolved "https://registry.npmjs.org/@windicss/plugin-utils/-/plugin-utils-0.6.0.tgz#34eb852b7ff338bb933b0079112318a30d2aee00" | |
1724 | - integrity sha512-CpXn3CRrAaDrpTjenidVfBz0JONLuGTFP6qjrwZ2tmhsKOuvTWw8Ic9JQ2a9L0AkYBH33lTso1qk70/PjnE6WQ== | |
1720 | +"@windicss/plugin-utils@0.6.2": | |
1721 | + version "0.6.2" | |
1722 | + resolved "https://registry.npmjs.org/@windicss/plugin-utils/-/plugin-utils-0.6.2.tgz#8fc76d9f2a1e3de123ffd54fdd9d1583801bb087" | |
1723 | + integrity sha512-qR2h/vDn3LZtL0cC3id9nxPwhYqCtkcwASs63sHTUOzLhxz+zkG4xR+odndbR6PTjrlTgBC7n5hLjpq0lxRksg== | |
1725 | 1724 | dependencies: |
1726 | 1725 | esbuild "^0.8.52" |
1727 | 1726 | esbuild-register "^2.0.0" |
... | ... | @@ -3678,13 +3677,13 @@ eslint-visitor-keys@^2.0.0: |
3678 | 3677 | resolved "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.0.0.tgz#21fdc8fbcd9c795cc0321f0563702095751511a8" |
3679 | 3678 | integrity sha512-QudtT6av5WXels9WjIM7qz1XD1cWGvX4gGXvp/zBn9nXG02D0utdU3Em2m/QjTnrsk6bBjmCygl3rmj118msQQ== |
3680 | 3679 | |
3681 | -eslint@^7.20.0: | |
3682 | - version "7.20.0" | |
3683 | - resolved "https://registry.npmjs.org/eslint/-/eslint-7.20.0.tgz#db07c4ca4eda2e2316e7aa57ac7fc91ec550bdc7" | |
3684 | - integrity sha512-qGi0CTcOGP2OtCQBgWZlQjcTuP0XkIpYFj25XtRTQSHC+umNnp7UMshr2G8SLsRFYDdAPFeHOsiteadmMH02Yw== | |
3680 | +eslint@^7.21.0: | |
3681 | + version "7.21.0" | |
3682 | + resolved "https://registry.npmjs.org/eslint/-/eslint-7.21.0.tgz#4ecd5b8c5b44f5dedc9b8a110b01bbfeb15d1c83" | |
3683 | + integrity sha512-W2aJbXpMNofUp0ztQaF40fveSsJBjlSCSWpy//gzfTvwC+USs/nceBrKmlJOiM8r1bLwP2EuYkCqArn/6QTIgg== | |
3685 | 3684 | dependencies: |
3686 | 3685 | "@babel/code-frame" "7.12.11" |
3687 | - "@eslint/eslintrc" "^0.3.0" | |
3686 | + "@eslint/eslintrc" "^0.4.0" | |
3688 | 3687 | ajv "^6.10.0" |
3689 | 3688 | chalk "^4.0.0" |
3690 | 3689 | cross-spawn "^7.0.2" |
... | ... | @@ -3697,7 +3696,7 @@ eslint@^7.20.0: |
3697 | 3696 | espree "^7.3.1" |
3698 | 3697 | esquery "^1.4.0" |
3699 | 3698 | esutils "^2.0.2" |
3700 | - file-entry-cache "^6.0.0" | |
3699 | + file-entry-cache "^6.0.1" | |
3701 | 3700 | functional-red-black-tree "^1.0.1" |
3702 | 3701 | glob-parent "^5.0.0" |
3703 | 3702 | globals "^12.1.0" |
... | ... | @@ -4030,6 +4029,13 @@ file-entry-cache@^6.0.0: |
4030 | 4029 | dependencies: |
4031 | 4030 | flat-cache "^3.0.4" |
4032 | 4031 | |
4032 | +file-entry-cache@^6.0.1: | |
4033 | + version "6.0.1" | |
4034 | + resolved "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz#211b2dd9659cb0394b073e7323ac3c933d522027" | |
4035 | + integrity sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg== | |
4036 | + dependencies: | |
4037 | + flat-cache "^3.0.4" | |
4038 | + | |
4033 | 4039 | file-type@5.2.0, file-type@^5.2.0: |
4034 | 4040 | version "5.2.0" |
4035 | 4041 | resolved "https://registry.npmjs.org/file-type/-/file-type-5.2.0.tgz#2ddbea7c73ffe36368dfae49dc338c058c2b8ad6" |
... | ... | @@ -8968,12 +8974,12 @@ vite-plugin-theme@^0.4.8: |
8968 | 8974 | es-module-lexer "^0.3.26" |
8969 | 8975 | tinycolor2 "^1.4.2" |
8970 | 8976 | |
8971 | -vite-plugin-windicss@0.6.0: | |
8972 | - version "0.6.0" | |
8973 | - resolved "https://registry.npmjs.org/vite-plugin-windicss/-/vite-plugin-windicss-0.6.0.tgz#ac8f24e70439904b67adc1f133e692fb6257ecaf" | |
8974 | - integrity sha512-PSFdm0hrAGaKFzkFOiz31+dODoKNbh9wo/3m/7/012WwV9oJ1mX/9OxDxACykW7hMR0YvWHFmC0UwtvMra+InQ== | |
8977 | +vite-plugin-windicss@0.6.2: | |
8978 | + version "0.6.2" | |
8979 | + resolved "https://registry.npmjs.org/vite-plugin-windicss/-/vite-plugin-windicss-0.6.2.tgz#2b406c65768ce7df22451dc7b47c0026abd4bb24" | |
8980 | + integrity sha512-V4WnjkxvriJSVQjswY+SrDKogOLNq1eG6dQw1wWcJRV+0QUz9pAGrMolSwed4d4MwSSbJrCA7If8xa+EFLUigw== | |
8975 | 8981 | dependencies: |
8976 | - "@windicss/plugin-utils" "0.6.0" | |
8982 | + "@windicss/plugin-utils" "0.6.2" | |
8977 | 8983 | windicss "^2.2.0" |
8978 | 8984 | |
8979 | 8985 | vite@2.0.4: | ... | ... |