fix(jd): 京东数据库摘除公司 tab(2026-11-16 用户定案「删除掉公司 tab 参考品牌数据库」=品牌库 2026-10-06 先例同形:摘的不只是 tab)——前端 admin_jd_database 退出 COMPANY_SCOPED_PAGES 注册表(定案注释+「公司维度不得回流」SHARED 清单钉住)+routes companyScoped:false+页面卸 companyTab watch 与两处 companyId 发送口(列表 params/类目下拉 fetchJdProductCategories 无参化,JdProductAssignPane 取数同形);后端读侧同窗摘:XML productConds 与 selectProductCategories 的公司维谓词删除(行 company_id 列保留=同步来源标记,JdSchemaContractTest 契约不动)、JdProductMapper.countProducts/selectProductPage 8 参、selectProductCategories() 无参、JdProductQueryService.page 10 参+Filter 去 companyId、AdminJdProductController.page 10 参数+categories(request) 去 superAdminScopedCompanyId 与 DataReadScope 注入、JdCollectController.categories() 调用方同步。判据:vue-tsc rc=0;node --test 9 文件 56/56(wiring SEND_POINTS 27→25、分组 21→19、watch 分母 12→11;menu-route 钉 companyScoped=false;jd-page 钉退出注册表);vitest mount 28/28(删「切公司 Tab 重取」用例,companyId 发送口全改 not.toHaveProperty);mvn -o test-compile rc=0;mvn -o test jd 模块全绿(AdminJdProductControllerTest 20/20:结构判据改「读侧零公司维度_公司tab口径整批摘除」反向钉 company_id/superAdminScopedCompanyId/DataReadScope 不得回潜,行为样本改 requireJdAccess 正门装 200 信封)

This commit is contained in:
2026-11-16 12:05:18 +08:00
parent 3bccc97698
commit 7b853a605e
16 changed files with 240 additions and 295 deletions
@@ -3,7 +3,8 @@
*
* 形态:panel-box + 筛选行(商品编码/标题关键字/分类/分类状态/类目/同步起止 date 对)+
* 查询/重置/店铺分类 + 自绘明细表(点行开详情抽屉)+ OldPagination;
* 公司 tab 切换=清筛选重取(company-tab-wiring 同口径)。
* 公司维度 2026-11-16 整页摘除(「删除掉公司 tab,参考品牌数据库」):页面不消费公司 tab
* store、列表/类目下拉不带 company_id(反向钉在 company-tab-wiring「公司维度不得回流」)。
* 商品状态筛选/列与导出按钮已随 2026-11-15 客户口径从前端下线(后端端点保留);
* 店铺筛选与店铺列同日客户口径「店铺不需要」下线(后端 shop_name 参数同窗撤,店铺仍收详情抽屉)。
* 不用 readFileSync(source-pin-ratchet 对台账外新文件带读点即红),全部走真实挂载断言。
@@ -17,7 +18,6 @@ import { createPinia, setActivePinia, type Pinia } from 'pinia'
import JdDatabasePage from '@/pages/jd/JdDatabasePage.vue'
import JdProductGroupDialog from '@/pages/jd/JdProductGroupDialog.vue'
import { useAdminSessionStore } from '@/stores/admin-session'
import { useCompanyTabStore } from '@/stores/company-tab'
const jdApi = vi.hoisted(() => ({
JD_PRODUCT_ENDPOINT: '/api/admin/jd-products',
@@ -79,7 +79,6 @@ beforeEach(() => {
pinia = createPinia()
setActivePinia(pinia)
useAdminSessionStore().user = { id: 1, username: 'root', role: 'super_admin' }
useCompanyTabStore().setActiveId(1)
jdApi.fetchJdProductGroups.mockResolvedValue([])
jdApi.fetchJdProductCategories.mockResolvedValue([])
confirmMock.mockResolvedValue(true)
@@ -94,13 +93,14 @@ async function mountWith(payload: unknown): Promise<VueWrapper<Element>> {
}
describe('京东数据库页(v1.4 Phase 5)', () => {
it('挂载后按首屏分页参数取列表(pageSize 默认 20、带公司 tab),行数=本页条数', async () => {
it('挂载后按首屏分页参数取列表(pageSize 默认 20、不带公司维度),行数=本页条数', async () => {
const wrapper = await mountWith({ items: [item(1), item(2), item(3)], total: 42, page: 1, pageSize: 20 })
expect(jdApi.fetchJdProductList).toHaveBeenCalledTimes(1)
const firstCall = jdApi.fetchJdProductList.mock.calls[0][0]
expect(firstCall.page).toBe(1)
expect(firstCall.pageSize).toBe(20)
expect(firstCall.companyId).toBe(1)
// 公司维度 2026-11-16 整页摘除:入参层不再有 companyId 键(单参 toHaveProperty 才是「键不存在」的真判据)。
expect(firstCall).not.toHaveProperty('companyId')
expect(wrapper.findAll('tbody tr')).toHaveLength(3)
expect(wrapper.find('.jd-summary').text()).toContain('共 42 条京东商品')
})
@@ -242,12 +242,12 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
syncedFrom: '2026-11-01',
syncedTo: '2026-11-09',
page: 1,
companyId: 1,
})
// 单参 toHaveProperty 才是「键不存在」的真判据(第二参会稀释成值断言):
// 页面 load() 入参已不带这两个键(店铺/商品状态筛选下线)。
// 页面 load() 入参已不带这三个键(店铺/商品状态筛选下线、公司维度 2026-11-16 摘除)。
expect(last).not.toHaveProperty('shopName')
expect(last).not.toHaveProperty('saleStatus')
expect(last).not.toHaveProperty('companyId')
})
it('分组下拉选中即查', async () => { jdApi.fetchJdProductGroups.mockResolvedValue([
@@ -269,13 +269,13 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7', page: 1 })
})
it('类目京麦同款级联面板:一/二级静态导航展开,第三栏=已落库末级全集+行数,点末级即查回第一页', async () => {
it('类目京麦同款级联面板(2026-11-16 真树重做):授权一级 3 个逐级下钻,点末级即查回第一页', async () => {
jdApi.fetchJdProductCategories.mockResolvedValue([
{ name: '艺考形体服', productCount: 120 },
{ name: '啦啦队服', productCount: 8 },
])
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
expect(jdApi.fetchJdProductCategories).toHaveBeenCalledWith(1)
expect(jdApi.fetchJdProductCategories).toHaveBeenCalledWith()
const trigger = wrapper.find('.cat-trigger')
expect(trigger.text()).toContain('全部类目', '未选时触发框显示占位「全部类目」')
@@ -283,58 +283,74 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
await trigger.trigger('click')
expect(wrapper.find('.cat-panel').exists()).toBe(true)
// 第一栏=静态一级导航(京麦同款顺序,服饰内衣在首)。
// 第一栏=京麦授权一级真树(2026-11-16 真机取证就 3 个:服饰内衣/母婴/运动户外)。
const firstCol = wrapper.findAll('.cat-col')[0]
expect(firstCol.text()).toContain('服饰内衣')
expect(firstCol.text()).toContain('母婴')
expect(firstCol.text()).toContain('运动户外')
// hover 一级展开第二栏(服饰内衣的静态二级=京麦面板样本同款)。
await firstCol.findAll('.cat-row')[0].trigger('mouseenter')
const cols = wrapper.findAll('.cat-col')
expect(cols).toHaveLength(3, '点亮有静态子级的一级后第二栏出现(第三栏常驻)')
// 点一级展开第二栏(非末级行点击=下钻)。
await firstCol.findAll('.cat-row').find((row) => row.text().includes('服饰内衣'))!.trigger('click')
let cols = wrapper.findAll('.cat-col')
expect(cols).toHaveLength(2, '点亮一级后第二栏出现(树内逐级下钻)')
expect(cols[1].text()).toContain('服饰配件')
expect(cols[1].text()).toContain('女装')
// 第三栏=已落库末级全集+行数(与二级不联动——采集链无层级归属,组件头注释如实声明)。
expect(cols[2].text()).toContain('艺考形体服')
expect(cols[2].text()).toContain('120')
expect(cols[2].text()).toContain('啦啦队服')
// 点二级展开第三栏(京麦同款三级末级,取证快照:服饰配件 13 个)。
await cols[1].findAll('.cat-row').find((row) => row.text().includes('服饰配件'))!.trigger('click')
cols = wrapper.findAll('.cat-col')
expect(cols).toHaveLength(3, '三级栏出现(末级行不再下钻)')
expect(cols[2].text()).toContain('腰带/腰链')
// 点末级=选中即查(等值过滤口径不变)、面板收起、触发框显示已选名。
const leafRows = cols[2].findAll('.cat-row')
await leafRows.find((row) => row.text().includes('啦啦队服'))!.trigger('click')
// 点末级=选中即查(按 category_path 等值过滤口径不变)、面板收起、触发框显示已选名。
await cols[2].findAll('.cat-row').find((row) => row.text().includes('腰带/腰链'))!.trigger('click')
await flushPromises()
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ category: '啦啦队服', page: 1 })
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ category: '腰带/腰链', page: 1 })
expect(wrapper.find('.cat-panel').exists()).toBe(false, '选中后面板收起')
expect(wrapper.find('.cat-trigger').text()).toContain('啦啦队服')
expect(wrapper.find('.cat-trigger').text()).toContain('腰带/腰链')
})
it('类目级联搜索与清选:搜索词过滤第三栏;「全部类目」行/触发框 × 都能清选重查', async () => {
it('类目级联搜索与清选(2026-11-16 真树重做):树内末级命中+树外兜底段;「全部类目」行/触发框 × 都能清选重查', async () => {
jdApi.fetchJdProductCategories.mockResolvedValue([
{ name: '艺考形体服', productCount: 120 },
{ name: '啦啦队服', productCount: 8 },
{ name: '已下架历史类目', productCount: 3 },
])
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
await wrapper.find('.cat-trigger').trigger('click')
const leafCol = wrapper.findAll('.cat-col').at(-1)!
await leafCol.find('.cat-search').setValue('艺考')
const visibleRows = leafCol.findAll('.cat-row').filter((row) => row.text().includes('艺考'))
expect(visibleRows).toHaveLength(1, '搜索词过滤后只剩匹配项')
expect(leafCol.text()).not.toContain('啦啦队服', '不匹配的末级被搜索词滤掉')
// 搜索态:树内末级按名称/路径命中(艺考形体服在树内=女装支末级)。
await wrapper.findAll('.cat-col')[0].find('.cat-search').setValue('艺考')
const searchCol = wrapper.find('.cat-col-search')
const visibleRows = searchCol.findAll('.cat-row')
expect(visibleRows).toHaveLength(1, '搜索「艺考」只命中树内末级「艺考形体服」')
expect(searchCol.text()).toContain('艺考形体服')
expect(searchCol.text()).not.toContain('已下架历史类目', '不匹配项不出现')
await visibleRows[0].trigger('click')
await flushPromises()
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ category: '艺考形体服', page: 1 })
// 清空搜索后点「全部类目」= 清选重查(category 入参回空串、query 层不下发,回第一页)。
await leafCol.find('.cat-search').setValue('')
// 树外兜底:已落库但京麦树里已没有的名字(历史行)从兜底段搜出可选。
await wrapper.find('.cat-trigger').trigger('click')
await wrapper.findAll('.cat-col')[0].find('.cat-search').setValue('已下架历史')
const fallbackCol = wrapper.find('.cat-col-search')
expect(fallbackCol.text()).toContain('已落库类目(树外历史)')
expect(fallbackCol.text()).toContain('已下架历史类目')
await fallbackCol.findAll('.cat-row').find((row) => row.text().includes('已下架历史类目'))!.trigger('click')
await flushPromises()
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ category: '已下架历史类目' })
// 点「全部类目」行=清选重查(category 入参回空串、query 层不下发,回第一页)。
await wrapper.find('.cat-trigger').trigger('click')
const callsBefore = jdApi.fetchJdProductList.mock.calls.length
await leafCol.find('.cat-row-all').trigger('click')
await wrapper.find('.cat-row-all').trigger('click')
await flushPromises()
expect(jdApi.fetchJdProductList.mock.calls.length).toBe(callsBefore + 1, '清选也要重查')
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].category).toBe('')
// 触发框已选时出 × 清除按钮:点了同样清选。
await wrapper.find('.cat-trigger').trigger('click')
await wrapper.findAll('.cat-col').at(-1)!.findAll('.cat-row').find((row) => row.text().includes('啦啦队服'))!.trigger('click')
await wrapper.findAll('.cat-col')[0].find('.cat-search').setValue('艺考')
await wrapper.find('.cat-col-search').findAll('.cat-row')[0].trigger('click')
await flushPromises()
expect(wrapper.find('.cat-trigger').text()).toContain('啦啦队服')
expect(wrapper.find('.cat-trigger').text()).toContain('艺考形体服')
const callsBeforeClear = jdApi.fetchJdProductList.mock.calls.length
await wrapper.find('.cat-clear').trigger('click')
await flushPromises()
@@ -627,7 +643,7 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
expect(jdApi.fetchJdProductGroups).toHaveBeenLastCalledWith()
// 右栏取数复用 fetchJdProductList:不带公司维度(公共库),默认「全部」范围不带 ungrouped=true。
const dialogCall = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
expect(dialogCall.companyId).toBeNull()
expect(dialogCall).not.toHaveProperty('companyId')
expect(dialogCall.ungrouped).toBe(false)
// 模拟分类管理里删了一个分类:emit changed → 页面刷新分类下拉与列表(回第一页)
@@ -635,7 +651,7 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
await flushPromises()
await flushPromises()
expect(jdApi.fetchJdProductList.mock.calls.length).toBeGreaterThan(callsBefore)
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ page: 1, companyId: 1 })
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ page: 1 })
})
it('店铺分类弹窗:左侧点亮分类→勾选商品→「归入所选分类」按(ids, 目标分类 id)调批量归类', async () => {
@@ -688,7 +704,7 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
await wrapper.findAll('.scope-tabs button').find((b) => b.text() === '未分类')!.trigger('click')
await flushPromises()
expect(jdApi.fetchJdProductList.mock.calls.length).toBe(listCallsBefore + 1, '切「未分类」必须立刻重取')
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ ungrouped: true, companyId: null })
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ ungrouped: true })
await wrapper.findAll('tbody input[type="checkbox"]')[0].setValue(true)
jdApi.batchAssignJdProductGroup.mockResolvedValue(1)
@@ -698,34 +714,6 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1], null)
})
it('切公司 Tab 重取并清掉上一家的筛选(company-tab-wiring 同口径;分组公共不清)', async () => {
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 3 }])
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
const textInputs = wrapper.findAll('.form-group input[type="text"]')
await textInputs[0].setValue('JD-1001')
await textInputs[1].setValue('保温杯')
await wrapper.find('select').setValue('7')
const callsBefore = jdApi.fetchJdProductList.mock.calls.length
useCompanyTabStore().setActiveId(2)
await flushPromises()
await flushPromises()
expect(jdApi.fetchJdProductList.mock.calls.length).toBeGreaterThan(callsBefore)
const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
expect(last.companyId).toBe(2)
expect(last.productCode).toBe('', '切公司必须清掉上一家的商品编码')
expect(last.titleKeyword).toBe('', '切公司必须清掉上一家的标题关键字')
expect(last.groupId).toBe('7', '分组全平台一份(公共),groupId 与公司维度正交——切 tab 不清')
expect(last.category).toBe('', '切公司必须清掉上一家选的类目(入参回空串、query 层不下发)')
expect(last).not.toHaveProperty('shopName', '店铺筛选已下线:页面入参层不再传该键')
expect(last.page).toBe(1)
// 分组选项是全局的:切 tab 不重取(首屏那一次之后就不再增长),且任何一次拉取都不带公司维度。
for (const call of jdApi.fetchJdProductGroups.mock.calls) {
expect(call).toEqual([], '分组选项是全局的,任何一次拉取都不带公司维度')
}
})
it('空态与加载失败条(失败给重试,不把整页打死)', async () => {
const empty = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
const tip = empty.find('.empty-tip')