feat: router
parent
cb51ea031e
commit
351171b29a
|
@ -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",
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
// 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
|
||||
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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue