feat(admin): 侧边栏顶部加亚马逊/京东平台tab切换(2026-11-16 用户定案「不混一起」)
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
/** 平台 tab 口径的唯一清单(2026-11-16 用户定案「亚马逊/京东不混一起」)。
|
||||
* 仿 company-scope.ts 的形状:单独成文件而不是塞进 routes.ts——护栏用例要从这里
|
||||
* 反读清单与注册表对撞,放在一起会成环。 */
|
||||
|
||||
export type PlatformTabId = 'amazon' | 'jd'
|
||||
|
||||
export interface PlatformTabDef {
|
||||
id: PlatformTabId
|
||||
label: string
|
||||
}
|
||||
|
||||
/** 侧边栏顶部平台 tab 的固定顺序:亚马逊在前(存量主体),京东在后。 */
|
||||
export const PLATFORM_TABS: readonly PlatformTabDef[] = [
|
||||
{ id: 'amazon', label: '亚马逊' },
|
||||
{ id: 'jd', label: '京东' },
|
||||
]
|
||||
|
||||
/** 京东侧菜单的 menuKey 唯一清单(与 routes.ts 的 menuKey 逐字一致,用例钉住)。
|
||||
* 2026-11-16 用户按截图圈定四项;后续京东新页面上线把 key 加进这里即可,
|
||||
* 清单外的 key(含店铺管理/生成记录等存量页)一律归亚马逊。 */
|
||||
export const JD_MENU_KEYS: readonly string[] = [
|
||||
'admin_users',
|
||||
'admin_group_manage',
|
||||
'admin_companies',
|
||||
'admin_jd_database',
|
||||
]
|
||||
|
||||
/** menuKey → 平台归属:命中京东清单即 jd,其余(未知 key 在内)默认亚马逊。 */
|
||||
export function platformOfMenuKey(key: string): PlatformTabId {
|
||||
return JD_MENU_KEYS.includes(key) ? 'jd' : 'amazon'
|
||||
}
|
||||
@@ -6,6 +6,10 @@ import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
import { joinAdminPath } from '@/config/app'
|
||||
import { pageTitleOf, topbarUserOf } from '@/layout/topbar-model'
|
||||
import { groupKeysForActive, toSidebarEntries } from '@/layout/menu-mapper'
|
||||
import { filterMenuTreeByPlatform, visiblePlatformsFor } from '@/layout/platform-menu-filter'
|
||||
import { PLATFORM_TABS, platformOfMenuKey } from '@/config/platform-scope'
|
||||
import { usePlatformTabStore } from '@/stores/platform-tab'
|
||||
import { firstVisiblePath } from '@/router/helpers'
|
||||
import {
|
||||
EMPTY_MENU_DESCRIPTION,
|
||||
EMPTY_MENU_TITLE,
|
||||
@@ -31,7 +35,15 @@ const router = useRouter()
|
||||
const session = useAdminSessionStore()
|
||||
|
||||
const activePath = computed(() => route.path)
|
||||
const menuEntries = computed(() => toSidebarEntries(session.menuTree))
|
||||
const platformTab = usePlatformTabStore()
|
||||
// 平台 tab(亚马逊/京东,2026-11-16「不混」定案)只做显示分组:准入仍是 session.menuTree
|
||||
// (后端按权限裁剪)+路由守卫,这里只把当前用户已被授权的菜单按平台分侧展示。
|
||||
const menuEntries = computed(() =>
|
||||
toSidebarEntries(filterMenuTreeByPlatform(session.menuTree, platformTab.active)),
|
||||
)
|
||||
const visibleTabIds = computed(() => visiblePlatformsFor(session.menuTree))
|
||||
const visibleTabDefs = computed(() => PLATFORM_TABS.filter((tab) => visibleTabIds.value.includes(tab.id)))
|
||||
const showPlatformTabs = computed(() => visibleTabIds.value.length > 1)
|
||||
const openedKeys = computed(() => groupKeysForActive(menuEntries.value, route.path))
|
||||
const emptyMenu = computed(() => shouldShowEmptyMenu(menuEntries.value.length > 0, session.loading, session.initialized))
|
||||
const pageTitle = computed(() => pageTitleOf(route.meta.title))
|
||||
@@ -45,6 +57,30 @@ watch(
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
// 直达 URL/面包屑跳到另一平台的页面时,tab 指示自动跟过去(与侧边栏保持一致)。
|
||||
watch(
|
||||
() => route.meta.menuKey as string | undefined,
|
||||
(menuKey) => {
|
||||
if (!menuKey) return
|
||||
const target = platformOfMenuKey(menuKey)
|
||||
if (target !== platformTab.active && visibleTabIds.value.includes(target)) {
|
||||
platformTab.setActive(target)
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
// 切到另一侧 tab 时当前页多半不在那边:跳到该侧第一个可见页;该侧为空(tab 不可见)则不动。
|
||||
watch(
|
||||
() => platformTab.active,
|
||||
(tab) => {
|
||||
const menuKey = route.meta.menuKey as string | undefined
|
||||
if (!menuKey || platformOfMenuKey(menuKey) === tab) return
|
||||
const first = firstVisiblePath(filterMenuTreeByPlatform(session.menuTree, tab))
|
||||
if (first) void router.replace(first)
|
||||
},
|
||||
)
|
||||
|
||||
async function signOut() {
|
||||
try {
|
||||
await runLogout({
|
||||
@@ -77,6 +113,19 @@ async function signOut() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<nav v-if="showPlatformTabs" class="admin-platform-tabs" role="tablist" aria-label="按平台切换菜单">
|
||||
<button
|
||||
v-for="tab in visibleTabDefs"
|
||||
:key="tab.id"
|
||||
type="button"
|
||||
role="tab"
|
||||
class="admin-platform-tab"
|
||||
:class="{ 'is-active': tab.id === platformTab.active }"
|
||||
:aria-selected="tab.id === platformTab.active"
|
||||
@click="platformTab.setActive(tab.id)"
|
||||
>{{ tab.label }}</button>
|
||||
</nav>
|
||||
|
||||
<el-scrollbar class="admin-menu-scroll">
|
||||
<el-menu :default-active="activePath" :default-openeds="openedKeys" router class="admin-menu">
|
||||
<template v-for="entry in menuEntries" :key="entry.key">
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import type { AdminMenuNode } from '../types/admin'
|
||||
import { PLATFORM_TABS, platformOfMenuKey } from '../config/platform-scope.ts'
|
||||
import type { PlatformTabId } from '../config/platform-scope.ts'
|
||||
import { firstVisiblePath } from '../router/helpers.ts'
|
||||
|
||||
/**
|
||||
* 按平台 tab 过滤后端菜单树(2026-11-16「亚马逊/京东不混」):**只做显示分组,不做鉴权**——
|
||||
* 准入仍由 session.menuTree(后端按权限裁剪)与路由守卫负责,这里只是把当前用户已被授权的
|
||||
* 菜单按平台分到两个 tab 下展示。
|
||||
* 规则:叶子按 platformOfMenuKey(key) 留下;分组节点(admin_group_*)自身的 key 不参与平台
|
||||
* 判定,按「留住的子项数 > 0」决定去留——否则京东 tab 下「账号与权限」这类混合分组会被整组
|
||||
* 误剪。节点的 key/name/route/children 形状原样透传(浅拷贝不改写),toSidebarEntries、
|
||||
* groupKeysForActive 与面包屑都不受影响。
|
||||
*/
|
||||
export function filterMenuTreeByPlatform(
|
||||
nodes: AdminMenuNode[] | null | undefined,
|
||||
platform: PlatformTabId,
|
||||
): AdminMenuNode[] {
|
||||
const filtered: AdminMenuNode[] = []
|
||||
for (const node of nodes || []) {
|
||||
const children = filterMenuTreeByPlatform(node.children, platform)
|
||||
if (children.length > 0) {
|
||||
filtered.push({ ...node, children })
|
||||
continue
|
||||
}
|
||||
if ((node.children || []).length > 0) continue
|
||||
if (platformOfMenuKey(node.key || '') === platform) filtered.push({ ...node })
|
||||
}
|
||||
return filtered
|
||||
}
|
||||
|
||||
/** 当前用户在哪些平台下至少有一个可点页面(tab 显示依据);顺序固定随 PLATFORM_TABS。
|
||||
* 「可点」沿用 firstVisiblePath 这一把尺子(有 route 即可点),不另写第二处判定。 */
|
||||
export function visiblePlatformsFor(nodes: AdminMenuNode[] | null | undefined): PlatformTabId[] {
|
||||
return PLATFORM_TABS
|
||||
.filter((tab) => firstVisiblePath(filterMenuTreeByPlatform(nodes, tab.id)) !== '')
|
||||
.map((tab) => tab.id)
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
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)
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -65,6 +65,22 @@ button, input, textarea, select { font: inherit; }
|
||||
.admin-brand-copy strong { color: var(--admin-text); font-size: 15px; font-weight: 600; letter-spacing: .5px; white-space: nowrap; }
|
||||
.admin-brand-copy span { color: #77899b; font-size: 11px; white-space: nowrap; }
|
||||
|
||||
/* 侧边栏顶部平台 tab(亚马逊/京东,2026-11-16「不混」定案):纯显示分组,只对当前用户
|
||||
* 已授权菜单分侧展示;单侧无可见菜单时整条隐藏(AdminLayout showPlatformTabs)。 */
|
||||
.admin-platform-tabs { display: flex; gap: 6px; padding: 10px 12px 0; }
|
||||
.admin-platform-tab {
|
||||
flex: 1; height: 34px; text-align: center; font-size: 13px; font-weight: 600;
|
||||
color: var(--admin-sidebar-text); background: transparent;
|
||||
border: 1px solid var(--admin-border); border-radius: 9px; cursor: pointer;
|
||||
}
|
||||
.admin-platform-tab:hover { color: #1e3b57; background: rgba(47, 93, 139, 0.16); }
|
||||
.admin-platform-tab.is-active {
|
||||
color: var(--admin-primary-strong);
|
||||
background: linear-gradient(180deg, #dce9f5, #edf4fa);
|
||||
border-color: #b6cbe0;
|
||||
box-shadow: inset 0 2px 0 #5f85ad;
|
||||
}
|
||||
|
||||
.admin-menu-scroll { flex: 1; padding: 12px 10px; }
|
||||
.admin-menu { border-right: 0; background: transparent; }
|
||||
.admin-menu .el-sub-menu__title,
|
||||
|
||||
Reference in New Issue
Block a user