Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions frontend/src/router/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const userStore = useUserStore()
const { wsCache } = useCache()
const whiteList = ['/login', '/admin-login']
const assistantWhiteList = ['/assistant', '/embeddedPage', '/embeddedCommon', '/401']

const wsAdminRouterList = ['/ds/index', '/as/index']
export const watchRouter = (router: Router) => {
router.beforeEach(async (to: any, from: any, next: any) => {
await loadXpackStatic()
Expand All @@ -35,14 +37,15 @@ export const watchRouter = (router: Router) => {
next(toLoginPage(to.fullPath))
return
}
let isFirstDynamicPath = false
if (!userStore.getUid) {
await userStore.info()
generateDynamicRouters(router)
isFirstDynamicPath = to?.path && ['/ds/index', '/as/index'].includes(to.path)
const isFirstDynamicPath = to?.path && ['/ds/index', '/as/index'].includes(to.path)
if (isFirstDynamicPath) {
next({ ...to, replace: true })
return
if (userStore.isSpaceAdmin) {
next({ ...to, replace: true })
return
}
}
}
if (to.path === '/' || accessCrossPermission(to)) {
Expand All @@ -62,9 +65,14 @@ const accessCrossPermission = (to: any) => {
if (!to?.path) return false
return (
(to.path.startsWith('/system') && !userStore.isAdmin) ||
(to.path.startsWith('/set') && !userStore.isSpaceAdmin)
(to.path.startsWith('/set') && !userStore.isSpaceAdmin) ||
(isWsAdminRouter(to) && !userStore.isSpaceAdmin)
)
}

const isWsAdminRouter = (to?: any) => {
return wsAdminRouterList.some((item: string) => to?.path?.startsWith(item))
}
const loadXpackStatic = () => {
if (document.getElementById('sqlbot_xpack_static')) {
return Promise.resolve()
Expand Down