feat(前端): 公司管理加角色内在闸门(注册表+守卫+剪枝)
- 新建 src/config/company-scope.ts:SUPER_ADMIN_ONLY_MENU_KEYS=['admin_companies'] 与 COMPANY_SCOPED_PAGES(批次 1 的 8 页口径清单,后续任务的唯一分母) - routes.ts:AdminPageDef 加 superAdminOnly/companyScoped;公司管理标 superAdminOnly: true, 8 个 A 类页标 companyScoped: true,C 类两页显式写 false(声明而非留空) - helpers.ts:pruneSuperAdminOnly 纯函数(超管原样返回,非超管递归剪掉专属节点) - router/index.ts:菜单授权之外补一条与菜单树无关的角色判定 - admin-session.ts:菜单树唯一写点内接剪枝(顺序仍在 fetchCurrentUser 之后) - 新增 tests/company-super-admin-only.test.ts 5 支护栏 - task-29 的主路径断言随唯一写点改写(原断言只认 canonicalize 裸赋值, 剪枝并入同一写点后必然失配;改为同时要求 prune + canonicalize,意图不降反强)
This commit is contained in:
@@ -3,7 +3,7 @@ import { fetchAdminMenuTree, fetchCurrentUser, logout } from '@/api/session'
|
||||
import { joinAdminPath } from '@/config/app'
|
||||
import type { AdminMenuNode, AdminUser } from '@/types/admin'
|
||||
import { isSuperAdminRole } from '@/types/admin'
|
||||
import { firstVisiblePath } from '@/router/helpers'
|
||||
import { firstVisiblePath, pruneSuperAdminOnly } from '@/router/helpers'
|
||||
import { canonicalizeMenuTree } from '@/router/menu-route-map'
|
||||
|
||||
export const useAdminSessionStore = defineStore('admin-session', {
|
||||
@@ -27,7 +27,11 @@ export const useAdminSessionStore = defineStore('admin-session', {
|
||||
this.error = ''
|
||||
try {
|
||||
this.user = await fetchCurrentUser()
|
||||
this.menuTree = canonicalizeMenuTree(await fetchAdminMenuTree())
|
||||
// 剪枝是角色内在闸门的第三处(注册表 + 守卫 + 菜单树),必须在 this.user 赋值之后。
|
||||
this.menuTree = pruneSuperAdminOnly(
|
||||
canonicalizeMenuTree(await fetchAdminMenuTree()),
|
||||
isSuperAdminRole(this.user?.role),
|
||||
)
|
||||
this.initialized = true
|
||||
} catch (error) {
|
||||
this.error = error instanceof Error ? error.message : '后台初始化失败'
|
||||
|
||||
Reference in New Issue
Block a user