feat(jd): 采集分类换 el-select 下拉多选(2026-11-17 客户口径「不要全展示出来,弄个下拉式多选」)——9 行复选列表收进 collapse-tags 下拉(+N 徽标),选择模型改 id 数组、双键按快照原序同源反查(点选先后不进请求体);暗色主题套壳。判据:纯测试钉 el-select multiple 在册+shop-cat-list 旧形状反向钉;挂载两格改用真实 ElementPlus 经 update:modelValue 模拟点选(轮询格保持轻量桩——真件在 fake timers 下会打断任务面板轮询链,实测教训写进注释)。node --test 9 例+vitest 挂载 10 例+vue-tsc rc=0
This commit is contained in:
@@ -21,7 +21,7 @@ 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 { JD_SHOP_CATEGORY_SNAPSHOT, type JdShopCategory } from './jd-shop-category.ts'
|
||||
import { JD_SHOP_CATEGORY_SNAPSHOT } from './jd-shop-category.ts'
|
||||
|
||||
/** 京东「获取店铺数据」(v1.5):一键建单 → 推送本机客户端 → 右侧任务面板实时进度。
|
||||
*
|
||||
@@ -55,23 +55,23 @@ const submitting = ref(false)
|
||||
const errorMessage = ref('')
|
||||
const successMessage = ref('')
|
||||
|
||||
// ---- 采集分类(可选,多选;空=全店采集)----
|
||||
// ---- 采集分类(可选,下拉多选;空=全店采集)----
|
||||
/** 选项集=京麦「店内分类」快照(getShopCategoryList,2026-11-16 真机取证 9 个;
|
||||
* 京麦侧改分类后按取证路重抓,见 jd-shop-category.ts 头注释——快照不会自动过期告警)。 */
|
||||
* 京麦侧改分类后按取证路重抓,见 jd-shop-category.ts 头注释——快照不会自动过期告警)。
|
||||
* 2026-11-17 客户口径「不要全展示出来,弄个下拉式多选」:复选列表换 el-select 多选
|
||||
* (collapse-tags 折叠成「+N」徽标),选择模型改存分类 id 数组,label/id 双键从快照反查。 */
|
||||
const shopCategoryOptions = JD_SHOP_CATEGORY_SNAPSHOT
|
||||
const selectedShopCategories = ref<JdShopCategory[]>([])
|
||||
|
||||
function toggleShopCategory(category: JdShopCategory) {
|
||||
const hit = selectedShopCategories.value.find((item) => item.value === category.value)
|
||||
selectedShopCategories.value = hit
|
||||
? selectedShopCategories.value.filter((item) => item.value !== category.value)
|
||||
: [...selectedShopCategories.value, category]
|
||||
}
|
||||
const selectedShopCategoryValues = ref<string[]>([])
|
||||
|
||||
function clearShopCategories() {
|
||||
selectedShopCategories.value = []
|
||||
selectedShopCategoryValues.value = []
|
||||
}
|
||||
|
||||
/** 选中项按快照原序反查回对象(下拉里点选的先后不进请求体——双键顺序恒等于快照序)。 */
|
||||
const selectedShopCategories = computed(() =>
|
||||
shopCategoryOptions.filter((item) => selectedShopCategoryValues.value.includes(item.value)),
|
||||
)
|
||||
|
||||
/** 建单/推送载荷的选中值:label 与 id 双键同发(行级填充形状未取证,任一键命中即命中)。 */
|
||||
const selectedShopCategoryNames = computed(() => selectedShopCategories.value.map((item) => item.label))
|
||||
const selectedShopCategoryIds = computed(() => selectedShopCategories.value.map((item) => item.value))
|
||||
@@ -413,22 +413,17 @@ onUnmounted(() => {
|
||||
<aside class="left-panel">
|
||||
<div class="category-block">
|
||||
<span class="category-label">采集分类(可选,多选)</span>
|
||||
<ul class="shop-cat-list">
|
||||
<li v-for="category in shopCategoryOptions" :key="category.value">
|
||||
<label class="shop-cat-item" :title="`${category.label}(id ${category.value})`">
|
||||
<input type="checkbox" class="shop-cat-check"
|
||||
:checked="selectedShopCategories.some((item) => item.value === category.value)"
|
||||
@change="toggleShopCategory(category)" />
|
||||
<span class="shop-cat-name">{{ category.label }}</span>
|
||||
</label>
|
||||
</li>
|
||||
</ul>
|
||||
<el-select v-model="selectedShopCategoryValues" multiple collapse-tags collapse-tags-tooltip
|
||||
:max-collapse-tags="1" placeholder="不选=全店采集(点击选择分类)" class="shop-cat-select">
|
||||
<el-option v-for="category in shopCategoryOptions" :key="category.value"
|
||||
:label="category.label" :value="category.value" />
|
||||
</el-select>
|
||||
<p class="category-hint">
|
||||
{{ selectedShopCategories.length
|
||||
? `只采选中 ${selectedShopCategories.length} 个分类的商品;`
|
||||
{{ selectedShopCategoryValues.length
|
||||
? `只采选中 ${selectedShopCategoryValues.length} 个分类的商品;`
|
||||
: '不选=全店采集。' }}
|
||||
分类是京麦后台「店内分类」(2026-11-16 快照);商品要先在京麦挂上分类才会被选中。
|
||||
<button v-if="selectedShopCategories.length" class="shop-cat-clear" type="button"
|
||||
<button v-if="selectedShopCategoryValues.length" class="shop-cat-clear" type="button"
|
||||
@click="clearShopCategories">清空</button>
|
||||
</p>
|
||||
</div>
|
||||
@@ -667,42 +662,21 @@ onUnmounted(() => {
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
/* 采集分类多选块(2026-11-16 京麦店内分类快照):label 复用 category-label,
|
||||
* 列表项按暗色主题复选行样式(快照是纯前端数据,无加载失败分支)。 */
|
||||
.shop-cat-list {
|
||||
margin: 8px 0 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
/* 采集分类下拉多选(2026-11-17 客户口径「别全展示,弄下拉式多选」):
|
||||
* 暗色主题套品牌页 el-select 同款壳(wrapper 底色/描边/文字色),
|
||||
* 面板内弹层由 Element Plus 自带样式,不再逐条铺 9 行复选框。 */
|
||||
.shop-cat-select {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.shop-cat-item {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 5px 10px;
|
||||
border: 1px solid #3e4a62;
|
||||
border-radius: 6px;
|
||||
background: #232b3d;
|
||||
.shop-cat-select :deep(.el-select__wrapper) {
|
||||
background-color: #232b3d;
|
||||
box-shadow: 0 0 0 1px #3e4a62 inset;
|
||||
}
|
||||
|
||||
.shop-cat-select :deep(.el-select__placeholder),
|
||||
.shop-cat-select :deep(.el-select__selected-item) {
|
||||
color: #c8d2e2;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.shop-cat-item:hover {
|
||||
border-color: #5a6b8c;
|
||||
}
|
||||
|
||||
.shop-cat-check {
|
||||
accent-color: #e1251b;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.shop-cat-name {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.shop-cat-clear {
|
||||
|
||||
@@ -71,6 +71,10 @@ test('分类多选来自京麦店内分类快照,平台分组从本页下线',
|
||||
'JdCollectTab.vue 必须消费京麦店内分类快照(jd-shop-category.ts)作采集分类多选选项')
|
||||
assert.ok(page.includes('采集分类(可选,多选)'),
|
||||
'JdCollectTab.vue 必须以「采集分类(可选,多选)」展示分类块')
|
||||
assert.ok(page.includes('<el-select') && page.includes('multiple'),
|
||||
'采集分类必须是下拉式多选(el-select multiple,2026-11-17 客户口径「不要全展示出来,弄个下拉式的多选」)')
|
||||
assert.ok(!page.includes('shop-cat-list'),
|
||||
'JdCollectTab.vue 不得再回到逐条复选框列表(旧形状 2026-11-17 下线)')
|
||||
assert.ok(!page.includes('JdCategoryCascader'),
|
||||
'JdCollectTab.vue 不得再引用类目级联(2026-11-16 客户口径「类目不需要」)')
|
||||
assert.ok(!page.includes('fetchJdCollectGroups'),
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import ElementPlus, { ElOption, ElSelect } from 'element-plus'
|
||||
|
||||
import JdCollectTab from '@/pages/jd/JdCollectTab.vue'
|
||||
|
||||
@@ -101,13 +102,33 @@ function batchOf(item: Record<string, unknown>) {
|
||||
|
||||
let wrapper: VueWrapper | null = null
|
||||
|
||||
async function mountPage() {
|
||||
/** el-select/el-option 轻量桩:轮询组用例不带真实 ElementPlus——真件在 fake timers 下
|
||||
* 的内部计时/Popper 会被 `advanceTimersByTimeAsync(60s)` 一并点燃、打断任务面板轮询链
|
||||
* (2026-11-17 改版实测 SUCCESS/FAILED 两格因此转红)。下拉形状由分类两格的真实组件
|
||||
* 用例兜底,这里只保证模板可解析、v-model 透传、选项渲染计数。 */
|
||||
const ElSelectStub = {
|
||||
name: 'ElSelect',
|
||||
props: ['modelValue'],
|
||||
emits: ['update:modelValue'],
|
||||
template: '<div class="shop-cat-select"><slot /></div>',
|
||||
}
|
||||
const ElOptionStub = {
|
||||
name: 'ElOption',
|
||||
props: ['label', 'value'],
|
||||
template: '<div class="shop-cat-option">{{ label }}</div>',
|
||||
}
|
||||
|
||||
async function mountPage(realSelect = false) {
|
||||
wrapper = mount(JdCollectTab, {
|
||||
global: {
|
||||
// 分类两格用真实 ElementPlus 组件树(经 update:modelValue 模拟点选,
|
||||
// 弹层 teleport 到 body,不依赖开合动画);其余格用桩。
|
||||
...(realSelect ? { plugins: [ElementPlus] } : {}),
|
||||
stubs: {
|
||||
NotificationBell: true,
|
||||
RouterLink: { template: '<a class="router-link-stub"><slot /></a>' },
|
||||
'router-link': { template: '<a class="router-link-stub"><slot /></a>' },
|
||||
...(realSelect ? {} : { 'el-select': ElSelectStub, 'el-option': ElOptionStub }),
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -284,52 +305,52 @@ describe('获取店铺数据:一键采集 + 任务面板', () => {
|
||||
expect(w.find('.feedback.error').exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('勾选分类后建单:店内分类双键随建单请求体与推送载荷同链下发', async () => {
|
||||
// 2026-11-16 客户口径「类目不需要只要分类」「选京麦的内部分类去采集」+「做成多选的」:
|
||||
// 选项集=京麦「店内分类」快照(jd-shop-category.ts,getShopCategoryList 取证 9 个),
|
||||
// checkbox 多选;建单请求体与推送载荷带 label+id 双键(行级填充形状未取证,客户端
|
||||
// 任一键命中即命中)——mock 选中项用快照真实行(拉丁舞服/1024347572),贴合下发形状。
|
||||
const w = await mountPage()
|
||||
it('下拉选分类后建单:店内分类双键随建单请求体与推送载荷同链下发', async () => {
|
||||
// 2026-11-16 客户口径「类目不需要只要分类」「选京麦的内部分类去采集」;
|
||||
// 2026-11-17 客户口径「不要全展示出来,弄个下拉式多选」:checkbox 列表换 el-select
|
||||
// 多选(collapse-tags)。选项集=京麦「店内分类」快照(jd-shop-category.ts,取证 9 个),
|
||||
// 选择模型是 id 数组;建单请求体与推送载荷带 label+id 双键、按快照原序反查(行级填充
|
||||
// 形状未取证,客户端任一键命中即命中)——选中项用快照真实行,贴合下发形状。
|
||||
const w = await mountPage(true)
|
||||
|
||||
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)
|
||||
const select = w.findComponent(ElSelect)
|
||||
expect(select.exists(), '采集分类必须是下拉多选(el-select),不再是逐条复选框').toBe(true)
|
||||
await select.vm.$emit('update:modelValue', ['1024347572', '1024347567'])
|
||||
await flushPromises()
|
||||
|
||||
await startCollect(w)
|
||||
|
||||
// 双键顺序恒等于快照序(工作制服在前),与点选先后无关——同源反查,不随 UI 顺序漂。
|
||||
expect(api.createJdCollectTask).toHaveBeenCalledWith('京麦后台', ['ONSALE', 'OFFSALE'], 0, [],
|
||||
['拉丁舞服', '工作制服'], ['1024347572', '1024347567'])
|
||||
['工作制服', '拉丁舞服'], ['1024347567', '1024347572'])
|
||||
const payload = api.enqueue.mock.calls[0][0]
|
||||
expect(payload.data).toEqual({
|
||||
taskId: 88,
|
||||
shopName: '京麦后台',
|
||||
listTabs: ['ONSALE', 'OFFSALE'],
|
||||
maxProducts: 0,
|
||||
shopCategoryNames: ['拉丁舞服', '工作制服'],
|
||||
shopCategoryIds: ['1024347572', '1024347567'],
|
||||
shopCategoryNames: ['工作制服', '拉丁舞服'],
|
||||
shopCategoryIds: ['1024347567', '1024347572'],
|
||||
})
|
||||
})
|
||||
|
||||
it('采集分类块:快照选项全量渲染并可取消勾选(清空恢复全店采集)', async () => {
|
||||
const w = await mountPage()
|
||||
it('采集分类块:下拉渲染快照全量选项并可清空(恢复全店采集)', async () => {
|
||||
const w = await mountPage(true)
|
||||
|
||||
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)
|
||||
// 快照 9 项全进下拉选项(客户端「能看见管理员/商家建的分类」口径落点就在这;
|
||||
// 弹层 teleport 到 body,选项组件仍挂在页面组件树里,按组件计数不按 DOM)
|
||||
expect(w.findAllComponents(ElOption).length).toBe(9)
|
||||
expect(block!.find('.shop-cat-select').exists(), '分类块必须是 el-select 下拉').toBe(true)
|
||||
expect(block!.text()).toContain('不选=全店采集')
|
||||
|
||||
const first = block!.findAll('.shop-cat-item')[0]
|
||||
await first.find('input').setValue(true)
|
||||
const select = block!.findComponent(ElSelect)
|
||||
await select.vm.$emit('update:modelValue', ['1024347567'])
|
||||
await flushPromises()
|
||||
expect(block!.text()).toContain('只采选中 1 个分类的商品')
|
||||
expect(block!.find('.shop-cat-clear').exists()).toBe(true, '选中后出「清空」')
|
||||
expect(block!.find('.shop-cat-clear').exists(), '选中后出「清空」').toBe(true)
|
||||
await block!.find('.shop-cat-clear').trigger('click')
|
||||
await flushPromises()
|
||||
expect(block!.text()).toContain('不选=全店采集')
|
||||
|
||||
Reference in New Issue
Block a user