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
8 changes: 6 additions & 2 deletions ui/src/layout/LayoutHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@ const canReturnWorkspace = computed(() => isWorkspaceManager.value || isOrdinary

function switchMode() {
if (isWorkspace(props.mode)) {
const workspaceId = getWorkspaceId()
if (workspaceId) localStorage.setItem('workspaceId', workspaceId)
router.push({ name: 'system-home' })
return
}
const workspaceId = user.userInfo?.workspace_list?.[0]?.id || 'default'
// 缓存的工作空间仅用于从系统管理返回工作空间。
const workspaceId = localStorage.getItem('workspaceId') || user.userInfo?.workspace_list?.[0]?.id || 'default'
router.push({ name: 'workspace-home', params: { workspaceId } })
}
</script>
Expand All @@ -78,11 +81,12 @@ function switchMode() {
<span>升级</span>
</el-button>
<el-divider direction="vertical" />
<!-- 保存当前工作空间并进入系统管理 -->
<el-button v-if="isWorkspace(mode) && (isWorkspaceManager || canManageSystem)" class="-mx-1" text @click="switchMode">
<MkIcon name="icon_admin_outlined" />
<span>系统管理</span>
</el-button>
<!-- TODO 只有系统管理员权限没有返回工作空间 -->
<!-- 返回进入系统管理前的工作空间 -->
<el-button v-if="isSystem(mode) && canReturnWorkspace" class="-mx-1" text @click="switchMode">
<MkIcon name="icon_left_outlined" />
<span>返回工作空间</span>
Expand Down
5 changes: 4 additions & 1 deletion ui/src/router/ROUTE_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
Workspace 使用 `AppLayout`,左侧导航根据 `scope: 'workspace'` 对应路由的 `children` 自动生成。

Workspace 根地址为 `/admin/workspace/:workspaceId`。`workspaceId` 只以当前路由参数为准。应用根
地址、登录成功和从 System 返回 Workspace 时统一进入 `/admin/workspace/default`;若当前用户
地址和登录成功时进入 `/admin/workspace/default`。顶部 `LayoutHeader` 切换到 System 时将当前
工作空间 ID 保存到 localStorage 的 `workspaceId`;仅在该组件返回 Workspace 时读取缓存,
无缓存时使用用户首个工作空间或 `default`。退出登录时由 Admin `clearToken()` 清除缓存。
其他位置不得读取该缓存,工作空间上下文仍以路由参数为准。若当前用户
只属于 `workspace_list` 中的部分工作空间且目标 `workspaceId` 不在其中,路由守卫会自动重定向到
其首个可访问工作空间(仅对携带 `workspaceId` 参数的工作空间路由生效)。父路由的 `scope`
会合并到匹配的子路由 `meta` 中。
Expand Down
1 change: 1 addition & 0 deletions ui/src/stores/admin/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const useAuthStore = defineStore('auth', {
clearToken() {
this.token = ''
localStorage.removeItem(TOKEN_STORAGE_KEY)
localStorage.removeItem('workspaceId')
useUserStore().clearCurrentUser()
},
},
Expand Down
Loading