fix(admin-vue): 京东侧栏店铺名单铺开+添加店铺常驻(对齐原型《商品数据商城》)

This commit is contained in:
2026-11-22 02:02:43 +08:00
parent f742df9f20
commit 19b32414ac
3 changed files with 105 additions and 117 deletions
@@ -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) {