From ee3ff6fe8c60b7fe6c1f218c17366cc30cbd9a65 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=BB=84=E8=87=AA=E8=BE=BE?= <980324341@qq.com>
Date: Mon, 16 Nov 2026 00:14:10 +0800
Subject: [PATCH] =?UTF-8?q?feat(jd):=20=E7=B1=BB=E7=9B=AE=E7=AD=9B?=
=?UTF-8?q?=E9=80=89=E6=94=B9=E4=BA=AC=E9=BA=A6=E5=90=8C=E6=AC=BE=E7=BA=A7?=
=?UTF-8?q?=E8=81=94=E9=9D=A2=E6=9D=BF=EF=BC=88=E4=B8=80/=E4=BA=8C?=
=?UTF-8?q?=E7=BA=A7=E9=9D=99=E6=80=81=E5=AF=BC=E8=88=AA=EF=BC=8B=E6=9C=AB?=
=?UTF-8?q?=E7=BA=A7=E5=85=A8=E9=9B=86=E6=90=9C=E7=B4=A2=E7=82=B9=E9=80=89?=
=?UTF-8?q?=EF=BC=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/pages/jd/JdCategoryCascader.vue | 333 ++++++++++++++++++
.../src/pages/jd/JdDatabasePage.vue | 22 +-
.../src/pages/jd/jd-category-tree.ts | 67 ++++
.../tests/jd-product-group.test.ts | 19 +
.../mount/jd-database-page.mount.test.ts | 91 +++--
5 files changed, 505 insertions(+), 27 deletions(-)
create mode 100644 admin-frontend-vue/src/pages/jd/JdCategoryCascader.vue
create mode 100644 admin-frontend-vue/src/pages/jd/jd-category-tree.ts
diff --git a/admin-frontend-vue/src/pages/jd/JdCategoryCascader.vue b/admin-frontend-vue/src/pages/jd/JdCategoryCascader.vue
new file mode 100644
index 000000000..a3abb2f35
--- /dev/null
+++ b/admin-frontend-vue/src/pages/jd/JdCategoryCascader.vue
@@ -0,0 +1,333 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ child }}
+ ›
+
+
+
+
+
+
+
+ 全部类目
+
+
+
未找到类目
+
+
+ {{ leaf.name }}
+ {{ leaf.productCount }}
+
+
+
+
+
+
+
diff --git a/admin-frontend-vue/src/pages/jd/JdDatabasePage.vue b/admin-frontend-vue/src/pages/jd/JdDatabasePage.vue
index 17f67ef9e..4716dd0f3 100644
--- a/admin-frontend-vue/src/pages/jd/JdDatabasePage.vue
+++ b/admin-frontend-vue/src/pages/jd/JdDatabasePage.vue
@@ -30,6 +30,7 @@ import { createJdProductFilterState } from './jd-product-filter.ts'
import JdProductDetailDrawer from './JdProductDetailDrawer.vue'
import JdProductEditDrawer from './JdProductEditDrawer.vue'
import JdProductGroupDialog from './JdProductGroupDialog.vue'
+import JdCategoryCascader from './JdCategoryCascader.vue'
import OldPagination from '@/components/OldPagination.vue'
import { useCompanyTabStore } from '@/stores/company-tab'
import { showAdminFeedback } from '@/components/admin-feedback-ui'
@@ -145,6 +146,13 @@ function apply(): void {
void load()
}
+/** 类目级联面板点末级即查:选完立刻按该类目过滤刷新(回第一页),同分组下拉口径;
+ * 点「全部类目」/触发框 × = 清选重查。 */
+function onCategoryPicked(name: string): void {
+ filter.category = name
+ apply()
+}
+
/** 重置:筛选面回出厂空态,回第一页重取。 */
function reset(): void {
Object.assign(filter, createJdProductFilterState())
@@ -289,13 +297,13 @@ onMounted(() => {
-
-
+
+
diff --git a/admin-frontend-vue/src/pages/jd/jd-category-tree.ts b/admin-frontend-vue/src/pages/jd/jd-category-tree.ts
new file mode 100644
index 000000000..13ad88796
--- /dev/null
+++ b/admin-frontend-vue/src/pages/jd/jd-category-tree.ts
@@ -0,0 +1,67 @@
+/** 京东类目级联的导航树(2026-11-16 客户口径「类目要京麦同款级联样式」)。
+ *
+ * 数据边界(先说清,防止后人当它是全量类目树):
+ * - 落库 biz_jd_product.category_path = 京麦列表接口 categoryDetailVO.lastCategoryName
+ * (末级类目名,jd-collect-api-contract.md §2.3 E3),采集链**没有**一/二级类目数据;
+ * - 所以级联面板的一/二级用这里的**静态导航树**(京东公开类目体系;服饰内衣子树的二级
+ * 按京麦面板真机样本逐字校正:服饰配件/内衣/女装/男装/定制服装工装),**不参与过滤**;
+ * - 第三栏(选中发生地)永远是页面传入的**已落库末级类目全集**(/categories 现算)+搜索框,
+ * 选中后仍按 category_path 等值过滤(后端契约零改动)。采集链日后补齐一/二级回传时,
+ * 把本文件的静态树换成 /categories 的树形返回即可,组件已按树形契约设计。
+ *
+ * 纯数据+纯函数,node --test 直测。 */
+
+/** 静态导航树节点:一级/二级。children 缺省=该一级下暂无静态二级(面板少一栏,直接第三栏)。 */
+export interface JdCategoryNavNode {
+ name: string
+ children?: string[]
+}
+
+/** 京东 POP 零售一级类目(常用集,名称按京东公开类目体系;非全量——长尾一级随需要再补)。 */
+export const JD_CATEGORY_NAV_TREE: JdCategoryNavNode[] = [
+ {
+ name: '服饰内衣',
+ // 京麦面板真机样本(2026-11-16 客户提供截图)逐字:服饰配件/内衣/女装/男装/定制服装/工装。
+ children: ['服饰配件', '内衣', '女装', '男装', '定制服装/工装'],
+ },
+ {
+ name: '母婴',
+ children: ['奶粉', '营养辅食', '尿裤湿巾', '喂养用品', '洗护用品', '妈妈专区', '童车童床', '儿童安全座椅'],
+ },
+ {
+ name: '运动户外',
+ children: ['运动服饰', '运动鞋', '健身器械', '户外装备', '骑行运动', '体育用品', '垂钓用品'],
+ },
+ { name: '鞋靴' },
+ { name: '箱包' },
+ { name: '珠宝首饰' },
+ { name: '钟表' },
+ { name: '美妆护肤' },
+ { name: '个护清洁' },
+ { name: '手机通讯' },
+ { name: '数码' },
+ { name: '电脑办公' },
+ { name: '家用电器' },
+ { name: '家居家装' },
+ { name: '厨具' },
+ { name: '家具' },
+ { name: '家装建材' },
+ { name: '食品饮料' },
+ { name: '酒类' },
+ { name: '生鲜' },
+ { name: '玩具乐器' },
+ { name: '宠物生活' },
+ { name: '汽车用品' },
+ { name: '图书文娱' },
+ { name: '营养保健' },
+]
+
+/** 一级类目名列表(面板第一栏顺序)。 */
+export function jdCategoryNavRoots(): string[] {
+ return JD_CATEGORY_NAV_TREE.map((node) => node.name)
+}
+
+/** 某一级下的静态二级列表;无静态子级返回空数组(面板该栏缺省)。 */
+export function jdCategoryNavChildren(rootName: string): string[] {
+ return JD_CATEGORY_NAV_TREE.find((node) => node.name === rootName)?.children ?? []
+}
diff --git a/admin-frontend-vue/tests/jd-product-group.test.ts b/admin-frontend-vue/tests/jd-product-group.test.ts
index b468f3638..5921909d2 100644
--- a/admin-frontend-vue/tests/jd-product-group.test.ts
+++ b/admin-frontend-vue/tests/jd-product-group.test.ts
@@ -23,6 +23,10 @@ import {
createJdProductFilterState,
toJdProductListParams,
} from '../src/pages/jd/jd-product-filter.ts'
+import {
+ jdCategoryNavChildren,
+ jdCategoryNavRoots,
+} from '../src/pages/jd/jd-category-tree.ts'
import {
jdPriceRange,
parseJdProductDetail,
@@ -30,6 +34,21 @@ import {
toJdProductItem,
} from '../src/pages/jd/jd-product-model.ts'
+test('类目级联静态导航树——服饰内衣二级与京麦面板样本逐字同源,一级集非空且无重名', () => {
+ // 京麦面板真机样本(2026-11-16 客户截图):服饰内衣下就是这五个二级,改名即红。
+ assert.deepEqual(jdCategoryNavChildren('服饰内衣'), ['服饰配件', '内衣', '女装', '男装', '定制服装/工装'])
+ assert.deepEqual(jdCategoryNavChildren('不存在的类目'), [], '未知一级回落空子级(面板不出第二栏)')
+
+ const roots = jdCategoryNavRoots()
+ assert.ok(roots.length >= 20, `一级导航 ${roots.length} 个,常用集不应被清空`)
+ assert.equal(new Set(roots).size, roots.length, '一级类目名不得重复')
+ assert.equal(roots[0], '服饰内衣', '服饰内衣置首(客户商品全在服饰类目)')
+ for (const root of roots) {
+ const children = jdCategoryNavChildren(root)
+ assert.equal(new Set(children).size, children.length, `${root} 的二级不得重复`)
+ }
+})
+
test('京东列表参数——snake 形状:groupId 空→不带、有值→group_id,日期空白/非法不下发', () => {
const full = toJdProductListParams(
{
diff --git a/admin-frontend-vue/tests/mount/jd-database-page.mount.test.ts b/admin-frontend-vue/tests/mount/jd-database-page.mount.test.ts
index 4c4571fca..6941a52f5 100644
--- a/admin-frontend-vue/tests/mount/jd-database-page.mount.test.ts
+++ b/admin-frontend-vue/tests/mount/jd-database-page.mount.test.ts
@@ -245,12 +245,13 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
page: 1,
companyId: 1,
})
- expect(last).not.toHaveProperty('shopName', '店铺筛选已下线,入参不再带 shopName')
- expect(last).not.toHaveProperty('saleStatus', '商品状态筛选已下线,入参不再带 saleStatus')
+ // 单参 toHaveProperty 才是「键不存在」的真判据(第二参会稀释成值断言):
+ // 页面 load() 入参已不带这两个键(店铺/商品状态筛选下线)。
+ expect(last).not.toHaveProperty('shopName')
+ expect(last).not.toHaveProperty('saleStatus')
})
- it('分组下拉选中即查', async () => {
- jdApi.fetchJdProductGroups.mockResolvedValue([
+ it('分组下拉选中即查', async () => { jdApi.fetchJdProductGroups.mockResolvedValue([
{ id: 7, name: '甲组', sortOrder: 0, productCount: 3 },
{ id: 8, name: '乙组', sortOrder: 1, productCount: 1 },
])
@@ -269,27 +270,77 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7', page: 1 })
})
- it('类目下拉:选项来自 GET /categories(带商品数),选中即查回第一页', async () => {
+ it('类目京麦同款级联面板:一/二级静态导航展开,第三栏=已落库末级全集+行数,点末级即查回第一页', async () => {
jdApi.fetchJdProductCategories.mockResolvedValue([
- { name: '服饰内衣', productCount: 120 },
- { name: '运动户外', productCount: 8 },
+ { name: '艺考形体服', productCount: 120 },
+ { name: '啦啦队服', productCount: 8 },
])
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
expect(jdApi.fetchJdProductCategories).toHaveBeenCalledWith(1)
- // 第 1 个 select = 分组(既有契约不动),第 2 个 = 分类状态(2026-11-15 增),类目下拉第 3
- const selects = wrapper.findAll('.jd-filter-row select')
- expect(selects).toHaveLength(3)
- const categorySelect = selects[2]
- const optionTexts = categorySelect.findAll('option').map((o) => o.text())
- expect(optionTexts[0]).toBe('全部类目')
- expect(optionTexts).toContain('服饰内衣(120)')
+ const trigger = wrapper.find('.cat-trigger')
+ expect(trigger.text()).toContain('全部类目', '未选时触发框显示占位「全部类目」')
+ expect(wrapper.find('.cat-panel').exists()).toBe(false, '面板初始不展开')
- const callsBeforeSelect = jdApi.fetchJdProductList.mock.calls.length
- await categorySelect.setValue('运动户外')
+ await trigger.trigger('click')
+ expect(wrapper.find('.cat-panel').exists()).toBe(true)
+ // 第一栏=静态一级导航(京麦同款顺序,服饰内衣在首)。
+ 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, '点亮有静态子级的一级后第二栏出现(第三栏常驻)')
+ 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('啦啦队服')
+
+ // 点末级=选中即查(等值过滤口径不变)、面板收起、触发框显示已选名。
+ const leafRows = cols[2].findAll('.cat-row')
+ await leafRows.find((row) => row.text().includes('啦啦队服'))!.trigger('click')
await flushPromises()
- expect(jdApi.fetchJdProductList.mock.calls.length).toBe(callsBeforeSelect + 1, '选中类目必须立刻重查')
- 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('啦啦队服')
+ })
+
+ it('类目级联搜索与清选:搜索词过滤第三栏;「全部类目」行/触发框 × 都能清选重查', async () => {
+ jdApi.fetchJdProductCategories.mockResolvedValue([
+ { name: '艺考形体服', productCount: 120 },
+ { name: '啦啦队服', productCount: 8 },
+ ])
+ 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('啦啦队服', '不匹配的末级被搜索词滤掉')
+
+ // 清空搜索后点「全部类目」= 清选重查(category 入参回空串、query 层不下发,回第一页)。
+ await leafCol.find('.cat-search').setValue('')
+ const callsBefore = jdApi.fetchJdProductList.mock.calls.length
+ await leafCol.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 flushPromises()
+ expect(wrapper.find('.cat-trigger').text()).toContain('啦啦队服')
+ const callsBeforeClear = jdApi.fetchJdProductList.mock.calls.length
+ await wrapper.find('.cat-clear').trigger('click')
+ await flushPromises()
+ expect(jdApi.fetchJdProductList.mock.calls.length).toBe(callsBeforeClear + 1, '× 清除同样触发重查')
+ expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].category).toBe('')
})
it('分类状态下拉:全部/已分类/未分类三档,选中即查回第一页并下发对应参数', async () => {
@@ -594,8 +645,8 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
expect(last.productCode).toBe('', '切公司必须清掉上一家的商品编码')
expect(last.titleKeyword).toBe('', '切公司必须清掉上一家的标题关键字')
expect(last.groupId).toBe('7', '分组全平台一份(公共),groupId 与公司维度正交——切 tab 不清')
- expect(last).not.toHaveProperty('category', '切公司必须清掉上一家选的类目')
- expect(last).not.toHaveProperty('shopName', '店铺筛选已下线,入参不再带 shopName')
+ expect(last.category).toBe('', '切公司必须清掉上一家选的类目(入参回空串、query 层不下发)')
+ expect(last).not.toHaveProperty('shopName', '店铺筛选已下线:页面入参层不再传该键')
expect(last.page).toBe(1)
// 分组选项是全局的:切 tab 不重取(首屏那一次之后就不再增长),且任何一次拉取都不带公司维度。
for (const call of jdApi.fetchJdProductGroups.mock.calls) {