feat(京东数据库): 撤销按公司隔离回归全平台共享采集池+后管商品目录改京东平台类目平铺

客户口径(2026-11-26):「采集的数据可以重复被操作分类,大家一起采集,但分类后的
数据就自己看,所以会有数据副本」「被分类后按组 id 绑定拷贝数据副本,原来的数据
也要留着」。

- 可见口径:商品行全平台共享(2026-11-23 的按公司隔离整批撤销),读侧撤
  companyId 谓词(列表/类目下拉/候选店铺/详情/导出),写侧撤 assertRowsInCompany
  行级公司闸——越权由端点级 requireJdProductWrite(仅平台超管+公司超管)兜住。
  「副本」落在 V203 归属行上:同一商品可多组各一条 owner_group_id,分类列/分类
  筛选各看各的;原商品行一条不删不藏,别组分过类的在本组仍显示未分类、可再分。
- 用户端选品 pageInScope 不再按 companyId 收窄(只认可见分组下的归属行)。
- 后管左栏「商品目录」:授权类目树/内置花屿巷快照退役,改为 /categories 的
  category_path 平铺(末级类目名+商品数),点行=末级名等值过滤;删
  jd-category-tree.ts / jd-shop-category-api.ts 及其测试,JdDatabasePage 不再取树。
- 判据:AdminJdProductControllerTest 34、JdProductMapperSqlTest 5、
  JdGroupShopServiceTest 10、JdProductQueryServiceUserPageTest 7 全绿;
  后管 node --test 1963/vitest 250/vue-tsc rc=0。
This commit is contained in:
2026-11-26 13:08:21 +08:00
parent f88b3d4622
commit bddde97285
25 changed files with 434 additions and 1846 deletions
@@ -1,22 +1,17 @@
<script setup lang="ts">
/** 京东数据库页左侧栏(v1.6 蓝图 Phase 2,additive——页面接线随 Phase 5):
* 双 Tab=商品目录(京麦授权类目真树+计数徽标+展开折叠+树外类目组)/
* 店铺分类(当前数据权限分组的分类平铺+计数+新建分类+分类管理入口)。
/** 京东数据库页左侧栏:
* 双 Tab=商品目录(<b>京东平台类目平铺</b>:后端 `/categories` 的 DISTINCT `category_path`
* 末级类目名+商品数)/店铺分类(当前数据权限分组的分类平铺+计数+新建分类+分类管理入口)。
*
* 纯展示组件:取数与失败兜底全在页面(props 流入、emit 流出),本组件不发请求、
* 不 import api——mount 测试免 mock;内部状态只有双 Tab 切换、树展开/折叠与新建输入框。
* 计数聚合走 jdCategoryCountTree(v1.6 Phase 1):节点徽标=自身名+子树叶和(与
* 「点节点 → 子树展开 IN 过滤」的命中集合同源)。树只渲染本店真有商品的类目分支
* (零命中整支剪掉,2026-11-24),树上挂不上的本店类目平铺/归组显示,点行=单名等值
* 旧形状(path 空数组交给页面回落)。 */
import { computed, nextTick, ref, watch } from 'vue'
import {
JD_CATEGORY_TREE,
jdCategoryCountTree,
jdCategoryPruneZero,
type JdCategoryCountedNode,
type JdCategoryNode,
} from './jd-category-tree.ts'
* 不 import api——mount 测试免 mock;内部状态只有双 Tab 切换与新建输入框。
*
* 2026-11-26 客户口径(「京东分类是百分百有的,京东内分类就不需要」):商品目录改用
* **京东平台类目**,不再依赖按店铺上报的授权类目树 `biz_jd_shop_category_tree`,也不再
* 回落内置快照 `JD_CATEGORY_TREE`(那是 2026-11-16 一家店的历史取证,换店必整树零命中,
* 此前靠「零命中剪枝+树外兜底组」打补丁)。平铺一层后点行=该末级类目名等值过滤,
* 与后端 `p.category_path IN (...)` 单元素集合逐字同形。 */
import { computed, ref } from 'vue'
import type { JdProductCategoryOption, JdProductGroup } from './jd-product-api.ts'
const props = withDefaults(defineProps<{
@@ -35,10 +30,6 @@ const props = withDefaults(defineProps<{
selectedGroupId?: number | null
/** 当前店铺筛选(v1.7 店铺名单点选;空/缺省=未按店铺过滤)。 */
selectedShopName?: string | null
/** 授权类目树(2026-11-23):页面从服务端取「已上报店铺并集」的真树传入;
* 缺省/空数组=回落内置快照(`JD_CATEGORY_TREE`,一家店的历史取证,
* 另由零命中剪枝兜住,不冒充本店类目)。 */
categoryTree?: JdCategoryNode[] | null
/** 类目计数行是否已取过(页面 loading 态投影;缺省/true=已就绪)。首帧未就绪时侧栏
* 不画树:否则会先把回落快照整棵树(别店类目、徽标全 0、「全部商品 0」)画出来,计数
* 到达后再收成「本店无匹配」一行——用户肉眼看到一次「过一会变了」的闪变。 */
@@ -50,8 +41,8 @@ const props = withDefaults(defineProps<{
})
const emit = defineEmits<{
/** 选类目:树内节点带完整路径(页面按子树展开类目名集合 IN 下发);树外名
* path=[](序列化回落单名等值);null=「全部商品」清选重查。 */
/** 选类目:京东平台类目末级名,path 恒为空数组(页面按单名集合 IN 下发);
* null=「全部商品」清选重查。 */
(event: 'select-category', value: { name: string; path: string[] } | null): void
/** 选分类:分类 id;再点已选中的=清选(emit null,回全部分类)。 */
(event: 'select-group', id: number | null): void
@@ -78,196 +69,31 @@ const emit = defineEmits<{
/** 左 Tab 内置展示态:出厂停在「商品目录」(首屏主筛选面)。 */
const activeTab = ref<'catalog' | 'custom'>('catalog')
// ---------------- 计数聚合(Phase 1 纯函数) ----------------
/** 生效的授权类目树:服务端真树优先,没有则回落到内置快照(一家店的历史取证)。 */
const activeTree = computed<JdCategoryNode[]>(() =>
(props.categoryTree && props.categoryTree.length ? props.categoryTree : JD_CATEGORY_TREE))
const counted = computed(() => jdCategoryCountTree(props.categoryOptions ?? [], activeTree.value))
// ---------------- 商品目录(京东平台类目平铺) ----------------
/** 类目计数就绪(页面首帧未回时只留加载行,总数显示「—」)。 */
const catalogReady = computed(() => props.categoriesReady !== false)
/** 只渲染「本店真有商品」的类目分支(2026-11-24 客户口径「正确是一开始显示的那样,而不是
* 什么树兜底」):授权树里 count=0 的整支剪掉——落地后效果是
* - 本店商品名都在树上(如花屿巷旗舰店)⇒ 只显示命中分支,别店的空分支不出现;
* - 树与本店不同源(如家居日用店看花屿巷快照)⇒ 整树剪空 ⇒ 本店类目名平铺成一级列表,
* 既不再显示别店的服饰树,也不再出现「树外兜底」这种退化分组。
* 树内节点徽标本来就是子树去重和(jdCategoryCountTree 同源),剪枝只裁掉 count=0 且无子的节点。 */
const visibleRoots = computed(() => jdCategoryPruneZero(counted.value.roots))
/** 树之外的本店类目(授权树里对不上的名字);树被剪空时它们就是整列内容,故不摆分组头。 */
const extraIsSolo = computed(() => visibleRoots.value.length === 0)
/** 「全部商品」徽标=全部计数行求和(树内+树外=有类目名的商品总数;无类目名的行
* 不在任何类目筛选的命中集里,不计进任何徽标)。 */
/** 「全部商品」徽标=全部计数行求和(有类目名的商品总数;无类目名的行不在任何类目筛选的
* 命中集里,不计进任何徽标)。 */
const totalCount = computed(() =>
(props.categoryOptions ?? []).reduce((sum, row) => sum + (row.productCount || 0), 0))
/** 展开态:按路径串('/' 连接)记。出厂(无记忆)一级默认展开(二级可见);
* v1.7 树增强:展开态持久化 localStorage `jd_db_cat_expand`(切页/重进不丢),损坏/不存在
* =按出厂态(宁可重展一级也不冒充用户记忆)。 */
const EXPAND_STORAGE_KEY = 'jd_db_cat_expand'
/** 商品目录行:后端 `/categories` 已按类目名升序 DISTINCT,这里只归一脏数据
* (空名/负计数),一列平铺——没有树、没有展开折叠、没有「树外兜底」分组。 */
const catalogRows = computed(() =>
(props.categoryOptions ?? [])
.filter((row) => !!row.name && !!row.name.trim())
.map((row) => ({ name: row.name, productCount: row.productCount || 0 })))
/** 读展开记忆:合法字符串数组才采信;返回「键集+是否有记忆」两个值——空数组 `[]` 是
* 用户主动「全部收起」的合法记忆,不得与「没存过」混为一谈(混了=全收起被重置成
* 一级展开,用户意图被吞)。坏形状/不可读回无记忆。 */
function loadExpandedKeys(): { keys: Set<string>; stored: boolean } {
try {
const raw = localStorage.getItem(EXPAND_STORAGE_KEY)
if (raw === null) return { keys: new Set(), stored: false }
const parsed: unknown = JSON.parse(raw)
if (!Array.isArray(parsed)) return { keys: new Set(), stored: false }
return { keys: new Set(parsed.filter((value): value is string => typeof value === 'string')), stored: true }
} catch {
return { keys: new Set(), stored: false }
}
}
const initialExpand = loadExpandedKeys()
const expanded = ref<Set<string>>(initialExpand.keys)
const expandKey = (path: string[]): string => path.join('/')
function persistExpanded(): void {
try {
localStorage.setItem(EXPAND_STORAGE_KEY, JSON.stringify([...expanded.value]))
} catch {
// 存储不可写(隐私模式/配额满)=展开态只活在本会话,树功能不受影响。
}
}
/** 是否有持久化记忆:有(哪怕空集=全收起)=尊重记忆(不再补一级展开);无=树根到达时
* 补一级默认展开。注意 setup 时树数据通常还没到(页面先 scope 后列表),「一级默认展开」
* 必须挂树根 watch 而不是 init 直接遍历(旧写法 roots 为空什么也没加=默认展开从未真正生效)。 */
let hasStoredExpand = initialExpand.stored
watch(
() => visibleRoots.value,
(roots) => {
if (hasStoredExpand) return
// 树还没到(首帧计数空 / 整树被剪空)不置位:等真根到达时再补一级展开。
if (!roots.length) return
const next = new Set(expanded.value)
for (const root of roots) next.add(expandKey([root.name]))
// 补过一次就置位:之后类目重取不再补默认(用户中途收起的一级行不被重取展开回去)。
hasStoredExpand = true
if (next.size !== expanded.value.size) {
expanded.value = next
persistExpanded()
}
},
{ immediate: true },
)
// ---------------- 商品目录树:扁平渲染(深度缩进 + 祖先全展开才可见) ----------------
interface FlatNode {
node: JdCategoryCountedNode
path: string[]
depth: number
}
const flatTree = computed<FlatNode[]>(() => {
const out: FlatNode[] = []
const walk = (nodes: JdCategoryCountedNode[], depth: number, prefix: string[]): void => {
for (const node of nodes) {
const path = [...prefix, node.name]
out.push({ node, path, depth })
if (node.children.length && expanded.value.has(expandKey(path))) {
walk(node.children, depth + 1, path)
}
}
}
walk(visibleRoots.value, 0, [])
return out
})
function toggleExpand(path: string[]): void {
const key = expandKey(path)
const next = new Set(expanded.value)
if (next.has(key)) next.delete(key)
else next.add(key)
expanded.value = next
persistExpanded()
}
/** 全部展开(v1.7 树增强):把每个有子级的节点 path 全收进展开集(深树一次到底)。 */
function expandAll(): void {
const next = new Set<string>()
const walk = (nodes: JdCategoryCountedNode[], prefix: string[]): void => {
for (const node of nodes) {
const path = [...prefix, node.name]
if (node.children.length) {
next.add(expandKey(path))
walk(node.children, path)
}
}
}
walk(visibleRoots.value, [])
expanded.value = next
hasStoredExpand = true
persistExpanded()
}
/** 全部收起:清空展开集(一级也收,用户主动点了收起就是要全收)。 */
function collapseAll(): void {
expanded.value = new Set()
hasStoredExpand = true
persistExpanded()
}
/** 点树行=选中即筛;非末级行顺手展开(下钻感,与京麦列表筛选器同形;收起走箭头)。 */
function pickNode(node: FlatNode): void {
if (node.node.children.length && !expanded.value.has(expandKey(node.path))) {
toggleExpand(node.path)
}
emit('select-category', { name: node.node.name, path: node.path })
}
/** 外部选中态(重置/清选/页面回显):展开选中节点的全部祖先,让它可见,并把选中行
* 滚进视口(v1.7 树增强;jsdom 无 scrollIntoView 自动跳过——测试不需要真滚)。
* immediate=页面带着已激活的类目筛选挂载侧栏时(如切换回本页),选中路径直接展开到位。 */
watch(
() => props.selectedCategory,
(selected) => {
if (!selected || !selected.path.length) return
const next = new Set(expanded.value)
for (let i = 1; i < selected.path.length; i++) {
next.add(expandKey(selected.path.slice(0, i)))
}
if (next.size !== expanded.value.size) {
expanded.value = next
persistExpanded()
}
void nextTick(() => {
const picked = document.querySelector('.jd-side-tree .jd-side-row.selected')
if (picked && typeof picked.scrollIntoView === 'function') {
picked.scrollIntoView({ block: 'nearest' })
}
})
},
{ immediate: true },
)
const isSelectedNode = (node: FlatNode): boolean => {
const selected = props.selectedCategory
if (!selected || selected.path.length !== node.path.length) return false
return selected.path.every((name, index) => name === node.path[index])
}
// ---------------- 树外类目组(树上挂不上的本店行,单名等值出口) ----------------
const extraOpen = ref(true)
function pickExtra(name: string): void {
// 树外名不进树:path 空数组=页面按「无路径」序列化(单名等值旧形状,不静默丢筛选)。
/** 点一行=按该末级类目名等值过滤(path 空数组,页面按单名集合下发,不静默丢筛选)。 */
function pickCatalogRow(name: string): void {
emit('select-category', { name, path: [] })
}
const isSelectedExtra = (name: string): boolean => {
const selected = props.selectedCategory
return !!selected && selected.path.length === 0 && selected.name === name
}
/** 选中回显:当前筛选的类目名与行名逐字相同即高亮。 */
const isSelectedCatalogRow = (name: string): boolean =>
!!props.selectedCategory && props.selectedCategory.name === name
// ---------------- 店铺分类 Tab(当前分组分类平铺+店铺名单 v1.7) ----------------
@@ -364,7 +190,8 @@ function cancelShopRename(): void {
>店铺分类</button>
</div>
<!-- 商品目录:全部商品 + 京麦授权类目树(计数徽标)+ 树外类目组 -->
<!-- 商品目录(2026-11-26):全部商品 + 京东平台类目平铺(category_path 末级名+计数)。
不再依赖授权类目树/店铺内分类——客户口径「京东分类是百分百有的,京东内分类不需要」。 -->
<div v-show="activeTab === 'catalog'" class="jd-sidebar-body jd-side-catalog">
<button
type="button"
@@ -375,69 +202,25 @@ function cancelShopRename(): void {
<span class="jd-side-name">全部商品</span>
<span class="jd-side-count">{{ catalogReady ? totalCount : '—' }}</span>
</button>
<!-- 类目计数未就绪(页面首帧):只留一行加载提示,不画整棵树——
否则会先显示回落快照的别店类目(徽标全 0),数据到达后再收树,肉眼一次闪变。 -->
<!-- 类目计数未就绪(页面首帧):只留一行加载提示,不画列表(先画空列表再跳成有数据会闪变)。 -->
<p v-if="!catalogReady" class="jd-side-loading">类目加载中…</p>
<!-- 全部展开/收起(v1.7 树增强,对齐原型树控件):深树一次到底/一键收干净。
只对「真有命中的树」摆(整树被剪空时下面直接是本店类目平铺列表)。 -->
<div v-if="catalogReady && flatTree.length" class="jd-side-tree-ops">
<button type="button" aria-label="展开全部类目" @click="expandAll">全部展开</button>
<button type="button" aria-label="收起全部类目" @click="collapseAll">全部收起</button>
</div>
<!-- 授权树里「本店真有商品」的分支(2026-11-24 客户口径:正确是一开始显示的那棵树,
而不是树外兜底这种退化分组)。零命中的别店分支已由 jdCategoryPruneZero 剪掉,
整树剪空时这里不渲染,本店类目由下方平铺列表承担。 -->
<div class="jd-side-tree" v-show="catalogReady && flatTree.length">
<div v-else class="jd-side-tree">
<button
v-for="flat in flatTree"
:key="flat.path.join('/')"
v-for="row in catalogRows"
:key="row.name"
type="button"
class="jd-side-row"
:class="[`depth-${flat.depth}`, { selected: isSelectedNode(flat) }]"
:title="flat.path.join(' / ')"
@click="pickNode(flat)"
class="jd-side-row depth-0"
:class="{ selected: isSelectedCatalogRow(row.name) }"
:title="row.name"
@click="pickCatalogRow(row.name)"
>
<span
v-if="flat.node.children.length"
class="jd-side-arrow"
:class="{ open: expanded.has(flat.path.join('/')) }"
role="button"
:aria-label="`展开或收起 ${flat.node.name}`"
@click.stop="toggleExpand(flat.path)"
>▸</span>
<span v-else class="jd-side-leaf-dot" />
<span class="jd-side-name">{{ flat.node.name }}</span>
<span class="jd-side-count">{{ flat.node.count }}</span>
<span class="jd-side-leaf-dot" />
<span class="jd-side-name">{{ row.name }}</span>
<span class="jd-side-count">{{ row.productCount }}</span>
</button>
</div>
<!-- 树外名(授权树里挂不上的本店类目):树被剪空时它们就是整列内容,直接铺成一级、
不摆分组头;树有命中时仍收在「授权树外的类目」组里(可折叠,单名等值仍可选)。 -->
<div v-if="catalogReady && counted.extra.length" class="jd-side-extra" :class="{ 'jd-side-extra-solo': extraIsSolo }">
<button
v-if="!extraIsSolo"
type="button"
class="jd-side-row jd-side-extra-head"
:aria-expanded="extraOpen"
@click="extraOpen = !extraOpen"
>
<span class="jd-side-name">授权树外的类目</span>
<span class="jd-side-count">{{ counted.extraTotal }}</span>
</button>
<template v-if="extraIsSolo || extraOpen">
<button
v-for="row in counted.extra"
:key="row.name"
type="button"
class="jd-side-row"
:class="[{ 'depth-1': !extraIsSolo, selected: isSelectedExtra(row.name) }]"
:title="row.name"
@click="pickExtra(row.name)"
>
<span class="jd-side-leaf-dot" />
<span class="jd-side-name">{{ row.name }}</span>
<span class="jd-side-count">{{ row.productCount }}</span>
</button>
</template>
<p v-if="!catalogRows.length" class="jd-side-empty">
还没有采集到类目数据(先采集一次店铺即有)
</p>
</div>
</div>
@@ -663,20 +446,6 @@ function cancelShopRename(): void {
}
.jd-side-row.depth-1 { padding-left: 22px; }
.jd-side-row.depth-2 { padding-left: 36px; }
.jd-side-row.depth-3 { padding-left: 50px; }
.jd-side-arrow {
width: 14px;
flex-shrink: 0;
color: #909399;
transition: transform 0.15s;
cursor: pointer;
}
.jd-side-arrow.open {
transform: rotate(90deg);
}
.jd-side-leaf-dot {
width: 14px;
@@ -712,44 +481,6 @@ function cancelShopRename(): void {
background: #d9ecff;
}
/* 树顶展开/收起操作行(v1.7 树增强):弱化小按钮,不与树行抢视觉。 */
.jd-side-tree-ops {
display: flex;
gap: 6px;
padding: 0 4px 4px;
}
.jd-side-tree-ops button {
padding: 2px 8px;
border: 1px solid #dcdfe6;
border-radius: 6px;
background: #fff;
color: #909399;
font-size: 12px;
cursor: pointer;
}
.jd-side-tree-ops button:hover {
color: #409eff;
border-color: #c6e2ff;
}
.jd-side-extra {
margin-top: 4px;
border-top: 1px dashed #e4e7ed;
padding-top: 4px;
}
/* 树外名分组(授权树挂不上的本店类目):树被剪空时它就是主列表,不画上缘虚线。 */
.jd-side-extra-solo {
border-top: none;
padding-top: 0;
}
.jd-side-extra-head {
color: #909399;
}
.jd-side-empty {
margin: 8px 4px;
font-size: 13px;
@@ -757,7 +488,7 @@ function cancelShopRename(): void {
text-align: center;
}
/* 类目加载行(首帧未就绪占位):与空态同款弱化,不让整棵别店快照树先闪出来。 */
/* 类目加载行(首帧未就绪占位):与空态同款弱化,不让空列表先闪一下。 */
.jd-side-loading {
margin: 8px 4px;
font-size: 13px;
@@ -46,8 +46,6 @@ import {
JD_PRODUCT_PAGE_SIZE_OPTIONS,
} from './jd-product-filter.ts'
import { JD_PRODUCT_DEFAULT_SIZE, type JdProductItem } from './jd-product-model.ts'
import { JD_CATEGORY_TREE, jdCategoryNamesUnder, type JdCategoryNode } from './jd-category-tree.ts'
import { fetchJdShopCategoryTree } from './jd-shop-category-api.ts'
import JdCategorySidebar from './JdCategorySidebar.vue'
import JdProductCard from './JdProductCard.vue'
import JdProductDetailModal from './JdProductDetailModal.vue'
@@ -127,9 +125,9 @@ const canManageCategories = computed(() => currentGroupOption.value?.editable ==
* 弹窗右栏的勾选面 ⇒ 勾选面对「本组可写」放开,否则管理人员没有归类入口。 */
const hasSelection = computed(() => canWriteProducts.value || canManageCategories.value)
/** 侧栏选中回显:类目(name+完整名称路径;树外名 path 空数组)与分类 id。 */
/** 侧栏选中回显:类目(京东平台末级类目名;path 恒空——平铺列表没有层级)与分类 id。 */
const selectedCategoryInfo = computed(() =>
filter.category ? { name: filter.category, path: filter.categoryPath ?? [] } : null)
filter.category ? { name: filter.category, path: [] } : null)
const selectedGroupIdNum = computed(() => {
const id = Number.parseInt(filter.groupId, 10)
return Number.isFinite(id) && id > 0 ? id : null
@@ -164,17 +162,12 @@ const activeFilterChips = computed(() => {
return chips
})
/** 侧栏选类目:树内节点带完整路径(序列化按子树展开 IN 下发)、树外名 path 空=
* 单名等值旧形状;null=「全部商品」清选重查。选中即查(回第一页)。 */
/** 侧栏选类目(2026-11-26 客户口径「京东分类是百分百有的,京东内分类就不需要」):
* 左栏「商品目录」=后端 `/categories` 的 DISTINCT `category_path`(京麦末级类目名+计数),
* 点一行=按该末级类目名**等值**过滤(后端 `p.category_path IN (...)`,单元素集合);
* null=「全部商品」清选重查。不再有授权类目树/内置快照,也就没有父级展开集合。 */
function onSelectCategory(value: { name: string; path: string[] } | null): void {
filter.category = value?.name || ''
filter.categoryPath = value?.path ?? []
// 父级点选的子树展开集合按**当前生效的树**算好存进过滤态(2026-11-23):树换成服务端
// 真树后,点「收纳用品」展开的就是真树的子类目名;filter 纯函数层不持有树,
// 避免「侧栏用真树、查询用快照树」两处各读一份。
filter.categoryNames = value && value.path.length
? (jdCategoryNamesUnder(value.path, activeCategoryTree.value) ?? undefined)
: undefined
apply()
}
@@ -396,28 +389,6 @@ async function loadCategoryOptions(): Promise<void> {
}
}
/** 服务端授权类目树(2026-11-23:客户端采集时按店铺上报、服务端并集)。
* null=还没取到或取不到 ⇒ 左栏回落内置快照(侧栏只渲染命中分支,零命中整支剪掉)。 */
const serverCategoryTree = ref<JdCategoryNode[] | null>(null)
/** 左栏实际生效的授权树:服务端真树优先,否则内置快照。
* 它同时是「父级点选展开集合」的口径源——树换了两处必须同源,不能各读各的。 */
const activeCategoryTree = computed<JdCategoryNode[]>(() =>
(serverCategoryTree.value && serverCategoryTree.value.length
? serverCategoryTree.value
: JD_CATEGORY_TREE))
/** 取授权类目树:失败静默回落快照(左栏不是首屏主功能,不占 loadFailure 提示,
* 与 loadCategoryOptions 同档兜底)。 */
async function loadShopCategoryTree(): Promise<void> {
try {
const result = await fetchJdShopCategoryTree()
serverCategoryTree.value = result.nodes.length ? result.nodes : null
} catch {
serverCategoryTree.value = null
}
}
/** 切换「分组」下拉:分类筛选(属于上一组的分类)清空,分类选项换成本组,回第一页重取。
* 勾选集是按商品 id 记的(跨页累计),切组不清——归类的落点组随 ownerGroupId 走,
* 误跨组批量归类由归类对话框里的组名标注防住。 */
@@ -495,10 +466,6 @@ async function load(): Promise<void> {
pageSize: pageSize.value,
keyword: filter.keyword,
category: filter.category,
categoryPath: filter.categoryPath,
// 父级点选按当前生效树展开好的集合透传给查询(2026-11-25 断链修复:此前只存在
// 过滤态里没进 api 入参,列表查询退回快照树展开,真树≠快照时点开父级 0 条)。
categoryNames: filter.categoryNames,
shopName: filter.shopName,
groupId: filter.groupId,
classified: filter.classified,
@@ -675,7 +642,6 @@ onMounted(async () => {
// 不要先发一条不带 owner_group_id 的列表请求再补,两次请求会落在不同默认组上)。
await loadCategoryScope()
void loadCategoryOptions()
void loadShopCategoryTree()
await load()
})
</script>
@@ -863,9 +829,10 @@ onMounted(async () => {
</section>
<div class="jd-body">
<!-- 左侧栏(v1.6 → v1.7 名单维度):商品目录(京麦授权类目树+计数徽标+树外类目)/
店铺分类(分类平铺+店铺名单展开/点选过滤/行内改名移除+添加店铺入口+新建+
分类管理入口)。取数在页面,侧栏纯展示。 -->
<!-- 左侧栏:商品目录(京东平台类目=/categories 的 category_path 平铺+计数徽标,
2026-11-26 客户口径「京东分类百分百有,京东内分类不需要」)/店铺分类(分类平铺+
店铺名单展开/点选过滤/行内改名移除+添加店铺入口+新建+分类管理入口)。
取数在页面,侧栏纯展示。 -->
<JdCategorySidebar
:category-options="categoryOptions"
:categories="groupOptions"
@@ -873,7 +840,6 @@ onMounted(async () => {
:selected-category="selectedCategoryInfo"
:selected-group-id="selectedGroupIdNum"
:selected-shop-name="filter.shopName"
:category-tree="activeCategoryTree"
:categories-ready="categoryOptionsReady"
@select-category="onSelectCategory"
@select-group="onSelectGroup"
File diff suppressed because one or more lines are too long
@@ -28,10 +28,6 @@ export async function fetchJdProductList(
{
keyword: params.keyword ?? '',
category: params.category ?? '',
categoryPath: params.categoryPath ?? [],
// 页面按当前生效树算好的子树展开集合必须透传(2026-11-25 断链修复):丢了它,
// 序列化层会拿内置快照树重展开,真树≠快照时父级点选退化成单名等值查 0 条。
categoryNames: params.categoryNames ?? [],
shopName: params.shopName ?? '',
groupId: params.groupId ?? '',
classified: (params.classified ?? '') as '' | 'classified' | 'ungrouped',
@@ -19,7 +19,6 @@
* 日期默认空字符串:同步台账是累计数据,默认当天会让首屏只剩今天同步的行
* (date-filter-default-today 护栏 EXEMPT 口径,外观专利页同款)。 */
import { validIsoDateOrUndefined } from '../asin/asin-filter.ts'
import { jdCategoryNamesUnder } from './jd-category-tree.ts'
/** 每页条数默认 50(v1.6 蓝图 Phase 1 新契约,商城款式一屏 50),上限 1000
* (v1.7 对齐原型档位 50/100/200/500/1000,与后端 MAX_PAGE_SIZE 逐字同步——契约
@@ -47,17 +46,11 @@ export interface JdProductFilterState {
/** 合并搜索词(v1.7 对齐原型:一个框同时搜商品编码与标题,OR 语义在后端 SQL)。
* 旧 productCode/titleKeyword 两框随 v1.7 前端下线(后端参数保留兼容在飞请求)。 */
keyword: string
/** 类目(京麦类目名,末级或父级;选项来自侧栏商品目录树),空串=全部类目。 */
/** 类目(京麦末级类目名=后端 `category_path` DISTINCT 值;选项来自侧栏商品目录平铺),
* 空串=全部类目。2026-11-26 客户口径「京东分类是百分百有的,京东内分类就不需要」:
* 只按末级类目名等值过滤,不再有「父级点选→子树展开集合」这一层(旧 categoryPath/
* categoryNames 两个字段随内置花屿巷快照树一并退役)。 */
category: string
/** 选中节点的名称路径(2026-11-18 一级/二级类目可选中):非空时序列化按
* jdCategoryNamesUnder 展开为子树类目名集合下发(后端 IN);空=末级/树外行,
* 按单名等值下发(旧形状)。 */
categoryPath?: string[]
/** 父级点选时按**当前生效授权树**展开好的类目名集合(2026-11-23):树可以是服务端
* 按店铺上报的真树,纯函数层不持有树,所以由页面在选中那一刻算好放在这里。
* 有值时优先于按内置快照展开的 `jdCategoryNamesUnder(categoryPath)`;
* 空/缺省=照旧按快照树展开(向后兼容旧调用与测试)。 */
categoryNames?: string[]
/** 店铺名(v1.7 店铺名单维度:侧栏点店铺行下发,精确 eq;空串不限)。 */
shopName: string
/** 分类 id 文本(侧栏店铺分类 Tab 里那一行),空串=全部分类。 */
@@ -86,8 +79,6 @@ export function createJdProductFilterState(): JdProductFilterState {
return {
keyword: '',
category: '',
categoryPath: [],
categoryNames: [],
shopName: '',
groupId: '',
classified: JD_PRODUCT_DEFAULT_CLASSIFIED,
@@ -144,13 +135,6 @@ export interface JdProductListParams {
pageSize: number
keyword?: string
category?: string
/** 选中类目节点路径(见 JdProductFilterState.categoryPath;空=单名等值)。 */
categoryPath?: string[]
/** 页面按**当前生效树**(服务端真树优先)展开好的子树类目名集合(见
* JdProductFilterState.categoryNames)。2026-11-25 补:api 层此前没有这个字段,
* 页面算好的集合到不了序列化层,父级点选退回内置快照树重展开——真树≠快照时
* 展开失败退化成单名等值,「收纳用品 81」点开 0 条。序列化按它优先。 */
categoryNames?: string[]
shopName?: string
groupId?: string
/** 分类状态快筛(''/缺省=全部,'classified'/'ungrouped' 见 JdProductFilterState)。 */
@@ -173,16 +157,10 @@ function toJdProductFilterQuery(state: JdProductFilterState): Omit<JdProductQuer
if (keyword) query.keyword = keyword
const category = (state.category || '').trim()
if (category) {
// 2026-11-18 一级/二级类目可选中:带路径=按子树展开类目名集合(后端 IN);
// 路径失效(树外历史名)回落单名等值集合——与旧 eq 语义逐字同形。
// 2026-11-23:页面若已按服务端真树算好 categoryNames,直接用(两处口径同源,
// 不再拿内置快照树重算一遍)。
const expanded = state.categoryNames && state.categoryNames.length
? state.categoryNames
: state.categoryPath && state.categoryPath.length
? jdCategoryNamesUnder(state.categoryPath)
: null
query.category = expanded && expanded.length ? expanded : [category]
// 末级类目名等值:单元素集合下发,后端 `p.category_path IN (...)` 单值等价 eq。
// 2026-11-26 起左栏商品目录=京东平台类目平铺(category_path DISTINCT),
// 不再有「父级点选→子树展开集合」这条链。
query.category = [category]
}
const shopName = (state.shopName || '').trim()
if (shopName) query.shop_name = shopName
@@ -248,8 +226,8 @@ export function jdOwnershipSelectValue(state: JdProductFilterState): string {
/** 归属下拉选档 → 筛选态(原地改 state;调用方随后自行重查,本函数不发请求):
* - `cat:<id>`=按分类查询:写 groupId、清状态档;店铺谓词一起清——店铺名单挂在分类下
* (v1.7 名单维度),换分类后旧店铺词是孤儿谓词(店铺全平台 DISTINCT,会命中别组分类
* 下的同名店),与侧栏 onSelectGroup 同一条纪律;类目维(category/categoryPath)是
* 京麦树,独立维度不碰。
* 下的同名店),与侧栏 onSelectGroup 同一条纪律;类目维(category=京东平台末级类目名)
* 是独立维度,不碰。
* - ''/classified/ungrouped=状态档:写 classified、清 groupId;店铺词不属分类维度,
* 与既有三档行为一致不动 shopName。
* 脏值(未知前缀/非数字 id)按「全部」档兜底——不拿脏值冒充档位(classified 序列化同形)。 */
@@ -1,53 +0,0 @@
/** 京麦授权类目树读取(2026-11-23):GET `/api/jd-shop-category-tree`。
*
* 数据来源=客户端采集窗口顺手收到的 `getVenderLicenseCategory`(按店铺上报、服务端并集),
* 与内置快照 `JD_CATEGORY_TREE`(2026-11-16 一家店的历史取证)**同形**——
* `{name, value, children}`,页面拿到后直接替换树数据源,计数/兜底/展开逻辑零改动。
*
* 失败/空一律返回空节点数组:页面据此回落内置快照(侧栏只渲染本店命中的分支,
* 零命中整支剪掉、树空就把本店类目平铺成一级),绝不让接口抖动把左栏变成错误块。 */
import { http } from '@/api/http'
import { unwrap } from '../../api/envelope.ts'
import { parseJdCategoryNodeTree, type JdCategoryNode } from './jd-category-tree.ts'
export { parseJdCategoryNodeTree }
export const JD_SHOP_CATEGORY_TREE_ENDPOINT = '/api/jd-shop-category-tree'
/** 已上报店铺(页面只用于「有没有真树」的判断与排查展示)。 */
export interface JdShopCategoryTreeShop {
shopId: string
shopName: string | null
capturedAt: string | null
nodeCount: number
}
export interface JdShopCategoryTreeResult {
/** 并集森林;空数组=服务端还没有任何店铺上报过。 */
nodes: JdCategoryNode[]
shops: JdShopCategoryTreeShop[]
}
/** 递归解析已在 `jd-category-tree.ts`(零依赖、node --test 可直测),这里只做请求与装配。 */
export async function fetchJdShopCategoryTree(): Promise<JdShopCategoryTreeResult> {
const { data } = await http.get<unknown>(JD_SHOP_CATEGORY_TREE_ENDPOINT)
const core = unwrap<unknown>(data)
if (!core || typeof core !== 'object') return { nodes: [], shops: [] }
const record = core as Record<string, unknown>
const shops: JdShopCategoryTreeShop[] = []
for (const raw of Array.isArray(record.shops) ? record.shops : []) {
if (!raw || typeof raw !== 'object') continue
const row = raw as Record<string, unknown>
const shopId = row.shopId == null ? '' : String(row.shopId).trim()
if (!shopId) continue
shops.push({
shopId,
shopName: typeof row.shopName === 'string' ? row.shopName : null,
capturedAt: typeof row.capturedAt === 'string' ? row.capturedAt : null,
nodeCount: typeof row.nodeCount === 'number' && Number.isFinite(row.nodeCount)
? Math.max(0, Math.floor(row.nodeCount))
: 0,
})
}
return { nodes: parseJdCategoryNodeTree(record.nodes), shops }
}