(router: Router)
| 15 | |
| 16 | const wsAdminRouterList = ['/ds/index', '/as/index'] |
| 17 | export const watchRouter = (router: Router) => { |
| 18 | router.beforeEach(async (to: any, from: any, next: any) => { |
| 19 | await loadXpackStatic() |
| 20 | await appearanceStore.setAppearance() |
| 21 | LicenseGenerator.generateRouters(router) |
| 22 | if (to.path.startsWith('/login') && userStore.getUid) { |
| 23 | next(to?.query?.redirect || '/') |
| 24 | return |
| 25 | } |
| 26 | if (assistantWhiteList.includes(to.path)) { |
| 27 | next() |
| 28 | return |
| 29 | } |
| 30 | const token = wsCache.get('user.token') |
| 31 | if (whiteList.includes(to.path)) { |
| 32 | next() |
| 33 | return |
| 34 | } |
| 35 | if (!token) { |
| 36 | // ElMessage.error('Please login first') |
| 37 | next(toLoginPage(to.fullPath)) |
| 38 | return |
| 39 | } |
| 40 | if (!userStore.getUid) { |
| 41 | await userStore.info() |
| 42 | generateDynamicRouters(router) |
| 43 | const isFirstDynamicPath = to?.path && ['/ds/index', '/as/index'].includes(to.path) |
| 44 | if (isFirstDynamicPath) { |
| 45 | if (userStore.isSpaceAdmin) { |
| 46 | next({ ...to, replace: true }) |
| 47 | return |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | if (to.path === '/docs') { |
| 52 | location.href = to.fullPath |
| 53 | return |
| 54 | } |
| 55 | if (to.path === '/' || accessCrossPermission(to)) { |
| 56 | next('/chat') |
| 57 | return |
| 58 | } |
| 59 | if (to.path === '/login' || to.path === '/admin-login') { |
| 60 | console.info(from) |
| 61 | next('/chat') |
| 62 | } else { |
| 63 | next() |
| 64 | } |
| 65 | }) |
| 66 | } |
| 67 | |
| 68 | const accessCrossPermission = (to: any) => { |
| 69 | if (!to?.path) return false |
no test coverage detected