fix(admin-vue): 密钥管理/用量统计两菜单扩京东侧+两页按平台 tab 隔离取数(2026-11-22 用户口径「后台京东tab下也要加密钥管理和密钥统计量 数据不要弄过来」)
- platform-scope.ts BOTH_PLATFORM_MENU_KEYS 加 admin_user_secrets/admin_user_secret_usage(与后端 AdminMenuPlatformScope.BOTH_MENU_KEYS 逐字同源;侧栏分组/授权树/AdminLayout 切 tab 自动跟随)
- user-secrets.ts/user-secret-usage.ts 查询加 platform 入参(同 companyId 形状:白名单构造不收,只认原始入参)
- 两页 fetch 带 platform: platformTab.active+watch(platformTab.active) 重置关键字/页码并重取(UsersPage 同形)
- company-tab-wiring PLATFORM_WIRING_PINS 钉 api/fetch/watch 三形状(含正负判据自证);platform-menu-filter/menu-manage-platform/admin-layout-platform-lock 三测试期望同步(node 21 绿+mount 6 绿+vue-tsc rc=0)
随下一 admin-vue 窗上线;与后端 4819b243 必须同窗发布(单发一侧=侧栏分组与权限门错位)
This commit is contained in:
@@ -33,6 +33,8 @@ export interface UserSecretUsageQuery {
|
||||
groupId?: number
|
||||
/** 公司 tab 的当前口径;不传 = 后端按操作者自己的公司(批次 1 里非超管只有这一家)。 */
|
||||
companyId?: number | null
|
||||
/** 平台 tab(amazon/jd):按 users.platform 过滤(2026-11-22 京东侧新增);不传 = 旧行为不筛。 */
|
||||
platform?: string
|
||||
page: number
|
||||
pageSize: number
|
||||
}
|
||||
@@ -47,6 +49,8 @@ export async function fetchUserSecretUsage(params: UserSecretUsageQuery): Promis
|
||||
// 用 `!= null` 而不是上面几行的 truthy 写法:这一项类型是 `number | null`(null = 没选公司)。
|
||||
// 后端把 company_id<=0 归一成「没选公司」(DataReadScope.readScope 第一行),0 与缺失等价,按类型判即可。
|
||||
if (params.companyId != null) query.company_id = params.companyId
|
||||
// 平台值(2026-11-22)同 companyId 形状:白名单构造不收,只认原始入参。
|
||||
if (params.platform) query.platform = params.platform
|
||||
const { data } = await http.get('/api/admin/user-secret-usage', { params: query })
|
||||
return unwrap<AdminUserSecretUsagePage>(data)
|
||||
}
|
||||
|
||||
@@ -117,6 +117,8 @@ export interface UserSecretQuery {
|
||||
groupId?: number
|
||||
/** 公司 tab 的当前口径;不传 = 后端按操作者自己的公司(批次 1 里非超管只有这一家)。 */
|
||||
companyId?: number | null
|
||||
/** 平台 tab(amazon/jd):按 users.platform 过滤(2026-11-22 京东侧新增);不传 = 旧行为不筛。 */
|
||||
platform?: string
|
||||
page: number
|
||||
pageSize: number
|
||||
}
|
||||
@@ -130,6 +132,8 @@ export async function fetchUserSecretList(params: UserSecretQuery): Promise<Admi
|
||||
// 用 `!= null` 而不是上面几行的 truthy 写法:这一项类型是 `number | null`(null = 没选公司)。
|
||||
// 后端把 company_id<=0 归一成「没选公司」(DataReadScope.readScope 第一行),0 与缺失等价,按类型判即可。
|
||||
if (params.companyId != null) query.company_id = params.companyId
|
||||
// 平台值(2026-11-22)同 companyId 形状:白名单构造不收,只认原始入参。
|
||||
if (params.platform) query.platform = params.platform
|
||||
const { data } = await http.get('/api/admin/user-secrets', { params: query })
|
||||
return unwrap<AdminUserSecretPage>(data)
|
||||
}
|
||||
|
||||
@@ -38,12 +38,16 @@ export const JD_APP_MENU_KEYS: readonly string[] = [
|
||||
]
|
||||
|
||||
/** 双侧共用账号管理页面:用户、分组、公司与菜单权限配置。
|
||||
* 密钥管理/密钥用量统计按 2026-11-18 截图口径收回亚马逊侧。 */
|
||||
* 密钥管理/密钥用量统计(admin_user_secrets/admin_user_secret_usage)按 2026-11-22 用户拍板
|
||||
* 扩回双侧(「后台京东 tab 下也要加密钥管理和密钥统计量」);页面数据按当前平台 tab 过滤
|
||||
* (platform 查询参数,后端 AdminUserSecretQuery.platform),菜单归属与数据隔离是两层。 */
|
||||
export const BOTH_PLATFORM_MENU_KEYS: readonly string[] = [
|
||||
'admin_users',
|
||||
'admin_group_manage',
|
||||
'admin_companies',
|
||||
'admin_columns',
|
||||
'admin_user_secrets',
|
||||
'admin_user_secret_usage',
|
||||
]
|
||||
|
||||
/** menuKey → 平台归属清单(唯一判定出口):京东独占(后台或桌面端清单)→ ['jd'];
|
||||
|
||||
@@ -10,11 +10,13 @@ import {
|
||||
import type { GroupOption } from '@/api/user-secrets'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
import { useCompanyTabStore } from '@/stores/company-tab'
|
||||
import { usePlatformTabStore } from '@/stores/platform-tab'
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
import LoadFailureBar from '@/components/LoadFailureBar.vue'
|
||||
|
||||
const session = useAdminSessionStore()
|
||||
const companyTab = useCompanyTabStore()
|
||||
const platformTab = usePlatformTabStore()
|
||||
/** 仅超管需要分组维度:非超管数据由后端裁剪到本人分组,分组筛选/列一律不展示。 */
|
||||
const isSuperAdmin = computed(() => session.isSuperAdmin)
|
||||
|
||||
@@ -57,6 +59,8 @@ async function load() {
|
||||
keyword: keyword.value.trim() || undefined,
|
||||
groupId: groupFilter.value || undefined,
|
||||
companyId: companyTab.requestCompanyId,
|
||||
// 平台 tab(2026-11-22)与公司同形状:由上方 tab 决定而不是用户填的筛选项,每次现取。
|
||||
platform: platformTab.active,
|
||||
page: page.value,
|
||||
pageSize: pageSize.value,
|
||||
})
|
||||
@@ -80,6 +84,14 @@ async function load() {
|
||||
// 切公司 = 重新取数。不重取的页 = tab 在那页上是假的(G1 的 pageFiles 断言盯着这条)。
|
||||
watch(() => companyTab.activeId, () => void load())
|
||||
|
||||
// 切平台 tab(2026-11-22 密钥两页进京东侧)= 同 UsersPage 的重取数:汇总卡/列表都按平台过滤,
|
||||
// 关键字/翻页跨平台无意义,一并清掉。
|
||||
watch(() => platformTab.active, () => {
|
||||
keyword.value = ''
|
||||
page.value = 1
|
||||
void load()
|
||||
})
|
||||
|
||||
function search() {
|
||||
page.value = 1
|
||||
load()
|
||||
|
||||
@@ -32,12 +32,14 @@ import {
|
||||
} from './user-secret-model.ts'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
import { useCompanyTabStore } from '@/stores/company-tab'
|
||||
import { usePlatformTabStore } from '@/stores/platform-tab'
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
import { openAdminConfirm } from '@/components/admin-confirm'
|
||||
import LoadFailureBar from '@/components/LoadFailureBar.vue'
|
||||
|
||||
const session = useAdminSessionStore()
|
||||
const companyTab = useCompanyTabStore()
|
||||
const platformTab = usePlatformTabStore()
|
||||
/** 仅超管需要分组维度:非超管数据由后端裁剪到本人分组,分组筛选/列一律不展示。 */
|
||||
const isSuperAdmin = computed(() => session.isSuperAdmin)
|
||||
|
||||
@@ -144,6 +146,8 @@ async function load() {
|
||||
checkStatus: statusFilter.value || undefined,
|
||||
groupId: groupFilter.value || undefined,
|
||||
companyId: companyTab.requestCompanyId,
|
||||
// 平台 tab(2026-11-22)与公司同形状:由上方 tab 决定而不是用户填的筛选项,每次现取。
|
||||
platform: platformTab.active,
|
||||
page: page.value,
|
||||
pageSize: pageSize.value,
|
||||
})
|
||||
@@ -215,6 +219,14 @@ function proxyLineOf(userId: number) {
|
||||
// 切公司 = 重新取数。不重取的页 = tab 在那页上是假的(G1 的 pageFiles 断言盯着这条)。
|
||||
watch(() => companyTab.activeId, () => void load())
|
||||
|
||||
// 切平台 tab(2026-11-22 密钥两页进京东侧)= 同 UsersPage 的重取数:列表按平台过滤,
|
||||
// 关键字/翻页跨平台无意义,一并清掉。
|
||||
watch(() => platformTab.active, () => {
|
||||
keyword.value = ''
|
||||
page.value = 1
|
||||
void load()
|
||||
})
|
||||
|
||||
function search() {
|
||||
page.value = 1
|
||||
load()
|
||||
|
||||
@@ -1043,3 +1043,48 @@ test('公司维度不得回流:品牌库/商品类目/京东数据库已定案
|
||||
`${file} 重新引回了公司 tab store,而它对应的 tab 条已经摘掉`)
|
||||
}
|
||||
})
|
||||
|
||||
// ── 平台 tab 接线(2026-11-22 密钥两页进京东侧)─────────────────────────────────
|
||||
// 与 company_id 复评 I-2 同一课:tab 画了、请求发了、参数没有 = 静默失效。两页的
|
||||
// platform 值必须现取页面 platformTab store;api 侧只认本函数自己的 params.platform
|
||||
//(白名单构造不收中间对象——取自归一化中间对象是 TS 绿、运行时恒 undefined 的洞)。
|
||||
|
||||
const PLATFORM_WIRING_PINS = [
|
||||
{
|
||||
menuKey: 'admin_user_secrets',
|
||||
apiFile: 'src/api/user-secrets.ts',
|
||||
apiShape: /query\.platform\s*=\s*params\.platform\b/,
|
||||
pageFile: 'src/pages/account/UserSecretsPage.vue',
|
||||
fetchShape: /platform:\s*platformTab\.active/,
|
||||
watchShape: /watch\(\(\)\s*=>\s*platformTab\.active/,
|
||||
},
|
||||
{
|
||||
menuKey: 'admin_user_secret_usage',
|
||||
apiFile: 'src/api/user-secret-usage.ts',
|
||||
apiShape: /query\.platform\s*=\s*params\.platform\b/,
|
||||
pageFile: 'src/pages/account/UserSecretUsagePage.vue',
|
||||
fetchShape: /platform:\s*platformTab\.active/,
|
||||
watchShape: /watch\(\(\)\s*=>\s*platformTab\.active/,
|
||||
},
|
||||
] as const
|
||||
|
||||
test('平台 tab 接线(2026-11-22):密钥两页的 platform 必须现取 platformTab.active,切 tab 必须 watch 重取', () => {
|
||||
// 判据自证(全局约束 15:反向钉不许独自成立)——正样本匹配、取错根不匹配。
|
||||
assert.ok(PLATFORM_WIRING_PINS[0].apiShape.test('if (params.platform) query.platform = params.platform'),
|
||||
'api 判据连正样本都匹配不出 ⇒ 恒绿')
|
||||
assert.equal(PLATFORM_WIRING_PINS[0].apiShape.test('if (params.platform) query.platform = normalized.platform'), false,
|
||||
'api 判据对「取自归一化中间对象」也放行 ⇒ 取值口失守(复评 I-2 的洞)')
|
||||
assert.ok(PLATFORM_WIRING_PINS[0].watchShape.test('watch(() => platformTab.active, () => { void load() })'),
|
||||
'watch 判据连正样本都匹配不出 ⇒ 恒绿')
|
||||
|
||||
for (const pin of PLATFORM_WIRING_PINS) {
|
||||
const api = stripComments(read(pin.apiFile))
|
||||
assert.ok(pin.apiShape.test(api),
|
||||
`${pin.apiFile} 的 platform 右半边不是本函数自己的 params.platform(${pin.menuKey})——tab 画了、参数没有或取错根`)
|
||||
const page = stripComments(read(pin.pageFile))
|
||||
assert.ok(pin.fetchShape.test(page),
|
||||
`${pin.pageFile} 的列表请求没带 platform: platformTab.active(${pin.menuKey})——切平台 tab 数据不换`)
|
||||
assert.ok(pin.watchShape.test(page),
|
||||
`${pin.pageFile} 没有 watch(platformTab.active) 重取数(${pin.menuKey})——tab 在那页上是假的`)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -29,7 +29,7 @@ vi.mock('@/layout/OperationGuide.vue', () => ({ default: { template: '<div class
|
||||
vi.mock('@/layout/CompanyTabs.vue', () => ({ default: { template: '<div class="company-tabs-stub" />' } }))
|
||||
vi.mock('@/layout/GlobalErrorContainer.vue', () => ({ default: { template: '<div class="error-stub" />' } }))
|
||||
|
||||
/** 后端裁剪后下发给京东用户的树形状:双侧账号域六页 + 京东数据库(无任何亚马逊叶子)。 */
|
||||
/** 后端裁剪后下发给京东用户的树形状:双侧账号域(含 2026-11-22 扩双侧的密钥两页)+ 京东数据库(无任何亚马逊叶子)。 */
|
||||
const JD_TREE: AdminMenuNode[] = [
|
||||
{
|
||||
key: 'admin_group_account',
|
||||
@@ -112,10 +112,10 @@ describe('AdminLayout × 平台锁定(2026-11-18)', () => {
|
||||
const texts = wrapper.findAll('.admin-menu .el-menu-item').map((item) => item.text())
|
||||
expect(texts).toContain('京东数据库')
|
||||
expect(texts).not.toContain('查询ASIN')
|
||||
// 共用菜单配置保留,两个密钥入口仅亚马逊侧可见。
|
||||
// 共用菜单配置保留;密钥两页 2026-11-22 扩双侧,京东用户树里照画(数据按 users.platform 过滤)。
|
||||
expect(texts).toContain('菜单权限配置')
|
||||
expect(texts).not.toContain('密钥管理')
|
||||
expect(texts).not.toContain('密钥用量统计')
|
||||
expect(texts).toContain('密钥管理')
|
||||
expect(texts).toContain('密钥用量统计')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
|
||||
@@ -104,6 +104,13 @@ async function clickNextPage(page: VueWrapper<Element>) {
|
||||
await flushPromises()
|
||||
}
|
||||
|
||||
async function clickPrevPage(page: VueWrapper<Element>) {
|
||||
const prev = page.findAll('.old-pagination button').find((button) => button.text() === '上一页')
|
||||
expect(prev).toBeTruthy()
|
||||
await prev!.trigger('click')
|
||||
await flushPromises()
|
||||
}
|
||||
|
||||
/** 通过真实分页收齐表格行,避免只检查首屏而漏掉后页的跨平台菜单。 */
|
||||
async function allVisibleNames(page: VueWrapper<Element>) {
|
||||
const names = visibleNames(page)
|
||||
@@ -130,21 +137,24 @@ async function pickMenuType(page: VueWrapper<Element>, label: string) {
|
||||
}
|
||||
|
||||
describe('菜单权限配置页的平台隔离', () => {
|
||||
it('京东表格排除视频图片和密钥,保留账号基础菜单、数据管理祖先及京东工具', async () => {
|
||||
it('京东表格排除视频图片,保留账号基础菜单、密钥两页(2026-11-22 扩双侧)、数据管理祖先及京东工具', async () => {
|
||||
usePlatformTabStore().setActive('jd')
|
||||
const page = await mountMenus()
|
||||
|
||||
expect(await allVisibleNames(page)).toEqual([
|
||||
'账号与权限管理', '菜单权限管理', '用户管理', '分组管理', '公司管理',
|
||||
'密钥管理', '密钥用量统计',
|
||||
'数据管理', '京东数据库', '京东工具台', '京东店铺数据采集', '京东商品上架',
|
||||
])
|
||||
// 12 条翻页收齐名单后 DOM 停在末页;京东数据库在第 1 页,翻回去再做行级断言。
|
||||
await clickPrevPage(page)
|
||||
const databaseRow = page.findAll('tbody tr')
|
||||
.find((row) => row.find('.menu-name-text').text() === '京东数据库')
|
||||
expect(databaseRow!.findAll('td')[5].text()).toBe('数据管理')
|
||||
expect(databaseRow!.find('.column-child-mark').exists()).toBe(true)
|
||||
})
|
||||
|
||||
it('从京东切回亚马逊,视频图片和密钥仍在,京东数据库及京东工具均消失', async () => {
|
||||
it('从京东切回亚马逊,视频图片和密钥仍在(密钥两页双侧共见),京东数据库及京东工具均消失', async () => {
|
||||
usePlatformTabStore().setActive('jd')
|
||||
const page = await mountMenus()
|
||||
usePlatformTabStore().setActive('amazon')
|
||||
@@ -175,11 +185,13 @@ describe('菜单权限配置页的平台隔离', () => {
|
||||
|
||||
expect(nameInput.element.value).toBe('')
|
||||
expect(page.findAll('.menus-filter-row .el-select__selected-item').map((item) => item.text())).toContain('全部')
|
||||
expect(page.get('.page-cur').text()).toBe('第 1 / 1 页')
|
||||
expect(page.get('.page-total').text()).toBe('共 10 条')
|
||||
// 2026-11-22 密钥两页扩双侧后京东侧 12 条(页大小 10),首页画前 10 行。
|
||||
expect(page.get('.page-cur').text()).toBe('第 1 / 2 页')
|
||||
expect(page.get('.page-total').text()).toBe('共 12 条')
|
||||
expect(visibleNames(page)).toEqual([
|
||||
'账号与权限管理', '菜单权限管理', '用户管理', '分组管理', '公司管理',
|
||||
'数据管理', '京东数据库', '京东工具台', '京东店铺数据采集', '京东商品上架',
|
||||
'密钥管理', '密钥用量统计',
|
||||
'数据管理', '京东数据库', '京东工具台',
|
||||
])
|
||||
expect(menuApi.loadMenuManageTree).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
@@ -25,7 +25,7 @@ const node = (key: string, name: string, route?: string, children?: AdminMenuNod
|
||||
return out
|
||||
}
|
||||
|
||||
/** 侧边栏实测形状的缩影:账号与权限(混编京东侧账号菜单与亚马逊侧配置/密钥菜单)+数据管理。 */
|
||||
/** 侧边栏实测形状的缩影:账号与权限(双侧账号域+密钥两页,2026-11-22 扩双侧)+数据管理。 */
|
||||
const TREE: AdminMenuNode[] = [
|
||||
node('admin_group_account', '账号与权限', undefined, [
|
||||
node('admin_columns', '菜单权限配置', '/account/menus'),
|
||||
@@ -60,11 +60,12 @@ test('menuKey 平台归属:京东独占即 [jd],双侧清单即两侧,其
|
||||
assert.deepEqual(platformsOfMenuKey(''), ['amazon'])
|
||||
})
|
||||
|
||||
test('京东 tab:账号与权限保留账号管理四项,隐藏密钥管理与用量统计;数据管理保留京东数据库', () => {
|
||||
test('京东 tab:账号与权限保留账号管理四项与密钥两页(2026-11-22 扩双侧);数据管理保留京东数据库', () => {
|
||||
const filtered = filterMenuTreeByPlatform(TREE, 'jd')
|
||||
assert.deepEqual(filtered.map((item) => item.key), ['admin_group_account', 'admin_group_data'])
|
||||
assert.deepEqual(groupChildKeys(filtered, 'admin_group_account'),
|
||||
['admin_columns', 'admin_users', 'admin_group_manage', 'admin_companies'])
|
||||
['admin_columns', 'admin_users', 'admin_group_manage', 'admin_user_secrets',
|
||||
'admin_user_secret_usage', 'admin_companies'])
|
||||
// 2026-11-17 晚用户口径「京东分类管理并到京东数据库分类编辑里」:分类管理子菜单
|
||||
// (V204)下线,京东侧数据管理组只剩京东数据库一页。
|
||||
assert.deepEqual(groupChildKeys(filtered, 'admin_group_data'), ['admin_jd_database'])
|
||||
@@ -116,7 +117,7 @@ test('tab 显示依据:两侧都有可见页才画 tab 条,仅一侧授权
|
||||
assert.deepEqual(visiblePlatformsFor(null), [])
|
||||
})
|
||||
|
||||
test('平台 tab 定义与菜单清单钉死(防清单漂移):京东独占后台仅数据库一页、双侧共用账号域三页、桌面端京东工具台三件(V209)', () => {
|
||||
test('平台 tab 定义与菜单清单钉死(防清单漂移):京东独占后台仅数据库一页、双侧共用账号域四页+密钥两页(2026-11-22)、桌面端京东工具台三件(V209)', () => {
|
||||
assert.deepEqual(PLATFORM_TABS, [
|
||||
{ id: 'amazon', label: '亚马逊' },
|
||||
{ id: 'jd', label: '京东' },
|
||||
@@ -124,9 +125,10 @@ test('平台 tab 定义与菜单清单钉死(防清单漂移):京东独占
|
||||
// 2026-11-17 晚分类管理(admin_jd_category_manage)并入京东数据库页后从清单摘除。
|
||||
assert.deepEqual([...JD_MENU_KEYS], ['admin_jd_database'])
|
||||
assert.deepEqual([...BOTH_PLATFORM_MENU_KEYS].sort(),
|
||||
['admin_columns', 'admin_companies', 'admin_group_manage', 'admin_users'])
|
||||
assert.deepEqual(platformsOfMenuKey('admin_user_secrets'), ['amazon'])
|
||||
assert.deepEqual(platformsOfMenuKey('admin_user_secret_usage'), ['amazon'])
|
||||
['admin_columns', 'admin_companies', 'admin_group_manage', 'admin_user_secret_usage',
|
||||
'admin_user_secrets', 'admin_users'])
|
||||
assert.deepEqual(platformsOfMenuKey('admin_user_secrets'), ['amazon', 'jd'])
|
||||
assert.deepEqual(platformsOfMenuKey('admin_user_secret_usage'), ['amazon', 'jd'])
|
||||
// 桌面端(app)清单与 JD_MENU_KEYS 分列:app 菜单没有 admin 路由,不得混进
|
||||
// 「与 routes.ts 对撞」的那份(下方护栏用例只扫 JD_MENU_KEYS/BOTH 两份是刻意的)。
|
||||
assert.deepEqual([...JD_APP_MENU_KEYS].sort(), ['jd-collect', 'jd-publish', 'jd_tools'])
|
||||
|
||||
Reference in New Issue
Block a user