diff --git a/package.json b/package.json index e42db59..ba007b2 100644 --- a/package.json +++ b/package.json @@ -101,7 +101,7 @@ "esno": "^0.16.3", "fs-extra": "^11.1.0", "husky": "^8.0.3", - "inquirer": "^9.1.4", + "inquirer": "^9.1.5", "less": "^4.1.3", "lint-staged": "^13.2.0", "picocolors": "^1.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9e1c0d6..fc9f8c6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -50,7 +50,7 @@ specifiers: esno: ^0.16.3 fs-extra: ^11.1.0 husky: ^8.0.3 - inquirer: ^9.1.4 + inquirer: ^9.1.5 intro.js: ^6.0.0 less: ^4.1.3 lint-staged: ^13.2.0 @@ -171,7 +171,7 @@ devDependencies: esno: 0.16.3 fs-extra: 11.1.0 husky: 8.0.3 - inquirer: 9.1.4 + inquirer: 9.1.5 less: 4.1.3 lint-staged: 13.2.0 picocolors: 1.0.0 @@ -5563,9 +5563,9 @@ packages: resolution: {integrity: sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==} dev: true - /inquirer/9.1.4: - resolution: {integrity: sha512-9hiJxE5gkK/cM2d1mTEnuurGTAoHebbkX0BYl3h7iEg7FYfuNIom+nDfBCSWtvSnoSrWCeBxqqBZu26xdlJlXA==} - engines: {node: '>=12.0.0'} + /inquirer/9.1.5: + resolution: {integrity: sha512-3ygAIh8gcZavV9bj6MTdYddG2zPSYswP808fKS46NOwlF0zZljVpnLCHODDqItWJDbDpLb3aouAxGaJbkxoppA==} + engines: {node: '>=14.18.0'} dependencies: ansi-escapes: 6.0.0 chalk: 5.2.0 @@ -5574,7 +5574,7 @@ packages: external-editor: 3.1.0 figures: 5.0.0 lodash: 4.17.21 - mute-stream: 0.0.8 + mute-stream: 1.0.0 ora: 6.1.2 run-async: 2.4.1 rxjs: 7.8.0 @@ -6557,8 +6557,9 @@ packages: resolution: {integrity: sha512-YVE1mIJ4VpUMqZObFndk9CJu6DBJR/GB13p3tXuNbwD4XExaI5EOuRl6BHeIDxIqXZVxSfAC+y6U1Z/IxCfKUg==} dev: true - /mute-stream/0.0.8: - resolution: {integrity: sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==} + /mute-stream/1.0.0: + resolution: {integrity: sha512-avsJQhyd+680gKXyG/sQc0nXaC6rBkPOfyHYcFb9+hdkqQkR9bdnkJ0AMZhke0oesPqIO+mFFJ+IdBc7mst4IA==} + engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} dev: true /nanoid/3.3.4: diff --git a/src/enums/pageEnum.ts b/src/enums/pageEnum.ts index d329ec4..f1ee851 100644 --- a/src/enums/pageEnum.ts +++ b/src/enums/pageEnum.ts @@ -2,7 +2,7 @@ export enum PageEnum { // basic login path BASE_LOGIN = '/login', // basic home path - BASE_HOME = '/dashboard', + BASE_HOME = '/dashboard/analysis', // error page path ERROR_PAGE = '/exception', // error log page path diff --git a/src/main.ts b/src/main.ts index 6d438b4..9c167bd 100644 --- a/src/main.ts +++ b/src/main.ts @@ -57,6 +57,8 @@ async function bootstrap() { // Configure global error handling // 配置全局错误处理 setupErrorHandle(app) + // https://next.router.vuejs.org/api/#isready + await router.isReady() // https://next.router.vuejs.org/api/#isready // await router.isReady(); diff --git a/src/router/guard/index.ts b/src/router/guard/index.ts index f7e659e..1fc56ed 100644 --- a/src/router/guard/index.ts +++ b/src/router/guard/index.ts @@ -52,7 +52,7 @@ function createPageLoadingGuard(router: Router) { const appStore = useAppStoreWithOut() const { getOpenPageLoading } = useTransitionSetting() router.beforeEach(async (to) => { - if (!userStore.getToken) { + if (!userStore.getAccessToken) { return true } if (to.meta.loaded) { diff --git a/src/router/guard/permissionGuard.ts b/src/router/guard/permissionGuard.ts index cfd121a..069258b 100644 --- a/src/router/guard/permissionGuard.ts +++ b/src/router/guard/permissionGuard.ts @@ -3,33 +3,35 @@ import type { Router, RouteRecordRaw } from 'vue-router' import { usePermissionStoreWithOut } from '@/store/modules/permission' import { PageEnum } from '@/enums/pageEnum' +import { useDictStoreWithOut } from '@/store/modules/dict' import { useUserStoreWithOut } from '@/store/modules/user' import { PAGE_NOT_FOUND_ROUTE } from '@/router/routes/basic' -import { RootRoute } from '@/router/routes' +// import { RootRoute } from '@/router/routes' const LOGIN_PATH = PageEnum.BASE_LOGIN -const ROOT_PATH = RootRoute.path +// const ROOT_PATH = RootRoute.path const whitePathList: PageEnum[] = [LOGIN_PATH] export function createPermissionGuard(router: Router) { + const dictStore = useDictStoreWithOut() const userStore = useUserStoreWithOut() const permissionStore = usePermissionStoreWithOut() router.beforeEach(async (to, from, next) => { - if ( - from.path === ROOT_PATH && - to.path === PageEnum.BASE_HOME && - userStore.getUserInfo.homePath && - userStore.getUserInfo.homePath !== PageEnum.BASE_HOME - ) { - next(userStore.getUserInfo.homePath) - return - } - - const token = userStore.getToken + // if ( + // from.path === ROOT_PATH && + // to.path === PageEnum.BASE_HOME && + // userStore.getUserInfo.homePath && + // userStore.getUserInfo.homePath !== PageEnum.BASE_HOME + // ) { + // next(userStore.getUserInfo.homePath) + // return + // } + + const token = userStore.getAccessToken // Whitelist can be directly entered if (whitePathList.includes(to.path as PageEnum)) { @@ -46,7 +48,8 @@ export function createPermissionGuard(router: Router) { next() return } - // token or user does not exist + + // token does not exist if (!token) { // You can access without permission. You need to set the routing meta.ignoreAuth to true if (to.meta.ignoreAuth) { @@ -70,15 +73,14 @@ export function createPermissionGuard(router: Router) { } // Jump to the 404 page after processing the login - if ( - from.path === LOGIN_PATH && - to.name === PAGE_NOT_FOUND_ROUTE.name && - to.fullPath !== (userStore.getUserInfo.homePath || PageEnum.BASE_HOME) - ) { - next(userStore.getUserInfo.homePath || PageEnum.BASE_HOME) + if (from.path === LOGIN_PATH && to.name === PAGE_NOT_FOUND_ROUTE.name && to.fullPath !== PageEnum.BASE_HOME) { + next(PageEnum.BASE_HOME) return } + if (!dictStore.getIsSetDict) { + await dictStore.setDictMap() + } // get userinfo while last fetch time is empty if (userStore.getLastUpdateTime === 0) { try { diff --git a/src/store/modules/permission.ts b/src/store/modules/permission.ts index b91996c..9ca3748 100644 --- a/src/store/modules/permission.ts +++ b/src/store/modules/permission.ts @@ -226,6 +226,7 @@ export const usePermissionStore = defineStore('app-permission', { // Background routing to menu structure // 后台路由到菜单结构 const backMenuList = transformRouteToMenu([dashboard, ...routeList]) + console.info(backMenuList) this.setBackMenuList(backMenuList) // remove meta.ignoreRoute item diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index ee500ca..2c393bf 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -128,6 +128,7 @@ export const useUserStore = defineStore('app-user', { router.addRoute(PAGE_NOT_FOUND_ROUTE as unknown as RouteRecordRaw) permissionStore.setDynamicAddedRoute(true) } + console.info(router.replace(PageEnum.BASE_HOME)) goHome && (await router.replace(PageEnum.BASE_HOME)) } return userInfo