Files
crawler-plugin/admin-frontend-vue/src/stores/platform-tab.ts
T
huangzd1997 2a8bdd7d29 feat(platform): 后管与桌面端菜单按用户平台隔离(2026-11-18 用户口径「隔离下除 admin 外,京东用户只看京东菜单、亚马逊看不了」)——AdminMenuPlatformScope 成为菜单 key→平台归属唯一出处(京东独占 admin_jd_database+app 三件;双侧六件=账号域基础三页+本笔补侧的菜单权限配置/密钥管理/密钥用量统计;未知 key 默认 amazon 与前端 platform-scope 同形;platform null/空白归一 amazon=列 DEFAULT 同口径,不把「没带」读成京东侧全拦),filterMenuVosByPlatform 扁平过滤保留祖先链保组树完整、分组节点按存活子项去留(与前端 filterMenuTreeNodesByPlatform 同形);裁剪只挂三个下发出口(current-user/menus 非站点超管按 users.platform 收窄+登录 VO adminColumns/appColumns 双树=后管+桌面端一起)与逐页门(requireConsolePageAccess 平台门置于 isAdmin 直通之前,越侧 key 一律 403),红线=不动 getUserColumnPermissions 本体(授权编辑读接口与整树替换保存语义不变、授权行保留);current-user 增 platform 键;前端 allowedPlatformsForUser(超管随菜单树分布、其余锁 users.platform 侧、未知/缺省兜底 amazon、交集空仍锁死本人平台)+AdminLayout watch clamp(localStorage 残留另一侧自动归位、当前页在被禁侧跳回本人平台第一可见页、单侧时 tab 条整个隐藏)+platform-tab.syncToAllowed;app 树 37 key 全集核对无平台无关 key(withdraw=取款挂品牌运营工具、erp/purchase 挂后勤工具)。判据:AdminMenuPlatformScopeTest 11+ConsolePageTest +5 平台门+AdminConsoleCurrentUserMenusPlatformTest 3+AuthServicePlatformMenuTest 3+CompanyTest +1 platform 键=43 例绿;前端 platform-menu-filter 9/9(+2)、mount admin-layout-platform-lock 4/4、授权树过滤对齐扩双侧;vue-tsc rc=0;node --test 1937/1938(唯一红=在册 B116-03 ENOENT);vitest mount 184/184;mvn -o test-compile rc=0;快检后端 2 红格=环境假红(缺 Git 工具链 PATH,前置后 30/30 绿)、四面可读棘轮红=PermissionMenuService 1661→1676 行随本笔点名记账(ops 仓同窗);桌面端界面随 appColumns 下发生效,客户端出包另窗
2026-11-18 01:28:49 +08:00

51 lines
1.8 KiB
TypeScript

import { defineStore } from 'pinia'
import { PLATFORM_TABS } from '@/config/platform-scope'
import type { PlatformTabId } from '@/config/platform-scope'
const STORAGE_KEY = 'admin-platform-tab'
const DEFAULT_TAB: PlatformTabId = 'amazon'
function isKnownTab(id: unknown): id is PlatformTabId {
return PLATFORM_TABS.some((tab) => tab.id === id)
}
/** 读取持久化偏好;无存储/值非法/存储不可用一律回落亚马逊(隐私模式不阻断交互)。 */
function readStoredTab(): PlatformTabId {
try {
const raw = typeof localStorage === 'undefined' ? null : localStorage.getItem(STORAGE_KEY)
return isKnownTab(raw) ? raw : DEFAULT_TAB
} catch {
return DEFAULT_TAB
}
}
function writeStoredTab(id: PlatformTabId): void {
try {
if (typeof localStorage !== 'undefined') localStorage.setItem(STORAGE_KEY, id)
} catch {
// localStorage 不可用(隐私模式等)时忽略
}
}
/** 侧边栏平台 tab(亚马逊/京东)状态:纯显示分组不参与鉴权(2026-11-16 用户定案)。
* 菜单可见性仍由 session.menuTree(后端按权限裁剪)决定,这里只记「当前看哪一侧」。 */
export const usePlatformTabStore = defineStore('platform-tab', {
state: () => ({
active: readStoredTab(),
}),
actions: {
setActive(id: PlatformTabId) {
this.active = id
writeStoredTab(id)
},
/** 平台锁定(2026-11-18 用户口径「非站点超管只看自己平台侧」):允许集收敛时把 active
* 归位——localStorage 残留的另一侧(超管在同一浏览器切过 tab)自动回落本人平台;
* 允许集为空(会话未就位)不动。 */
syncToAllowed(allowed: readonly PlatformTabId[]) {
if (allowed.length > 0 && !allowed.includes(this.active)) {
this.setActive(allowed[0])
}
},
},
})