fix(admin-vue): 京东侧栏店铺名单铺开+添加店铺常驻(对齐原型《商品数据商城》)
This commit is contained in:
@@ -19,7 +19,7 @@ const props = defineProps<{
|
||||
/** /categories 计数行(京麦末级类目+商品数;页面持有,失败静默回空数组)。 */
|
||||
categoryOptions: JdProductCategoryOption[]
|
||||
/** 当前数据权限分组的分类(V203 归属口径,带 productCount 徽标;v1.7 每行可带
|
||||
* shops 店铺名单——分类行出展开箭头,展开后店铺行点选过滤)。 */
|
||||
* shops 店铺名单——铺开渲染店铺行点选过滤,空分类也常驻「添加店铺」入口)。 */
|
||||
categories: JdProductGroup[]
|
||||
/** 当前分组分类可写(scope.editable 投影):可写档渲染「新建分类」行、分类/店铺行的
|
||||
* hover 改名/删除与「添加店铺」入口;「分类管理」入口对所有人渲染(同组普通号只读可看,
|
||||
@@ -252,38 +252,15 @@ function submitCreate(): void {
|
||||
|
||||
// ---------------- 店铺名单(v1.7 F6 完整对齐原型:分类下挂店铺名单) ----------------
|
||||
|
||||
/** 名单展开态(按分类 id 记):有名单的分类行出箭头,出厂收起。 */
|
||||
const expandedShops = ref<Set<number>>(new Set())
|
||||
/** 名单铺开渲染(2026-11-22 原型对齐:分类→店铺名单→「+ 添加店铺」直接可见)。
|
||||
* 旧折叠版把入口藏在展开区里,且箭头只在已有名单时才出 ⇒ 空分类永远加不进
|
||||
* 第一个店铺(死锁);铺开后名单与入口常驻,空分类直接可加。 */
|
||||
|
||||
function toggleShops(group: JdProductGroup): void {
|
||||
const next = new Set(expandedShops.value)
|
||||
if (next.has(group.id)) next.delete(group.id)
|
||||
else next.add(group.id)
|
||||
expandedShops.value = next
|
||||
}
|
||||
|
||||
/** 店铺行点选:分类+店铺成对下发(页面发 group_id+shop_name 过滤);再点已选中的
|
||||
* =emit null(只清店铺筛选,分类选中保留——每层独立 toggle)。 */
|
||||
function pickShop(group: JdProductGroup, shopName: string): void {
|
||||
const picked = props.selectedGroupId === group.id && props.selectedShopName === shopName
|
||||
emit('select-shop', picked ? null : { groupId: group.id, shopName })
|
||||
}
|
||||
|
||||
/** 页面带着店铺筛选挂载/回流时(重置后再选、切页返回),宿主分类自动展开到位。 */
|
||||
watch(
|
||||
() => props.selectedShopName,
|
||||
(shop) => {
|
||||
if (!shop) return
|
||||
const host = (props.categories ?? []).find((group) => (group.shops ?? []).includes(shop))
|
||||
if (host && !expandedShops.value.has(host.id)) {
|
||||
const next = new Set(expandedShops.value)
|
||||
next.add(host.id)
|
||||
expandedShops.value = next
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
// 行内改名(分类与店铺同构):点 hover ✎ 进编辑形态,Enter/✓ 提交、✕ 取消。
|
||||
const renamingCategory = ref<number | null>(null)
|
||||
const renameCategoryDraft = ref('')
|
||||
@@ -435,7 +412,8 @@ function cancelShopRename(): void {
|
||||
|
||||
<template v-if="categories.length">
|
||||
<!-- 分类行(div role=button,行内要嵌 hover 操作按钮——button 嵌 button 非法 HTML):
|
||||
有名单(shops)出展开箭头;可写档 hover 出改名/删除;展开后店铺行+添加店铺入口。 -->
|
||||
铺开形态(2026-11-22 原型对齐)无折叠箭头;可写档 hover 出改名/删除;
|
||||
名单店铺行与「添加店铺」入口直接铺在分类行下。 -->
|
||||
<template v-for="cat in categories" :key="cat.id">
|
||||
<div
|
||||
class="jd-side-row jd-side-cat"
|
||||
@@ -446,15 +424,7 @@ function cancelShopRename(): void {
|
||||
@click="pickGroup(cat)"
|
||||
@keydown.enter="pickGroup(cat)"
|
||||
>
|
||||
<span
|
||||
v-if="(cat.shops?.length || 0) > 0"
|
||||
class="jd-side-arrow"
|
||||
:class="{ open: expandedShops.has(cat.id) }"
|
||||
role="button"
|
||||
:aria-label="`展开或收起 ${cat.name} 的店铺名单`"
|
||||
@click.stop="toggleShops(cat)"
|
||||
>▸</span>
|
||||
<span v-else class="jd-side-leaf-dot" />
|
||||
<span class="jd-side-leaf-dot" />
|
||||
<span class="jd-side-name">{{ cat.name }}</span>
|
||||
<span class="jd-side-count">{{ cat.productCount }}</span>
|
||||
<span v-if="editable" class="jd-side-ops">
|
||||
@@ -485,60 +455,58 @@ function cancelShopRename(): void {
|
||||
<button type="button" :aria-label="`确认改名分类 ${cat.name}`" @click.stop="submitRenameCategory(cat)">✓</button>
|
||||
<button type="button" aria-label="取消改名" @click.stop="cancelRenameCategory()">✕</button>
|
||||
</div>
|
||||
<!-- 展开的店铺名单(v1.7):点店铺=分类+店铺成对过滤;可写档 hover 改名/移除;
|
||||
名单尾「+ 添加店铺」入口开页面级弹窗。 -->
|
||||
<template v-if="expandedShops.has(cat.id)">
|
||||
<template v-for="shop in (cat.shops ?? [])" :key="`${cat.id}:${shop}`">
|
||||
<div
|
||||
class="jd-side-row jd-side-shop depth-1"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
:class="{ selected: selectedGroupId === cat.id && selectedShopName === shop }"
|
||||
:title="shop"
|
||||
@click="pickShop(cat, shop)"
|
||||
@keydown.enter="pickShop(cat, shop)"
|
||||
>
|
||||
<span class="jd-side-leaf-dot" />
|
||||
<span class="jd-side-name">{{ shop }}</span>
|
||||
<span v-if="editable" class="jd-side-ops">
|
||||
<button
|
||||
type="button"
|
||||
class="jd-side-op"
|
||||
:aria-label="`改名店铺 ${shop}`"
|
||||
title="改名"
|
||||
@click.stop="startRenameShop(cat, shop)"
|
||||
>✎</button>
|
||||
<button
|
||||
type="button"
|
||||
class="jd-side-op jd-side-op-danger"
|
||||
:aria-label="`移除店铺 ${shop}`"
|
||||
title="移除"
|
||||
@click.stop="emit('remove-shop', cat, shop)"
|
||||
>✕</button>
|
||||
</span>
|
||||
</div>
|
||||
<!-- 店铺行内改名(编辑形态替换该行)。 -->
|
||||
<div v-if="renamingShop && renamingShop.categoryId === cat.id" class="jd-side-inline-edit jd-side-shop-edit depth-1">
|
||||
<input
|
||||
v-model="renameShopDraft"
|
||||
type="text"
|
||||
:aria-label="`修改店铺名称(原:${renamingShop.name})`"
|
||||
@keyup.enter="submitRenameShop(cat)"
|
||||
/>
|
||||
<button type="button" :aria-label="`确认改名店铺 ${renamingShop.name}`" @click.stop="submitRenameShop(cat)">✓</button>
|
||||
<button type="button" aria-label="取消改名" @click.stop="cancelShopRename()">✕</button>
|
||||
</div>
|
||||
</template>
|
||||
<button
|
||||
v-if="editable"
|
||||
type="button"
|
||||
class="jd-side-row jd-side-shop-add depth-1"
|
||||
@click="emit('add-shops', cat)"
|
||||
<!-- 铺开的店铺名单(v1.7 铺开形态):点店铺=分类+店铺成对过滤;可写档 hover 改名/移除;
|
||||
名单尾「+ 添加店铺」入口常驻(空分类也能加第一个店)开页面级弹窗。 -->
|
||||
<template v-for="shop in (cat.shops ?? [])" :key="`${cat.id}:${shop}`">
|
||||
<div
|
||||
class="jd-side-row jd-side-shop depth-1"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
:class="{ selected: selectedGroupId === cat.id && selectedShopName === shop }"
|
||||
:title="shop"
|
||||
@click="pickShop(cat, shop)"
|
||||
@keydown.enter="pickShop(cat, shop)"
|
||||
>
|
||||
<span class="jd-side-leaf-dot" />
|
||||
<span class="jd-side-name">+ 添加店铺</span>
|
||||
</button>
|
||||
<span class="jd-side-name">{{ shop }}</span>
|
||||
<span v-if="editable" class="jd-side-ops">
|
||||
<button
|
||||
type="button"
|
||||
class="jd-side-op"
|
||||
:aria-label="`改名店铺 ${shop}`"
|
||||
title="改名"
|
||||
@click.stop="startRenameShop(cat, shop)"
|
||||
>✎</button>
|
||||
<button
|
||||
type="button"
|
||||
class="jd-side-op jd-side-op-danger"
|
||||
:aria-label="`移除店铺 ${shop}`"
|
||||
title="移除"
|
||||
@click.stop="emit('remove-shop', cat, shop)"
|
||||
>✕</button>
|
||||
</span>
|
||||
</div>
|
||||
<!-- 店铺行内改名(编辑形态替换该行)。 -->
|
||||
<div v-if="renamingShop && renamingShop.categoryId === cat.id" class="jd-side-inline-edit jd-side-shop-edit depth-1">
|
||||
<input
|
||||
v-model="renameShopDraft"
|
||||
type="text"
|
||||
:aria-label="`修改店铺名称(原:${renamingShop.name})`"
|
||||
@keyup.enter="submitRenameShop(cat)"
|
||||
/>
|
||||
<button type="button" :aria-label="`确认改名店铺 ${renamingShop.name}`" @click.stop="submitRenameShop(cat)">✓</button>
|
||||
<button type="button" aria-label="取消改名" @click.stop="cancelShopRename()">✕</button>
|
||||
</div>
|
||||
</template>
|
||||
<button
|
||||
v-if="editable"
|
||||
type="button"
|
||||
class="jd-side-row jd-side-shop-add depth-1"
|
||||
@click="emit('add-shops', cat)"
|
||||
>
|
||||
<span class="jd-side-leaf-dot" />
|
||||
<span class="jd-side-name">+ 添加店铺</span>
|
||||
</button>
|
||||
</template>
|
||||
</template>
|
||||
<p v-else class="jd-side-empty">{{ editable ? '本组暂无分类,先新建一个' : '本组暂无分类' }}</p>
|
||||
@@ -593,6 +561,28 @@ function cancelShopRename(): void {
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
padding: 6px;
|
||||
/* 滚动带常驻(2026-11-21 用户口径「这边还要个进度条」,红框指树右缘滚动带):
|
||||
Win 新版 Chrome/Edge 的 fluent overlay 滚动条不悬停不显形,长类目树看不出可滚;
|
||||
标准属性(Chrome/Edge/Firefox 通用)+自绘 webkit 滚动条兜旧版,无溢出时不占位。 */
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: #bccfe1 transparent;
|
||||
}
|
||||
|
||||
.jd-sidebar-body::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
}
|
||||
|
||||
.jd-sidebar-body::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.jd-sidebar-body::-webkit-scrollbar-thumb {
|
||||
background: #bccfe1;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.jd-sidebar-body::-webkit-scrollbar-thumb:hover {
|
||||
background: #9fb7cd;
|
||||
}
|
||||
|
||||
@media (max-width: 980px) {
|
||||
|
||||
@@ -290,43 +290,48 @@ describe('店铺分类 Tab(当前分组分类平铺+入口分档)', () =>
|
||||
})
|
||||
})
|
||||
|
||||
/** 店铺名单(v1.7 F6 完整对齐原型《商品数据商城》):分类行展开箭头→店铺行(点选过滤/
|
||||
* 行内改名移除)+「+ 添加店铺」入口+分类行 hover 改名/删除。侧栏纯展示:全部只 emit,
|
||||
* API 调用与刷新在页面。 */
|
||||
describe('店铺名单(v1.7:分类下挂店铺名单)', () => {
|
||||
/** 店铺名单(v1.7 F6,2026-11-22 原型对齐铺开形态):分类行下直接铺店铺行(点选过滤/
|
||||
* 行内改名移除)+「+ 添加店铺」入口常驻(空分类也能加第一个店——旧折叠版箭头只在
|
||||
* 已有名单时才出 ⇒ 空分类永远加不进第一个店铺的死锁,判据就在下面的空分类用例)。
|
||||
* 侧栏纯展示:全部只 emit,API 调用与刷新在页面。 */
|
||||
describe('店铺名单(v1.7 铺开形态:分类下挂店铺名单)', () => {
|
||||
async function openCustomTab(wrapper: VueWrapper<Element>): Promise<void> {
|
||||
const tabs = wrapper.findAll('.jd-sidebar-tab')
|
||||
await tabs[1]!.trigger('click')
|
||||
await flushPromises()
|
||||
}
|
||||
|
||||
it('有名单的分类行出展开箭头(无名单不出);出厂收起,点箭头展开店铺行+添加店铺入口,再点收起', async () => {
|
||||
it('店铺名单铺开:店铺行直接可见(无折叠箭头),可写档名单尾出添加店铺入口', async () => {
|
||||
const wrapper = mountSidebar({ categories: CATEGORIES_WITH_SHOPS })
|
||||
await openCustomTab(wrapper)
|
||||
const custom = wrapper.get('.jd-side-custom')
|
||||
expect(custom.get('[aria-label="展开或收起 裙装 的店铺名单"]').exists()).toBe(true, '有名单出箭头')
|
||||
expect(custom.find('[aria-label="展开或收起 裤装 的店铺名单"]').exists()).toBe(false, '无名单不出箭头')
|
||||
expect(custom.findAll('.jd-side-shop')).toHaveLength(0, '出厂收起(店铺行不可见)')
|
||||
|
||||
await custom.get('[aria-label="展开或收起 裙装 的店铺名单"]').trigger('click')
|
||||
await flushPromises()
|
||||
expect(custom.find('[aria-label="展开或收起 裙装 的店铺名单"]').exists()).toBe(false,
|
||||
'铺开形态无店铺名单折叠箭头(类目树的箭头不受影响)')
|
||||
const shops = custom.findAll('.jd-side-shop')
|
||||
expect(shops).toHaveLength(2, '展开后店铺行可见(服务端升序原样渲染)')
|
||||
expect(shops).toHaveLength(2, '店铺行首屏直接可见(服务端升序原样渲染)')
|
||||
expect(shops[0]!.text()).toContain('绿屿街道店')
|
||||
expect(shops[1]!.text()).toContain('花屿巷旗舰店')
|
||||
expect(custom.get('.jd-side-shop-add').text()).toContain('+ 添加店铺', '可写档名单尾出添加入口')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
await custom.get('[aria-label="展开或收起 裙装 的店铺名单"]').trigger('click')
|
||||
it('空分类也常驻「+ 添加店铺」入口(2026-11-22 死锁修复:空分类能加进第一个店铺)', async () => {
|
||||
const wrapper = mountSidebar({ categories: CATEGORIES })
|
||||
await openCustomTab(wrapper)
|
||||
const custom = wrapper.get('.jd-side-custom')
|
||||
expect(custom.findAll('.jd-side-shop')).toHaveLength(0, '两个分类都无名单')
|
||||
const addRows = custom.findAll('.jd-side-shop-add')
|
||||
expect(addRows).toHaveLength(2, '空分类名单尾照样出添加入口(旧折叠版此处为 0=加不进第一个店)')
|
||||
await addRows[1]!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper.get('.jd-side-custom').findAll('.jd-side-shop')).toHaveLength(0, '再点箭头=收起')
|
||||
expect(wrapper.emitted('add-shops')).toEqual([[CATEGORIES[1]]],
|
||||
'点裤装(空分类)的添加入口=emit 该分类')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('点店铺行 emit {groupId, shopName} 成对下发;选中回流高亮;再点已选 emit null(只清店铺保留分类)', async () => {
|
||||
const wrapper = mountSidebar({ categories: CATEGORIES_WITH_SHOPS, selectedGroupId: 7 })
|
||||
await openCustomTab(wrapper)
|
||||
await wrapper.get('[aria-label="展开或收起 裙装 的店铺名单"]').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
const shopRow = wrapper.get('.jd-side-custom').findAll('.jd-side-shop')[0]!
|
||||
await shopRow.trigger('click')
|
||||
@@ -343,12 +348,11 @@ describe('店铺名单(v1.7:分类下挂店铺名单)', () => {
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('页面带着店铺筛选挂载:宿主分类自动展开(店铺行可见,不用再点箭头)', async () => {
|
||||
it('页面带着店铺筛选挂载:店铺行直接可见并高亮(铺开态无需展开)', async () => {
|
||||
const wrapper = mountSidebar({ categories: CATEGORIES_WITH_SHOPS, selectedGroupId: 7, selectedShopName: '花屿巷旗舰店' })
|
||||
await openCustomTab(wrapper)
|
||||
expect(wrapper.get('.jd-side-custom').findAll('.jd-side-shop')).toHaveLength(2,
|
||||
'watch immediate 展开宿主分类')
|
||||
const selected = wrapper.get('.jd-side-custom').findAll('.jd-side-shop').find((row) => row.text().includes('花屿巷旗舰店'))
|
||||
expect(selected, '铺开态店铺行首屏可见').toBeTruthy()
|
||||
expect(selected!.classes()).toContain('selected')
|
||||
wrapper.unmount()
|
||||
})
|
||||
@@ -380,9 +384,7 @@ describe('店铺名单(v1.7:分类下挂店铺名单)', () => {
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('rename-category')).toHaveLength(1, '未改动不白发请求')
|
||||
|
||||
// 店铺行 hover 操作钮在展开后可见。
|
||||
await custom.get('[aria-label="展开或收起 裙装 的店铺名单"]').trigger('click')
|
||||
await flushPromises()
|
||||
// 店铺行 hover 操作钮随铺开直接可见。
|
||||
expect(custom.get('[aria-label="改名店铺 绿屿街道店"]').exists()).toBe(true)
|
||||
expect(custom.get('[aria-label="移除店铺 绿屿街道店"]').exists()).toBe(true)
|
||||
wrapper.unmount()
|
||||
@@ -392,8 +394,6 @@ describe('店铺名单(v1.7:分类下挂店铺名单)', () => {
|
||||
const wrapper = mountSidebar({ categories: CATEGORIES_WITH_SHOPS })
|
||||
await openCustomTab(wrapper)
|
||||
const custom = wrapper.get('.jd-side-custom')
|
||||
await custom.get('[aria-label="展开或收起 裙装 的店铺名单"]').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
// 店铺改名:✎ → 预填 → 改名 → ✓ 提交。
|
||||
await custom.get('[aria-label="改名店铺 绿屿街道店"]').trigger('click')
|
||||
@@ -423,8 +423,6 @@ describe('店铺名单(v1.7:分类下挂店铺名单)', () => {
|
||||
const custom = wrapper.get('.jd-side-custom')
|
||||
expect(custom.find('[aria-label="改名分类 裙装"]').exists()).toBe(false, '分类行无改名钮')
|
||||
expect(custom.find('[aria-label="删除分类 裙装"]').exists()).toBe(false, '分类行无删除钮')
|
||||
await custom.get('[aria-label="展开或收起 裙装 的店铺名单"]').trigger('click')
|
||||
await flushPromises()
|
||||
expect(custom.findAll('.jd-side-shop')).toHaveLength(2, '店铺行照常可见(读面)')
|
||||
expect(custom.find('.jd-side-shop-add').exists()).toBe(false, '只读档无添加店铺入口')
|
||||
expect(custom.find('[aria-label="改名店铺 绿屿街道店"]').exists()).toBe(false, '店铺行无改名钮')
|
||||
@@ -440,8 +438,6 @@ describe('店铺名单(v1.7:分类下挂店铺名单)', () => {
|
||||
it('分类行仍是 toggle 选中(点行 emit id/再点 null),店铺行高亮不改变分类行选中判定', async () => {
|
||||
const wrapper = mountSidebar({ categories: CATEGORIES_WITH_SHOPS, selectedGroupId: 7 })
|
||||
await openCustomTab(wrapper)
|
||||
await wrapper.get('[aria-label="展开或收起 裙装 的店铺名单"]').trigger('click')
|
||||
await flushPromises()
|
||||
expect(rowByText(wrapper, '裙装').classes()).toContain('selected', '分类行选中(含选店铺时)')
|
||||
|
||||
await rowByText(wrapper, '裙装').trigger('click')
|
||||
|
||||
@@ -981,8 +981,10 @@ describe('筛选与分页(v1.7:合并搜索+筛选弹层;AC-2/AC-4)',
|
||||
expect(last).toMatchObject({ keyword: '', groupId: '', category: '', page: 1 }, '重置后筛选全空、回第一页')
|
||||
expect(wrapper.find('.jd-filter-popover').exists()).toBe(false, '重置后弹层收起')
|
||||
expect(sideCustom(wrapper).findAll('.jd-side-row.selected')).toHaveLength(0, '侧栏分类选中态随重置清空')
|
||||
expect(sideCustom(wrapper).findAll('.jd-side-row')).toHaveLength(2,
|
||||
expect(sideCustom(wrapper).findAll('.jd-side-cat')).toHaveLength(2,
|
||||
'重置只清筛选面:侧栏分类清单(当前组)保留,清选语义=再点已选行')
|
||||
expect(sideCustom(wrapper).findAll('.jd-side-shop').length).toBeGreaterThan(0,
|
||||
'铺开名单(2026-11-22)不受重置影响:店铺行照常可见')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user