| | |
| | | |
| | | // 路由加载前 |
| | | router.beforeEach(async (to, from, next) => { |
| | | console.info("router.beforeEach to: " + to.fullPath + " from: " + from.fullPath) |
| | | start() |
| | | loadStart() |
| | | if (getAccessToken()) { |
| | | if (to.path === '/login') { |
| | | next({ path: '/' }) |
| | | } else { |
| | | // 获取所有字典 |
| | | const dictStore = useDictStoreWithOut() |
| | | const userStore = useUserStoreWithOut() |
| | | const permissionStore = usePermissionStoreWithOut() |
| | | if (!dictStore.getIsSetDict) { |
| | | await dictStore.setDictMap() |
| | | } |
| | | if (!userStore.getIsSetUser) { |
| | | isRelogin.show = true |
| | | await userStore.setUserInfoAction() |
| | | isRelogin.show = false |
| | | // 后端过滤菜单 |
| | | await permissionStore.generateRoutes() |
| | | permissionStore.getAddRouters.forEach((route) => { |
| | | router.addRoute(route as unknown as RouteRecordRaw) // 动态添加可访问路由表 |
| | | }) |
| | | |
| | | // 新增【诊室选择】逻辑 |
| | | if (userStore.getRoles.includes("doctor") && !userStore.getRoles.includes("super_admin") && !userStore.getIsSetRoom ) { |
| | | next({path: `/roomselect?redirect=${to.fullPath}`}) |
| | | } |
| | | // <<<【诊室选择】<<< |
| | | else { |
| | | const redirectPath = from.query.redirect || to.path |
| | | // 修复跳转时不带参数的问题 |
| | | const redirect = decodeURIComponent(redirectPath as string) |
| | | const {paramsObject: query} = parseURL(redirect) |
| | | const nextData = to.path === redirect ? {...to, replace: true} : {path: redirect, query} |
| | | next(nextData) |
| | | } |
| | | if (!getAccessToken()) { |
| | | if (whiteList.indexOf(to.path) !== -1) { |
| | | next() |
| | | return |
| | | } else { |
| | | next() |
| | | next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页 |
| | | return |
| | | } |
| | | } |
| | | } else { |
| | | if (whiteList.indexOf(to.path) !== -1) { |
| | | next() |
| | | } else { |
| | | next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页 |
| | | } |
| | | } |
| | | |
| | | if (to.path === '/login') { |
| | | next({ path: '/' }) |
| | | return |
| | | } |
| | | |
| | | // 获取所有字典 |
| | | const dictStore = useDictStoreWithOut() |
| | | const userStore = useUserStoreWithOut() |
| | | const permissionStore = usePermissionStoreWithOut() |
| | | if (!dictStore.getIsSetDict) { |
| | | await dictStore.setDictMap() |
| | | } |
| | | |
| | | if (userStore.getIsSetUser ) { |
| | | |
| | | // <<<【诊室选择】<<< |
| | | if ( to.path !== '/roomselect' && |
| | | userStore.getRoles.includes("doctor") && !userStore.getRoles.includes("super_admin") |
| | | && !userStore.getIsSetRoom ) { |
| | | next({path: `/roomselect?redirect=${to.fullPath}`}) |
| | | return |
| | | } |
| | | |
| | | next() |
| | | return |
| | | } |
| | | |
| | | isRelogin.show = true |
| | | await userStore.setUserInfoAction() |
| | | isRelogin.show = false |
| | | |
| | | // 后端过滤菜单 |
| | | await permissionStore.generateRoutes() |
| | | permissionStore.getAddRouters.forEach((route) => { |
| | | router.addRoute(route as unknown as RouteRecordRaw) // 动态添加可访问路由表 |
| | | }) |
| | | |
| | | // <<<【诊室选择】<<< |
| | | if ( to.path !== '/roomselect' && |
| | | userStore.getRoles.includes("doctor") && !userStore.getRoles.includes("super_admin") |
| | | && !userStore.getIsSetRoom ) { |
| | | next({path: `/roomselect?redirect=${to.fullPath}`}) |
| | | return |
| | | } |
| | | |
| | | const redirectPath = from.query.redirect || to.path |
| | | // 修复跳转时不带参数的问题 |
| | | const redirect = decodeURIComponent(redirectPath as string) |
| | | const {paramsObject: query} = parseURL(redirect) |
| | | const nextData = to.path === redirect ? {...to, replace: true} : {path: redirect, query} |
| | | next(nextData) |
| | | }) |
| | | |
| | | router.afterEach((to) => { |