feat(jd): 建单页加京东类目多选级联(客户端窗口同页面,选类目去采集同步后台)——JdCategoryCascader.vue+jd-category-tree.ts 从后管复制改多选(第三栏已落库末级全集+搜索点选 toggle,方点 checkbox,全部类目=清空=全店采集;触发框暗色主题适配,「已选 N 个类目」;选项空态不阻塞建单);JdCollectTab 左面板加「采集类目(可选,多选)」,startCollect/pushToClientQueue/retryTaskRecord 三处全链带 categoryPaths(重试从历史行同源带回,推送载荷与建单请求体、兜底拉取三处同键);jd-collect.ts 加 fetchJdCollectCategories/createJdCollectTask 第4参/JdCollectHistoryItemVo.categoryPaths;endpoints 注册 /api/jd-collect/categories。判据:jd-collect-tab.test +3 源码绊线(payload 带 categoryPaths/建单传参/重试带回)+categories 端点注册,jd-category-tree.test 与后管同判据两份正本同形;vue-tsc 零错、node --test 10 例全绿。客户端读参过滤另笔(多仓边界)

This commit is contained in:
2026-11-16 01:17:37 +08:00
parent 8b4f7a3a6b
commit 9e3f28079b
7 changed files with 608 additions and 9 deletions
@@ -0,0 +1,371 @@
<script setup lang="ts">
/** 建单页「采集类目」多选级联面板(2026-11-16 客户口径「客户端前端也要同步加上京东类目」)。
*
* 形状照后管京东数据库的筛选面板(admin-frontend-vue/src/pages/jd/JdCategoryCascader.vue,
* 京麦同款三栏:一级静态导航 / 二级纯导航 / 第三栏已落库末级全集+搜索),两处差异:
* ① **多选**——第三栏行点击=toggle(方点 checkbox),「全部类目」行=清空,触发框显示
* 「已选 N 个类目」;② 触发框配色按本页暗色主题适配(面板本体仍是白底弹层)。
*
* 数据边界与后管同源(见 ./jd-category-tree.ts 头注释):采集链只有末级类目名,一/二级
* 不参与过滤;第三栏选项=/api/jd-collect/categories 现算的公共库已落库全集,从未采集过
* 的店铺类目不在集内(先全店采一次即有)。选中值随建单走 categoryPaths → 客户端按
* categoryPath 等值过滤。零依赖自绘(方点/箭头都是 CSS),无 element 依赖。
*
* 交互:点开面板 → 点/hover 一级展第二栏 → 第三栏搜索或点行勾选/取消 → 收面板;
* 「全部类目」行=清空;触发框已选时出 × 清除;面板外点透明遮罩关闭。 */
import { computed, ref } from 'vue'
import { jdCategoryNavChildren, jdCategoryNavRoots } from './jd-category-tree.ts'
const props = defineProps<{
/** 已落库末级类目选项(/api/jd-collect/categories 现算,页面传入:{name, productCount})。 */
options: { name: string; productCount: number }[]
/** 当前选中的末级类目名列表;空数组 = 全部类目(全店采集)。 */
modelValue: string[]
}>()
const emit = defineEmits<{ (event: 'change', value: string[]): void }>()
const open = ref(false)
const activeRoot = ref('')
const searchText = ref('')
const roots = jdCategoryNavRoots()
/** 第二栏=点亮一级的静态二级;无静态子级的一级不出第二栏。 */
const activeChildren = computed(() => jdCategoryNavChildren(activeRoot.value))
/** 第三栏=已落库末级全集按搜索词过滤(大小写不敏感的 includes)。 */
const filteredLeaves = computed(() => {
const keyword = searchText.value.trim().toLowerCase()
if (!keyword) return props.options
return props.options.filter((option) => option.name.toLowerCase().includes(keyword))
})
/** 触发框文案:空=全店采集;一个=类目名;多个=已选 N 个类目(title 列全名)。 */
const triggerText = computed(() => {
const picked = props.modelValue
if (!picked.length) return '全部类目(全店采集)'
if (picked.length === 1) return picked[0]
return `已选 ${picked.length} 个类目`
})
function toggle(): void {
if (open.value) {
close()
return
}
activeRoot.value = ''
searchText.value = ''
open.value = true
}
function close(): void {
open.value = false
activeRoot.value = ''
}
function pickRoot(name: string): void {
activeRoot.value = name
}
function clearAll(): void {
emit('change', [])
close()
}
/** 第三栏行点击=toggle(多选);勾选状态由页面传入的 modelValue 决定。 */
function toggleLeaf(name: string): void {
const picked = props.modelValue.includes(name)
? props.modelValue.filter((item) => item !== name)
: [...props.modelValue, name]
emit('change', picked)
}
function clear(): void {
emit('change', [])
}
</script>
<template>
<div class="cat-cascader">
<button
class="cat-trigger"
type="button"
:class="{ open, filled: modelValue.length > 0 }"
:title="modelValue.length ? modelValue.join('、') : '不选类目=全店采集'"
@click="toggle"
>
<span class="cat-trigger-text">{{ triggerText }}</span>
<span
v-if="modelValue.length"
class="cat-clear"
role="button"
aria-label="清除类目"
@click.stop="clear"
>×</span>
<span class="cat-chevron" aria-hidden="true"></span>
</button>
<!-- 面板外点透明遮罩关闭(零 document 监听器,无泄漏面)。 -->
<div v-if="open" class="cat-mask" @click="close"></div>
<div v-if="open" class="cat-panel">
<!-- 第一栏:静态一级导航(radio 形状照京麦,点选只展开不落值)。 -->
<div class="cat-col">
<div
v-for="root in roots"
:key="root"
class="cat-row"
:class="{ active: activeRoot === root }"
@click="pickRoot(root)"
@mouseenter="pickRoot(root)"
>
<span class="cat-dot" aria-hidden="true"></span>
<span class="cat-name" :title="root">{{ root }}</span>
<span v-if="jdCategoryNavChildren(root).length" class="cat-arrow" aria-hidden="true">›</span>
</div>
</div>
<!-- 第二栏:点亮一级的静态二级(纯导航;归属数据缺,不联动第三栏——组件头注释)。 -->
<div v-if="activeChildren.length" class="cat-col">
<div
v-for="child in activeChildren"
:key="child"
class="cat-row"
>
<span class="cat-dot" aria-hidden="true"></span>
<span class="cat-name" :title="child">{{ child }}</span>
<span class="cat-arrow" aria-hidden="true">›</span>
</div>
</div>
<!-- 第三栏:已落库末级全集+搜索(选中发生地;点行=勾选/取消,随建单走 categoryPaths)。 -->
<div class="cat-col cat-col-leaf">
<div class="cat-row cat-row-all" :class="{ active: !modelValue.length }" @click="clearAll">
<span class="cat-dot" :class="{ on: !modelValue.length }" aria-hidden="true"></span>
<span class="cat-name">全部类目(全店采集)</span>
</div>
<input
v-model="searchText"
type="text"
class="cat-search"
placeholder="搜索类目"
@click.stop
/>
<div v-if="!filteredLeaves.length" class="cat-empty">
{{ options.length ? '未找到类目' : '暂无可选类目:先全店采集一次,落库后这里出选项' }}
</div>
<div
v-for="leaf in filteredLeaves"
:key="leaf.name"
class="cat-row"
:class="{ active: modelValue.includes(leaf.name) }"
@click="toggleLeaf(leaf.name)"
>
<span
class="cat-dot cat-dot-check"
:class="{ on: modelValue.includes(leaf.name) }"
aria-hidden="true"
></span>
<span class="cat-name" :title="leaf.name">{{ leaf.name }}</span>
<span class="cat-count">{{ leaf.productCount }}</span>
</div>
</div>
</div>
</div>
</template>
<style scoped>
.cat-cascader {
position: relative;
min-width: 0;
}
/* 触发框按建单页暗色主题适配(后管筛选框是浅色页,这里页面底 #1a1f2e)。 */
.cat-trigger {
display: flex;
align-items: center;
gap: 8px;
width: 100%;
min-height: 44px;
padding: 8px 12px;
border: 1px solid #3e4a62;
border-radius: 8px;
background: #232b3d;
color: #f5f8fc;
font-size: 13.5px;
font-family: inherit;
cursor: pointer;
text-align: left;
transition: border-color 160ms ease, background 160ms ease;
}
.cat-trigger:hover {
border-color: #5f85ad;
}
.cat-trigger.open {
background: #2b3447;
border-color: #5f85ad;
}
.cat-trigger-text {
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.cat-trigger:not(.filled) .cat-trigger-text {
color: #a0acbe;
}
.cat-clear {
flex: none;
width: 18px;
height: 18px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
background: #3e4a62;
color: #c8d2e2;
font-size: 13px;
line-height: 1;
}
.cat-clear:hover {
background: #52627e;
color: #f5f8fc;
}
/* 下拉箭头:CSS 三角(京麦同款向下 chevron,展开翻向上)。 */
.cat-chevron {
flex: none;
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 6px solid #7b8a99;
transition: transform 160ms ease;
}
.cat-trigger.open .cat-chevron {
transform: rotate(180deg);
}
.cat-mask {
position: fixed;
inset: 0;
z-index: 2550;
}
.cat-panel {
position: absolute;
top: calc(100% + 4px);
left: 0;
right: 0;
z-index: 2560;
display: flex;
align-items: stretch;
max-width: min(720px, 90vw);
border: 1px solid #d8e3ee;
border-radius: 10px;
background: #ffffff;
box-shadow: 0 16px 44px rgba(0, 0, 0, 0.35);
overflow: hidden;
}
.cat-col {
width: 200px;
max-height: 320px;
overflow-y: auto;
padding: 6px 0;
border-right: 1px solid #e7eef5;
}
.cat-col:last-child {
border-right: 0;
}
.cat-col-leaf {
width: 250px;
}
/* 行=京麦同款:圆点 + 名称 + 右箭头;hover 浅蓝底。 */
.cat-row {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 12px;
font-size: 13.5px;
color: #24384d;
cursor: pointer;
}
.cat-row:hover,
.cat-row.active {
background: #f1f7fb;
}
.cat-row.active {
color: #2f5d8b;
font-weight: 550;
}
.cat-dot {
flex: none;
width: 13px;
height: 13px;
border: 1px solid #c0ccda;
border-radius: 50%;
background: #ffffff;
}
/* radio 选中=京麦同款蓝芯;一级/二级的圆点是导航形状,不落选中态。 */
.cat-dot.on {
border-color: #3b82c4;
background: radial-gradient(circle, #3b82c4 0 4px, #ffffff 4.6px);
}
/* 第三栏多选=方点 checkbox(与第一/二栏的导航圆点区分形状)。 */
.cat-dot-check {
border-radius: 3px;
}
.cat-dot-check.on {
background: #3b82c4;
position: relative;
}
.cat-dot-check.on::after {
content: '';
position: absolute;
left: 3px;
top: 0.5px;
width: 5px;
height: 9px;
border: solid #ffffff;
border-width: 0 2px 2px 0;
transform: rotate(45deg);
}
.cat-name {
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.cat-arrow {
flex: none;
color: #9fb0c0;
font-size: 15px;
line-height: 1;
}
.cat-count {
flex: none;
color: #8293a5;
font-size: 12px;
}
.cat-search {
display: block;
width: calc(100% - 20px);
margin: 4px 10px 8px;
min-height: 30px;
padding: 4px 10px;
border: 1px solid #cbd9e6;
border-radius: 8px;
background: #f8fbfd;
color: #24384d;
font-size: 12.5px;
font-family: inherit;
outline: none;
}
.cat-search:focus {
background: #ffffff;
border-color: #5f85ad;
}
.cat-empty {
padding: 16px 12px;
color: #8293a5;
font-size: 12.5px;
text-align: center;
}
</style>
+74 -8
View File
@@ -7,10 +7,12 @@ import {
activateJdCollectTask,
createJdCollectTask,
deleteJdCollectTask,
fetchJdCollectCategories,
fetchJdCollectDashboard,
fetchJdCollectHistory,
fetchJdCollectTaskProgressBatch,
interruptJdCollectTask,
type JdCollectCategoryVo,
type JdCollectHistoryItemVo,
type JdListTab,
} from '@/shared/api/types/modules/jd-collect'
@@ -21,11 +23,14 @@ import { userNotice } from '@/shared/utils/user-notice'
import { formatDateTime } from '@/shared/utils/datetime'
import { useLiveTaskBoard } from '@/shared/composables/useLiveTaskBoard'
import NotificationBell from '@/shared/components/NotificationBell.vue'
import JdCategoryCascader from './JdCategoryCascader.vue'
/** 京东「获取店铺数据」(v1.5):一键建单 → 推送本机客户端 → 右侧任务面板实时进度。
*
* 四个真源与四条边界(照 v1.4 已落地的采集契约与外观专利任务面板骨架,不另造流程):
* 1. 建单走后端 `/api/jd-collect/tasks`(通道恒 LOCAL,服务端落 PENDING);
* 1. 建单走后端 `/api/jd-collect/tasks`(通道恒 LOCAL,服务端落 PENDING);可选多选采集
* 类目(京麦末级类目名,`categoryPaths`)——空=全店采集,选中值随建单进 request_json、
* 随推送/兜底拉取进客户端,客户端按行 categoryPath 等值过滤(三处同键契约);
* 2. 建单成功把 `jd-shop-collect-run` 载荷推进本机客户端队列——只建单不推送会让任务
* 卡在 PENDING 等兜底拉取(v1.4 Phase 6.1 P0-1 的教训);推送失败不回滚建单;
* 3. 进度只读服务端:任务状态 + 合并写游标里的 itemsReceived/total。`total` 缺失时
@@ -46,6 +51,25 @@ const submitting = ref(false)
const errorMessage = ref('')
const successMessage = ref('')
// ---- 采集类目(可选,多选;空=全店采集)----
/** 选项集=公共库已落库 category_path 全集(/api/jd-collect/categories 现算)。
* 拉取失败不阻塞建单(不选类目=全店采集),只把空态文案打出来。 */
const categoryOptions = ref<JdCollectCategoryVo[]>([])
const categoryOptionsLoaded = ref(false)
const selectedCategories = ref<string[]>([])
async function loadCategoryOptions() {
if (categoryOptionsLoaded.value) return
try {
categoryOptions.value = await fetchJdCollectCategories()
} catch (err) {
// 选项是锦上添花:拉不到就保持空态文案,不把「全店采集」这条主路堵死。
console.error('[jd-collect] 类目选项拉取失败(不选类目仍可全店采集)', err)
} finally {
categoryOptionsLoaded.value = true
}
}
function uidForStorage() {
return typeof window !== 'undefined' ? window.localStorage.getItem('uid') || '0' : '0'
}
@@ -220,7 +244,8 @@ async function retryTaskRecord(item: JdCollectHistoryItemVo | null | undefined)
const activateError = await activateTask(taskId)
if (!activateError) {
await pushToClientQueue(taskId, item?.shopName || DEFAULT_SHOP_NAME,
(item?.listTabs?.length ? item.listTabs : DEFAULT_TABS) as JdListTab[])
(item?.listTabs?.length ? item.listTabs : DEFAULT_TABS) as JdListTab[],
item?.categoryPaths ?? [])
}
board.addPollingTask(taskId)
await refreshBoard()
@@ -258,11 +283,14 @@ async function activateTask(id: number): Promise<string | null> {
}
}
/** 建单成功后推送本机队列;返回 null 表示环境无队列能力(浏览器预览),返回 string 表示失败原因。 */
/** 建单成功后推送本机队列;返回 null 表示环境无队列能力(浏览器预览),返回 string 表示失败原因。
* categoryPaths 是建单时选的采集类目(重试/继续从历史行同源带回)——推送载荷与建单请求体、
* 客户端兜底拉取(request_json)三处同键,缺一处客户端就按全店采集跑。 */
async function pushToClientQueue(
id: number,
shop: string,
tabs: JdListTab[],
categoryPaths: string[] = [],
): Promise<string | null> {
const api = getPywebviewApi()
if (!api?.enqueue_json) {
@@ -271,7 +299,7 @@ async function pushToClientQueue(
const payload = {
type: 'jd-shop-collect-run',
ts: Date.now(),
data: { taskId: id, shopName: shop, listTabs: tabs, maxProducts: 0 },
data: { taskId: id, shopName: shop, listTabs: tabs, maxProducts: 0, categoryPaths },
}
const pushResult = await api.enqueue_json(payload)
if (pushResult?.success) {
@@ -293,8 +321,9 @@ async function startCollect() {
submitting.value = true
const shop = DEFAULT_SHOP_NAME
const tabs = DEFAULT_TABS
const categories = [...selectedCategories.value]
try {
const vo = await createJdCollectTask(shop, tabs, 0)
const vo = await createJdCollectTask(shop, tabs, 0, categories)
board.addPollingTask(vo.taskId)
let pushNote = ''
const activateError = await activateTask(vo.taskId)
@@ -304,7 +333,7 @@ async function startCollect() {
pushNote = activateError
} else {
try {
const pushError = await pushToClientQueue(vo.taskId, shop, tabs)
const pushError = await pushToClientQueue(vo.taskId, shop, tabs, categories)
if (pushError) pushNote = pushError
} catch (pushErr) {
// 推送自身异常不回滚建单:任务可由服务端兜底拉取认领。
@@ -315,7 +344,9 @@ async function startCollect() {
if (pushNote) {
errorMessage.value = pushNote
} else {
successMessage.value = '任务已创建并推送给本机客户端,进度显示在右侧任务区'
successMessage.value = categories.length
? `任务已创建(只采 ${categories.length} 个类目)并推送给本机客户端,进度显示在右侧任务区`
: '任务已创建并推送给本机客户端,进度显示在右侧任务区'
}
await Promise.all([board.loadDashboard(), board.loadHistory({ force: true })])
} catch (err) {
@@ -332,6 +363,7 @@ onMounted(async () => {
await Promise.all([
board.loadDashboard().catch(() => undefined),
board.loadHistory().catch(() => undefined),
loadCategoryOptions(),
])
board.seedRunningTasksFromHistory()
board.seedPendingFileTasksFromHistory()
@@ -372,8 +404,22 @@ onUnmounted(() => {
<main class="jd-body">
<aside class="left-panel">
<div class="category-block">
<span class="category-label">采集类目(可选,多选)</span>
<JdCategoryCascader
v-model="selectedCategories"
:options="categoryOptions"
@change="selectedCategories = $event"
/>
<p class="category-hint">
{{ selectedCategories.length
? `只采选中 ${selectedCategories.length} 个类目的商品;清空恢复全店采集。`
: '不选=全店采集。选项来自「京东数据库」已落库类目,新店铺先全店采一次即出。' }}
</p>
</div>
<button class="collect-btn" type="button" :disabled="isRunning" @click="startCollect">
{{ isRunning ? '获取中…' : '一键获取店铺数据' }}
{{ isRunning ? '获取中…' : (selectedCategories.length ? `获取选中类目数据` : '一键获取店铺数据') }}
</button>
<p class="collect-hint">
@@ -603,6 +649,26 @@ onUnmounted(() => {
transition: all 0.2s;
}
/* 类目选择块:与按钮同宽,label 用面板小字口径。 */
.category-block {
margin-bottom: 16px;
}
.category-label {
display: block;
margin-bottom: 8px;
color: #c8d2e2;
font-size: 13px;
font-weight: 600;
}
.category-hint {
margin: 8px 0 0;
color: #7f8ca3;
font-size: 12px;
line-height: 1.6;
}
.collect-btn:hover:not(:disabled) {
filter: brightness(1.1);
transform: translateY(-1px);
@@ -0,0 +1,70 @@
/** 京东类目级联的导航树(建单页「选类目去采集」用;2026-11-16 客户口径「类目要京麦同款
* 级联样式」)。与后管 admin-frontend-vue/src/pages/jd/jd-category-tree.ts 同数据两份正本
* (两个前端仓没有共享包,改树必须两边同轮同步)。
*
* 数据边界(先说清,防止后人当它是全量类目树):
* - 落库 biz_jd_product.category_path = 京麦列表接口 categoryDetailVO.lastCategoryName
* (末级类目名,jd-collect-api-contract.md §2.3 E3),采集链**没有**一/二级类目数据;
* - 所以级联面板的一/二级用这里的**静态导航树**(京东公开类目体系;服饰内衣子树的二级
* 按京麦面板真机样本逐字校正:服饰配件/内衣/女装/男装/定制服装工装),**不参与过滤**;
* - 第三栏(选中发生地)永远是页面传入的**已落库末级类目全集**(/api/jd-collect/categories
* 现算,公共库口径)+搜索框,选中后随建单走 categoryPaths → 客户端按 categoryPath
* 等值过滤。采集链日后补齐一/二级回传时,把本文件的静态树换成 /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 ?? []
}
+2
View File
@@ -207,6 +207,8 @@ export const API_ENDPOINTS = {
/** 京东店铺商品采集(v1.4):建单走 LOCAL 通道,由本机客户端在已登录京麦的窗口内执行。 */
jdCollect: {
create: '/api/jd-collect/tasks',
/** 采集类目下拉数据源(公共库已落库 category_path 全集,建单页多选面板用) */
categories: '/api/jd-collect/categories',
/** 激活(PENDING→RUNNING):推客户端队列**之前**必须调用,否则分片被拒、心跳要求客户端收手 */
activate: '/api/jd-collect/tasks/{taskId}/activate',
/** 采集进度(用户端「获取店铺数据」进度条数据源) */
@@ -61,7 +61,31 @@ export function activateJdCollectTask(taskId: number) {
return unwrapJavaResponse(post<JavaApiResponse<null>, Record<string, unknown>>(path + query, {}))
}
export function createJdCollectTask(shopName: string, listTabs: JdListTab[], maxProducts = 0) {
/** 采集类目选项(GET /api/jd-collect/categories:公共库已落库 category_path 全集+行数)。 */
export interface JdCollectCategoryVo {
name: string;
productCount: number;
}
/**
* 类目选项集(建单页多选面板第三栏)。公共库口径:从未采集过的店铺/新类目不在集内
* (先全店采集一次即有),拉取失败不阻塞建单——不选类目=全店采集。
*/
export function fetchJdCollectCategories() {
return unwrapJavaResponse(
get<JavaApiResponse<JdCollectCategoryVo[]>>(
buildJavaUrl(API_ENDPOINTS.jdCollect.categories),
{ params: { user_id: getCurrentUserId() } },
),
);
}
export function createJdCollectTask(
shopName: string,
listTabs: JdListTab[],
maxProducts = 0,
categoryPaths: string[] = [],
) {
return unwrapJavaResponse(post<JavaApiResponse<JdCollectTaskVo>, Record<string, unknown>>(
buildJavaUrl(API_ENDPOINTS.jdCollect.create),
{
@@ -74,6 +98,9 @@ export function createJdCollectTask(shopName: string, listTabs: JdListTab[], max
shopName,
listTabs,
maxProducts,
// 京麦末级类目名多选;空数组=全店采集(后端归一化后进 request_json,客户端按
// categoryPath 等值过滤——三处同键契约见 JdTaskPullSpiImplTest / jd_base.process_task)。
categoryPaths,
},
))
}
@@ -106,6 +133,8 @@ export interface JdCollectHistoryItemVo {
errorMessage?: string;
shopName?: string;
listTabs?: string[];
/** 建单时选的采集类目(京麦末级类目名多选;空=全店采集)。重试/继续重建推送载荷时同源带回 */
categoryPaths?: string[];
/** 已落京东数据库的商品行数 */
rowCount?: number;
itemsReceived?: number;
@@ -0,0 +1,19 @@
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { jdCategoryNavChildren, jdCategoryNavRoots } from '../src/pages/jd/jd-category-tree.ts'
/** 建单页类目级联的静态导航树(与后管 admin-frontend-vue/tests/jd-product-group.test.ts
* 同判据同数据——两份正本必须同形,改树两边同轮同步)。 */
test('类目级联静态导航树——服饰内衣二级与京麦面板样本逐字同源', () => {
assert.deepEqual(jdCategoryNavChildren('服饰内衣'),
['服饰配件', '内衣', '女装', '男装', '定制服装/工装'])
assert.deepEqual(jdCategoryNavChildren('不存在的一级'), [],
'未知一级回落空子级(面板该栏缺省)')
})
test('一级导航顺序——服饰内衣置首、不得重复、常用集在册', () => {
const roots = jdCategoryNavRoots()
assert.ok(roots.length >= 20, '一级类目常用集至少 20 个')
assert.equal(new Set(roots).size, roots.length, '一级类目不得重复')
assert.equal(roots[0], '服饰内衣', '服饰内衣置首(客户主采类目)')
})
+42
View File
@@ -40,6 +40,48 @@ test('endpoints 注册 jdCollect 端点组', () => {
'endpoints.ts 缺 jdCollect 端点组(建单/心跳/回传三件)')
})
/** 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(建单页类目多选面板的选项源)')
})
test('建单请求体与推送载荷都带 categoryPaths', () => {
const api = readIfExists(
join(process.cwd(), 'src', 'shared', 'api', 'types', 'modules', 'jd-collect.ts'),
'jd-collect.ts',
)
const apiStart = api.indexOf('export function createJdCollectTask')
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(空数组=全店采集)')
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')
})
test('重试/继续从历史行同源带回 categoryPaths', () => {
const page = readIfExists(
join(process.cwd(), 'src', 'pages', 'jd', 'JdCollectTab.vue'),
'JdCollectTab.vue',
)
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 同源字段),缺了客户端会按全店采集跑')
})
/** 2026-11-14 真机实录:建单请求体写成 `user_id` 时后端回一句「user_id 不合法」直接拒,
* 管理员点「一键获取店铺数据」永远失败——Java 侧 DTO 是 camelCase `userId`(无 snake 命名
* 策略),snake 键会被静默丢掉。进度接口的 `?user_id=` 是 @RequestParam,那个名字不改。