feat(jd-database): v1.7 侧栏店铺名单——分类下挂店铺、点店铺过滤、行内改名/移除、添加店铺弹窗
This commit is contained in:
@@ -18,15 +18,19 @@ import type { JdProductCategoryOption, JdProductGroup } from './jd-product-api.t
|
|||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
/** /categories 计数行(京麦末级类目+商品数;页面持有,失败静默回空数组)。 */
|
/** /categories 计数行(京麦末级类目+商品数;页面持有,失败静默回空数组)。 */
|
||||||
categoryOptions: JdProductCategoryOption[]
|
categoryOptions: JdProductCategoryOption[]
|
||||||
/** 当前数据权限分组的分类(V203 归属口径,带 productCount 徽标)。 */
|
/** 当前数据权限分组的分类(V203 归属口径,带 productCount 徽标;v1.7 每行可带
|
||||||
|
* shops 店铺名单——分类行出展开箭头,展开后店铺行点选过滤)。 */
|
||||||
categories: JdProductGroup[]
|
categories: JdProductGroup[]
|
||||||
/** 当前分组分类可写(scope.editable 投影):可写档渲染「新建分类」行;
|
/** 当前分组分类可写(scope.editable 投影):可写档渲染「新建分类」行、分类/店铺行的
|
||||||
* 「分类管理」入口对所有人渲染(同组普通号只读可看,V203,写控件由对话框分档)。 */
|
* hover 改名/删除与「添加店铺」入口;「分类管理」入口对所有人渲染(同组普通号只读可看,
|
||||||
|
* V203,写控件由对话框分档)。 */
|
||||||
editable: boolean
|
editable: boolean
|
||||||
/** 当前类目选中(name+完整名称路径;树外历史名 path 为空数组;null=全部商品)。 */
|
/** 当前类目选中(name+完整名称路径;树外历史名 path 为空数组;null=全部商品)。 */
|
||||||
selectedCategory?: { name: string; path: string[] } | null
|
selectedCategory?: { name: string; path: string[] } | null
|
||||||
/** 当前分类选中 id(null=全部分类)。 */
|
/** 当前分类选中 id(null=全部分类)。 */
|
||||||
selectedGroupId?: number | null
|
selectedGroupId?: number | null
|
||||||
|
/** 当前店铺筛选(v1.7 店铺名单点选;空/缺省=未按店铺过滤)。 */
|
||||||
|
selectedShopName?: string | null
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
@@ -35,9 +39,22 @@ const emit = defineEmits<{
|
|||||||
(event: 'select-category', value: { name: string; path: string[] } | null): void
|
(event: 'select-category', value: { name: string; path: string[] } | null): void
|
||||||
/** 选分类:分类 id;再点已选中的=清选(emit null,回全部分类)。 */
|
/** 选分类:分类 id;再点已选中的=清选(emit null,回全部分类)。 */
|
||||||
(event: 'select-group', id: number | null): void
|
(event: 'select-group', id: number | null): void
|
||||||
|
/** 选店铺(v1.7 名单点选):分类+店铺名成对下发(点店铺=该分类归属 ∩ 该店铺,
|
||||||
|
* 精确 eq);再点已选中的=emit null(只清店铺筛选,分类选中保留)。 */
|
||||||
|
(event: 'select-shop', value: { groupId: number; shopName: string } | null): void
|
||||||
/** 新建分类(可写档):页面调 createJdProductGroup 落当前分组,成功后刷新,
|
/** 新建分类(可写档):页面调 createJdProductGroup 落当前分组,成功后刷新,
|
||||||
* 侧栏数据随 props 流回(本组件不感知成功/失败,输入框提交即清)。 */
|
* 侧栏数据随 props 流回(本组件不感知成功/失败,输入框提交即清)。 */
|
||||||
(event: 'create-category', name: string): void
|
(event: 'create-category', name: string): void
|
||||||
|
/** 分类行内改名(可写档 hover ✎):分类 id+新名,API 调用与刷新在页面。 */
|
||||||
|
(event: 'rename-category', category: JdProductGroup, name: string): void
|
||||||
|
/** 分类行内删除(可写档 hover ✕):页面二次确认后调 deleteJdProductGroup。 */
|
||||||
|
(event: 'delete-category', category: JdProductGroup): void
|
||||||
|
/** 店铺行内改名(可写档 hover ✎):分类、老名、新名(同分类查重 409 由后端拒)。 */
|
||||||
|
(event: 'rename-shop', category: JdProductGroup, oldName: string, newName: string): void
|
||||||
|
/** 店铺行内移除(可写档 hover ✕):页面调 removeJdGroupShop。 */
|
||||||
|
(event: 'remove-shop', category: JdProductGroup, shopName: string): void
|
||||||
|
/** 打开添加店铺弹窗(可写档「+ 添加店铺」行):弹窗与提交在页面。 */
|
||||||
|
(event: 'add-shops', category: JdProductGroup): void
|
||||||
/** 打开分类管理对话框(建/改名/删+搜索,V204 并入的既有组件)。 */
|
/** 打开分类管理对话框(建/改名/删+搜索,V204 并入的既有组件)。 */
|
||||||
(event: 'manage-categories'): void
|
(event: 'manage-categories'): void
|
||||||
}>()
|
}>()
|
||||||
@@ -134,10 +151,11 @@ const isSelectedExtra = (name: string): boolean => {
|
|||||||
return !!selected && selected.path.length === 0 && selected.name === name
|
return !!selected && selected.path.length === 0 && selected.name === name
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------- 店铺分类 Tab(当前分组分类平铺) ----------------
|
// ---------------- 店铺分类 Tab(当前分组分类平铺+店铺名单 v1.7) ----------------
|
||||||
|
|
||||||
function pickGroup(group: JdProductGroup): void {
|
function pickGroup(group: JdProductGroup): void {
|
||||||
// 再点已选中的=清选(回全部分类),与旧「全部分类」下拉行的语义等价。
|
// 再点已选中的=清选(回全部分类),与旧「全部分类」下拉行的语义等价。
|
||||||
|
// 店铺筛选随分类清选一起走(店铺名单挂在分类下,分类清了店铺筛选无意义——页面同清)。
|
||||||
emit('select-group', props.selectedGroupId === group.id ? null : group.id)
|
emit('select-group', props.selectedGroupId === group.id ? null : group.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,6 +167,85 @@ function submitCreate(): void {
|
|||||||
emit('create-category', name)
|
emit('create-category', name)
|
||||||
newCategoryName.value = ''
|
newCategoryName.value = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------- 店铺名单(v1.7 F6 完整对齐原型:分类下挂店铺名单) ----------------
|
||||||
|
|
||||||
|
/** 名单展开态(按分类 id 记):有名单的分类行出箭头,出厂收起。 */
|
||||||
|
const expandedShops = ref<Set<number>>(new Set())
|
||||||
|
|
||||||
|
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('')
|
||||||
|
const renamingShop = ref<{ categoryId: number; name: string } | null>(null)
|
||||||
|
const renameShopDraft = ref('')
|
||||||
|
|
||||||
|
function startRenameCategory(group: JdProductGroup): void {
|
||||||
|
cancelShopRename()
|
||||||
|
renamingCategory.value = group.id
|
||||||
|
renameCategoryDraft.value = group.name
|
||||||
|
}
|
||||||
|
|
||||||
|
function submitRenameCategory(group: JdProductGroup): void {
|
||||||
|
const name = renameCategoryDraft.value.trim()
|
||||||
|
cancelRenameCategory()
|
||||||
|
// 空名/未改动不 emit(静默收编辑态,不白发请求)。
|
||||||
|
if (!name || name === group.name) return
|
||||||
|
emit('rename-category', group, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancelRenameCategory(): void {
|
||||||
|
renamingCategory.value = null
|
||||||
|
renameCategoryDraft.value = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
function startRenameShop(group: JdProductGroup, shopName: string): void {
|
||||||
|
cancelRenameCategory()
|
||||||
|
renamingShop.value = { categoryId: group.id, name: shopName }
|
||||||
|
renameShopDraft.value = shopName
|
||||||
|
}
|
||||||
|
|
||||||
|
function submitRenameShop(group: JdProductGroup): void {
|
||||||
|
const entry = renamingShop.value
|
||||||
|
if (!entry) return
|
||||||
|
const name = renameShopDraft.value.trim()
|
||||||
|
cancelShopRename()
|
||||||
|
if (!name || name === entry.name) return
|
||||||
|
emit('rename-shop', group, entry.name, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancelShopRename(): void {
|
||||||
|
renamingShop.value = null
|
||||||
|
renameShopDraft.value = ''
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -250,19 +347,112 @@ function submitCreate(): void {
|
|||||||
<button type="button" class="jd-side-manage" @click="emit('manage-categories')">分类管理</button>
|
<button type="button" class="jd-side-manage" @click="emit('manage-categories')">分类管理</button>
|
||||||
|
|
||||||
<template v-if="categories.length">
|
<template v-if="categories.length">
|
||||||
<button
|
<!-- 分类行(div role=button,行内要嵌 hover 操作按钮——button 嵌 button 非法 HTML):
|
||||||
v-for="cat in categories"
|
有名单(shops)出展开箭头;可写档 hover 出改名/删除;展开后店铺行+添加店铺入口。 -->
|
||||||
:key="cat.id"
|
<template v-for="cat in categories" :key="cat.id">
|
||||||
type="button"
|
<div
|
||||||
class="jd-side-row"
|
class="jd-side-row jd-side-cat"
|
||||||
:class="{ selected: selectedGroupId === cat.id }"
|
role="button"
|
||||||
:title="cat.name"
|
tabindex="0"
|
||||||
@click="pickGroup(cat)"
|
:class="{ selected: selectedGroupId === cat.id }"
|
||||||
>
|
:title="cat.name"
|
||||||
<span class="jd-side-leaf-dot" />
|
@click="pickGroup(cat)"
|
||||||
<span class="jd-side-name">{{ cat.name }}</span>
|
@keydown.enter="pickGroup(cat)"
|
||||||
<span class="jd-side-count">{{ cat.productCount }}</span>
|
>
|
||||||
</button>
|
<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-name">{{ cat.name }}</span>
|
||||||
|
<span class="jd-side-count">{{ cat.productCount }}</span>
|
||||||
|
<span v-if="editable" class="jd-side-ops">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="jd-side-op"
|
||||||
|
:aria-label="`改名分类 ${cat.name}`"
|
||||||
|
title="改名"
|
||||||
|
@click.stop="startRenameCategory(cat)"
|
||||||
|
>✎</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="jd-side-op jd-side-op-danger"
|
||||||
|
:aria-label="`删除分类 ${cat.name}`"
|
||||||
|
title="删除"
|
||||||
|
@click.stop="emit('delete-category', cat)"
|
||||||
|
>✕</button>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<!-- 分类行内改名(编辑形态替换该行):Enter/✓ 提交(空名/未改动静默收起)。 -->
|
||||||
|
<div v-if="renamingCategory === cat.id" class="jd-side-inline-edit">
|
||||||
|
<input
|
||||||
|
v-model="renameCategoryDraft"
|
||||||
|
type="text"
|
||||||
|
:aria-label="`修改分类名称(原:${cat.name})`"
|
||||||
|
@keyup.enter="submitRenameCategory(cat)"
|
||||||
|
/>
|
||||||
|
<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)"
|
||||||
|
>
|
||||||
|
<span class="jd-side-leaf-dot" />
|
||||||
|
<span class="jd-side-name">+ 添加店铺</span>
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
</template>
|
||||||
</template>
|
</template>
|
||||||
<p v-else class="jd-side-empty">{{ editable ? '本组暂无分类,先新建一个' : '本组暂无分类' }}</p>
|
<p v-else class="jd-side-empty">{{ editable ? '本组暂无分类,先新建一个' : '本组暂无分类' }}</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -465,4 +655,92 @@ function submitCreate(): void {
|
|||||||
.jd-side-manage:hover {
|
.jd-side-manage:hover {
|
||||||
color: #409eff;
|
color: #409eff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 店铺名单(v1.7 F6):分类行 hover 操作钮(改名/删除)、店铺行缩进、行内改名编辑形态、
|
||||||
|
「+ 添加店铺」入口。行本体是 div role=button(行内嵌操作按钮,button 嵌 button 非法)。 */
|
||||||
|
.jd-side-row.jd-side-cat,
|
||||||
|
.jd-side-row.jd-side-shop {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
/* hover 操作钮:默认藏,行 hover 时浮出(占位 0 宽,不挤名字/徽标布局)。 */
|
||||||
|
.jd-side-ops {
|
||||||
|
display: inline-flex;
|
||||||
|
gap: 2px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
width: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
transition: width 120ms ease;
|
||||||
|
}
|
||||||
|
.jd-side-row:hover .jd-side-ops,
|
||||||
|
.jd-side-row:focus-within .jd-side-ops {
|
||||||
|
width: 36px;
|
||||||
|
}
|
||||||
|
.jd-side-op {
|
||||||
|
width: 17px;
|
||||||
|
height: 17px;
|
||||||
|
padding: 0;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
background: transparent;
|
||||||
|
color: #909399;
|
||||||
|
font-size: 11px;
|
||||||
|
line-height: 1;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.jd-side-op:hover {
|
||||||
|
background: #e6edf4;
|
||||||
|
color: #409eff;
|
||||||
|
}
|
||||||
|
.jd-side-op-danger:hover {
|
||||||
|
background: #fdf1ef;
|
||||||
|
color: #a04432;
|
||||||
|
}
|
||||||
|
/* 行内改名编辑形态:替换该行的紧凑输入行(Enter/✓ 提交、✕ 取消)。 */
|
||||||
|
.jd-side-inline-edit {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
padding: 3px 8px;
|
||||||
|
}
|
||||||
|
.jd-side-inline-edit.jd-side-shop-edit {
|
||||||
|
padding-left: 22px;
|
||||||
|
}
|
||||||
|
.jd-side-inline-edit input {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
padding: 4px 8px;
|
||||||
|
border: 1px solid #9fc3e8;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 12.5px;
|
||||||
|
font-family: inherit;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
.jd-side-inline-edit input:focus {
|
||||||
|
box-shadow: 0 0 0 2px rgba(95, 133, 173, 0.18);
|
||||||
|
}
|
||||||
|
.jd-side-inline-edit button {
|
||||||
|
width: 22px;
|
||||||
|
height: 24px;
|
||||||
|
padding: 0;
|
||||||
|
border: 1px solid #dcdfe6;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #fff;
|
||||||
|
color: #409eff;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.jd-side-inline-edit button:last-child {
|
||||||
|
color: #909399;
|
||||||
|
}
|
||||||
|
/* 「+ 添加店铺」入口:名单尾部的弱化行(虚线上缘分隔),可写档才渲染(v-if 在模板)。 */
|
||||||
|
.jd-side-shop-add {
|
||||||
|
color: #409eff;
|
||||||
|
border-top: 1px dashed #e4e7ed;
|
||||||
|
border-radius: 0;
|
||||||
|
}
|
||||||
|
.jd-side-shop-add:hover {
|
||||||
|
color: #2f7cd6;
|
||||||
|
background: #f0f7ff;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -19,11 +19,15 @@ import { computed, onMounted, reactive, ref } from 'vue'
|
|||||||
import {
|
import {
|
||||||
batchAssignJdProductGroup,
|
batchAssignJdProductGroup,
|
||||||
createJdProductGroup,
|
createJdProductGroup,
|
||||||
|
deleteJdProductGroup,
|
||||||
deleteJdProducts,
|
deleteJdProducts,
|
||||||
fetchJdCategoryScope,
|
fetchJdCategoryScope,
|
||||||
fetchJdProductCategories,
|
fetchJdProductCategories,
|
||||||
fetchJdProductGroups,
|
fetchJdProductGroups,
|
||||||
fetchJdProductList,
|
fetchJdProductList,
|
||||||
|
removeJdGroupShop,
|
||||||
|
renameJdGroupShop,
|
||||||
|
updateJdProductGroup,
|
||||||
type JdCategoryGroupOption,
|
type JdCategoryGroupOption,
|
||||||
type JdProductCategoryOption,
|
type JdProductCategoryOption,
|
||||||
type JdProductGroup,
|
type JdProductGroup,
|
||||||
@@ -41,6 +45,7 @@ import JdProductDetailModal from './JdProductDetailModal.vue'
|
|||||||
import JdProductEditDrawer from './JdProductEditDrawer.vue'
|
import JdProductEditDrawer from './JdProductEditDrawer.vue'
|
||||||
import JdBatchAssignDialog from './JdBatchAssignDialog.vue'
|
import JdBatchAssignDialog from './JdBatchAssignDialog.vue'
|
||||||
import JdCategoryManageDialog from './JdCategoryManageDialog.vue'
|
import JdCategoryManageDialog from './JdCategoryManageDialog.vue'
|
||||||
|
import JdShopPickerDialog from './JdShopPickerDialog.vue'
|
||||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||||
import { openAdminConfirm } from '@/components/admin-confirm'
|
import { openAdminConfirm } from '@/components/admin-confirm'
|
||||||
import { loadFailureMessage } from '@/components/load-failure-model'
|
import { loadFailureMessage } from '@/components/load-failure-model'
|
||||||
@@ -156,9 +161,110 @@ function onSelectCategory(value: { name: string; path: string[] } | null): void
|
|||||||
/** 侧栏选分类:id 或 null(清选,与旧「全部分类」下拉行同语义)。选中即查。 */
|
/** 侧栏选分类:id 或 null(清选,与旧「全部分类」下拉行同语义)。选中即查。 */
|
||||||
function onSelectGroup(id: number | null): void {
|
function onSelectGroup(id: number | null): void {
|
||||||
filter.groupId = id ? String(id) : ''
|
filter.groupId = id ? String(id) : ''
|
||||||
|
// 店铺筛选挂在分类下(v1.7 名单维度):分类清选时店铺筛选一起清,否则发一条
|
||||||
|
// 「分类不限 ∩ 店铺=X」的孤儿谓词(店铺全平台 DISTINCT,会命中别组分类下的同名店)。
|
||||||
|
filter.shopName = ''
|
||||||
apply()
|
apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------- 店铺名单(v1.7 F6:侧栏展开/点店铺过滤/行内改名移除/添加店铺弹窗) ----------------
|
||||||
|
|
||||||
|
/** 添加店铺弹窗的目标分类(名单挂在分类下;null=弹窗关着)。 */
|
||||||
|
const addShopsTarget = ref<JdProductGroup | null>(null)
|
||||||
|
const addShopsVisible = ref(false)
|
||||||
|
|
||||||
|
/** 侧栏点店铺行:分类+店铺成对下发(精确 eq);null=清店铺筛选(分类选中保留)。 */
|
||||||
|
function onSelectShop(value: { groupId: number; shopName: string } | null): void {
|
||||||
|
if (!value) {
|
||||||
|
filter.shopName = ''
|
||||||
|
apply()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
filter.groupId = String(value.groupId)
|
||||||
|
filter.shopName = value.shopName
|
||||||
|
apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 侧栏分类行内改名:成功后刷新分类(侧栏随 props 流回);失败弹后端中文文案(409 重名等)。 */
|
||||||
|
async function onRenameCategory(category: JdProductGroup, name: string): Promise<void> {
|
||||||
|
try {
|
||||||
|
await updateJdProductGroup(category.id, { name, sortOrder: category.sortOrder })
|
||||||
|
showAdminFeedback(`已把分类「${category.name}」改名为「${name}」`, 'success')
|
||||||
|
await loadGroupOptions()
|
||||||
|
} catch (error) {
|
||||||
|
const text = error instanceof Error && error.message ? error.message : '改名失败,请稍后重试'
|
||||||
|
showAdminFeedback(text, 'error')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 侧栏分类行内删除:二次确认(点名只解挂归属、商品保留)→ 删除 → 若当前筛选停在该
|
||||||
|
* 分类(含其店铺行)则清分类筛选,分类列表与行集都重取。 */
|
||||||
|
async function onDeleteCategory(category: JdProductGroup): Promise<void> {
|
||||||
|
const ok = await openAdminConfirm({ title: '删除分类', message: `确定删除分类「${category.name}」吗?只删除该分类的归属关系(${category.productCount} 个商品回到未分类),商品本身保留在公共库;分类下的店铺名单一并删除。此操作不可恢复。`, confirmText: '确认删除', danger: true })
|
||||||
|
if (!ok) return
|
||||||
|
try {
|
||||||
|
await deleteJdProductGroup(category.id)
|
||||||
|
showAdminFeedback(`已删除分类「${category.name}」`, 'success')
|
||||||
|
if (filter.groupId === String(category.id)) {
|
||||||
|
filter.groupId = ''
|
||||||
|
filter.shopName = ''
|
||||||
|
}
|
||||||
|
await loadGroupOptions()
|
||||||
|
await load()
|
||||||
|
} catch (error) {
|
||||||
|
const text = error instanceof Error && error.message ? error.message : '删除分类失败,请稍后重试'
|
||||||
|
showAdminFeedback(text, 'error')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 店铺行内改名:成功后刷新名单;若当前筛选正停在这个店(同分类)则把筛选词同步成新名。 */
|
||||||
|
async function onRenameShop(category: JdProductGroup, oldName: string, newName: string): Promise<void> {
|
||||||
|
try {
|
||||||
|
await renameJdGroupShop(category.id, oldName, newName)
|
||||||
|
showAdminFeedback(`已把店铺「${oldName}」改名为「${newName}」`, 'success')
|
||||||
|
if (filter.groupId === String(category.id) && filter.shopName === oldName) {
|
||||||
|
filter.shopName = newName
|
||||||
|
await load()
|
||||||
|
}
|
||||||
|
await loadGroupOptions()
|
||||||
|
} catch (error) {
|
||||||
|
const text = error instanceof Error && error.message ? error.message : '改名失败,请稍后重试'
|
||||||
|
showAdminFeedback(text, 'error')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 店铺行内移除(可重做——再加回名单即可,不设二次确认);筛选正停在它身上则清店铺筛选。 */
|
||||||
|
async function onRemoveShop(category: JdProductGroup, shopName: string): Promise<void> {
|
||||||
|
try {
|
||||||
|
await removeJdGroupShop(category.id, shopName)
|
||||||
|
showAdminFeedback(`已把「${shopName}」移出「${category.name}」的名单`, 'success')
|
||||||
|
if (filter.groupId === String(category.id) && filter.shopName === shopName) {
|
||||||
|
filter.shopName = ''
|
||||||
|
await load()
|
||||||
|
}
|
||||||
|
await loadGroupOptions()
|
||||||
|
} catch (error) {
|
||||||
|
const text = error instanceof Error && error.message ? error.message : '移除失败,请稍后重试'
|
||||||
|
showAdminFeedback(text, 'error')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 打开添加店铺弹窗(侧栏「+ 添加店铺」行;名单写闸 editable 在侧栏已分档,后端同闸兜底)。 */
|
||||||
|
function openAddShops(category: JdProductGroup): void {
|
||||||
|
addShopsTarget.value = category
|
||||||
|
addShopsVisible.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 添加店铺成功:回执=实际新增行数(幂等跳过不计)。只刷新名单(侧栏店铺行随 props
|
||||||
|
* 流回)——名单是筛选器的候选面,不动商品行集,行集谓词 shop_name 无需重查。 */
|
||||||
|
async function onShopsAdded(added: number, categoryName: string): Promise<void> {
|
||||||
|
showAdminFeedback(
|
||||||
|
added > 0 ? `已把 ${added} 个店铺加进「${categoryName}」` : '所选店铺都已在名单里,没有新增',
|
||||||
|
'success',
|
||||||
|
)
|
||||||
|
await loadGroupOptions()
|
||||||
|
}
|
||||||
|
|
||||||
/** 侧栏新建分类(可写档):落当前分组,成功后刷新分类(侧栏徽标随 props 流回)。 */
|
/** 侧栏新建分类(可写档):落当前分组,成功后刷新分类(侧栏徽标随 props 流回)。 */
|
||||||
async function onCreateCategory(name: string): Promise<void> {
|
async function onCreateCategory(name: string): Promise<void> {
|
||||||
try {
|
try {
|
||||||
@@ -666,17 +772,25 @@ onMounted(async () => {
|
|||||||
</section>
|
</section>
|
||||||
|
|
||||||
<div class="jd-body">
|
<div class="jd-body">
|
||||||
<!-- 左侧栏(v1.6):商品目录(京麦授权类目树+计数徽标+树外兜底)/店铺分类
|
<!-- 左侧栏(v1.6 → v1.7 名单维度):商品目录(京麦授权类目树+计数徽标+树外兜底)/
|
||||||
(当前分组分类平铺+新建+分类管理入口)。取数在页面,侧栏纯展示。 -->
|
店铺分类(分类平铺+店铺名单展开/点选过滤/行内改名移除+添加店铺入口+新建+
|
||||||
|
分类管理入口)。取数在页面,侧栏纯展示。 -->
|
||||||
<JdCategorySidebar
|
<JdCategorySidebar
|
||||||
:category-options="categoryOptions"
|
:category-options="categoryOptions"
|
||||||
:categories="groupOptions"
|
:categories="groupOptions"
|
||||||
:editable="canManageCategories"
|
:editable="canManageCategories"
|
||||||
:selected-category="selectedCategoryInfo"
|
:selected-category="selectedCategoryInfo"
|
||||||
:selected-group-id="selectedGroupIdNum"
|
:selected-group-id="selectedGroupIdNum"
|
||||||
|
:selected-shop-name="filter.shopName"
|
||||||
@select-category="onSelectCategory"
|
@select-category="onSelectCategory"
|
||||||
@select-group="onSelectGroup"
|
@select-group="onSelectGroup"
|
||||||
|
@select-shop="onSelectShop"
|
||||||
@create-category="onCreateCategory"
|
@create-category="onCreateCategory"
|
||||||
|
@rename-category="onRenameCategory"
|
||||||
|
@delete-category="onDeleteCategory"
|
||||||
|
@rename-shop="onRenameShop"
|
||||||
|
@remove-shop="onRemoveShop"
|
||||||
|
@add-shops="openAddShops"
|
||||||
@manage-categories="openManage"
|
@manage-categories="openManage"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@@ -751,6 +865,15 @@ onMounted(async () => {
|
|||||||
@close="batchEditVisible = false"
|
@close="batchEditVisible = false"
|
||||||
@done="onBatchAssigned"
|
@done="onBatchAssigned"
|
||||||
/>
|
/>
|
||||||
|
<!-- 添加店铺弹窗(v1.7 F6):侧栏「+ 添加店铺」行打开,弹窗自取候选(available)
|
||||||
|
与批量提交,done 回执带新增行数给页面刷名单。 -->
|
||||||
|
<JdShopPickerDialog
|
||||||
|
:visible="addShopsVisible"
|
||||||
|
:category-id="addShopsTarget?.id ?? 0"
|
||||||
|
:category-name="addShopsTarget?.name ?? ''"
|
||||||
|
@close="addShopsVisible = false"
|
||||||
|
@done="onShopsAdded"
|
||||||
|
/>
|
||||||
<JdCategoryManageDialog
|
<JdCategoryManageDialog
|
||||||
:visible="manageVisible"
|
:visible="manageVisible"
|
||||||
:owner-group-id="ownerGroupId"
|
:owner-group-id="ownerGroupId"
|
||||||
|
|||||||
@@ -0,0 +1,439 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
/** 添加店铺弹窗(v1.7 F6 对齐原型《商品数据商城》的「店铺名单维度」):
|
||||||
|
* 侧栏店铺分类 Tab 展开某分类后的「+ 添加店铺」行打开。候选=服务端
|
||||||
|
* fetchJdAvailableShops(biz_jd_product.shop_name DISTINCT,关键词包含匹配+排除本分类
|
||||||
|
* 已有名单,limit ≤ 200——商品行 shop_name 是京麦店铺全名,与名单来源同源);
|
||||||
|
* 勾选候选+手输自定义项(不在候选里的新店名)合并成一个待添加清单,一次批量提交
|
||||||
|
* (服务侧 trim/去重/上限 100,INSERT IGNORE 幂等跳过已存在行,回执=实际新增行数)。
|
||||||
|
* 结构复制 JdBatchAssignDialog(modal-mask+modal-head/tip/foot 同款皮肤)。 */
|
||||||
|
import { computed, ref, watch } from 'vue'
|
||||||
|
import { addJdGroupShops, fetchJdAvailableShops } from './jd-product-api.ts'
|
||||||
|
import { requestErrorMessage } from '../../api/envelope.ts'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
visible: boolean
|
||||||
|
/** 目标分类(名单挂在分类下)。 */
|
||||||
|
categoryId: number
|
||||||
|
categoryName: string
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{ (event: 'close'): void; (event: 'done', added: number, categoryName: string): void }>()
|
||||||
|
|
||||||
|
/** 候选搜索(关键词输入后手动点「搜索」或 Enter 触发——不随输入逐键打后端)。 */
|
||||||
|
const keyword = ref('')
|
||||||
|
const candidates = ref<string[]>([])
|
||||||
|
const searching = ref(false)
|
||||||
|
const searched = ref(false)
|
||||||
|
/** 待添加清单(勾选的候选+手输自定义项,Set 保序去重)。 */
|
||||||
|
const pending = ref<string[]>([])
|
||||||
|
/** 手输自定义项输入框。 */
|
||||||
|
const customName = ref('')
|
||||||
|
const submitting = ref(false)
|
||||||
|
const errorText = ref('')
|
||||||
|
|
||||||
|
/** 批量上限与服务端 JdGroupShopService.MAX_ADD_SHOPS 同值(文案点名 100)。 */
|
||||||
|
const MAX_ADD_SHOPS = 100
|
||||||
|
|
||||||
|
const canSubmit = computed(() => pending.value.length > 0 && !submitting.value)
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.visible,
|
||||||
|
(visible) => {
|
||||||
|
if (visible) {
|
||||||
|
keyword.value = ''
|
||||||
|
candidates.value = []
|
||||||
|
searched.value = false
|
||||||
|
pending.value = []
|
||||||
|
customName.value = ''
|
||||||
|
errorText.value = ''
|
||||||
|
// 打开即拉一次空关键词候选(让用户不输词也有东西可勾)。
|
||||||
|
void search()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
async function search(): Promise<void> {
|
||||||
|
searching.value = true
|
||||||
|
errorText.value = ''
|
||||||
|
try {
|
||||||
|
candidates.value = await fetchJdAvailableShops(keyword.value, props.categoryId)
|
||||||
|
searched.value = true
|
||||||
|
} catch (error) {
|
||||||
|
errorText.value = requestErrorMessage(error) || '候选店铺加载失败'
|
||||||
|
} finally {
|
||||||
|
searching.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleCandidate(name: string): void {
|
||||||
|
const index = pending.value.indexOf(name)
|
||||||
|
if (index >= 0) pending.value = pending.value.filter((item) => item !== name)
|
||||||
|
else pending.value = [...pending.value, name]
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 手输自定义项:空白不收;与待添加清单重复不收(静默忽略——清单里已有就是同一个)。 */
|
||||||
|
function addCustom(): void {
|
||||||
|
const name = customName.value.trim()
|
||||||
|
if (!name) return
|
||||||
|
if (!pending.value.includes(name)) pending.value = [...pending.value, name]
|
||||||
|
customName.value = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
function removePending(name: string): void {
|
||||||
|
pending.value = pending.value.filter((item) => item !== name)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submit(): Promise<void> {
|
||||||
|
if (!canSubmit.value) return
|
||||||
|
submitting.value = true
|
||||||
|
errorText.value = ''
|
||||||
|
try {
|
||||||
|
const added = await addJdGroupShops(props.categoryId, pending.value)
|
||||||
|
emit('done', added, props.categoryName)
|
||||||
|
emit('close')
|
||||||
|
} catch (error) {
|
||||||
|
errorText.value = requestErrorMessage(error) || '添加店铺失败'
|
||||||
|
} finally {
|
||||||
|
submitting.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div v-if="visible" class="modal-mask" @click.self="emit('close')">
|
||||||
|
<div class="shop-picker-modal">
|
||||||
|
<div class="modal-head">
|
||||||
|
<h3>添加店铺<span v-if="categoryName" class="modal-sub">· {{ categoryName }}</span></h3>
|
||||||
|
<button class="modal-close" type="button" aria-label="关闭" @click="emit('close')">×</button>
|
||||||
|
</div>
|
||||||
|
<p class="modal-tip">
|
||||||
|
从已采集商品的店铺里勾选,或手动输入名单里还没有的店铺名;
|
||||||
|
一次最多添加 {{ MAX_ADD_SHOPS }} 个,已有的会自动跳过。
|
||||||
|
</p>
|
||||||
|
<p v-if="errorText" class="group-error">{{ errorText }}</p>
|
||||||
|
|
||||||
|
<!-- 候选搜索:关键词包含匹配(服务端 DISTINCT+like),Enter 或按钮触发。 -->
|
||||||
|
<div class="shop-search">
|
||||||
|
<input
|
||||||
|
v-model="keyword"
|
||||||
|
type="text"
|
||||||
|
placeholder="搜索店铺名"
|
||||||
|
aria-label="候选店铺关键词"
|
||||||
|
@keyup.enter="search"
|
||||||
|
/>
|
||||||
|
<button type="button" :disabled="searching" @click="search">{{ searching ? '搜索中...' : '搜索' }}</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ul class="shop-candidate-list">
|
||||||
|
<li v-if="searching" class="shop-list-tip">搜索中...</li>
|
||||||
|
<li v-else-if="!candidates.length && searched" class="shop-list-tip">没有可添加的候选店铺(已采商品的店铺都在名单里了,试试手动输入)</li>
|
||||||
|
<li
|
||||||
|
v-for="name in candidates"
|
||||||
|
:key="name"
|
||||||
|
class="shop-candidate-row"
|
||||||
|
:class="{ active: pending.includes(name) }"
|
||||||
|
:title="name"
|
||||||
|
@click="toggleCandidate(name)"
|
||||||
|
>
|
||||||
|
<span class="shop-check" aria-hidden="true"></span>
|
||||||
|
<span class="shop-name">{{ name }}</span>
|
||||||
|
<span v-if="pending.includes(name)" class="shop-picked-tag">已选</span>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<!-- 手输自定义项+待添加清单(chips 可移除)。 -->
|
||||||
|
<div class="shop-custom">
|
||||||
|
<input
|
||||||
|
v-model="customName"
|
||||||
|
type="text"
|
||||||
|
placeholder="手动输入店铺名(自定义)"
|
||||||
|
aria-label="自定义店铺名"
|
||||||
|
@keyup.enter="addCustom"
|
||||||
|
/>
|
||||||
|
<button type="button" :disabled="!customName.trim() || pending.length >= MAX_ADD_SHOPS" @click="addCustom">加入</button>
|
||||||
|
</div>
|
||||||
|
<div v-if="pending.length" class="shop-pending">
|
||||||
|
<span v-for="name in pending" :key="name" class="shop-chip">
|
||||||
|
{{ name }}
|
||||||
|
<button type="button" :aria-label="`移除待添加 ${name}`" @click="removePending(name)">×</button>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-foot">
|
||||||
|
<button class="btn btn-secondary" type="button" @click="emit('close')">取消</button>
|
||||||
|
<button class="btn" type="button" :disabled="!canSubmit" @click="submit">
|
||||||
|
{{ submitting ? '提交中...' : `添加(${pending.length})` }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.modal-mask {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
z-index: 2800;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 40px 20px;
|
||||||
|
background: rgba(45, 66, 86, 0.36);
|
||||||
|
backdrop-filter: blur(6px);
|
||||||
|
}
|
||||||
|
.shop-picker-modal {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
width: min(460px, 100%);
|
||||||
|
max-height: 80vh;
|
||||||
|
padding: 18px 20px 20px;
|
||||||
|
border: 1px solid #c7d7e5;
|
||||||
|
border-radius: 14px;
|
||||||
|
background: #ffffff;
|
||||||
|
box-shadow: 0 22px 60px rgba(39, 67, 94, 0.2);
|
||||||
|
}
|
||||||
|
.modal-head {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
.modal-head h3 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 650;
|
||||||
|
color: #24384d;
|
||||||
|
}
|
||||||
|
.modal-sub {
|
||||||
|
margin-left: 6px;
|
||||||
|
color: #5b6f83;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
.modal-close {
|
||||||
|
width: 30px;
|
||||||
|
height: 30px;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
border-radius: 9px;
|
||||||
|
background: none;
|
||||||
|
color: #5b6f83;
|
||||||
|
font-size: 20px;
|
||||||
|
line-height: 1;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.modal-close:hover {
|
||||||
|
border-color: #cbd9e6;
|
||||||
|
background: #eef4fa;
|
||||||
|
color: #24384d;
|
||||||
|
}
|
||||||
|
.modal-tip {
|
||||||
|
margin: 8px 0 10px;
|
||||||
|
color: #8293a5;
|
||||||
|
font-size: 12.5px;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
.group-error {
|
||||||
|
margin: 0 0 8px;
|
||||||
|
padding: 10px 12px;
|
||||||
|
border: 1px solid #f0c9c2;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: #fdf1ef;
|
||||||
|
color: #a04432;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
.shop-search {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
.shop-search input {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
min-height: 36px;
|
||||||
|
padding: 6px 10px;
|
||||||
|
border: 1px solid #cbd9e6;
|
||||||
|
border-radius: 8px;
|
||||||
|
font-size: 13px;
|
||||||
|
font-family: inherit;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
.shop-search input:focus {
|
||||||
|
border-color: #5f85ad;
|
||||||
|
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||||
|
}
|
||||||
|
.shop-search button {
|
||||||
|
padding: 6px 14px;
|
||||||
|
border: 1px solid #c7d7e5;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: #ffffff;
|
||||||
|
color: #5b6f83;
|
||||||
|
font-size: 13px;
|
||||||
|
font-family: inherit;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.shop-search button:disabled {
|
||||||
|
cursor: not-allowed;
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
.shop-candidate-list {
|
||||||
|
flex: 1;
|
||||||
|
min-height: 0;
|
||||||
|
overflow-y: auto;
|
||||||
|
margin: 0 0 10px;
|
||||||
|
padding: 0;
|
||||||
|
list-style: none;
|
||||||
|
border: 1px solid #e7eef5;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
.shop-candidate-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
padding: 9px 10px;
|
||||||
|
border-bottom: 1px solid #eef3f8;
|
||||||
|
font-size: 13px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.shop-candidate-row:last-child {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
.shop-candidate-row:hover {
|
||||||
|
background: #f1f7fb;
|
||||||
|
}
|
||||||
|
.shop-candidate-row.active {
|
||||||
|
background: #e8f1fa;
|
||||||
|
box-shadow: inset 3px 0 0 #4f78a5;
|
||||||
|
}
|
||||||
|
.shop-check {
|
||||||
|
flex: none;
|
||||||
|
width: 14px;
|
||||||
|
height: 14px;
|
||||||
|
border: 1.6px solid #9fb7cd;
|
||||||
|
border-radius: 4px;
|
||||||
|
background: #ffffff;
|
||||||
|
}
|
||||||
|
.shop-candidate-row.active .shop-check {
|
||||||
|
border-color: #4f78a5;
|
||||||
|
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||||||
|
box-shadow: inset 0 0 0 2.4px #ffffff;
|
||||||
|
}
|
||||||
|
.shop-name {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
color: #24384d;
|
||||||
|
}
|
||||||
|
.shop-picked-tag {
|
||||||
|
flex: none;
|
||||||
|
padding: 1px 7px;
|
||||||
|
border-radius: 9px;
|
||||||
|
background: #d9ecff;
|
||||||
|
color: #2f5d8b;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
.shop-list-tip {
|
||||||
|
padding: 22px 12px;
|
||||||
|
color: #8293a5;
|
||||||
|
font-size: 12.5px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.shop-custom {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
.shop-custom input {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
min-height: 36px;
|
||||||
|
padding: 6px 10px;
|
||||||
|
border: 1px solid #cbd9e6;
|
||||||
|
border-radius: 8px;
|
||||||
|
font-size: 13px;
|
||||||
|
font-family: inherit;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
.shop-custom input:focus {
|
||||||
|
border-color: #5f85ad;
|
||||||
|
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||||
|
}
|
||||||
|
.shop-custom button {
|
||||||
|
padding: 6px 14px;
|
||||||
|
border: 1px solid #c7d7e5;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: #ffffff;
|
||||||
|
color: #5b6f83;
|
||||||
|
font-size: 13px;
|
||||||
|
font-family: inherit;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.shop-custom button:disabled {
|
||||||
|
cursor: not-allowed;
|
||||||
|
opacity: 0.55;
|
||||||
|
}
|
||||||
|
.shop-pending {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 6px;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
.shop-chip {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
padding: 3px 6px 3px 10px;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: #e8f1f9;
|
||||||
|
color: #3d5a77;
|
||||||
|
font-size: 12.5px;
|
||||||
|
}
|
||||||
|
.shop-chip button {
|
||||||
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
padding: 0;
|
||||||
|
border: none;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #c9dcea;
|
||||||
|
color: #3d5a77;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.shop-chip button:hover {
|
||||||
|
background: #b3cde4;
|
||||||
|
}
|
||||||
|
.modal-foot {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: 10px;
|
||||||
|
margin-top: 14px;
|
||||||
|
}
|
||||||
|
.btn {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
min-height: 38px;
|
||||||
|
padding: 7px 16px;
|
||||||
|
border: 1px solid #4f78a5;
|
||||||
|
border-radius: 9px;
|
||||||
|
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||||||
|
color: #ffffff;
|
||||||
|
font-family: inherit;
|
||||||
|
font-size: 13px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.btn:disabled {
|
||||||
|
cursor: not-allowed;
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
.btn-secondary {
|
||||||
|
background: #ffffff;
|
||||||
|
color: #5b6f83;
|
||||||
|
border-color: #c7d7e5;
|
||||||
|
}
|
||||||
|
.btn-secondary:hover:not(:disabled) {
|
||||||
|
color: #2f5d8b;
|
||||||
|
border-color: #95b1cb;
|
||||||
|
background: #edf5fb;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -324,6 +324,67 @@ export async function batchAssignJdProductGroup(
|
|||||||
return groupDataOf<number>(data)
|
return groupDataOf<number>(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------- 店铺名单(v1.7 F6,V214)
|
||||||
|
|
||||||
|
/** 名单行形状=纯店名字符串(GET /{id}/shops 返回 shop_name 升序数组)。 */
|
||||||
|
|
||||||
|
/** 某分类的店铺名单(服务端已升序;前端只滤空白不重排)。失败文案原样抛给调用方。 */
|
||||||
|
export async function fetchJdGroupShops(categoryId: number): Promise<string[]> {
|
||||||
|
const { data } = await http.get<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/${categoryId}/shops`)
|
||||||
|
const core = groupDataOf<unknown>(data)
|
||||||
|
return Array.isArray(core)
|
||||||
|
? core
|
||||||
|
.filter((shop): shop is string => typeof shop === 'string' && shop.trim() !== '')
|
||||||
|
.map((shop) => shop.trim())
|
||||||
|
: []
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 批量添加店铺到分类名单(弹窗勾选候选+手输自定义项合并下发):服务侧 trim/去空/
|
||||||
|
* 去重/上限 100,INSERT IGNORE 幂等跳过已存在行;返回实际新增行数(全重复=0 不报错)。 */
|
||||||
|
export async function addJdGroupShops(categoryId: number, shopNames: string[]): Promise<number> {
|
||||||
|
const { data } = await http.post<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/${categoryId}/shops`, { shopNames })
|
||||||
|
return groupDataOf<number>(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 移除分类名单里的店铺(删 (分类, 店铺名) 那一行);该分类下不存在时后端按业务错误拒绝。 */
|
||||||
|
export async function removeJdGroupShop(categoryId: number, shopName: string): Promise<void> {
|
||||||
|
const { data } = await http.delete<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/${categoryId}/shops`, {
|
||||||
|
params: { shop_name: shopName },
|
||||||
|
})
|
||||||
|
groupDataOf<unknown>(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 改名分类名单里的店铺:老名必须在该名单里,新名同分类查重 409;
|
||||||
|
* 名单改名只更新名单表(商品归类不带店铺维,无原型 assignment 同步链)。 */
|
||||||
|
export async function renameJdGroupShop(categoryId: number, oldName: string, newName: string): Promise<void> {
|
||||||
|
const { data } = await http.patch<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/${categoryId}/shops/rename`, {
|
||||||
|
oldName,
|
||||||
|
newName,
|
||||||
|
})
|
||||||
|
groupDataOf<unknown>(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 可添加的店铺候选(biz_jd_product.shop_name DISTINCT +关键词包含匹配+排除指定分类
|
||||||
|
* 已有名单;limit ≤ 200 服务侧钳制)。商品是全平台公共的,候选同样全平台去重。 */
|
||||||
|
export async function fetchJdAvailableShops(
|
||||||
|
keyword: string,
|
||||||
|
excludeCategoryId?: number | null,
|
||||||
|
limit?: number,
|
||||||
|
): Promise<string[]> {
|
||||||
|
const params: Record<string, unknown> = {}
|
||||||
|
const trimmed = (keyword || '').trim()
|
||||||
|
if (trimmed) params.keyword = trimmed
|
||||||
|
if (typeof excludeCategoryId === 'number' && excludeCategoryId > 0) {
|
||||||
|
params.exclude_category_id = excludeCategoryId
|
||||||
|
}
|
||||||
|
if (typeof limit === 'number' && limit > 0) params.limit = limit
|
||||||
|
const { data } = await http.get<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/shops/available`, { params })
|
||||||
|
const core = groupDataOf<unknown>(data)
|
||||||
|
return Array.isArray(core)
|
||||||
|
? core.filter((shop): shop is string => typeof shop === 'string' && shop.trim() !== '')
|
||||||
|
: []
|
||||||
|
}
|
||||||
|
|
||||||
/** CSV 导出的本地兜底文件名(yyyyMMddHHmm,与后端导出文件名同一格式;秒位不要——
|
/** CSV 导出的本地兜底文件名(yyyyMMddHHmm,与后端导出文件名同一格式;秒位不要——
|
||||||
* 同一分钟内的两次导出覆盖旧文件是可接受语义,别拿毫秒名刷屏下载目录)。 */
|
* 同一分钟内的两次导出覆盖旧文件是可接受语义,别拿毫秒名刷屏下载目录)。 */
|
||||||
function csvFilenameTimestamp(): string {
|
function csvFilenameTimestamp(): string {
|
||||||
|
|||||||
@@ -29,20 +29,29 @@ const CATEGORIES: JdProductGroup[] = [
|
|||||||
{ id: 8, name: '裤装', ownerGroupId: 11, sortOrder: 1, productCount: 1 },
|
{ id: 8, name: '裤装', ownerGroupId: 11, sortOrder: 1, productCount: 1 },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
/** 店铺名单夹具(v1.7 F6):裙装带两名单店,裤装无名单(无箭头)。 */
|
||||||
|
const CATEGORIES_WITH_SHOPS: JdProductGroup[] = [
|
||||||
|
{ id: 7, name: '裙装', ownerGroupId: 11, sortOrder: 0, productCount: 3, shops: ['绿屿街道店', '花屿巷旗舰店'] },
|
||||||
|
{ id: 8, name: '裤装', ownerGroupId: 11, sortOrder: 1, productCount: 1 },
|
||||||
|
]
|
||||||
|
|
||||||
interface MountOptions {
|
interface MountOptions {
|
||||||
editable?: boolean
|
editable?: boolean
|
||||||
selectedCategory?: { name: string; path: string[] } | null
|
selectedCategory?: { name: string; path: string[] } | null
|
||||||
selectedGroupId?: number | null
|
selectedGroupId?: number | null
|
||||||
|
selectedShopName?: string | null
|
||||||
|
categories?: JdProductGroup[]
|
||||||
}
|
}
|
||||||
|
|
||||||
function mountSidebar(options: MountOptions = {}): VueWrapper<Element> {
|
function mountSidebar(options: MountOptions = {}): VueWrapper<Element> {
|
||||||
return mount(JdCategorySidebar, {
|
return mount(JdCategorySidebar, {
|
||||||
props: {
|
props: {
|
||||||
categoryOptions: CATEGORY_OPTIONS,
|
categoryOptions: CATEGORY_OPTIONS,
|
||||||
categories: CATEGORIES,
|
categories: options.categories ?? CATEGORIES,
|
||||||
editable: options.editable ?? true,
|
editable: options.editable ?? true,
|
||||||
selectedCategory: options.selectedCategory ?? null,
|
selectedCategory: options.selectedCategory ?? null,
|
||||||
selectedGroupId: options.selectedGroupId ?? null,
|
selectedGroupId: options.selectedGroupId ?? null,
|
||||||
|
selectedShopName: options.selectedShopName ?? null,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -231,3 +240,164 @@ describe('店铺分类 Tab(当前分组分类平铺+入口分档)', () =>
|
|||||||
readonly.unmount()
|
readonly.unmount()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/** 店铺名单(v1.7 F6 完整对齐原型《商品数据商城》):分类行展开箭头→店铺行(点选过滤/
|
||||||
|
* 行内改名移除)+「+ 添加店铺」入口+分类行 hover 改名/删除。侧栏纯展示:全部只 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 () => {
|
||||||
|
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()
|
||||||
|
const shops = custom.findAll('.jd-side-shop')
|
||||||
|
expect(shops).toHaveLength(2, '展开后店铺行可见(服务端升序原样渲染)')
|
||||||
|
expect(shops[0]!.text()).toContain('绿屿街道店')
|
||||||
|
expect(shops[1]!.text()).toContain('花屿巷旗舰店')
|
||||||
|
expect(custom.get('.jd-side-shop-add').text()).toContain('+ 添加店铺', '可写档名单尾出添加入口')
|
||||||
|
|
||||||
|
await custom.get('[aria-label="展开或收起 裙装 的店铺名单"]').trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
expect(wrapper.get('.jd-side-custom').findAll('.jd-side-shop')).toHaveLength(0, '再点箭头=收起')
|
||||||
|
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')
|
||||||
|
await flushPromises()
|
||||||
|
expect(wrapper.emitted('select-shop')).toEqual([[{ groupId: 7, shopName: '绿屿街道店' }]],
|
||||||
|
'点店铺=分类+店铺成对(页面发 group_id+shop_name 精确过滤)')
|
||||||
|
|
||||||
|
await wrapper.setProps({ selectedShopName: '绿屿街道店' })
|
||||||
|
expect(wrapper.get('.jd-side-custom').findAll('.jd-side-shop')[0]!.classes()).toContain('selected', '选中回流高亮')
|
||||||
|
|
||||||
|
await wrapper.get('.jd-side-custom').findAll('.jd-side-shop')[0]!.trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
expect(wrapper.emitted('select-shop')?.at(-1)).toEqual([null], '再点已选=清店铺筛选(分类保留)')
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
|
|
||||||
|
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!.classes()).toContain('selected')
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('可写档:分类行与店铺行 hover 出改名/删除操作钮;分类行内改名 Enter 提交 emit (cat, 新名)', 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.get('[aria-label="删除分类 裙装"]').exists()).toBe(true)
|
||||||
|
|
||||||
|
// 分类行内改名:点 ✎ → 行替换成编辑输入(预填原名)→ Enter 提交。
|
||||||
|
await custom.get('[aria-label="改名分类 裙装"]').trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
const editInput = custom.get('[aria-label="修改分类名称(原:裙装)"]')
|
||||||
|
expect((editInput.element as HTMLInputElement).value).toBe('裙装', '编辑形态预填原名')
|
||||||
|
await editInput.setValue('长裙')
|
||||||
|
await editInput.trigger('keyup.enter')
|
||||||
|
await flushPromises()
|
||||||
|
expect(wrapper.emitted('rename-category')).toEqual([[CATEGORIES_WITH_SHOPS[0], '长裙']],
|
||||||
|
'侧栏只 emit(API 调用与刷新在页面)')
|
||||||
|
|
||||||
|
// 空名/未改动不 emit(静默收编辑态)。
|
||||||
|
await custom.get('[aria-label="改名分类 裙装"]').trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
const unchanged = custom.get('[aria-label="修改分类名称(原:裙装)"]')
|
||||||
|
await unchanged.setValue(' 裙装 ')
|
||||||
|
await unchanged.trigger('keyup.enter')
|
||||||
|
await flushPromises()
|
||||||
|
expect(wrapper.emitted('rename-category')).toHaveLength(1, '未改动不白发请求')
|
||||||
|
|
||||||
|
// 店铺行 hover 操作钮在展开后可见。
|
||||||
|
await custom.get('[aria-label="展开或收起 裙装 的店铺名单"]').trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
expect(custom.get('[aria-label="改名店铺 绿屿街道店"]').exists()).toBe(true)
|
||||||
|
expect(custom.get('[aria-label="移除店铺 绿屿街道店"]').exists()).toBe(true)
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('店铺行内改名 emit (cat, oldName, newName);移除 emit (cat, shopName);添加店铺入口 emit (cat)', async () => {
|
||||||
|
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')
|
||||||
|
await flushPromises()
|
||||||
|
const shopEdit = custom.get('[aria-label="修改店铺名称(原:绿屿街道店)"]')
|
||||||
|
expect((shopEdit.element as HTMLInputElement).value).toBe('绿屿街道店')
|
||||||
|
await shopEdit.setValue('绿屿新址店')
|
||||||
|
await custom.get('[aria-label="确认改名店铺 绿屿街道店"]').trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
expect(wrapper.emitted('rename-shop')).toEqual([[CATEGORIES_WITH_SHOPS[0], '绿屿街道店', '绿屿新址店']])
|
||||||
|
|
||||||
|
// 移除:hover ✕ 直接 emit(可重做,不设二次确认)。
|
||||||
|
await custom.get('[aria-label="移除店铺 花屿巷旗舰店"]').trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
expect(wrapper.emitted('remove-shop')).toEqual([[CATEGORIES_WITH_SHOPS[0], '花屿巷旗舰店']])
|
||||||
|
|
||||||
|
// 添加店铺入口。
|
||||||
|
await custom.get('.jd-side-shop-add').trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
expect(wrapper.emitted('add-shops')).toEqual([[CATEGORIES_WITH_SHOPS[0]]])
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('只读档:无 hover 操作钮、无添加店铺入口;店铺行仍可见可点(读面 V203)', async () => {
|
||||||
|
const wrapper = mountSidebar({ categories: CATEGORIES_WITH_SHOPS, editable: false })
|
||||||
|
await openCustomTab(wrapper)
|
||||||
|
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, '店铺行无改名钮')
|
||||||
|
expect(custom.find('[aria-label="移除店铺 绿屿街道店"]').exists()).toBe(false, '店铺行无移除钮')
|
||||||
|
|
||||||
|
await custom.findAll('.jd-side-shop')[0]!.trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
expect(wrapper.emitted('select-shop')).toEqual([[{ groupId: 7, shopName: '绿屿街道店' }]],
|
||||||
|
'只读档点店铺照常过滤')
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
|
|
||||||
|
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')
|
||||||
|
await flushPromises()
|
||||||
|
expect(wrapper.emitted('select-group')).toEqual([[null]], '再点已选分类=清选(页面同清店铺筛选)')
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|||||||
@@ -43,6 +43,12 @@ const jdApi = vi.hoisted(() => ({
|
|||||||
deleteJdProductGroup: vi.fn(),
|
deleteJdProductGroup: vi.fn(),
|
||||||
updateJdProduct: vi.fn(),
|
updateJdProduct: vi.fn(),
|
||||||
batchAssignJdProductGroup: vi.fn(),
|
batchAssignJdProductGroup: vi.fn(),
|
||||||
|
// v1.7 店铺名单(V214):侧栏名单交互与添加店铺弹窗的 API 面。
|
||||||
|
removeJdGroupShop: vi.fn(),
|
||||||
|
renameJdGroupShop: vi.fn(),
|
||||||
|
fetchJdGroupShops: vi.fn(),
|
||||||
|
addJdGroupShops: vi.fn(),
|
||||||
|
fetchJdAvailableShops: vi.fn(),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const confirmMock = vi.hoisted(() => vi.fn())
|
const confirmMock = vi.hoisted(() => vi.fn())
|
||||||
@@ -112,7 +118,7 @@ const CATEGORY_OPTIONS = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
const GROUPS = [
|
const GROUPS = [
|
||||||
{ id: 7, name: '裙装', ownerGroupId: GROUP_A, sortOrder: 0, productCount: 3 },
|
{ id: 7, name: '裙装', ownerGroupId: GROUP_A, sortOrder: 0, productCount: 3, shops: ['绿屿街道店', '花屿巷旗舰店'] },
|
||||||
{ id: 8, name: '裤装', ownerGroupId: GROUP_A, sortOrder: 1, productCount: 1 },
|
{ id: 8, name: '裤装', ownerGroupId: GROUP_A, sortOrder: 1, productCount: 1 },
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -124,6 +130,11 @@ beforeEach(() => {
|
|||||||
jdApi.fetchJdCategoryScope.mockResolvedValue(singleGroupScope())
|
jdApi.fetchJdCategoryScope.mockResolvedValue(singleGroupScope())
|
||||||
jdApi.fetchJdProductGroups.mockResolvedValue([])
|
jdApi.fetchJdProductGroups.mockResolvedValue([])
|
||||||
jdApi.fetchJdProductCategories.mockResolvedValue([])
|
jdApi.fetchJdProductCategories.mockResolvedValue([])
|
||||||
|
// 店铺名单(v1.7)默认空回执:只有名单用例显式变形。
|
||||||
|
jdApi.removeJdGroupShop.mockResolvedValue(undefined)
|
||||||
|
jdApi.renameJdGroupShop.mockResolvedValue(undefined)
|
||||||
|
jdApi.fetchJdAvailableShops.mockResolvedValue([])
|
||||||
|
jdApi.addJdGroupShops.mockResolvedValue(0)
|
||||||
groupApi.createShopGroup.mockResolvedValue({ id: 21, name: '京东-团队', ownerGroupId: 21, sortOrder: 0, productCount: 0 })
|
groupApi.createShopGroup.mockResolvedValue({ id: 21, name: '京东-团队', ownerGroupId: 21, sortOrder: 0, productCount: 0 })
|
||||||
confirmMock.mockResolvedValue(true)
|
confirmMock.mockResolvedValue(true)
|
||||||
})
|
})
|
||||||
@@ -1375,3 +1386,147 @@ describe('首屏作用域同源与静默降级(Phase 0 黄金测试)', () =>
|
|||||||
wrapper.unmount()
|
wrapper.unmount()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/** 店铺名单接线(v1.7 F6,2026-11-21 拍板「完整对齐」):侧栏点店铺行→列表按
|
||||||
|
* group_id+shop_name 成对过滤;行内改名/移除与分类行删除走对应 API;添加店铺弹窗
|
||||||
|
* 开合与批量提交。API 全部 mock(端点形状在 jd-product-api 与后端 controller 对撞)。 */
|
||||||
|
describe('店铺名单接线(v1.7:点店铺过滤+名单维护+添加店铺弹窗)', () => {
|
||||||
|
/** 挂载带名单的页面并展开裙装的名单。 */
|
||||||
|
async function mountWithShops(): Promise<VueWrapper<Element>> {
|
||||||
|
jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS)
|
||||||
|
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||||||
|
await pickSideTab(wrapper, '店铺分类')
|
||||||
|
await sideCustom(wrapper).get('[aria-label="展开或收起 裙装 的店铺名单"]').trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
return wrapper
|
||||||
|
}
|
||||||
|
|
||||||
|
function shopRows(wrapper: VueWrapper<Element>) {
|
||||||
|
return sideCustom(wrapper).findAll('.jd-side-shop')
|
||||||
|
}
|
||||||
|
|
||||||
|
it('点店铺行 → 列表按 (groupId, shopName) 成对过滤回第一页;回显条出店铺芯片;再点已选=清店铺保留分类', async () => {
|
||||||
|
const wrapper = await mountWithShops()
|
||||||
|
await shopRows(wrapper)[0]!.trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject(
|
||||||
|
{ groupId: '7', shopName: '绿屿街道店', page: 1 },
|
||||||
|
'点店铺=该分类归属 ∩ 该店铺(精确 eq,后端 SQL 谓词)')
|
||||||
|
expect(wrapper.get('.jd-filter-chips').text()).toContain('店铺:绿屿街道店', '回显条带店铺芯片')
|
||||||
|
|
||||||
|
await shopRows(wrapper)[0]!.trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
||||||
|
expect(last.shopName).toBe('', '再点已选=清店铺筛选')
|
||||||
|
expect(last.groupId).toBe('7', '分类选中保留(每层独立 toggle)')
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('分类行内删除:二次确认(点名只解挂归属)→ deleteJdProductGroup → 停在该分类的筛选清空并重取', async () => {
|
||||||
|
const wrapper = await mountWithShops()
|
||||||
|
await shopRows(wrapper)[0]!.trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7' })
|
||||||
|
|
||||||
|
await sideCustom(wrapper).get('[aria-label="删除分类 裙装"]').trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
await flushPromises()
|
||||||
|
const options = confirmMock.mock.calls.at(-1)![0]
|
||||||
|
expect(options.title).toBe('删除分类')
|
||||||
|
expect(options.message).toContain('商品本身保留在公共库', '确认弹窗点名删除语义(只解挂归属)')
|
||||||
|
expect(options.danger).toBe(true)
|
||||||
|
expect(jdApi.deleteJdProductGroup).toHaveBeenCalledWith(7)
|
||||||
|
const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
||||||
|
expect(last).toMatchObject({ groupId: '', shopName: '' }, '停在该分类(含店铺行)的筛选随删除清空')
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('店铺行内改名:renameJdGroupShop 三参提交并刷新名单;筛选正停在该店时筛选词同步成新名', async () => {
|
||||||
|
const wrapper = await mountWithShops()
|
||||||
|
await shopRows(wrapper)[0]!.trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].shopName).toBe('绿屿街道店')
|
||||||
|
|
||||||
|
const custom = sideCustom(wrapper)
|
||||||
|
await custom.get('[aria-label="改名店铺 绿屿街道店"]').trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
await custom.get('[aria-label="修改店铺名称(原:绿屿街道店)"]').setValue('绿屿新址店')
|
||||||
|
await custom.get('[aria-label="确认改名店铺 绿屿街道店"]').trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
await flushPromises()
|
||||||
|
expect(jdApi.renameJdGroupShop).toHaveBeenCalledWith(7, '绿屿街道店', '绿屿新址店')
|
||||||
|
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].shopName).toBe('绿屿新址店',
|
||||||
|
'筛选词同步成新名(不然界面按旧店名查,名单里已没有这一行)')
|
||||||
|
expect(document.body.textContent).toContain('已把店铺「绿屿街道店」改名为「绿屿新址店」')
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('店铺行移除:removeJdGroupShop 提交;筛选正停在该店时清店铺筛选重取(可重做不设确认)', async () => {
|
||||||
|
const wrapper = await mountWithShops()
|
||||||
|
await shopRows(wrapper)[0]!.trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
|
||||||
|
await sideCustom(wrapper).get('[aria-label="移除店铺 绿屿街道店"]').trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
await flushPromises()
|
||||||
|
expect(jdApi.removeJdGroupShop).toHaveBeenCalledWith(7, '绿屿街道店')
|
||||||
|
expect(confirmMock).not.toHaveBeenCalledWith(expect.objectContaining({ title: '移除店铺' }),
|
||||||
|
'移除可重做(再加回名单即可),不设二次确认')
|
||||||
|
const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
||||||
|
expect(last.shopName).toBe('', '筛选正停在移除的店上=清店铺筛选')
|
||||||
|
expect(last.groupId).toBe('7', '分类选中保留')
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('添加店铺弹窗:打开即拉候选(排除本分类已有名单),勾选+手输合并批量提交,done 刷新名单', async () => {
|
||||||
|
jdApi.fetchJdAvailableShops.mockResolvedValue(['旗舷店', '望江路店'])
|
||||||
|
jdApi.addJdGroupShops.mockResolvedValue(2)
|
||||||
|
const wrapper = await mountWithShops()
|
||||||
|
const custom = sideCustom(wrapper)
|
||||||
|
const groupsCallsBefore = jdApi.fetchJdProductGroups.mock.calls.length
|
||||||
|
|
||||||
|
await custom.get('.jd-side-shop-add').trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
const modal = wrapper.get('.shop-picker-modal')
|
||||||
|
expect(modal.text()).toContain('添加店铺')
|
||||||
|
expect(modal.text()).toContain('裙装', '标题带目标分类名')
|
||||||
|
expect(jdApi.fetchJdAvailableShops).toHaveBeenCalledWith('', 7)
|
||||||
|
|
||||||
|
// 勾选一个候选+手输一个自定义项。
|
||||||
|
await modal.findAll('.shop-candidate-row')[0]!.trigger('click')
|
||||||
|
await modal.get('[aria-label="自定义店铺名"]').setValue('手输新店')
|
||||||
|
await modal.findAll('button').find((b) => b.text() === '加入')!.trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
expect(modal.text()).toContain('手输新店', '自定义项进待添加清单')
|
||||||
|
expect(modal.text()).toContain('添加(2)')
|
||||||
|
|
||||||
|
await modal.findAll('button').find((b) => /^添加(2)$/.test(b.text()))!.trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
await flushPromises()
|
||||||
|
expect(jdApi.addJdGroupShops).toHaveBeenCalledWith(7, ['旗舷店', '手输新店'])
|
||||||
|
expect(document.body.textContent).toContain('已把 2 个店铺加进「裙装」')
|
||||||
|
expect(wrapper.find('.shop-picker-modal').exists()).toBe(false, '成功后弹窗自动关闭')
|
||||||
|
expect(jdApi.fetchJdProductGroups.mock.calls.length).toBeGreaterThan(groupsCallsBefore, 'done 刷新名单')
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('普通员工(editable=false):侧栏无名单写入口(无添加店铺/无行内改名移除),点店铺过滤照常', async () => {
|
||||||
|
useAdminSessionStore().user = { id: 2, username: 'ops', role: 'normal' }
|
||||||
|
jdApi.fetchJdCategoryScope.mockResolvedValue(singleGroupScope(false))
|
||||||
|
jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS)
|
||||||
|
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||||||
|
await pickSideTab(wrapper, '店铺分类')
|
||||||
|
await sideCustom(wrapper).get('[aria-label="展开或收起 裙装 的店铺名单"]').trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
const custom = sideCustom(wrapper)
|
||||||
|
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)
|
||||||
|
|
||||||
|
await custom.findAll('.jd-side-shop')[0]!.trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7', shopName: '绿屿街道店' },
|
||||||
|
'只读档点店铺照常过滤')
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user