feat(phase-1): 京东数据库 UI 改造蓝图 Phase 1——类目计数聚合纯函数+首屏默认档 50
This commit is contained in:
@@ -153,3 +153,78 @@ export function jdCategoryNamesUnder(path: string[]): string[] | null {
|
||||
walk([target])
|
||||
return out
|
||||
}
|
||||
|
||||
/** GET /categories 的计数行({name, productCount},name=京麦末级类目即落库
|
||||
* category_path;同名末级在后端是同一等值桶,此处一行一名)。 */
|
||||
export interface JdCategoryCountEntry {
|
||||
name: string
|
||||
productCount: number
|
||||
}
|
||||
|
||||
/** 带计数的树节点:count=自身名+全部后代名(子树内去重)的 productCount 之和——
|
||||
* 与「点节点 → jdCategoryNamesUnder 展开集合 IN 过滤」的命中集合同源(v1.6 蓝图
|
||||
* Phase 1 备料):徽标数必须就是点它之后列表会命中的行数,两边各算各的就会出现
|
||||
* 「徽标 5、点进去 8 行」。leaf/children 与 JdCategoryNode 同义(leaf=children 空)。 */
|
||||
export interface JdCategoryCountedNode {
|
||||
name: string
|
||||
value: string
|
||||
count: number
|
||||
leaf: boolean
|
||||
children: JdCategoryCountedNode[]
|
||||
}
|
||||
|
||||
/** 计数聚合回执:roots=树形计数树(全部授权类目都在,无词条的节点 count=0);
|
||||
* extra=树上任何节点名(含非叶)都对不上的历史行(树外兜底组——京麦改树后的
|
||||
* 存量 category_path 从这里选,语义同旧版级联第三栏兜底)。 */
|
||||
export interface JdCategoryCountTree {
|
||||
roots: JdCategoryCountedNode[]
|
||||
extra: JdCategoryCountEntry[]
|
||||
/** 兜底组计数和(徽标直接用)。 */
|
||||
extraTotal: number
|
||||
}
|
||||
|
||||
/** /categories 计数行 → 树形计数聚合(v1.6 蓝图 Phase 1)。同名跨支叶(短裤/唐装/
|
||||
* 吊带/背心/赠品)按过滤语义如实计入两个分支——点哪个分支都按同一名字等值命中
|
||||
* 同一批行,不是双计;父层子树内按名字去重求和(与展开集合口径一致,父层徽标
|
||||
* 不因同名跨支翻倍)。名字对不上树上任何节点的行归树外兜底组。脏值归一:空名
|
||||
* 跳过、计数非有限数归 0、负数钳 0、同名多行求和。 */
|
||||
export function jdCategoryCountTree(entries: JdCategoryCountEntry[]): JdCategoryCountTree {
|
||||
const counts = new Map<string, number>()
|
||||
for (const entry of Array.isArray(entries) ? entries : []) {
|
||||
const name = entry && typeof entry.name === 'string' ? entry.name.trim() : ''
|
||||
if (!name) continue
|
||||
const raw = entry.productCount
|
||||
const value = typeof raw === 'number' && Number.isFinite(raw) ? Math.max(0, Math.floor(raw)) : 0
|
||||
counts.set(name, (counts.get(name) ?? 0) + value)
|
||||
}
|
||||
const treeNames = new Set<string>()
|
||||
const build = (
|
||||
nodes: JdCategoryNode[],
|
||||
): { out: JdCategoryCountedNode[]; names: Set<string> } => {
|
||||
const out: JdCategoryCountedNode[] = []
|
||||
const names = new Set<string>()
|
||||
for (const node of nodes) {
|
||||
treeNames.add(node.name)
|
||||
const child =
|
||||
node.children && node.children.length
|
||||
? build(node.children)
|
||||
: { out: [] as JdCategoryCountedNode[], names: new Set<string>() }
|
||||
const set = new Set(child.names)
|
||||
set.add(node.name)
|
||||
let count = 0
|
||||
for (const name of set) count += counts.get(name) ?? 0
|
||||
out.push({ name: node.name, value: node.value, count, leaf: child.out.length === 0, children: child.out })
|
||||
for (const name of set) names.add(name)
|
||||
}
|
||||
return { out, names }
|
||||
}
|
||||
const roots = build(JD_CATEGORY_TREE).out
|
||||
const extra: JdCategoryCountEntry[] = []
|
||||
let extraTotal = 0
|
||||
for (const [name, count] of counts) {
|
||||
if (treeNames.has(name)) continue
|
||||
extra.push({ name, productCount: count })
|
||||
extraTotal += count
|
||||
}
|
||||
return { roots, extra, extraTotal }
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/** 京东数据库页筛选纯函数(v1.4 Phase 5):商品编码/标题关键字/类目/分组/同步起止 + snake 分页参数。
|
||||
* 产出与后端契约 §列表 query 逐字对撞:`page`/`page_size`(默认 20、上限 100)、
|
||||
* 产出与后端契约 §列表 query 逐字对撞:`page`/`page_size`(默认 50、上限 100)、
|
||||
* `product_code`、`title_keyword`、`category`(京麦末级类目等值过滤,2026-11-15 增)、
|
||||
* `group_id`(当前分组下的分类 id)、`owner_group_id`(当前数据权限分组,V203)、
|
||||
* `synced_from`/`synced_to`(ISO yyyy-MM-dd;空白不下发)。
|
||||
@@ -15,9 +15,14 @@
|
||||
import { validIsoDateOrUndefined } from '../asin/asin-filter.ts'
|
||||
import { jdCategoryNamesUnder } from './jd-category-tree.ts'
|
||||
|
||||
/** 每页条数默认 20(v1.4 §3.4),上限 100。 */
|
||||
export const JD_PRODUCT_PAGE_SIZE = 20
|
||||
/** 每页条数默认 50(v1.6 蓝图 Phase 1 新契约,商城款式一屏 50),上限 100。
|
||||
* v1.4 §3.4 的默认 20 由 2026-11-21 蓝图拍板放宽;页面装配层 ref(20) 的旧硬编码
|
||||
* 随 Phase 5 重写改挂本常量,纯函数层先把新契约钉住。 */
|
||||
export const JD_PRODUCT_PAGE_SIZE = 50
|
||||
export const JD_PRODUCT_MAX_PAGE_SIZE = 100
|
||||
/** 每页条数档位(v1.6 新契约 20/50/100):页面装配层的档位选择器从这里取数,
|
||||
* 不再各写各的字面量(Phase 5 接线;旧全局 OldPagination 默认档 10/20/50/100 不动)。 */
|
||||
export const JD_PRODUCT_PAGE_SIZE_OPTIONS = [20, 50, 100] as const
|
||||
/** 页码上限:与后端 MAX_PAGE(CR-18 先例,外观专利同值)对齐,两侧不漂。 */
|
||||
export const JD_PRODUCT_MAX_PAGE = 10_000
|
||||
/** 分类状态快筛的出厂档位(2026-11-17 用户口径「不需要全部分类 默认卡在未分类上就行」):
|
||||
|
||||
@@ -48,8 +48,8 @@ export interface JdProductPageResult {
|
||||
pageSize: number
|
||||
}
|
||||
|
||||
/** 前端首屏默认容量(与 filter 侧 JD_PRODUCT_PAGE_SIZE 同值 20)。 */
|
||||
export const JD_PRODUCT_DEFAULT_SIZE = 20
|
||||
/** 前端首屏默认容量(与 filter 侧 JD_PRODUCT_PAGE_SIZE 同值 50,v1.6 蓝图 Phase 1 新契约)。 */
|
||||
export const JD_PRODUCT_DEFAULT_SIZE = 50
|
||||
|
||||
export function emptyJdProductPage(): JdProductPageResult {
|
||||
return { items: [], total: 0, page: 1, pageSize: JD_PRODUCT_DEFAULT_SIZE }
|
||||
|
||||
Reference in New Issue
Block a user