feat(jd): 类目筛选改京麦同款级联面板(一/二级静态导航+末级全集搜索点选)
This commit is contained in:
@@ -0,0 +1,333 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
/** 京东数据库「类目」筛选的京麦同款级联面板(2026-11-16 客户口径「京东类目要做成京麦
|
||||||
|
* 同款样式」)。三栏形状照京麦:第一栏静态一级导航(jd-category-tree,京东公开类目
|
||||||
|
* 体系;服饰内衣子树二级按京麦面板真机样本逐字)、第二栏该一级的静态二级(hover/点击
|
||||||
|
* 展开;radio 不选中——纯导航)、第三栏「已落库末级类目全集+搜索」(选中发生地)。
|
||||||
|
*
|
||||||
|
* 数据边界如实声明:采集链只有末级类目名(categoryDetailVO.lastCategoryName),没有
|
||||||
|
* 一/二级归属,所以第二栏与第三栏**不联动**(点了二级第三栏照旧全集+搜索)——过滤语义
|
||||||
|
* 零风险(仍按 category_path 等值,后端零改动);采集链补齐层级后,把静态树换掉、第三栏
|
||||||
|
* 按选中二级过滤即可升级真联动。零依赖自绘(radio 圆点/箭头都是 CSS),无 element 依赖。
|
||||||
|
*
|
||||||
|
* 交互:点开面板 → 点/hover 一级展第二栏 → 第三栏搜索或点行选中(radio 蓝)→ 收面板;
|
||||||
|
* 「全部类目」行=清选;触发框已选时出 × 清除;面板外点透明遮罩关闭。 */
|
||||||
|
import { computed, ref } from 'vue'
|
||||||
|
import { jdCategoryNavChildren, jdCategoryNavRoots } from './jd-category-tree.ts'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
/** 已落库末级类目选项(/categories 现算,页面传入:{name, productCount})。 */
|
||||||
|
options: { name: string; productCount: number }[]
|
||||||
|
/** 当前选中末级类目名;'' = 全部类目。 */
|
||||||
|
modelValue: string
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{ (event: 'change', value: string): void }>()
|
||||||
|
|
||||||
|
const open = ref(false)
|
||||||
|
const activeRoot = ref('')
|
||||||
|
const searchText = ref('')
|
||||||
|
|
||||||
|
const roots = jdCategoryNavRoots()
|
||||||
|
/** 第二栏=点亮一级的静态二级;无静态子级的一级不出第二栏。 */
|
||||||
|
const activeChildren = computed(() => jdCategoryNavChildren(activeRoot.value))
|
||||||
|
|
||||||
|
/** 第三栏=已落库末级全集按搜索词过滤(大小写不敏感的 includes)。 */
|
||||||
|
const filteredLeaves = computed(() => {
|
||||||
|
const keyword = searchText.value.trim().toLowerCase()
|
||||||
|
if (!keyword) return props.options
|
||||||
|
return props.options.filter((option) => option.name.toLowerCase().includes(keyword))
|
||||||
|
})
|
||||||
|
|
||||||
|
function toggle(): void {
|
||||||
|
if (open.value) {
|
||||||
|
close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
activeRoot.value = ''
|
||||||
|
searchText.value = ''
|
||||||
|
open.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
function close(): void {
|
||||||
|
open.value = false
|
||||||
|
activeRoot.value = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
function pickRoot(name: string): void {
|
||||||
|
activeRoot.value = name
|
||||||
|
}
|
||||||
|
|
||||||
|
function pickAll(): void {
|
||||||
|
emit('change', '')
|
||||||
|
close()
|
||||||
|
}
|
||||||
|
|
||||||
|
function pickLeaf(name: string): void {
|
||||||
|
emit('change', name)
|
||||||
|
close()
|
||||||
|
}
|
||||||
|
|
||||||
|
function clear(): void {
|
||||||
|
emit('change', '')
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="cat-cascader">
|
||||||
|
<button
|
||||||
|
class="cat-trigger"
|
||||||
|
type="button"
|
||||||
|
:class="{ open, filled: !!modelValue }"
|
||||||
|
@click="toggle"
|
||||||
|
>
|
||||||
|
<span class="cat-trigger-text" :title="modelValue || ''">{{ modelValue || '全部类目' }}</span>
|
||||||
|
<span
|
||||||
|
v-if="modelValue"
|
||||||
|
class="cat-clear"
|
||||||
|
role="button"
|
||||||
|
aria-label="清除类目"
|
||||||
|
@click.stop="clear"
|
||||||
|
>×</span>
|
||||||
|
<span class="cat-chevron" aria-hidden="true"></span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<!-- 面板外点透明遮罩关闭(零 document 监听器,无泄漏面)。 -->
|
||||||
|
<div v-if="open" class="cat-mask" @click="close"></div>
|
||||||
|
<div v-if="open" class="cat-panel">
|
||||||
|
<!-- 第一栏:静态一级导航(radio 形状照京麦,点选只展开不落值)。 -->
|
||||||
|
<div class="cat-col">
|
||||||
|
<div
|
||||||
|
v-for="root in roots"
|
||||||
|
:key="root"
|
||||||
|
class="cat-row"
|
||||||
|
:class="{ active: activeRoot === root }"
|
||||||
|
@click="pickRoot(root)"
|
||||||
|
@mouseenter="pickRoot(root)"
|
||||||
|
>
|
||||||
|
<span class="cat-dot" aria-hidden="true"></span>
|
||||||
|
<span class="cat-name" :title="root">{{ root }}</span>
|
||||||
|
<span v-if="jdCategoryNavChildren(root).length" class="cat-arrow" aria-hidden="true">›</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 第二栏:点亮一级的静态二级(纯导航;归属数据缺,不联动第三栏——组件头注释)。 -->
|
||||||
|
<div v-if="activeChildren.length" class="cat-col">
|
||||||
|
<div
|
||||||
|
v-for="child in activeChildren"
|
||||||
|
:key="child"
|
||||||
|
class="cat-row"
|
||||||
|
>
|
||||||
|
<span class="cat-dot" aria-hidden="true"></span>
|
||||||
|
<span class="cat-name" :title="child">{{ child }}</span>
|
||||||
|
<span class="cat-arrow" aria-hidden="true">›</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 第三栏:已落库末级全集+搜索(选中发生地;点行=按 category_path 等值过滤)。 -->
|
||||||
|
<div class="cat-col cat-col-leaf">
|
||||||
|
<div class="cat-row cat-row-all" :class="{ active: !modelValue }" @click="pickAll">
|
||||||
|
<span class="cat-dot" aria-hidden="true"></span>
|
||||||
|
<span class="cat-name">全部类目</span>
|
||||||
|
</div>
|
||||||
|
<input
|
||||||
|
v-model="searchText"
|
||||||
|
type="text"
|
||||||
|
class="cat-search"
|
||||||
|
placeholder="搜索类目"
|
||||||
|
@click.stop
|
||||||
|
/>
|
||||||
|
<div v-if="!filteredLeaves.length" class="cat-empty">未找到类目</div>
|
||||||
|
<div
|
||||||
|
v-for="leaf in filteredLeaves"
|
||||||
|
:key="leaf.name"
|
||||||
|
class="cat-row"
|
||||||
|
:class="{ active: modelValue === leaf.name }"
|
||||||
|
@click="pickLeaf(leaf.name)"
|
||||||
|
>
|
||||||
|
<span class="cat-dot" :class="{ on: modelValue === leaf.name }" aria-hidden="true"></span>
|
||||||
|
<span class="cat-name" :title="leaf.name">{{ leaf.name }}</span>
|
||||||
|
<span class="cat-count">{{ leaf.productCount }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.cat-cascader {
|
||||||
|
position: relative;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
/* 触发框像素对齐页面 .form-group select(42 高/9 圆角/#cbd9e6 边框/#f8fbfd 底)。 */
|
||||||
|
.cat-trigger {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
width: 100%;
|
||||||
|
min-height: 42px;
|
||||||
|
padding: 8px 12px;
|
||||||
|
border: 1px solid #cbd9e6;
|
||||||
|
border-radius: 9px;
|
||||||
|
background: #f8fbfd;
|
||||||
|
color: #24384d;
|
||||||
|
font-size: 13.5px;
|
||||||
|
font-family: inherit;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||||
|
}
|
||||||
|
.cat-trigger:hover {
|
||||||
|
border-color: #9fb7cd;
|
||||||
|
}
|
||||||
|
.cat-trigger.open,
|
||||||
|
.cat-trigger:focus {
|
||||||
|
background: #ffffff;
|
||||||
|
border-color: #5f85ad;
|
||||||
|
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||||
|
}
|
||||||
|
.cat-trigger-text {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
.cat-trigger:not(.filled) .cat-trigger-text {
|
||||||
|
color: #8293a5;
|
||||||
|
}
|
||||||
|
.cat-clear {
|
||||||
|
flex: none;
|
||||||
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #e7eef5;
|
||||||
|
color: #5b6f83;
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
.cat-clear:hover {
|
||||||
|
background: #dbe7f1;
|
||||||
|
color: #24384d;
|
||||||
|
}
|
||||||
|
/* 下拉箭头:CSS 三角(京麦同款向下 chevron,展开翻向上)。 */
|
||||||
|
.cat-chevron {
|
||||||
|
flex: none;
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
border-left: 5px solid transparent;
|
||||||
|
border-right: 5px solid transparent;
|
||||||
|
border-top: 6px solid #7b8a99;
|
||||||
|
transition: transform 160ms ease;
|
||||||
|
}
|
||||||
|
.cat-trigger.open .cat-chevron {
|
||||||
|
transform: rotate(180deg);
|
||||||
|
}
|
||||||
|
.cat-mask {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
z-index: 2550;
|
||||||
|
}
|
||||||
|
.cat-panel {
|
||||||
|
position: absolute;
|
||||||
|
top: calc(100% + 4px);
|
||||||
|
left: 0;
|
||||||
|
z-index: 2560;
|
||||||
|
display: flex;
|
||||||
|
align-items: stretch;
|
||||||
|
max-width: min(720px, 90vw);
|
||||||
|
border: 1px solid #d8e3ee;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: #ffffff;
|
||||||
|
box-shadow: 0 16px 44px rgba(39, 67, 94, 0.18);
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.cat-col {
|
||||||
|
width: 210px;
|
||||||
|
max-height: 340px;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: 6px 0;
|
||||||
|
border-right: 1px solid #e7eef5;
|
||||||
|
}
|
||||||
|
.cat-col:last-child {
|
||||||
|
border-right: 0;
|
||||||
|
}
|
||||||
|
.cat-col-leaf {
|
||||||
|
width: 240px;
|
||||||
|
}
|
||||||
|
/* 行=京麦同款:圆点 radio + 名称 + 右箭头;hover 浅蓝底。 */
|
||||||
|
.cat-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 8px 12px;
|
||||||
|
font-size: 13.5px;
|
||||||
|
color: #24384d;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.cat-row:hover,
|
||||||
|
.cat-row.active {
|
||||||
|
background: #f1f7fb;
|
||||||
|
}
|
||||||
|
.cat-row.active {
|
||||||
|
color: #2f5d8b;
|
||||||
|
font-weight: 550;
|
||||||
|
}
|
||||||
|
.cat-dot {
|
||||||
|
flex: none;
|
||||||
|
width: 13px;
|
||||||
|
height: 13px;
|
||||||
|
border: 1px solid #c0ccda;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #ffffff;
|
||||||
|
}
|
||||||
|
/* radio 选中=京麦同款蓝芯;一级/二级的圆点是导航形状,不落选中态。 */
|
||||||
|
.cat-dot.on {
|
||||||
|
border-color: #3b82c4;
|
||||||
|
background: radial-gradient(circle, #3b82c4 0 4px, #ffffff 4.6px);
|
||||||
|
}
|
||||||
|
.cat-name {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.cat-arrow {
|
||||||
|
flex: none;
|
||||||
|
color: #9fb0c0;
|
||||||
|
font-size: 15px;
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
.cat-count {
|
||||||
|
flex: none;
|
||||||
|
color: #8293a5;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
.cat-search {
|
||||||
|
display: block;
|
||||||
|
width: calc(100% - 20px);
|
||||||
|
margin: 4px 10px 8px;
|
||||||
|
min-height: 30px;
|
||||||
|
padding: 4px 10px;
|
||||||
|
border: 1px solid #cbd9e6;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: #f8fbfd;
|
||||||
|
color: #24384d;
|
||||||
|
font-size: 12.5px;
|
||||||
|
font-family: inherit;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
.cat-search:focus {
|
||||||
|
background: #ffffff;
|
||||||
|
border-color: #5f85ad;
|
||||||
|
}
|
||||||
|
.cat-empty {
|
||||||
|
padding: 16px 12px;
|
||||||
|
color: #8293a5;
|
||||||
|
font-size: 12.5px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -30,6 +30,7 @@ import { createJdProductFilterState } from './jd-product-filter.ts'
|
|||||||
import JdProductDetailDrawer from './JdProductDetailDrawer.vue'
|
import JdProductDetailDrawer from './JdProductDetailDrawer.vue'
|
||||||
import JdProductEditDrawer from './JdProductEditDrawer.vue'
|
import JdProductEditDrawer from './JdProductEditDrawer.vue'
|
||||||
import JdProductGroupDialog from './JdProductGroupDialog.vue'
|
import JdProductGroupDialog from './JdProductGroupDialog.vue'
|
||||||
|
import JdCategoryCascader from './JdCategoryCascader.vue'
|
||||||
import OldPagination from '@/components/OldPagination.vue'
|
import OldPagination from '@/components/OldPagination.vue'
|
||||||
import { useCompanyTabStore } from '@/stores/company-tab'
|
import { useCompanyTabStore } from '@/stores/company-tab'
|
||||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||||
@@ -145,6 +146,13 @@ function apply(): void {
|
|||||||
void load()
|
void load()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 类目级联面板点末级即查:选完立刻按该类目过滤刷新(回第一页),同分组下拉口径;
|
||||||
|
* 点「全部类目」/触发框 × = 清选重查。 */
|
||||||
|
function onCategoryPicked(name: string): void {
|
||||||
|
filter.category = name
|
||||||
|
apply()
|
||||||
|
}
|
||||||
|
|
||||||
/** 重置:筛选面回出厂空态,回第一页重取。 */
|
/** 重置:筛选面回出厂空态,回第一页重取。 */
|
||||||
function reset(): void {
|
function reset(): void {
|
||||||
Object.assign(filter, createJdProductFilterState())
|
Object.assign(filter, createJdProductFilterState())
|
||||||
@@ -289,13 +297,13 @@ onMounted(() => {
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>类目</label>
|
<label>类目</label>
|
||||||
<!-- 类目(京麦末级类目)选中即查:同分组口径,选完立刻按该类目过滤刷新(回第一页)。 -->
|
<!-- 类目(京麦末级类目)京麦同款级联面板(2026-11-16 客户口径):一/二级为静态导航
|
||||||
<select v-model="filter.category" @change="apply">
|
(采集链无层级数据),第三栏已落库末级+搜索,点行选中即查(回第一页)。 -->
|
||||||
<option value="">全部类目</option>
|
<JdCategoryCascader
|
||||||
<option v-for="cat in categoryOptions" :key="cat.name" :value="cat.name">
|
:options="categoryOptions"
|
||||||
{{ cat.name }}({{ cat.productCount }})
|
:model-value="filter.category"
|
||||||
</option>
|
@change="onCategoryPicked"
|
||||||
</select>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>同步开始日期</label>
|
<label>同步开始日期</label>
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
/** 京东类目级联的导航树(2026-11-16 客户口径「类目要京麦同款级联样式」)。
|
||||||
|
*
|
||||||
|
* 数据边界(先说清,防止后人当它是全量类目树):
|
||||||
|
* - 落库 biz_jd_product.category_path = 京麦列表接口 categoryDetailVO.lastCategoryName
|
||||||
|
* (末级类目名,jd-collect-api-contract.md §2.3 E3),采集链**没有**一/二级类目数据;
|
||||||
|
* - 所以级联面板的一/二级用这里的**静态导航树**(京东公开类目体系;服饰内衣子树的二级
|
||||||
|
* 按京麦面板真机样本逐字校正:服饰配件/内衣/女装/男装/定制服装工装),**不参与过滤**;
|
||||||
|
* - 第三栏(选中发生地)永远是页面传入的**已落库末级类目全集**(/categories 现算)+搜索框,
|
||||||
|
* 选中后仍按 category_path 等值过滤(后端契约零改动)。采集链日后补齐一/二级回传时,
|
||||||
|
* 把本文件的静态树换成 /categories 的树形返回即可,组件已按树形契约设计。
|
||||||
|
*
|
||||||
|
* 纯数据+纯函数,node --test 直测。 */
|
||||||
|
|
||||||
|
/** 静态导航树节点:一级/二级。children 缺省=该一级下暂无静态二级(面板少一栏,直接第三栏)。 */
|
||||||
|
export interface JdCategoryNavNode {
|
||||||
|
name: string
|
||||||
|
children?: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 京东 POP 零售一级类目(常用集,名称按京东公开类目体系;非全量——长尾一级随需要再补)。 */
|
||||||
|
export const JD_CATEGORY_NAV_TREE: JdCategoryNavNode[] = [
|
||||||
|
{
|
||||||
|
name: '服饰内衣',
|
||||||
|
// 京麦面板真机样本(2026-11-16 客户提供截图)逐字:服饰配件/内衣/女装/男装/定制服装/工装。
|
||||||
|
children: ['服饰配件', '内衣', '女装', '男装', '定制服装/工装'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '母婴',
|
||||||
|
children: ['奶粉', '营养辅食', '尿裤湿巾', '喂养用品', '洗护用品', '妈妈专区', '童车童床', '儿童安全座椅'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '运动户外',
|
||||||
|
children: ['运动服饰', '运动鞋', '健身器械', '户外装备', '骑行运动', '体育用品', '垂钓用品'],
|
||||||
|
},
|
||||||
|
{ name: '鞋靴' },
|
||||||
|
{ name: '箱包' },
|
||||||
|
{ name: '珠宝首饰' },
|
||||||
|
{ name: '钟表' },
|
||||||
|
{ name: '美妆护肤' },
|
||||||
|
{ name: '个护清洁' },
|
||||||
|
{ name: '手机通讯' },
|
||||||
|
{ name: '数码' },
|
||||||
|
{ name: '电脑办公' },
|
||||||
|
{ name: '家用电器' },
|
||||||
|
{ name: '家居家装' },
|
||||||
|
{ name: '厨具' },
|
||||||
|
{ name: '家具' },
|
||||||
|
{ name: '家装建材' },
|
||||||
|
{ name: '食品饮料' },
|
||||||
|
{ name: '酒类' },
|
||||||
|
{ name: '生鲜' },
|
||||||
|
{ name: '玩具乐器' },
|
||||||
|
{ name: '宠物生活' },
|
||||||
|
{ name: '汽车用品' },
|
||||||
|
{ name: '图书文娱' },
|
||||||
|
{ name: '营养保健' },
|
||||||
|
]
|
||||||
|
|
||||||
|
/** 一级类目名列表(面板第一栏顺序)。 */
|
||||||
|
export function jdCategoryNavRoots(): string[] {
|
||||||
|
return JD_CATEGORY_NAV_TREE.map((node) => node.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 某一级下的静态二级列表;无静态子级返回空数组(面板该栏缺省)。 */
|
||||||
|
export function jdCategoryNavChildren(rootName: string): string[] {
|
||||||
|
return JD_CATEGORY_NAV_TREE.find((node) => node.name === rootName)?.children ?? []
|
||||||
|
}
|
||||||
@@ -23,6 +23,10 @@ import {
|
|||||||
createJdProductFilterState,
|
createJdProductFilterState,
|
||||||
toJdProductListParams,
|
toJdProductListParams,
|
||||||
} from '../src/pages/jd/jd-product-filter.ts'
|
} from '../src/pages/jd/jd-product-filter.ts'
|
||||||
|
import {
|
||||||
|
jdCategoryNavChildren,
|
||||||
|
jdCategoryNavRoots,
|
||||||
|
} from '../src/pages/jd/jd-category-tree.ts'
|
||||||
import {
|
import {
|
||||||
jdPriceRange,
|
jdPriceRange,
|
||||||
parseJdProductDetail,
|
parseJdProductDetail,
|
||||||
@@ -30,6 +34,21 @@ import {
|
|||||||
toJdProductItem,
|
toJdProductItem,
|
||||||
} from '../src/pages/jd/jd-product-model.ts'
|
} from '../src/pages/jd/jd-product-model.ts'
|
||||||
|
|
||||||
|
test('类目级联静态导航树——服饰内衣二级与京麦面板样本逐字同源,一级集非空且无重名', () => {
|
||||||
|
// 京麦面板真机样本(2026-11-16 客户截图):服饰内衣下就是这五个二级,改名即红。
|
||||||
|
assert.deepEqual(jdCategoryNavChildren('服饰内衣'), ['服饰配件', '内衣', '女装', '男装', '定制服装/工装'])
|
||||||
|
assert.deepEqual(jdCategoryNavChildren('不存在的类目'), [], '未知一级回落空子级(面板不出第二栏)')
|
||||||
|
|
||||||
|
const roots = jdCategoryNavRoots()
|
||||||
|
assert.ok(roots.length >= 20, `一级导航 ${roots.length} 个,常用集不应被清空`)
|
||||||
|
assert.equal(new Set(roots).size, roots.length, '一级类目名不得重复')
|
||||||
|
assert.equal(roots[0], '服饰内衣', '服饰内衣置首(客户商品全在服饰类目)')
|
||||||
|
for (const root of roots) {
|
||||||
|
const children = jdCategoryNavChildren(root)
|
||||||
|
assert.equal(new Set(children).size, children.length, `${root} 的二级不得重复`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
test('京东列表参数——snake 形状:groupId 空→不带、有值→group_id,日期空白/非法不下发', () => {
|
test('京东列表参数——snake 形状:groupId 空→不带、有值→group_id,日期空白/非法不下发', () => {
|
||||||
const full = toJdProductListParams(
|
const full = toJdProductListParams(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -245,12 +245,13 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
|||||||
page: 1,
|
page: 1,
|
||||||
companyId: 1,
|
companyId: 1,
|
||||||
})
|
})
|
||||||
expect(last).not.toHaveProperty('shopName', '店铺筛选已下线,入参不再带 shopName')
|
// 单参 toHaveProperty 才是「键不存在」的真判据(第二参会稀释成值断言):
|
||||||
expect(last).not.toHaveProperty('saleStatus', '商品状态筛选已下线,入参不再带 saleStatus')
|
// 页面 load() 入参已不带这两个键(店铺/商品状态筛选下线)。
|
||||||
|
expect(last).not.toHaveProperty('shopName')
|
||||||
|
expect(last).not.toHaveProperty('saleStatus')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('分组下拉选中即查', async () => {
|
it('分组下拉选中即查', async () => { jdApi.fetchJdProductGroups.mockResolvedValue([
|
||||||
jdApi.fetchJdProductGroups.mockResolvedValue([
|
|
||||||
{ id: 7, name: '甲组', sortOrder: 0, productCount: 3 },
|
{ id: 7, name: '甲组', sortOrder: 0, productCount: 3 },
|
||||||
{ id: 8, name: '乙组', sortOrder: 1, productCount: 1 },
|
{ id: 8, name: '乙组', sortOrder: 1, productCount: 1 },
|
||||||
])
|
])
|
||||||
@@ -269,27 +270,77 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
|||||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7', page: 1 })
|
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7', page: 1 })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('类目下拉:选项来自 GET /categories(带商品数),选中即查回第一页', async () => {
|
it('类目京麦同款级联面板:一/二级静态导航展开,第三栏=已落库末级全集+行数,点末级即查回第一页', async () => {
|
||||||
jdApi.fetchJdProductCategories.mockResolvedValue([
|
jdApi.fetchJdProductCategories.mockResolvedValue([
|
||||||
{ name: '服饰内衣', productCount: 120 },
|
{ name: '艺考形体服', productCount: 120 },
|
||||||
{ name: '运动户外', productCount: 8 },
|
{ name: '啦啦队服', productCount: 8 },
|
||||||
])
|
])
|
||||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
|
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
|
||||||
expect(jdApi.fetchJdProductCategories).toHaveBeenCalledWith(1)
|
expect(jdApi.fetchJdProductCategories).toHaveBeenCalledWith(1)
|
||||||
|
|
||||||
// 第 1 个 select = 分组(既有契约不动),第 2 个 = 分类状态(2026-11-15 增),类目下拉第 3
|
const trigger = wrapper.find('.cat-trigger')
|
||||||
const selects = wrapper.findAll('.jd-filter-row select')
|
expect(trigger.text()).toContain('全部类目', '未选时触发框显示占位「全部类目」')
|
||||||
expect(selects).toHaveLength(3)
|
expect(wrapper.find('.cat-panel').exists()).toBe(false, '面板初始不展开')
|
||||||
const categorySelect = selects[2]
|
|
||||||
const optionTexts = categorySelect.findAll('option').map((o) => o.text())
|
|
||||||
expect(optionTexts[0]).toBe('全部类目')
|
|
||||||
expect(optionTexts).toContain('服饰内衣(120)')
|
|
||||||
|
|
||||||
const callsBeforeSelect = jdApi.fetchJdProductList.mock.calls.length
|
await trigger.trigger('click')
|
||||||
await categorySelect.setValue('运动户外')
|
expect(wrapper.find('.cat-panel').exists()).toBe(true)
|
||||||
|
// 第一栏=静态一级导航(京麦同款顺序,服饰内衣在首)。
|
||||||
|
const firstCol = wrapper.findAll('.cat-col')[0]
|
||||||
|
expect(firstCol.text()).toContain('服饰内衣')
|
||||||
|
expect(firstCol.text()).toContain('母婴')
|
||||||
|
expect(firstCol.text()).toContain('运动户外')
|
||||||
|
// hover 一级展开第二栏(服饰内衣的静态二级=京麦面板样本同款)。
|
||||||
|
await firstCol.findAll('.cat-row')[0].trigger('mouseenter')
|
||||||
|
const cols = wrapper.findAll('.cat-col')
|
||||||
|
expect(cols).toHaveLength(3, '点亮有静态子级的一级后第二栏出现(第三栏常驻)')
|
||||||
|
expect(cols[1].text()).toContain('服饰配件')
|
||||||
|
expect(cols[1].text()).toContain('女装')
|
||||||
|
// 第三栏=已落库末级全集+行数(与二级不联动——采集链无层级归属,组件头注释如实声明)。
|
||||||
|
expect(cols[2].text()).toContain('艺考形体服')
|
||||||
|
expect(cols[2].text()).toContain('120')
|
||||||
|
expect(cols[2].text()).toContain('啦啦队服')
|
||||||
|
|
||||||
|
// 点末级=选中即查(等值过滤口径不变)、面板收起、触发框显示已选名。
|
||||||
|
const leafRows = cols[2].findAll('.cat-row')
|
||||||
|
await leafRows.find((row) => row.text().includes('啦啦队服'))!.trigger('click')
|
||||||
await flushPromises()
|
await flushPromises()
|
||||||
expect(jdApi.fetchJdProductList.mock.calls.length).toBe(callsBeforeSelect + 1, '选中类目必须立刻重查')
|
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ category: '啦啦队服', page: 1 })
|
||||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ category: '运动户外', page: 1 })
|
expect(wrapper.find('.cat-panel').exists()).toBe(false, '选中后面板收起')
|
||||||
|
expect(wrapper.find('.cat-trigger').text()).toContain('啦啦队服')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('类目级联搜索与清选:搜索词过滤第三栏;「全部类目」行/触发框 × 都能清选重查', async () => {
|
||||||
|
jdApi.fetchJdProductCategories.mockResolvedValue([
|
||||||
|
{ name: '艺考形体服', productCount: 120 },
|
||||||
|
{ name: '啦啦队服', productCount: 8 },
|
||||||
|
])
|
||||||
|
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
|
||||||
|
|
||||||
|
await wrapper.find('.cat-trigger').trigger('click')
|
||||||
|
const leafCol = wrapper.findAll('.cat-col').at(-1)!
|
||||||
|
await leafCol.find('.cat-search').setValue('艺考')
|
||||||
|
const visibleRows = leafCol.findAll('.cat-row').filter((row) => row.text().includes('艺考'))
|
||||||
|
expect(visibleRows).toHaveLength(1, '搜索词过滤后只剩匹配项')
|
||||||
|
expect(leafCol.text()).not.toContain('啦啦队服', '不匹配的末级被搜索词滤掉')
|
||||||
|
|
||||||
|
// 清空搜索后点「全部类目」= 清选重查(category 入参回空串、query 层不下发,回第一页)。
|
||||||
|
await leafCol.find('.cat-search').setValue('')
|
||||||
|
const callsBefore = jdApi.fetchJdProductList.mock.calls.length
|
||||||
|
await leafCol.find('.cat-row-all').trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
expect(jdApi.fetchJdProductList.mock.calls.length).toBe(callsBefore + 1, '清选也要重查')
|
||||||
|
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].category).toBe('')
|
||||||
|
|
||||||
|
// 触发框已选时出 × 清除按钮:点了同样清选。
|
||||||
|
await wrapper.find('.cat-trigger').trigger('click')
|
||||||
|
await wrapper.findAll('.cat-col').at(-1)!.findAll('.cat-row').find((row) => row.text().includes('啦啦队服'))!.trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
expect(wrapper.find('.cat-trigger').text()).toContain('啦啦队服')
|
||||||
|
const callsBeforeClear = jdApi.fetchJdProductList.mock.calls.length
|
||||||
|
await wrapper.find('.cat-clear').trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
expect(jdApi.fetchJdProductList.mock.calls.length).toBe(callsBeforeClear + 1, '× 清除同样触发重查')
|
||||||
|
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].category).toBe('')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('分类状态下拉:全部/已分类/未分类三档,选中即查回第一页并下发对应参数', async () => {
|
it('分类状态下拉:全部/已分类/未分类三档,选中即查回第一页并下发对应参数', async () => {
|
||||||
@@ -594,8 +645,8 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
|||||||
expect(last.productCode).toBe('', '切公司必须清掉上一家的商品编码')
|
expect(last.productCode).toBe('', '切公司必须清掉上一家的商品编码')
|
||||||
expect(last.titleKeyword).toBe('', '切公司必须清掉上一家的标题关键字')
|
expect(last.titleKeyword).toBe('', '切公司必须清掉上一家的标题关键字')
|
||||||
expect(last.groupId).toBe('7', '分组全平台一份(公共),groupId 与公司维度正交——切 tab 不清')
|
expect(last.groupId).toBe('7', '分组全平台一份(公共),groupId 与公司维度正交——切 tab 不清')
|
||||||
expect(last).not.toHaveProperty('category', '切公司必须清掉上一家选的类目')
|
expect(last.category).toBe('', '切公司必须清掉上一家选的类目(入参回空串、query 层不下发)')
|
||||||
expect(last).not.toHaveProperty('shopName', '店铺筛选已下线,入参不再带 shopName')
|
expect(last).not.toHaveProperty('shopName', '店铺筛选已下线:页面入参层不再传该键')
|
||||||
expect(last.page).toBe(1)
|
expect(last.page).toBe(1)
|
||||||
// 分组选项是全局的:切 tab 不重取(首屏那一次之后就不再增长),且任何一次拉取都不带公司维度。
|
// 分组选项是全局的:切 tab 不重取(首屏那一次之后就不再增长),且任何一次拉取都不带公司维度。
|
||||||
for (const call of jdApi.fetchJdProductGroups.mock.calls) {
|
for (const call of jdApi.fetchJdProductGroups.mock.calls) {
|
||||||
|
|||||||
Reference in New Issue
Block a user