feat(jd-database): 归属筛选查询——归属下拉追加「按分类查询」组(2026-11-22 用户口径「还要加个归属筛选查询」,11-17 三档快筛升级):四类档位互斥单值(全部/已分类/未分类+当前分组分类项 cat:<id>),分类档走既有 group_id 归属表 EXISTS 下推与侧栏点分类同一条谓词=后端零改动;选分类清店铺孤儿谓词(侧栏同形);下拉值=filter 派生态单真源(jd-product-filter 纯函数 node --test 直测);el-option-group 按 EP 按需注册规矩补样式导入(perf 护栏钉住)

This commit is contained in:
2026-11-22 02:53:21 +08:00
parent 19b32414ac
commit 64e426a941
5 changed files with 219 additions and 23 deletions
@@ -36,8 +36,11 @@ import {
type JdProductGroup,
} from './jd-product-api.ts'
import {
applyJdOwnershipSelection,
createJdProductFilterState,
finitePriceOrNull,
JD_OWNERSHIP_CATEGORY_PREFIX,
jdOwnershipSelectValue,
jdProductFilterActive,
JD_PRODUCT_PAGE_SIZE_OPTIONS,
} from './jd-product-filter.ts'
@@ -170,6 +173,28 @@ function onSelectGroup(id: number | null): void {
apply()
}
// ---------------- 归属筛选查询(2026-11-22 用户口径「还要加个归属筛选查询」) ----------------
// 归属下拉是 filter 的视图:派生(显示档位)与回写(选档补丁)都在 jd-product-filter.ts
// 纯函数里(node --test 直测),本组件只接 change 与重查——真源永远只有 filter 一份。
/** 归属下拉显示档位:分类档(cat:<id>)优先于状态档(''/classified/ungrouped)。 */
const ownershipSelectValue = computed(() => jdOwnershipSelectValue(filter))
/** 「按分类查询」组选项(当前分组的分类;value 由 JD_OWNERSHIP_CATEGORY_PREFIX 拼出)。 */
const ownershipCategoryOptions = computed(() =>
groupOptions.value.map((cat) => ({
id: cat.id,
label: cat.name,
value: `${JD_OWNERSHIP_CATEGORY_PREFIX}${cat.id}`,
})),
)
/** 归属下拉选中即查(回第一页);分类档清店铺孤儿谓词的纪律在纯函数里(侧栏同形)。 */
function onOwnershipSelect(value: string): void {
applyJdOwnershipSelection(filter, value)
apply()
}
// ---------------- 店铺名单(v1.7 F6:侧栏展开/点店铺过滤/行内改名移除/添加店铺弹窗) ----------------
/** 添加店铺弹窗的目标分类(名单挂在分类下;null=弹窗关着)。 */
@@ -717,26 +742,35 @@ onMounted(async () => {
</el-select>
<span v-else class="jd-group-locked" title="你的数据权限内只有这一个分组">{{ currentGroupName }}</span>
</div>
<!-- 归属三档快筛(2026-11-17 用户口径「加个已分类和未分类的筛选」;2026-11-18
「加个全部选项」恢复全量档;2026-11-21「默认改成全部」出厂默认卡 '';
2026-11-22「文字也要改一下 默认全部」placeholder 同步改「全部」):
已分类=当前分组下有分类(V203 归属表,与侧栏分类选中同形);三档下拉、
出厂默认=「全部」(value=''),首屏即查当前分组全部商品(序列化不下发
classified 参数,后端 required=false 跳过谓词);选中即查(回第一页);
「重置」也回全部档。⚠ el-select 对 '' 值按空值处理(useSelect 的
hasModelValue 把 '' 算空)⇒ 界面显示的是本 placeholder 而非「全部」选项的
label,placeholder 文案必须与默认档同词「全部」;写回「未分类」=首屏
灰字撒谎(逻辑已查全量、界面谎称卡未分类)。 -->
<!-- 归属筛选查询(2026-11-22 用户口径「还要加个归属筛选查询」,把 11-17 三档快筛
升级成一颗能按分类查询的归属下拉):四类档位互斥单值——全部('',出厂默认)/
已分类/未分类(状态档,V203 归属表判当前分组下有无分类)+「按分类查询」组
(当前分组的分类项,cat:<id> → group_id 走归属表 EXISTS 下推,与侧栏点分类
同一条谓词);选中即查(回第一页),选分类清店铺孤儿谓词(侧栏同形);
「重置/清除筛选」回全部档,切分组清分类档(changeOwnerGroup 既有链)。
⚠ el-select 对 '' 值按空值处理(useSelect 的 hasModelValue 把 '' 算空)⇒
界面显示的是本 placeholder 而非「全部」选项的 label,placeholder 文案必须与
默认档同词「全部」;写回「未分类」=首屏灰字撒谎(逻辑已查全量、界面谎称卡
未分类)。下拉值是派生态(jdOwnershipSelectValue),不在 filter 里另立真源。 -->
<el-select
v-model="filter.classified"
:model-value="ownershipSelectValue"
class="admin-filter"
placeholder="全部"
aria-label="筛选分类状态"
@change="apply"
filterable
aria-label="筛选归属"
@change="onOwnershipSelect"
>
<el-option label="全部" value="" />
<el-option label="已分类" value="classified" />
<el-option label="未分类" value="ungrouped" />
<el-option-group v-if="ownershipCategoryOptions.length" label="按分类查询">
<el-option
v-for="cat in ownershipCategoryOptions"
:key="cat.id"
:label="cat.label"
:value="cat.value"
/>
</el-option-group>
</el-select>
</div>
@@ -1,5 +1,6 @@
/** 京东数据库页筛选纯函数(v1.7 对齐原型《商品数据商城》):合并搜索/类目/店铺/分组/
* 归属三档/价格区间/同步起止 + snake 分页参数。
* 归属筛选查询(状态三档+按分类查询,2026-11-22 用户口径「还要加个归属筛选查询」)/
* 价格区间/同步起止 + snake 分页参数。
* 产出与后端契约 §列表 query 逐字对撞:`page`/`page_size`(默认 50、上限 1000——v1.7
* 与后端 JdProductQueryService.MAX_PAGE_SIZE 逐字同步放宽,契约测试钉着这两个数)、
* `keyword`(v1.7 合并搜索:后端 `product_code LIKE OR title LIKE`,OR 语义在 SQL 段;
@@ -209,3 +210,45 @@ export function toJdProductListParams(
}
return query
}
// ---------------- 归属筛选查询(2026-11-22 用户口径「还要加个归属筛选查询」) ----------------
// 归属下拉从 11-17 的状态三档(全部/已分类/未分类)升级成一颗能按分类查询的归属下拉:
// 三档之外追加「按分类查询」组(当前分组的分类项),四类档位互斥、单值表达。分类档走
// 既有 group_id → 归属表 EXISTS 下推(铁律 1/20),与侧栏点分类同一条谓词,后端零改动。
/** 归属下拉「按分类查询」档位的 value 前缀:`cat:<id>`。与状态档共用一颗下拉,靠前缀
* 区分档类;模板选项与选档回写都必须从本常量拼/拆,不允许各写字面量。 */
export const JD_OWNERSHIP_CATEGORY_PREFIX = 'cat:'
/** 归属下拉当前应显示的档位值(派生——下拉是 filter 的视图,真源只有 groupId/classified
* 两个字段):分类档优先,groupId 非空时必须卡 `cat:<id>`(同一颗下拉里选了分类就不该
* 显示状态档,反之亦然);否则回状态档。'' 值的显示走 placeholder「全部」(el-select 对
* '' 按空值处理,placeholder 文案必须与默认档同词——f742df9f 同坑,别再写「未分类」)。 */
export function jdOwnershipSelectValue(state: JdProductFilterState): string {
const groupId = (state.groupId || '').trim()
if (groupId) return `${JD_OWNERSHIP_CATEGORY_PREFIX}${groupId}`
return state.classified || ''
}
/** 归属下拉选档 → 筛选态(原地改 state;调用方随后自行重查,本函数不发请求):
* - `cat:<id>`=按分类查询:写 groupId、清状态档;店铺谓词一起清——店铺名单挂在分类下
* (v1.7 名单维度),换分类后旧店铺词是孤儿谓词(店铺全平台 DISTINCT,会命中别组分类
* 下的同名店),与侧栏 onSelectGroup 同一条纪律;类目维(category/categoryPath)是
* 京麦树,独立维度不碰。
* - ''/classified/ungrouped=状态档:写 classified、清 groupId;店铺词不属分类维度,
* 与既有三档行为一致不动 shopName。
* 脏值(未知前缀/非数字 id)按「全部」档兜底——不拿脏值冒充档位(classified 序列化同形)。 */
export function applyJdOwnershipSelection(state: JdProductFilterState, value: string): void {
const raw = (value || '').trim()
if (raw.startsWith(JD_OWNERSHIP_CATEGORY_PREFIX)) {
const id = Number.parseInt(raw.slice(JD_OWNERSHIP_CATEGORY_PREFIX.length), 10)
if (Number.isFinite(id) && id > 0) {
state.groupId = String(id)
state.classified = ''
state.shopName = ''
return
}
}
state.groupId = ''
state.classified = raw === 'classified' || raw === 'ungrouped' ? raw : ''
}
@@ -75,6 +75,7 @@ import 'element-plus/es/components/input-number/style/css'
import 'element-plus/es/components/menu/style/css'
import 'element-plus/es/components/menu-item/style/css'
import 'element-plus/es/components/option/style/css'
import 'element-plus/es/components/option-group/style/css'
import 'element-plus/es/components/progress/style/css'
import 'element-plus/es/components/radio-button/style/css'
import 'element-plus/es/components/radio-group/style/css'
@@ -24,11 +24,14 @@ import { test } from 'node:test'
import assert from 'node:assert/strict'
import {
JD_OWNERSHIP_CATEGORY_PREFIX,
JD_PRODUCT_MAX_PAGE,
JD_PRODUCT_MAX_PAGE_SIZE,
JD_PRODUCT_PAGE_SIZE,
JD_PRODUCT_PAGE_SIZE_OPTIONS,
applyJdOwnershipSelection,
createJdProductFilterState,
jdOwnershipSelectValue,
toJdProductListParams,
} from '../src/pages/jd/jd-product-filter.ts'
import {
@@ -169,6 +172,59 @@ test('京东列表参数——classified 默认全部:已分类→true、未
}
})
/** 归属筛选查询(2026-11-22 用户口径「还要加个归属筛选查询」):归属下拉在状态三档之外
* 追加「按分类查询」组(cat:<id>),四类档位互斥单值。派生(jdOwnershipSelectValue)与
* 回写(applyJdOwnershipSelection)都在 filter 层纯函数里,本组用例钉三件事:
* ① 派生档位——分类档优先于状态档(groupId 非空必须卡 cat:<id>,否则同一颗下拉会同时
* 显示「已分类」和某分类、界面说谎);② 选分类档写 groupId、清状态档、清店铺孤儿谓词
* (店铺名单挂在分类下,换分类后旧店铺词会命中别组同名店——侧栏 onSelectGroup 同纪律);
* ③ 状态档清 groupId 不动店铺词(店铺不属分类维度,与既有三档行为一致);
* 脏值按「全部」兜底,不拿脏值冒充档位。 */
test('归属筛选查询——派生档位:分类档 cat:<id> 优先于状态档、默认卡全部', () => {
assert.equal(jdOwnershipSelectValue(createJdProductFilterState()), '',
'出厂态(groupId 空+classified 全部)下拉派生「全部」档')
assert.equal(
jdOwnershipSelectValue({ ...createJdProductFilterState(), classified: 'ungrouped' }),
'ungrouped',
'状态档原样派生',
)
const state = { ...createJdProductFilterState(), classified: 'classified', groupId: '7' }
assert.equal(jdOwnershipSelectValue(state), `${JD_OWNERSHIP_CATEGORY_PREFIX}7`,
'groupId 非空时分类档优先——下拉只显示分类,不显示状态档(否则界面说谎)')
})
test('归属筛选查询——选分类档写 groupId 清状态档清店铺词;状态档清 groupId 不动店铺词', () => {
// 选分类档:groupId 写入、状态档清空、店铺词清空(孤儿谓词纪律)
const catState = { ...createJdProductFilterState(), classified: 'classified', shopName: '绿屿街道店' }
applyJdOwnershipSelection(catState, `${JD_OWNERSHIP_CATEGORY_PREFIX}7`)
assert.equal(catState.groupId, '7', '选分类=按归属表查该分类(group_id EXISTS 下推)')
assert.equal(catState.classified, '', '分类档与状态档互斥——同一颗下拉选了分类就清状态档')
assert.equal(catState.shopName, '', '换分类必须清店铺词:旧店铺词是孤儿谓词(侧栏 onSelectGroup 同形)')
// 状态档:清 groupId、店铺词不动(店铺不属分类维度)
const stateState = { ...createJdProductFilterState(), groupId: '7', shopName: '绿屿街道店' }
applyJdOwnershipSelection(stateState, 'ungrouped')
assert.equal(stateState.groupId, '', '状态档与分类档互斥——选状态档清 groupId')
assert.equal(stateState.classified, 'ungrouped')
assert.equal(stateState.shopName, '绿屿街道店', '状态档不动店铺词(与既有三档行为一致)')
// 「全部」档:两字段都清
const allState = { ...createJdProductFilterState(), groupId: '7', classified: 'classified' }
applyJdOwnershipSelection(allState, '')
assert.equal(allState.groupId, '', '全部档清分类档')
assert.equal(allState.classified, '', '全部档清状态档')
// 脏值兜底:未知前缀/非数字 id 都按「全部」档,不拿脏值冒充档位
for (const dirty of ['cat:abc', 'cat:0', 'cat:-1', 'shop:9', 'nonsense']) {
const dirtyState = { ...createJdProductFilterState(), groupId: '7', classified: 'classified' }
applyJdOwnershipSelection(dirtyState, dirty)
assert.equal(dirtyState.groupId, '', `脏值 ${dirty} 按「全部」兜底清分类档`)
assert.equal(dirtyState.classified, '', `脏值 ${dirty} 按「全部」兜底清状态档`)
}
})
test('详情解析——attrGroups/images 结构化解析(snake 容错、缺 url 弃行)', () => {
const detail = parseJdProductDetail({
code: 0,
@@ -1,7 +1,7 @@
/**
* 京东数据库页(v1.6 装配 → v1.7 对齐原型《商品数据商城》)的挂载契约。
*
* 形态:顶部通栏面板(v1.7 搜索行:合并搜索框+「筛选」按钮+弹层锚点+分组+归属三档
* 形态:顶部通栏面板(v1.7 搜索行:合并搜索框+「筛选」按钮+弹层锚点+分组+归属筛选查询
* +工具栏:全选本页/取消本页/归入分类/取消归属/删除商品(N),2026-11-21 用户口径
* 「放到上面筛选框」红框整体上移,不再住主面板)+横排体 .jd-body(左侧栏
* JdCategorySidebar:商品目录=京麦授权类目树+计数徽标+树外兜底/店铺分类=当前分组
@@ -509,15 +509,16 @@ describe('分类管理入口(V204 独立页并入侧栏「分类管理」对
})
})
describe('归属三档快筛(三档,2026-11-21 用户口径默认改卡「全部」)', () => {
it('下拉三档且首屏就卡「全部」(首取不带 classified 键=后端跳过谓词查全量)', async () => {
describe('归属筛选查询(2026-11-22 用户口径「还要加个归属筛选查询」,11-17 三档快筛升级)', () => {
it('下拉四类档位互斥单值:状态三档+「按分类查询」组;首屏卡「全部」(首取不带 classified 键)', async () => {
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
expect(optionLabels(wrapper, '筛选分类状态')).toEqual(['全部', '已分类', '未分类'])
// 空分组(beforeEach 默认):只有状态三档,分类组 v-if 不渲染。
expect(optionLabels(wrapper, '筛选归属')).toEqual(['全部', '已分类', '未分类'])
// 首屏可见文案(2026-11-22 用户口径「文字也要改一下 默认全部」):'' 值被 el-select
// 按空值处理(useSelect.hasModelValue 把 '' 算空)⇒ 界面显示的是 placeholder 灰字,
// 不是「全部」选项的 label——placeholder 必须与默认档同词「全部」;写「未分类」=
// 逻辑已查全量、界面却谎称卡在未分类(0a769fa8 后的漏改半边)。
const placeholderEl = selectByLabel(wrapper, '筛选分类状态').find('.el-select__placeholder')
const placeholderEl = selectByLabel(wrapper, '筛选归属').find('.el-select__placeholder')
expect(placeholderEl.exists(), '归属快筛缺 placeholder 节点').toBe(true)
expect(placeholderEl.text()).toBe('全部')
expect(jdApi.fetchJdProductList.mock.calls[0][0]).not.toHaveProperty('classified',
@@ -525,21 +526,68 @@ describe('归属三档快筛(三档,2026-11-21 用户口径默认改卡「
wrapper.unmount()
})
it('有分类时下拉追加「按分类查询」组(当前分组分类项,cat:<id> 值形状)', async () => {
jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS)
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
expect(optionLabels(wrapper, '筛选归属')).toEqual(['全部', '已分类', '未分类', '裙装', '裤装'],
'三档之后追加当前分组的分类项(el-option-group 不产生额外 ElOption label)')
wrapper.unmount()
})
it('选「未分类」下发 classified:false;选「已分类」下发 classified 态', async () => {
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
await pickSelectOption(wrapper, '筛选分类状态', '未分类')
await pickSelectOption(wrapper, '筛选归属', '未分类')
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].classified).toBe('ungrouped',
'未分类是显式选档(api 序列化层再转 classified:false)')
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ page: 1 }, '选中即查回第一页')
await pickSelectOption(wrapper, '筛选分类状态', '已分类')
await pickSelectOption(wrapper, '筛选归属', '已分类')
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].classified).toBe('classified')
wrapper.unmount()
})
it('「重置」(弹层里)不放开筛选,而是回默认「全部」档(首取不带 classified 键)', async () => {
it('按分类查询:选「裙装」→ groupId 下发(归属表 EXISTS 谓词)且不带 classified 键;侧栏选中态同步高亮+回显芯片', async () => {
jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS)
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
await pickSelectOption(wrapper, '筛选分类状态', '已分类')
await pickSelectOption(wrapper, '筛选归属', '裙装')
const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
expect(last).toMatchObject({ groupId: '7', page: 1 }, '选分类=按 group_id 归属表查询(与侧栏点分类同一条谓词)')
expect(last.classified).toBe('', '分类档与状态档互斥——classified 回空(序列化层不下发,键缺省钉在 jd-product-group.test.ts)')
// 下拉是 filter 的视图:侧栏分类行按同一真源(selectedGroupIdNum)高亮。
await pickSideTab(wrapper, '店铺分类')
expect(sideRowBy(sideCustom(wrapper), '裙装').classes()).toContain('selected',
'下拉选分类=侧栏同真源,选中态必须同步高亮')
// 回显条出「分类:裙装」芯片(激活筛选)。
const chips = wrapper.get('.jd-filter-chips')
expect(chips.text()).toContain('分类:裙装')
wrapper.unmount()
})
it('下拉选分类清店铺孤儿谓词(店铺名单挂在分类下);状态档再选=分类档清空(互斥)', async () => {
jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS)
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
// 先经侧栏点店铺(groupId=7 + shopName),再在下拉里换到另一个分类。
await pickSideTab(wrapper, '店铺分类')
await sideRowBy(sideCustom(wrapper), '绿屿街道店').trigger('click')
await flushPromises()
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7', shopName: '绿屿街道店' })
await pickSelectOption(wrapper, '筛选归属', '裤装')
const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
expect(last).toMatchObject({ groupId: '8' }, '下拉换分类=切到新分类的归属查询')
expect(last.shopName).toBe('', '换分类必须清店铺词:旧店铺词是孤儿谓词(会命中别组同名店)')
// 分类档 → 状态档:groupId 清空(同一颗下拉四类档位互斥)。
await pickSelectOption(wrapper, '筛选归属', '已分类')
const after = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
expect(after.groupId).toBe('', '选状态档清分类档')
expect(after.classified).toBe('classified')
wrapper.unmount()
})
it('「重置」(弹层里)不放开筛选,而是回默认「全部」档(首取不带 classified 键);选分类后重置连分类档一起清', async () => {
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
await pickSelectOption(wrapper, '筛选归属', '已分类')
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].classified).toBe('classified')
await openFilterPopover(wrapper)
@@ -548,6 +596,20 @@ describe('归属三档快筛(三档,2026-11-21 用户口径默认改卡「
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).not.toHaveProperty('classified',
'重置回出厂默认档(全部=不带 classified 参数),不是回未分类')
wrapper.unmount()
// 分类档同链:重置清 groupId(回全部档),下拉派生值随之回「全部」。
jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS)
const wrapper2 = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
await pickSelectOption(wrapper2, '筛选归属', '裙装')
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].groupId).toBe('7')
await openFilterPopover(wrapper2)
await wrapper2.findAll('button').find((b) => b.text() === '重置')!.trigger('click')
await flushPromises()
const reset = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
expect(reset.groupId).toBe('', '重置连分类档一起清——归属筛选查询回全部档')
expect(reset.classified).toBe('', '重置回状态档「全部」')
wrapper2.unmount()
})
})