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 JdProductEditDrawer from './JdProductEditDrawer.vue'
|
||||
import JdProductGroupDialog from './JdProductGroupDialog.vue'
|
||||
import JdCategoryCascader from './JdCategoryCascader.vue'
|
||||
import OldPagination from '@/components/OldPagination.vue'
|
||||
import { useCompanyTabStore } from '@/stores/company-tab'
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
@@ -145,6 +146,13 @@ function apply(): void {
|
||||
void load()
|
||||
}
|
||||
|
||||
/** 类目级联面板点末级即查:选完立刻按该类目过滤刷新(回第一页),同分组下拉口径;
|
||||
* 点「全部类目」/触发框 × = 清选重查。 */
|
||||
function onCategoryPicked(name: string): void {
|
||||
filter.category = name
|
||||
apply()
|
||||
}
|
||||
|
||||
/** 重置:筛选面回出厂空态,回第一页重取。 */
|
||||
function reset(): void {
|
||||
Object.assign(filter, createJdProductFilterState())
|
||||
@@ -289,13 +297,13 @@ onMounted(() => {
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>类目</label>
|
||||
<!-- 类目(京麦末级类目)选中即查:同分组口径,选完立刻按该类目过滤刷新(回第一页)。 -->
|
||||
<select v-model="filter.category" @change="apply">
|
||||
<option value="">全部类目</option>
|
||||
<option v-for="cat in categoryOptions" :key="cat.name" :value="cat.name">
|
||||
{{ cat.name }}({{ cat.productCount }})
|
||||
</option>
|
||||
</select>
|
||||
<!-- 类目(京麦末级类目)京麦同款级联面板(2026-11-16 客户口径):一/二级为静态导航
|
||||
(采集链无层级数据),第三栏已落库末级+搜索,点行选中即查(回第一页)。 -->
|
||||
<JdCategoryCascader
|
||||
:options="categoryOptions"
|
||||
:model-value="filter.category"
|
||||
@change="onCategoryPicked"
|
||||
/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<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 ?? []
|
||||
}
|
||||
Reference in New Issue
Block a user