Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions ui/src/router/ROUTE_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
Workspace 使用 `AppLayout`,左侧导航根据 `scope: 'workspace'` 对应路由的 `children` 自动生成。

Workspace 根地址为 `/admin/workspace/:workspaceId`。`workspaceId` 只以当前路由参数为准。应用根
地址、登录成功和从 System 返回 Workspace 时统一进入 `/admin/workspace/default`。父路由的
`scope` 会合并到匹配的子路由 `meta` 中。
地址、登录成功和从 System 返回 Workspace 时统一进入 `/admin/workspace/default`;若当前用户
只属于 `workspace_list` 中的部分工作空间且目标 `workspaceId` 不在其中,路由守卫会自动重定向到
其首个可访问工作空间(仅对携带 `workspaceId` 参数的工作空间路由生效)。父路由的 `scope`
会合并到匹配的子路由 `meta` 中。

顶部工作空间切换统一由 `layout/header-workspace-dropdown/index.vue` 处理:选择不同工作空间时,
通过 `router.resolve()` 生成目标地址,再调用 `window.location.assign()` 整页加载,重新初始化
Expand Down
14 changes: 14 additions & 0 deletions ui/src/router/admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ router.beforeEach(async (to, from) => {
if (!user.userInfo) {
await auth.loadAuthBaseProfile()
}

// 用户只属于部分工作空间时,自动落到其首个可访问工作空间;
// 避免登录/根路径/返回等入口硬编码进入 default 而出现选中为空、无权限。
const workspaceId = to.params?.workspaceId as string | undefined
const workspace_list = user.userInfo?.workspace_list
if (to.name && workspaceId && workspace_list?.length) {
const accessibleIds = new Set(workspace_list.map((ws) => ws.id).filter((id): id is string => Boolean(id)))
if (!accessibleIds.has(workspaceId)) {
const fallbackId = workspace_list.find((ws) => ws.id)?.id ?? 'default'
if (fallbackId !== workspaceId) {
return { name: to.name, params: { ...to.params, workspaceId: fallbackId }, replace: true }
}
}
}
}

// 当前路由有权限,放行
Expand Down
Loading