diff --git a/yudao-ui-admin-vue3/src/main.ts b/yudao-ui-admin-vue3/src/main.ts index a7341b7ee..e7c935a28 100644 --- a/yudao-ui-admin-vue3/src/main.ts +++ b/yudao-ui-admin-vue3/src/main.ts @@ -26,10 +26,10 @@ import '@/styles/index.scss' import '@/plugins/animate.css' // 路由 -import { setupRouter } from './router' +import router, { setupRouter } from '@/router' // 权限 -import { setupAuth } from './directives' +import { setupAuth } from '@/directives' import { createApp } from 'vue' @@ -53,6 +53,8 @@ const setupAll = async () => { setupAuth(app) + await router.isReady() + app.mount('#app') } diff --git a/yudao-ui-admin-vue3/src/router/index.ts b/yudao-ui-admin-vue3/src/router/index.ts index 4fe42b515..68b4b7f53 100644 --- a/yudao-ui-admin-vue3/src/router/index.ts +++ b/yudao-ui-admin-vue3/src/router/index.ts @@ -6,15 +6,11 @@ import { isRelogin } from '@/config/axios/service' import { getAccessToken } from '@/utils/auth' import { useTitle } from '@/hooks/web/useTitle' import { useNProgress } from '@/hooks/web/useNProgress' -import { CACHE_KEY, useCache } from '@/hooks/web/useCache' import { usePageLoading } from '@/hooks/web/usePageLoading' import { useDictStoreWithOut } from '@/store/modules/dict' import { useUserStoreWithOut } from '@/store/modules/user' import { usePermissionStoreWithOut } from '@/store/modules/permission' import { getInfoApi } from '@/api/login' -import { listSimpleDictDataApi } from '@/api/system/dict/dict.data' - -const { wsCache } = useCache() const { start, done } = useNProgress() @@ -50,12 +46,11 @@ router.beforeEach(async (to, from, next) => { const dictStore = useDictStoreWithOut() const userStore = useUserStoreWithOut() const permissionStore = usePermissionStoreWithOut() - const dictMap = wsCache.get(CACHE_KEY.DICT_CACHE) - if (!dictMap) { - const res = await listSimpleDictDataApi() - dictStore.setDictMap(res) + if (!dictStore.getIsSetDict) { + dictStore.setDictMap() } if (!userStore.getIsSetUser) { + console.info(1) isRelogin.show = true const res = await getInfoApi() await userStore.setUserInfoAction(res) diff --git a/yudao-ui-admin-vue3/src/store/modules/dict.ts b/yudao-ui-admin-vue3/src/store/modules/dict.ts index 4b2d46413..2c80a0d52 100644 --- a/yudao-ui-admin-vue3/src/store/modules/dict.ts +++ b/yudao-ui-admin-vue3/src/store/modules/dict.ts @@ -3,6 +3,7 @@ import { store } from '../index' import { DictDataVO } from '@/api/system/dict/types' import { CACHE_KEY, useCache } from '@/hooks/web/useCache' const { wsCache } = useCache('sessionStorage') +import { listSimpleDictDataApi } from '@/api/system/dict/dict.data' export interface DictValueType { value: any @@ -16,45 +17,54 @@ export interface DictTypeType { } export interface DictState { dictMap: Map + isSetDict: boolean } export const useDictStore = defineStore('dict', { state: (): DictState => ({ - dictMap: new Map() + dictMap: new Map(), + isSetDict: false }), getters: { getDictMap(): Recordable { const dictMap = wsCache.get(CACHE_KEY.DICT_CACHE) - return dictMap ? dictMap : this.dictMap - }, - getHasDictData(): boolean { - if (this.dictMap.size > 0) { - return true - } else { - return false + if (dictMap) { + this.dictMap = dictMap } + return this.dictMap + }, + getIsSetDict(): boolean { + return this.isSetDict } }, actions: { - setDictMap(dictMap: Recordable) { - // 设置数据 - const dictDataMap = new Map() - dictMap.forEach((dictData: DictDataVO) => { - // 获得 dictType 层级 - const enumValueObj = dictDataMap[dictData.dictType] - if (!enumValueObj) { - dictDataMap[dictData.dictType] = [] - } - // 处理 dictValue 层级 - dictDataMap[dictData.dictType].push({ - value: dictData.value, - label: dictData.label, - colorType: dictData.colorType, - cssClass: dictData.cssClass + async setDictMap() { + const dictMap = wsCache.get(CACHE_KEY.DICT_CACHE) + if (dictMap) { + this.dictMap = dictMap + this.isSetDict = true + } else { + const res = await listSimpleDictDataApi() + // 设置数据 + const dictDataMap = new Map() + res.forEach((dictData: DictDataVO) => { + // 获得 dictType 层级 + const enumValueObj = dictDataMap[dictData.dictType] + if (!enumValueObj) { + dictDataMap[dictData.dictType] = [] + } + // 处理 dictValue 层级 + dictDataMap[dictData.dictType].push({ + value: dictData.value, + label: dictData.label, + colorType: dictData.colorType, + cssClass: dictData.cssClass + }) }) - }) - this.dictMap = dictDataMap - wsCache.set(CACHE_KEY.DICT_CACHE, dictDataMap, { exp: 60 }) // 60 秒 过期 + this.dictMap = dictDataMap + this.isSetDict = true + wsCache.set(CACHE_KEY.DICT_CACHE, dictDataMap, { exp: 60 }) // 60 秒 过期 + } } } })