fix(admin-jd): 别店快照类目树不再冒充本店——整树零命中时收树并点名
- jdCategoryCountTree 增 treeMatched(树内任一节点 count>0);侧栏据此判「内置授权树 与本店不同源」:JD_CATEGORY_TREE 是 2026-11-16 从花屿巷旗舰店抓的固定快照, 家居日用店打开时整树 0 命中、商品全落树外兜底,旧行为让界面看着像这家店卖女装。 - 整树零命中 ⇒ 树默认收起成一行「授权类目树(本店无匹配)」、点开给一句固定快照说明; 兜底行照旧单名等值可选(筛选不因收树失效);树内有命中时渲染与判据都不变。 - 判据:jd-category-tree.test.ts +1(treeMatched 三态)、mount +3(收起/点开/不误伤); 反向验证关掉判据=2 红。后管 node --test 1977 绿、vitest 250 绿、vue-tsc rc=0; 源码钉子基线只动本笔 cases 14→15(pins/reads 不变)。 - 可读性基线逐条点名:JdCategorySidebar.vue 846→890 行(本笔 +44,树消歧模板/文案/CSS)。
This commit is contained in:
@@ -65,6 +65,16 @@ const activeTab = ref<'catalog' | 'custom'>('catalog')
|
|||||||
// ---------------- 计数聚合(Phase 1 纯函数) ----------------
|
// ---------------- 计数聚合(Phase 1 纯函数) ----------------
|
||||||
|
|
||||||
const counted = computed(() => jdCategoryCountTree(props.categoryOptions ?? []))
|
const counted = computed(() => jdCategoryCountTree(props.categoryOptions ?? []))
|
||||||
|
|
||||||
|
/** 内置授权树与本店类目体系不同源:整棵树零命中、且兜底组确有行。内置 `JD_CATEGORY_TREE`
|
||||||
|
* 是 2026-11-16 从**一家店铺**(花屿巷旗舰店)京麦授权接口抓的固定快照,换一家店(如家居
|
||||||
|
* 日用店)打开时它仍是整棵服饰内衣/母婴/运动户外树、节点全 0,而库内商品(收纳盒/脏衣篓…)
|
||||||
|
* 全落树外兜底——不标注就会让人以为「这家店怎么冒出服饰类目」。数据没到(extra 也空)
|
||||||
|
* 不触发,避免把加载中误判成不同源。 */
|
||||||
|
const treeForeign = computed(() => !counted.value.treeMatched && counted.value.extra.length > 0)
|
||||||
|
|
||||||
|
/** 不同源时那棵树的展开态:默认收起(只留一行说明),点开可查原树形状。 */
|
||||||
|
const foreignOpen = ref(false)
|
||||||
/** 「全部商品」徽标=全部计数行求和(树内+树外=有类目名的商品总数;无类目名的行
|
/** 「全部商品」徽标=全部计数行求和(树内+树外=有类目名的商品总数;无类目名的行
|
||||||
* 不在任何类目筛选的命中集里,不计进任何徽标)。 */
|
* 不在任何类目筛选的命中集里,不计进任何徽标)。 */
|
||||||
const totalCount = computed(() =>
|
const totalCount = computed(() =>
|
||||||
@@ -339,12 +349,31 @@ function cancelShopRename(): void {
|
|||||||
<span class="jd-side-name">全部商品</span>
|
<span class="jd-side-name">全部商品</span>
|
||||||
<span class="jd-side-count">{{ totalCount }}</span>
|
<span class="jd-side-count">{{ totalCount }}</span>
|
||||||
</button>
|
</button>
|
||||||
<!-- 全部展开/收起(v1.7 树增强,对齐原型树控件):深树一次到底/一键收干净。 -->
|
<!-- 全部展开/收起(v1.7 树增强,对齐原型树控件):深树一次到底/一键收干净。
|
||||||
<div v-if="flatTree.length" class="jd-side-tree-ops">
|
不同源(treeForeign)时随树一起藏,只在手动点开那棵树时出现。 -->
|
||||||
|
<div v-if="flatTree.length && (!treeForeign || foreignOpen)" class="jd-side-tree-ops">
|
||||||
<button type="button" aria-label="展开全部类目" @click="expandAll">全部展开</button>
|
<button type="button" aria-label="展开全部类目" @click="expandAll">全部展开</button>
|
||||||
<button type="button" aria-label="收起全部类目" @click="collapseAll">全部收起</button>
|
<button type="button" aria-label="收起全部类目" @click="collapseAll">全部收起</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="jd-side-tree">
|
<!-- 不同源说明行(2026-11-23):内置授权树是别店的固定快照、本店类目一个都不在树上。
|
||||||
|
整棵树默认收起,只留这一行点名「本店无匹配」,避免把别店的服饰树当成自己店的类目。 -->
|
||||||
|
<template v-if="treeForeign">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="jd-side-row jd-side-foreign-head"
|
||||||
|
:aria-expanded="foreignOpen"
|
||||||
|
@click="foreignOpen = !foreignOpen"
|
||||||
|
>
|
||||||
|
<span class="jd-side-arrow" :class="{ open: foreignOpen }">▸</span>
|
||||||
|
<span class="jd-side-name">授权类目树(本店无匹配)</span>
|
||||||
|
<span class="jd-side-count">0</span>
|
||||||
|
</button>
|
||||||
|
<p v-if="foreignOpen" class="jd-side-foreign-tip">
|
||||||
|
内置授权类目树是固定快照(取自一家店铺的京麦授权类目),本店商品的类目名都不在其内,
|
||||||
|
已按原名归入下方「树外兜底」。
|
||||||
|
</p>
|
||||||
|
</template>
|
||||||
|
<div class="jd-side-tree" v-show="!treeForeign || foreignOpen">
|
||||||
<button
|
<button
|
||||||
v-for="flat in flatTree"
|
v-for="flat in flatTree"
|
||||||
:key="flat.path.join('/')"
|
:key="flat.path.join('/')"
|
||||||
@@ -694,6 +723,21 @@ function cancelShopRename(): void {
|
|||||||
padding-top: 4px;
|
padding-top: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 不同源说明(2026-11-23):整树零命中时树收成一行,这里给点名句;视觉弱化但可读。 */
|
||||||
|
.jd-side-foreign-head {
|
||||||
|
color: #909399;
|
||||||
|
}
|
||||||
|
|
||||||
|
.jd-side-foreign-tip {
|
||||||
|
margin: 2px 8px 6px;
|
||||||
|
padding: 6px 8px;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #fdf6ec;
|
||||||
|
color: #b88230;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
.jd-side-extra-head {
|
.jd-side-extra-head {
|
||||||
color: #909399;
|
color: #909399;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,6 +181,11 @@ export interface JdCategoryCountTree {
|
|||||||
extra: JdCategoryCountEntry[]
|
extra: JdCategoryCountEntry[]
|
||||||
/** 兜底组计数和(徽标直接用)。 */
|
/** 兜底组计数和(徽标直接用)。 */
|
||||||
extraTotal: number
|
extraTotal: number
|
||||||
|
/** 树内是否有任一节点真有行命中(count>0)。false+extra 非空=当前库内商品的类目名
|
||||||
|
* 一个都不在这棵内置快照树上——侧栏据此把整棵树收成一行提示、不以别店的树冒充本店;
|
||||||
|
* 树上节点全 0(如家居店打开服饰快照树)时这也是**结构性判断**,不是「数据还没到」
|
||||||
|
* (数据没到=extra 也空,不触发)。 */
|
||||||
|
treeMatched: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
/** /categories 计数行 → 树形计数聚合(v1.6 蓝图 Phase 1)。同名跨支叶(短裤/唐装/
|
/** /categories 计数行 → 树形计数聚合(v1.6 蓝图 Phase 1)。同名跨支叶(短裤/唐装/
|
||||||
@@ -226,5 +231,12 @@ export function jdCategoryCountTree(entries: JdCategoryCountEntry[]): JdCategory
|
|||||||
extra.push({ name, productCount: count })
|
extra.push({ name, productCount: count })
|
||||||
extraTotal += count
|
extraTotal += count
|
||||||
}
|
}
|
||||||
return { roots, extra, extraTotal }
|
let treeMatched = false
|
||||||
|
for (const [name, count] of counts) {
|
||||||
|
if (treeNames.has(name) && count > 0) {
|
||||||
|
treeMatched = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { roots, extra, extraTotal, treeMatched }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"note": "readSource 钉子逐文件基线。两把尺子:pins=落在用例体内的读盘,reads=全文读点总数(含模块级夹具与 helper)。都只许减;pins 下降而 reads 没同步下降=把读盘挪出体内,不算改进。由 tests/source-pin-ratchet.test.ts 生成。",
|
"note": "readSource 钉子逐文件基线。两把尺子:pins=落在用例体内的读盘,reads=全文读点总数(含模块级夹具与 helper)。都只许减;pins 下降而 reads 没同步下降=把读盘挪出体内,不算改进。由 tests/source-pin-ratchet.test.ts 生成。",
|
||||||
"totals": {
|
"totals": {
|
||||||
"files": 265,
|
"files": 265,
|
||||||
"cases": 1859,
|
"cases": 1860,
|
||||||
"pins": 463,
|
"pins": 463,
|
||||||
"reads": 664
|
"reads": 664
|
||||||
},
|
},
|
||||||
@@ -318,7 +318,7 @@
|
|||||||
"reads": 5
|
"reads": 5
|
||||||
},
|
},
|
||||||
"jd-category-tree.test.ts": {
|
"jd-category-tree.test.ts": {
|
||||||
"cases": 14,
|
"cases": 15,
|
||||||
"pins": 0,
|
"pins": 0,
|
||||||
"reads": 0
|
"reads": 0
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -244,6 +244,33 @@ test('计数聚合——脏值归一:空名跳过、非有限/负数归 0、
|
|||||||
assert.equal(tree.extraTotal, 0)
|
assert.equal(tree.extraTotal, 0)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('计数聚合——treeMatched 三态:树内有命中/整树零命中(别店快照树)/数据没到', () => {
|
||||||
|
// 树内任一节点有行 ⇒ true(正常店:库内类目名挂得上内置授权树)。
|
||||||
|
const matched = jdCategoryCountTree([{ name: '连衣裙', productCount: 3 }])
|
||||||
|
assert.equal(matched.treeMatched, true)
|
||||||
|
|
||||||
|
// 2026-11-23 活样本:家居日用店打开「花屿巷旗舰店」那份服饰授权快照树——库内
|
||||||
|
// 类目名一个都不在树上(收纳盒/收纳架全落兜底),树内节点全 0。
|
||||||
|
const foreign = jdCategoryCountTree([
|
||||||
|
{ name: '化妆品收纳盒', productCount: 260 },
|
||||||
|
{ name: '其他收纳架', productCount: 4 },
|
||||||
|
])
|
||||||
|
assert.equal(foreign.treeMatched, false, '整树零命中 ⇒ 侧栏收树、不拿别店的树冒充本店')
|
||||||
|
assert.equal(foreign.extra.length, 2)
|
||||||
|
assert.equal(foreign.extraTotal, 264)
|
||||||
|
assert.equal(foreign.roots.every((root) => root.count === 0), true)
|
||||||
|
|
||||||
|
// 数据没到(空输入)同样是 false,但兜底为空——侧栏必须靠 extra 非空才判「不同源」,
|
||||||
|
// 否则加载中会闪一下「本店无匹配」。
|
||||||
|
const empty = jdCategoryCountTree([])
|
||||||
|
assert.equal(empty.treeMatched, false)
|
||||||
|
assert.equal(empty.extra.length, 0)
|
||||||
|
|
||||||
|
// 树内名但计数 0(脏值/归一后)不算命中:徽标与命中集合必须同源。
|
||||||
|
const zero = jdCategoryCountTree([{ name: '连衣裙', productCount: 0 }])
|
||||||
|
assert.equal(zero.treeMatched, false)
|
||||||
|
})
|
||||||
|
|
||||||
test('计数聚合——空输入:全树 0、兜底组空(结构仍完整可渲染)', () => {
|
test('计数聚合——空输入:全树 0、兜底组空(结构仍完整可渲染)', () => {
|
||||||
const tree = jdCategoryCountTree([])
|
const tree = jdCategoryCountTree([])
|
||||||
assert.equal(tree.roots.length, 3)
|
assert.equal(tree.roots.length, 3)
|
||||||
|
|||||||
@@ -218,6 +218,70 @@ describe('树外兜底组(树上对不上的历史行,单名等值出口)'
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('内置授权树与本店不同源(2026-11-23:家居日用店打开服饰快照树)', () => {
|
||||||
|
/** 活样本:库里只有家居收纳类目(家居日用数据库店的 264 件),内置树(花屿巷旗舰店的
|
||||||
|
* 服饰授权快照)节点全 0——旧行为照样渲染整棵服饰树,界面看着像「这家店卖女装」。 */
|
||||||
|
const FOREIGN_OPTIONS: JdProductCategoryOption[] = [
|
||||||
|
{ name: '化妆品收纳盒', productCount: 260 },
|
||||||
|
{ name: '其他收纳架', productCount: 4 },
|
||||||
|
]
|
||||||
|
|
||||||
|
function mountForeign(): VueWrapper<Element> {
|
||||||
|
return mount(JdCategorySidebar, {
|
||||||
|
props: {
|
||||||
|
categoryOptions: FOREIGN_OPTIONS,
|
||||||
|
categories: CATEGORIES,
|
||||||
|
editable: true,
|
||||||
|
selectedCategory: null,
|
||||||
|
selectedGroupId: null,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 树容器的 v-show 态:直接读 inline style(jsdom 的 getComputedStyle 有缓存,
|
||||||
|
* 同一元素二次切换后 isVisible() 仍回旧值——不拿它当判据)。 */
|
||||||
|
function treeDisplay(catalog: VueWrapper<Element>): string {
|
||||||
|
return (catalog.get('.jd-side-tree').element as HTMLElement).style.display
|
||||||
|
}
|
||||||
|
|
||||||
|
it('整树零命中 ⇒ 树默认收起、只留一行「本店无匹配」,兜底行仍可选', async () => {
|
||||||
|
const wrapper = mountForeign()
|
||||||
|
const catalog = wrapper.get('.jd-side-catalog')
|
||||||
|
const head = catalog.get('.jd-side-foreign-head')
|
||||||
|
expect(head.text()).toContain('本店无匹配', '点名「这棵树不适用本店」,不让人以为本店有服饰类目')
|
||||||
|
expect(treeDisplay(catalog)).toBe('none', '整棵树收起(别店快照不冒充本店类目)')
|
||||||
|
expect(catalog.find('.jd-side-tree-ops').exists()).toBe(false, '收起态不摆展开/收起按钮')
|
||||||
|
const extra = rowByText(catalog, '化妆品收纳盒')
|
||||||
|
await extra.trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
expect(wrapper.emitted('select-category')).toEqual([[{ name: '化妆品收纳盒', path: [] }]],
|
||||||
|
'树外历史行照旧按单名等值出口,筛选不因收树失效')
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('点说明行 ⇒ 展开原树与提示文案;再点收起', async () => {
|
||||||
|
const wrapper = mountForeign()
|
||||||
|
const catalog = wrapper.get('.jd-side-catalog')
|
||||||
|
await catalog.get('.jd-side-foreign-head').trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
expect(treeDisplay(catalog)).not.toBe('none', '点开仍可查原树形状(只读参考)')
|
||||||
|
expect(catalog.get('.jd-side-foreign-tip').text()).toContain('固定快照')
|
||||||
|
expect(catalog.find('.jd-side-tree-ops').exists()).toBe(true, '点开后恢复展开/收起操作')
|
||||||
|
await catalog.get('.jd-side-foreign-head').trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
expect(treeDisplay(catalog)).toBe('none')
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('树内有命中时照旧全树渲染(不同源判据不误伤正常店)', () => {
|
||||||
|
const wrapper = mountSidebar()
|
||||||
|
const catalog = wrapper.get('.jd-side-catalog')
|
||||||
|
expect(catalog.find('.jd-side-foreign-head').exists()).toBe(false)
|
||||||
|
expect(treeDisplay(catalog)).not.toBe('none')
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('店铺分类 Tab(当前分组分类平铺+入口分档)', () => {
|
describe('店铺分类 Tab(当前分组分类平铺+入口分档)', () => {
|
||||||
it('点店铺分类切 Tab;分类行带计数;点行 emit id、再点已选中的 emit null(toggle 清选)', async () => {
|
it('点店铺分类切 Tab;分类行带计数;点行 emit id、再点已选中的 emit null(toggle 清选)', async () => {
|
||||||
const wrapper = mountSidebar()
|
const wrapper = mountSidebar()
|
||||||
|
|||||||
Reference in New Issue
Block a user