feat(admin-jd): 商品目录只渲染本店有商品的类目分支(去掉「树外兜底」退化解)
客户口径:「正确是一开始显示的那棵树,而不是什么树兜底」。授权树里零命中的分 支整支剪掉: - 本店商品名挂得上树(花屿巷旗舰店)⇒ 只显示命中分支,别店的空类目不再占屏; - 树与本店不同源(家居日用店看别店快照)⇒ 整树剪空,本店类目名平铺成一级列表, 不再出现「授权类目树(本店无匹配)」行 + 说明框,也不再出现「树外兜底」分组; - 树有命中时,挂不上树的本店历史名仍收在一组(改名「授权树外的类目」)。 - 纯函数 jdCategoryPruneZero(零命中整支剪掉、重算 leaf) - 一级默认展开改挂剪枝后的根(空根不置位,等真根到达再补) - 判据:jd-category-tree.test.ts +3(剪枝三态)、侧栏 mount 改写(平铺/剪支/真树)、 page mount 组名同步;source-pin 台账按文件点名 17→20 - 后管 node --test 1982 绿、vitest 252 绿、vue-tsc rc=0,快检四面绿
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
jdCategoryCountTree,
|
||||
jdCategoryLeaves,
|
||||
jdCategoryNamesUnder,
|
||||
jdCategoryPruneZero,
|
||||
jdCategoryRoots,
|
||||
jdCategorySearchLeaves,
|
||||
jdCategorySearchNodes,
|
||||
@@ -262,8 +263,8 @@ test('计数聚合——treeMatched 三态:树内有命中/整树零命中
|
||||
assert.equal(foreign.extraTotal, 264)
|
||||
assert.equal(foreign.roots.every((root) => root.count === 0), true)
|
||||
|
||||
// 数据没到(空输入)同样是 false,但兜底为空——侧栏必须靠 extra 非空才判「不同源」,
|
||||
// 否则加载中会闪一下「本店无匹配」。
|
||||
// 数据没到(空输入)同样是 false,但兜底为空——侧栏靠剪枝后树为空 + extra 非空决定
|
||||
// 怎么渲染(树空则本店类目平铺成一级列表),不靠 treeMatched 判「加载中」。
|
||||
const empty = jdCategoryCountTree([])
|
||||
assert.equal(empty.treeMatched, false)
|
||||
assert.equal(empty.extra.length, 0)
|
||||
@@ -346,3 +347,28 @@ test('计数聚合——传入服务端真树:家居类目挂得上树、不
|
||||
assert.equal(snapshot.treeMatched, false)
|
||||
assert.equal(snapshot.extraTotal, 264)
|
||||
})
|
||||
|
||||
test('剪枝——零命中的别店分支整支剪掉,整树剪空(2026-11-24 客户口径「要的是类目树,不是树外兜底」)', () => {
|
||||
const foreign = jdCategoryCountTree([
|
||||
{ name: '化妆品收纳盒', productCount: 260 },
|
||||
{ name: '其他收纳架', productCount: 4 },
|
||||
])
|
||||
assert.equal(jdCategoryPruneZero(foreign.roots).length, 0,
|
||||
'家居类目套服饰快照树 ⇒ 整树剪空,调用方把 extra 平铺成一级列表(不再有「本店无匹配」档)')
|
||||
})
|
||||
|
||||
test('剪枝——命中分支保留祖先链、重算 leaf,零命中兄弟支不出现', () => {
|
||||
const counted = jdCategoryCountTree([{ name: '连衣裙', productCount: 7 }])
|
||||
const pruned = jdCategoryPruneZero(counted.roots)
|
||||
assert.deepEqual(pruned.map((node) => node.name), ['服饰内衣'], '只有服饰内衣这一支真有商品')
|
||||
assert.equal(nodeAt(pruned, ['服饰内衣', '女装'])!.count, 7, '祖先链上徽标不变(子树去重和)')
|
||||
const dress = nodeAt(pruned, ['服饰内衣', '女装', '连衣裙'])!
|
||||
assert.equal(dress.leaf, true, '子级全被剪掉后重算 leaf(不再显示展开箭头)')
|
||||
assert.equal(nodeAt(pruned, ['服饰内衣', '男装']), null, '零命中兄弟支剪掉')
|
||||
assert.equal(nodeAt(pruned, ['母婴']), null, '整支零命中的一级剪掉')
|
||||
})
|
||||
|
||||
test('剪枝——空输入/异常入参回空数组(渲染层不炸)', () => {
|
||||
assert.deepEqual(jdCategoryPruneZero([]), [])
|
||||
assert.deepEqual(jdCategoryPruneZero(null as unknown as JdCategoryCountedNode[]), [])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user