feat(jd-collect): 建单页按京麦店内分类多选采集

客户口径「类目不需要只要分类」「做成多选的」:采集建单页下线类目级联与平台分组,
换京麦「店内分类」快照多选(getShopCategoryList 2026-11-16 取证 9 个,见
ops docs/jd-collect-api-contract.md §2.6)。建单请求体/页面推送/兜底拉取三处同键
shopCategoryNames+shopCategoryIds(label+id 双键,行级填充形状未取证,客户端任一
命中即命中);categoryPaths 标 @Deprecated 仅历史行兼容。超长归一化文案泛化为
normalizeStringSelection;历史行 VO 带回双键供重试/继续同源。
删除建单页唯一消费方的死件:JdCategoryCascader.vue/jd-category-tree.ts/其测试
(后管另有在用副本,不受影响)。

判据:JdCollectTaskServiceTest 三例(双键归一化/空白归 null/51 个拒)+
JdTaskPullSpiImplTest 七键载荷透传;前端 jd-collect-tab/jd-shop-category/mount
三支(快照消费、双键同链、绊线:级联组件与分组接口不得回流建单页)。
可读棘轮:JdCollectTab.vue 804→786 行(同款返回按钮 CSS 合并、死 .download 类删除)。
客户端侧(app_client jd_base 行级过滤)同窗另一仓提交。
This commit is contained in:
2026-11-16 20:14:40 +08:00
parent 61c361222d
commit e621deea58
16 changed files with 435 additions and 855 deletions
@@ -1,97 +0,0 @@
import { test } from 'node:test'
import assert from 'node:assert/strict'
import {
JD_CATEGORY_TREE,
jdCategoryChildren,
jdCategoryLeaves,
jdCategoryRoots,
jdCategorySearchLeaves,
} from '../src/pages/jd/jd-category-tree.ts'
/** 京麦授权类目真树(2026-11-16 真机取证 getVenderLicenseCategory 快照;与后管
* admin-frontend-vue 侧同数据两份正本,改树两边同轮同步)。判据钉的是取证读数:
* 3 个一级 / 250 个末级 / 最深 4 级 / 5 个同名跨支——改树先对取证数据(京麦面板
* 或 getVenderLicenseCategory 重抓),不得手改数字凑测试。 */
test('树形状=京麦授权类目真机读数:3 个一级、250 个末级、最深 4 级', () => {
const roots = jdCategoryRoots()
assert.deepEqual(
roots.map((node) => node.name),
['服饰内衣', '母婴', '运动户外'],
'一级就 3 个(京麦面板 2026-11-16 真机:该店铺授权经营类目,不得加回京东公开全量)',
)
assert.deepEqual(
roots.map((node) => node.value),
['1315', '1319', '1318'],
'一级类目 id 与取证响应逐字同',
)
const leaves = jdCategoryLeaves()
assert.equal(leaves.length, 250, '末级节点 250 个(取证读数)')
const maxDepth = Math.max(...leaves.map((leaf) => leaf.path.length))
assert.equal(maxDepth, 4, '树最深 4 级')
})
test('服饰内衣二级与京麦面板逐字同源;逐级下钻到真机样本叶', () => {
assert.deepEqual(
jdCategoryChildren(['服饰内衣']).map((node) => node.name),
['服饰配件', '内衣', '女装', '男装', '定制服装/工装'],
'服饰内衣二级 5 个(京麦面板逐字)',
)
assert.deepEqual(
jdCategoryChildren(['服饰内衣', '服饰配件']).map((node) => node.name),
['腰带/腰链', '耳罩/耳包', '领带/领结/领带夹', '男士丝巾/围巾', '女士丝巾/围巾/披肩', '鸭舌帽',
'礼帽', '手套', '围巾/手套/帽子套装', '毛线帽', '遮阳帽', '棒球帽', '渔夫帽'],
'服饰配件三级 13 个(京麦面板 2026-11-16 截图逐字前 6 +取证快照全量)',
)
assert.deepEqual(
jdCategoryChildren(['服饰内衣', '服饰配件', '腰带/腰链']),
[],
'三级叶子 children 空(末级,可选中)',
)
assert.deepEqual(
jdCategoryChildren(['不存在的一级']),
[],
'未知路径回落空子级(面板该栏缺省)',
)
})
test('落库末级名真机样本都在树内(category_path 等值过滤成立的前提)', () => {
const names = new Set(jdCategoryLeaves().map((leaf) => leaf.name))
for (const sample of ['艺考形体服', '啦啦队服', '拉丁舞服']) {
assert.ok(names.has(sample), `真机样本「${sample}」必须是树内末级(契约 E3 口径)`)
}
const yikao = jdCategoryLeaves().find((leaf) => leaf.name === '艺考形体服')
assert.ok(yikao, '艺考形体服在树内')
assert.equal(yikao!.path.length, 3, '艺考形体服是 level 3 节点(取证读数)')
})
test('同名跨支叶子如实登记:4 组重名(同名行等值过滤一起命中,B112-05 口径)', () => {
const counts = new Map<string, number>()
for (const leaf of jdCategoryLeaves()) {
counts.set(leaf.name, (counts.get(leaf.name) ?? 0) + 1)
}
const dups = [...counts.entries()].filter(([, count]) => count > 1)
assert.deepEqual(
dups.map(([name]) => name).sort(),
['唐装', '吊带/背心', '短裤', '赠品'].sort(),
'重名集与取证读数逐字同(改树后这里红=重名集变了,须复核登记)。注:「汉服」两处节点中'
+ '一处带四级子级是非叶(点它会下钻),不构成末级重名。',
)
})
test('搜索:按名称或路径段命中末级;空词返回全量', () => {
assert.equal(jdCategorySearchLeaves('').length, 250, '空词=全量末级')
const byName = jdCategorySearchLeaves('艺考')
assert.equal(byName.length, 1)
assert.equal(byName[0]!.name, '艺考形体服')
const byPath = jdCategorySearchLeaves('服饰配件')
assert.ok(byPath.length >= 12, '按路径段命中服饰配件全部末级')
assert.ok(byPath.every((leaf) => leaf.path.includes('服饰配件')))
assert.deepEqual(jdCategorySearchLeaves('不存在词xyz'), [])
})
test('树数据快照不可空、value 全非空(取证 id 留档完整)', () => {
assert.ok(JD_CATEGORY_TREE.length > 0)
for (const leaf of jdCategoryLeaves()) {
assert.ok(leaf.value, `叶子 ${leaf.name} 必须带京麦类目 id`)
}
})
+28 -24
View File
@@ -40,40 +40,44 @@ test('endpoints 注册 jdCollect 端点组', () => {
'endpoints.ts 缺 jdCollect 端点组(建单/心跳/回传三件)')
})
/** 2026-11-16 用户口径「客户端前端也要同步加上京东类目」:建单页多选末级类目随链下发。
* 三处同键契约(建单请求体 / 推送载荷 / 历史行带回)缺一处,客户端就按全店采集跑。 */
test('endpoints 注册采集类目 categories 下拉端点', () => {
/** 2026-11-16 建单页采集范围换成京麦「店内分类」多选(客户口径「类目不需要只要分类」
* 「选京麦的内部分类去采集」+「做成多选的」)。三处同键契约(建单请求体 / 推送载荷 /
* 历史行带回)缺一处,客户端就按全店采集跑。 */
test('endpoints 注册采集类目 categories 端点(数据面保留)', () => {
const endpoints = readIfExists(ENDPOINTS, 'endpoints.ts')
assert.ok(endpoints.includes("categories: '/api/jd-collect/categories'"),
'endpoints.ts jdCollect 组缺 categories(建单页类目多选面板的选项源)')
'endpoints.ts jdCollect 组仍须登记 categories(冻结快照口径;建单页 UI 已下线,仅数据面保留)')
})
/** 2026-11-16 客户口径「管理员弄了多少店铺分类 普通账户都能看到」:普通账号在
* 「获取店铺数据」页就能看到管理员在后管京东数据库建的分类全集与各组商品数;
* 本页只读——分类的增删改仍只在后管。「商品上架」落地后消费同一端点。 */
test('endpoints 注册店铺分类 groups 只读端点,页面加载并只读展示', () => {
/** 2026-11-16 口径修订:客户参照系是京麦后台的「店内分类」,平台分组 chips 从本页下线
* (分组数据面归后管京东数据库与商品上架,端点与 fetch 函数保留)。 */
test('分类多选来自京麦店内分类快照,平台分组从本页下线', () => {
const endpoints = readIfExists(ENDPOINTS, 'endpoints.ts')
assert.ok(endpoints.includes("groups: '/api/jd-collect/groups'"),
'endpoints.ts jdCollect 组缺 groups(店铺分类只读列表的选项源)')
'endpoints.ts jdCollect 组仍须登记 groups(冻结快照口径;建单页 UI 已下线,仅数据面保留)')
const api = readIfExists(
join(process.cwd(), 'src', 'shared', 'api', 'types', 'modules', 'jd-collect.ts'),
'jd-collect.ts',
)
assert.ok(api.includes('export function fetchJdCollectGroups'),
'jd-collect.ts 缺 fetchJdCollectGroups(页面取分类列表的发送口)')
'jd-collect.ts 保留 fetchJdCollectGroups(上架/数据面消费,非建单页)')
const page = readIfExists(
join(process.cwd(), 'src', 'pages', 'jd', 'JdCollectTab.vue'),
'JdCollectTab.vue',
)
assert.ok(page.includes('fetchJdCollectGroups'),
'JdCollectTab.vue 必须调 fetchJdCollectGroups(普通账号在这里看到管理员建的分类)')
assert.ok(page.includes('自定义分类</span>'),
'JdCollectTab.vue 必须以「自定义分类」展示分类块')
assert.ok(page.includes('JD_SHOP_CATEGORY_SNAPSHOT'),
'JdCollectTab.vue 必须消费京麦店内分类快照(jd-shop-category.ts)作采集分类多选选项')
assert.ok(page.includes('采集分类(可选,多选)'),
'JdCollectTab.vue 必须以「采集分类(可选,多选)」展示分类块')
assert.ok(!page.includes('JdCategoryCascader'),
'JdCollectTab.vue 不得再引用类目级联(2026-11-16 客户口径「类目不需要」)')
assert.ok(!page.includes('fetchJdCollectGroups'),
'JdCollectTab.vue 不得再消费平台分组接口(两套「分类」并存必混)')
})
test('建单请求体与推送载荷都带 categoryPaths', () => {
test('建单请求体与推送载荷都带店内分类双键', () => {
const api = readIfExists(
join(process.cwd(), 'src', 'shared', 'api', 'types', 'modules', 'jd-collect.ts'),
'jd-collect.ts',
@@ -82,20 +86,20 @@ test('建单请求体与推送载荷都带 categoryPaths', () => {
const apiEnd = api.indexOf('export interface JdCollectDashboardVo')
assert.ok(apiStart > 0 && apiEnd > apiStart, 'jd-collect.ts 缺 createJdCollectTask')
const apiBody = api.slice(apiStart, apiEnd)
assert.ok(apiBody.includes('categoryPaths'),
'createJdCollectTask 请求体必须带 categoryPaths(空数组=全店采集)')
assert.ok(apiBody.includes('shopCategoryNames') && apiBody.includes('shopCategoryIds'),
'createJdCollectTask 请求体必须带店内分类双键(label+id 同发:行级填充形状未取证,任一键命中即命中)')
const page = readIfExists(
join(process.cwd(), 'src', 'pages', 'jd', 'JdCollectTab.vue'),
'JdCollectTab.vue',
)
assert.ok(page.includes('maxProducts: 0, categoryPaths }'),
'推送载荷 data 必须带 categoryPaths(与后端 JdTaskPullSpiImplTest 键集断言同键)')
assert.ok(page.includes('createJdCollectTask(shop, tabs, 0, categories)'),
'startCollect 建单必须把选中的类目传给 createJdCollectTask')
assert.ok(page.includes('maxProducts: 0, shopCategoryNames, shopCategoryIds }'),
'推送载荷 data 必须带店内分类双键(与后端 JdTaskPullSpiImplTest 键集断言同键)')
assert.ok(page.includes('createJdCollectTask(shop, tabs, 0, [], shopNames, shopIds)'),
'startCollect 建单必须把选中的分类(names+ids)传给 createJdCollectTask')
})
test('重试/继续从历史行同源带回 categoryPaths', () => {
test('重试/继续从历史行同源带回店内分类双键', () => {
const page = readIfExists(
join(process.cwd(), 'src', 'pages', 'jd', 'JdCollectTab.vue'),
'JdCollectTab.vue',
@@ -103,8 +107,8 @@ test('重试/继续从历史行同源带回 categoryPaths', () => {
const startAt = page.indexOf('async function retryTaskRecord')
assert.ok(startAt > 0, 'JdCollectTab.vue 缺 retryTaskRecord')
const body = page.slice(startAt, page.indexOf('/** 手动刷新'))
assert.ok(body.includes('item?.categoryPaths ?? []'),
'重试/继续重建推送载荷必须从历史行带回 categoryPaths(后端 history VO 同源字段),缺了客户端会按全店采集跑')
assert.ok(body.includes('item?.shopCategoryNames ?? []') && body.includes('item?.shopCategoryIds ?? []'),
'重试/继续重建推送载荷必须从历史行带回店内分类双键(后端 history VO 同源字段),缺了客户端会按全店采集跑')
})
/** 2026-11-14 真机实录:建单请求体写成 `user_id` 时后端回一句「user_id 不合法」直接拒,
@@ -0,0 +1,54 @@
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { existsSync, readFileSync } from 'node:fs'
import { join } from 'node:path'
/** 京麦「店内分类」快照契约(2026-11-16 真机取证,建单页采集分类多选的选项集)。
*
* 快照是纯前端静态数据(getShopCategoryList 的 label/value 对,扁平单层)。判据钉四件:
* ① 快照非空且形状齐(label/value 都非空字符串);② label 不重复(多选以 label 下发,
* 重名会让客户端过滤语义歧义);③ 取证出处注释在位(后人按原路重抓,防止当它错改);
* ④ 建单页消费快照(对手面 jd-collect-tab.test.ts 的发送口断言)。 */
const SNAPSHOT = join(process.cwd(), 'src', 'pages', 'jd', 'jd-shop-category.ts')
function readIfExists(path: string, what: string): string {
assert.ok(existsSync(path), `${what} 尚未落地:${path}`)
return readFileSync(path, 'utf8')
}
test('店内分类快照非空且每项 label/value 齐全', async () => {
const mod = await import('../src/pages/jd/jd-shop-category.ts')
const { JD_SHOP_CATEGORY_SNAPSHOT } = mod as {
JD_SHOP_CATEGORY_SNAPSHOT: { label: string; value: string }[]
}
assert.ok(Array.isArray(JD_SHOP_CATEGORY_SNAPSHOT) && JD_SHOP_CATEGORY_SNAPSHOT.length > 0,
'快照不得为空(2026-11-16 取证 9 个)')
for (const item of JD_SHOP_CATEGORY_SNAPSHOT) {
assert.ok(typeof item.label === 'string' && item.label.trim().length > 0,
`label 必须是非空字符串: ${JSON.stringify(item)}`)
assert.ok(typeof item.value === 'string' && item.value.trim().length > 0,
`value(京麦分类 id)必须是非空字符串: ${JSON.stringify(item)}`)
}
})
test('快照 label 不重复(多选按 label 下发,重名会让过滤语义歧义)', async () => {
const mod = await import('../src/pages/jd/jd-shop-category.ts')
const { JD_SHOP_CATEGORY_SNAPSHOT } = mod as {
JD_SHOP_CATEGORY_SNAPSHOT: { label: string }[]
}
const labels = JD_SHOP_CATEGORY_SNAPSHOT.map((item) => item.label)
assert.equal(new Set(labels).size, labels.length,
`label 有重复: ${labels.join(', ')}`)
})
test('取证出处与边界注释在位(防后人当它错改)', () => {
const body = readIfExists(SNAPSHOT, 'jd-shop-category.ts')
assert.ok(body.includes('getShopCategoryList'),
'快照文件必须写明数据来源接口(ShopCategoryReadViewService.getShopCategoryList)')
assert.ok(body.includes('2026-11-16'), '快照文件必须带取证日期')
assert.ok(body.includes('shopCategorys') || body.includes('shopCategoryPath'),
'快照文件必须写明行级过滤键(shopCategorys/shopCategoryPath/groupId)')
assert.ok(body.includes('0/450') || body.includes('没给商品挂分类'),
'快照文件必须写明「采样店铺 0 商品挂分类」的现状边界(选分类=0 行命中是已知形状)')
})
@@ -151,8 +151,8 @@ describe('获取店铺数据:一键采集 + 任务面板', () => {
expect(api.createJdCollectTask).toHaveBeenCalledTimes(1)
// 店铺名留空 → 按「京麦后台」占位(客户端从京麦后台现读真实店铺名落库);
// 不选类目=空数组(全店采集,后端归一化为 null 进 request_json)
expect(api.createJdCollectTask).toHaveBeenCalledWith('京麦后台', ['ONSALE', 'OFFSALE'], 0, [])
// 不选分类=双键空数组(全店采集,后端归一化为 null 进 request_json)
expect(api.createJdCollectTask).toHaveBeenCalledWith('京麦后台', ['ONSALE', 'OFFSALE'], 0, [], [], [])
expect(api.activateJdCollectTask).toHaveBeenCalledWith(88)
expect(api.enqueue).toHaveBeenCalledTimes(1)
const payload = api.enqueue.mock.calls[0][0]
@@ -162,7 +162,8 @@ describe('获取店铺数据:一键采集 + 任务面板', () => {
shopName: '京麦后台',
listTabs: ['ONSALE', 'OFFSALE'],
maxProducts: 0,
categoryPaths: [],
shopCategoryNames: [],
shopCategoryIds: [],
})
// 轮询已启动:批量进度端点拿到任务 88
expect(api.fetchJdCollectTaskProgressBatch).toHaveBeenCalled()
@@ -283,75 +284,54 @@ describe('获取店铺数据:一键采集 + 任务面板', () => {
expect(w.find('.feedback.error').exists()).toBe(false)
})
it('勾选类目后建单:categoryPaths 随建单请求体与推送载荷同链下发', async () => {
// 2026-11-16 用户口径「客户端前端也要同步加上京东类目」+「你直接爬」:面板换京麦
// 授权类目真树(逐级下钻、末级勾选)——下钻 运动户外 → 舞蹈体操鞋服/装备(客户
// 舞蹈服类目在京麦归运动户外支)→ 勾末级「艺考形体服」后建单请求体与推送载荷都要
// 带 ['艺考形体服'](客户端按行 categoryPath 等值过滤的源头;mock 类目用树内真实
// 末级名,贴合落库形状)。
api.fetchJdCollectCategories.mockResolvedValue([
{ name: '艺考形体服', productCount: 5 },
{ name: '啦啦队服', productCount: 3 },
])
it('勾选分类后建单:店内分类双键随建单请求体与推送载荷同链下发', async () => {
// 2026-11-16 客户口径「类目不需要只要分类」「选京麦的内部分类去采集」+「做成多选的」:
// 选项集=京麦「店内分类」快照(jd-shop-category.ts,getShopCategoryList 取证 9 个),
// checkbox 多选;建单请求体与推送载荷带 label+id 双键(行级填充形状未取证,客户端
// 任一键命中即命中)——mock 选中项用快照真实行(拉丁舞服/1024347572),贴合下发形状。
const w = await mountPage()
await w.find('.cat-trigger').trigger('click')
await w.findAll('.cat-col')[0].findAll('.cat-row').find((row) => row.text().includes('运动户外'))!.trigger('click')
let cols = w.findAll('.cat-col')
expect(cols).toHaveLength(2, '点亮一级后第二栏出现(真树下钻)')
await cols[1].findAll('.cat-row').find((row) => row.text().includes('舞蹈体操鞋服/装备'))!.trigger('click')
cols = w.findAll('.cat-col')
expect(cols).toHaveLength(3, '二级非末级:第三栏出末级子级')
const leafRow = cols[2].findAll('.cat-row').find((row) => row.text().includes('艺考形体服'))
expect(leafRow, '第三栏必须渲染出该支的末级(艺考形体服)').toBeTruthy()
await leafRow!.trigger('click')
const rows = w.findAll('.shop-cat-item')
expect(rows.length).toBeGreaterThan(0, '分类多选列表必须渲染快照选项')
const latinRow = rows.find((row) => row.text().includes('拉丁舞服'))
expect(latinRow, '快照里必须有「拉丁舞服」').toBeTruthy()
await latinRow!.find('input').setValue(true)
const uniformRow = rows.find((row) => row.text().includes('工作制服'))
await uniformRow!.find('input').setValue(true)
await flushPromises()
expect(w.find('.cat-trigger-text').text()).toBe('艺考形体服', '单选勾选后触发框显示类目名')
await w.find('.cat-mask').trigger('click')
await startCollect(w)
expect(api.createJdCollectTask).toHaveBeenCalledWith('京麦后台', ['ONSALE', 'OFFSALE'], 0, ['艺考形体服'])
expect(api.createJdCollectTask).toHaveBeenCalledWith('京麦后台', ['ONSALE', 'OFFSALE'], 0, [],
['拉丁舞服', '工作制服'], ['1024347572', '1024347567'])
const payload = api.enqueue.mock.calls[0][0]
expect(payload.data).toEqual({
taskId: 88,
shopName: '京麦后台',
listTabs: ['ONSALE', 'OFFSALE'],
maxProducts: 0,
categoryPaths: ['艺考形体服'],
shopCategoryNames: ['拉丁舞服', '工作制服'],
shopCategoryIds: ['1024347572', '1024347567'],
})
})
it('店铺分类只读块:页面加载即拉取并把管理员建的分类与商品数展示出来', async () => {
// 2026-11-16 客户口径「管理员弄了多少店铺分类 普通账户都能看到」:普通账号在
// 「获取店铺数据」页就能看到后管京东数据库建的分类全集;本页只读,不提供增删改。
api.fetchJdCollectGroups.mockResolvedValue([
{ id: 1, name: 'ASSS', sortOrder: 0, productCount: 20 },
{ id: 2, name: '家居日用', sortOrder: 1, productCount: 7 },
])
it('采集分类块:快照选项全量渲染并可取消勾选(清空恢复全店采集)', async () => {
const w = await mountPage()
expect(api.fetchJdCollectGroups).toHaveBeenCalledTimes(1)
const block = w.findAll('.category-block').find((el) => el.text().includes('自定义分类'))
expect(block, '必须有「自定义分类」展示块').toBeTruthy()
expect(block!.text()).toContain('自定义分类')
const chips = block!.findAll('.group-chip')
expect(chips.length).toBe(2)
expect(chips[0].text()).toContain('ASSS(20)')
expect(chips[1].text()).toContain('家居日用(7)')
expect(chips[0].attributes('title')).toContain('ASSS:20 个商品')
})
const block = w.findAll('.category-block').find((el) => el.text().includes('采集分类'))
expect(block, '必须有「采集分类(可选,多选)」块').toBeTruthy()
expect(block!.text()).toContain('采集分类(可选,多选)')
// 快照 9 项全渲染(客户端「能看见管理员/商家建的分类」口径落点就在这)
expect(block!.findAll('.shop-cat-item').length).toBe(9)
expect(block!.text()).toContain('不选=全店采集')
it('后台还没建分类:只读块落空态提示,采集主路照常', async () => {
const w = await mountPage()
const block = w.findAll('.category-block').find((el) => el.text().includes('自定义分类'))
expect(block, '空态也要有「自定义分类」块(不能整块消失让用户以为没这功能)').toBeTruthy()
expect(block!.text()).toContain('后台还没建自定义分类')
expect(block!.text()).toContain('管理员可在「京东数据库」的类目面板中新建自定义分类')
expect(block!.text()).not.toContain('京东数据库 → 店铺分类')
expect(block!.find('.group-chip').exists()).toBe(false)
// 拉取失败只 warning、不影响建单主路(catch 口径见 catch-silence-ratchet 319)
expect(w.find('.collect-btn').exists()).toBe(true)
const first = block!.findAll('.shop-cat-item')[0]
await first.find('input').setValue(true)
await flushPromises()
expect(block!.text()).toContain('只采选中 1 个分类的商品')
expect(block!.find('.shop-cat-clear').exists()).toBe(true, '选中后出「清空」')
await block!.find('.shop-cat-clear').trigger('click')
await flushPromises()
expect(block!.text()).toContain('不选=全店采集')
})
})