feat(jd): 店铺分类弹窗下线——工具栏改「批量编辑分类」(勾选跨页记忆)+「京东分类管理」子菜单页 CRUD(V204)
This commit is contained in:
@@ -16,13 +16,16 @@ export const PLATFORM_TABS: readonly PlatformTabDef[] = [
|
||||
]
|
||||
|
||||
/** 京东侧菜单的 menuKey 唯一清单(与 routes.ts 的 menuKey 逐字一致,用例钉住)。
|
||||
* 2026-11-16 用户按截图圈定四项;后续京东新页面上线把 key 加进这里即可,
|
||||
* 清单外的 key(含店铺管理/生成记录等存量页)一律归亚马逊。 */
|
||||
* 2026-11-16 用户按截图圈定四项;2026-11-17 加京东分类管理(用户口径「这边分组是
|
||||
* 京东的分组管理的而不是亚马逊的」——分类管理子菜单归京东侧,不与亚马逊侧混排)。
|
||||
* 后续京东新页面上线把 key 加进这里即可,清单外的 key(含店铺管理/生成记录等
|
||||
* 存量页)一律归亚马逊。 */
|
||||
export const JD_MENU_KEYS: readonly string[] = [
|
||||
'admin_users',
|
||||
'admin_group_manage',
|
||||
'admin_companies',
|
||||
'admin_jd_database',
|
||||
'admin_jd_category_manage',
|
||||
]
|
||||
|
||||
/** menuKey → 平台归属:命中京东清单即 jd,其余(未知 key 在内)默认亚马逊。 */
|
||||
|
||||
@@ -129,6 +129,10 @@ export const OPERATION_GUIDES: Record<string, OperationGuideData> = {
|
||||
text: '本页只读:客户端采集的京东店铺商品自动同步到这里(同店铺同商品只保留最新一次),按分公司隔离分页展示;点行查看全部属性与图片,可用自定义分组归档商品。',
|
||||
steps: ['筛选商品记录', '查看属性与图片明细', '按分组归档管理'],
|
||||
},
|
||||
admin_jd_category_manage: {
|
||||
text: '本页维护京东自定义分类:分类按数据权限分组隔离,当前组只组长/超管可新建、改名、删除(删除不删商品,只解挂归属);给商品归类请到「京东数据库」页勾选后「批量编辑分类」。',
|
||||
steps: ['切换分组', '新建或改名分类', '到京东数据库页归类商品'],
|
||||
},
|
||||
}
|
||||
|
||||
/** 全部有独立/兜底提示的后台业务菜单 key。 */
|
||||
|
||||
@@ -0,0 +1,288 @@
|
||||
<script setup lang="ts">
|
||||
/** 批量编辑分类对话框(2026-11-17 用户口径「店铺分类弹窗删了,加个批量编辑分类」):
|
||||
* 京东数据库页勾选商品(翻页累计,由页面持有勾选集)→ 本对话框选目标分类或移出分类 →
|
||||
* 一次批量归类。归属写「本组」的归属行(biz_jd_product_group_assign,V203 一组一商品一行),
|
||||
* 归类不置人工编辑锁(采集照常更新价格/库存)。本组无分类时只有提示不给提交
|
||||
* (移出对未分类行是无谓操作),引导去「京东分类管理」新建。 */
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { batchAssignJdProductGroup, type JdProductGroup } from './jd-product-api.ts'
|
||||
import { requestErrorMessage } from '../../api/envelope.ts'
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean
|
||||
/** 当前数据权限分组(归类的落点组;V203 同一商品在其他组可另归一类)。 */
|
||||
ownerGroupId: number
|
||||
ownerGroupName: string
|
||||
/** 当前分组的分类选项(含商品数徽标;由页面在打开时刷新)。 */
|
||||
categories: JdProductGroup[]
|
||||
/** 页面持有的勾选集(跨页累计),展开成 id 数组传入。 */
|
||||
selectedIds: number[]
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{ (event: 'close'): void; (event: 'done', updated: number, targetName: string | null): void }>()
|
||||
|
||||
/** 选中的目标分类 id;0=移出分类(回到未分类)。 */
|
||||
const pickedId = ref(0)
|
||||
const assigning = ref(false)
|
||||
const errorText = ref('')
|
||||
|
||||
const picked = computed(() => props.categories.find((group) => group.id === pickedId.value) || null)
|
||||
const confirmText = computed(() => (picked.value ? `归入「${picked.value.name}」` : '移出分类'))
|
||||
/** 提交条件:有勾选、未在提交中,且选了目标分类(pickedId>0)或选了移出(pickedId=0,
|
||||
* 但本组得有分类可移——全组无分类时移出是无谓操作,整对话框只留提示)。 */
|
||||
const canSubmit = computed(() => props.selectedIds.length > 0 && !assigning.value
|
||||
&& (picked.value ? true : props.categories.length > 0))
|
||||
|
||||
watch(
|
||||
() => props.visible,
|
||||
(visible) => {
|
||||
if (visible) {
|
||||
pickedId.value = 0
|
||||
errorText.value = ''
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
async function submit(): Promise<void> {
|
||||
if (!canSubmit.value) return
|
||||
const target = picked.value
|
||||
assigning.value = true
|
||||
errorText.value = ''
|
||||
try {
|
||||
// target null=移出分类(groupId 传 null,后端只解挂本组归属行)。
|
||||
const updated = await batchAssignJdProductGroup(
|
||||
props.selectedIds,
|
||||
target ? target.id : null,
|
||||
props.ownerGroupId,
|
||||
)
|
||||
emit('done', updated, target ? target.name : null)
|
||||
emit('close')
|
||||
} catch (error) {
|
||||
errorText.value = requestErrorMessage(error) || '批量归类失败'
|
||||
} finally {
|
||||
assigning.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible" class="modal-mask" @click.self="emit('close')">
|
||||
<div class="batch-modal">
|
||||
<div class="modal-head">
|
||||
<h3>批量编辑分类<span v-if="ownerGroupName" class="modal-sub">· {{ ownerGroupName }}</span></h3>
|
||||
<button class="modal-close" type="button" aria-label="关闭" @click="emit('close')">×</button>
|
||||
</div>
|
||||
<p class="modal-tip">
|
||||
已勾选 {{ selectedIds.length }} 个商品(翻页累计)。选目标分类后确认;
|
||||
归类只记在分类归属上,不影响采集对价格/库存的更新。
|
||||
</p>
|
||||
<p v-if="errorText" class="group-error">{{ errorText }}</p>
|
||||
|
||||
<div v-if="!categories.length" class="batch-empty">本组暂无分类,先去「京东分类管理」新建一个</div>
|
||||
<ul v-else class="option-list">
|
||||
<li
|
||||
v-for="group in categories"
|
||||
:key="group.id"
|
||||
class="option-row"
|
||||
:class="{ active: pickedId === group.id }"
|
||||
@click="pickedId = group.id"
|
||||
>
|
||||
<span class="option-radio" aria-hidden="true"></span>
|
||||
<span class="option-name" :title="group.name">{{ group.name }}</span>
|
||||
<span class="option-meta">{{ group.productCount }}</span>
|
||||
</li>
|
||||
<li class="option-row option-detach" :class="{ active: pickedId === 0 }" @click="pickedId = 0">
|
||||
<span class="option-radio" aria-hidden="true"></span>
|
||||
<span class="option-name">移出分类</span>
|
||||
<span class="option-meta">回到未分类</span>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="modal-foot">
|
||||
<button class="btn btn-secondary" type="button" @click="emit('close')">取消</button>
|
||||
<button class="btn" type="button" :disabled="!canSubmit" @click="submit">
|
||||
{{ assigning ? '提交中...' : confirmText }}
|
||||
</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);
|
||||
}
|
||||
.batch-modal {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: min(430px, 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;
|
||||
}
|
||||
.batch-empty {
|
||||
padding: 26px 12px;
|
||||
border: 1px dashed #cbd9e6;
|
||||
border-radius: 10px;
|
||||
color: #8293a5;
|
||||
font-size: 13px;
|
||||
text-align: center;
|
||||
}
|
||||
.option-list {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
border-top: 1px solid #e7eef5;
|
||||
}
|
||||
.option-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 10px 8px;
|
||||
border-bottom: 1px solid #e7eef5;
|
||||
font-size: 13.5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.option-row:hover {
|
||||
background: #f1f7fb;
|
||||
}
|
||||
/* 点亮=归类目标:与旧弹窗左栏同款左缘蓝条。 */
|
||||
.option-row.active {
|
||||
background: #e8f1fa;
|
||||
box-shadow: inset 3px 0 0 #4f78a5;
|
||||
}
|
||||
.option-radio {
|
||||
flex: none;
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
border: 1.6px solid #9fb7cd;
|
||||
border-radius: 50%;
|
||||
background: #ffffff;
|
||||
}
|
||||
.option-row.active .option-radio {
|
||||
border-color: #4f78a5;
|
||||
background: radial-gradient(circle, #4f78a5 0 4px, #ffffff 4.6px);
|
||||
}
|
||||
.option-name {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
color: #24384d;
|
||||
}
|
||||
.option-detach .option-name {
|
||||
color: #a04432;
|
||||
}
|
||||
.option-meta {
|
||||
flex: none;
|
||||
min-width: 22px;
|
||||
padding: 1px 7px;
|
||||
border-radius: 9px;
|
||||
background: #eef4fa;
|
||||
color: #4e6479;
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.option-detach .option-meta {
|
||||
background: transparent;
|
||||
color: #8293a5;
|
||||
}
|
||||
.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>
|
||||
@@ -0,0 +1,486 @@
|
||||
<script setup lang="ts">
|
||||
/** 京东分类管理(2026-11-17 用户口径「店铺分类弹窗删了,加个京东分类管理的子菜单维护 CRUD」):
|
||||
* 当前数据权限分组的分类建/改名/删除独立成页(V204 菜单行);分组作用域与京东数据库页
|
||||
* 同一套(京东的分组管理,非亚马逊——platform-scope JD_MENU_KEYS 京东侧)。
|
||||
* 商品归类不在这里:去「京东数据库」页勾选商品后「批量编辑分类」。
|
||||
* 权限口径(V203):本组管理员/公司超管/平台超管可写(scope 的 editable);同组普通号
|
||||
* 只读(无新建行,改名/删除按钮逐行不渲染),后端同口径 403 兜底。 */
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import {
|
||||
createJdProductGroup,
|
||||
deleteJdProductGroup,
|
||||
fetchJdCategoryScope,
|
||||
fetchJdProductGroups,
|
||||
updateJdProductGroup,
|
||||
type JdCategoryGroupOption,
|
||||
type JdProductGroup,
|
||||
} from './jd-product-api.ts'
|
||||
import { openAdminConfirm } from '@/components/admin-confirm'
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
import { loadFailureMessage } from '@/components/load-failure-model'
|
||||
import LoadFailureBar from '@/components/LoadFailureBar.vue'
|
||||
import { requestErrorMessage } from '../../api/envelope.ts'
|
||||
|
||||
const loading = ref(false)
|
||||
/** 首屏取数失败(可见红条+重试);写操作失败走 errorText 红条(无重试语义)。 */
|
||||
const loadFailure = ref('')
|
||||
const errorText = ref('')
|
||||
const groups = ref<JdProductGroup[]>([])
|
||||
/** 新建:只收名称(排序输入 2026-11-15 客户口径下线,sortOrder 恒 0,后端契约不变)。 */
|
||||
const createName = ref('')
|
||||
const creating = ref(false)
|
||||
/** 改名:正在编辑的分类 id 与草稿名。 */
|
||||
const editingId = ref(0)
|
||||
const editingName = ref('')
|
||||
const saving = ref(false)
|
||||
|
||||
/** 分类作用域:可见分组 + 每组可写标记。失败回空作用域(页面提示不属于任何分组)。 */
|
||||
const categoryScope = ref<JdCategoryGroupOption[]>([])
|
||||
const scopeDefaultGroupId = ref(0)
|
||||
const ownerGroupId = ref(0)
|
||||
|
||||
const currentGroupOption = computed<JdCategoryGroupOption | null>(() =>
|
||||
categoryScope.value.find((group) => group.id === ownerGroupId.value) || null)
|
||||
const currentGroupName = computed(() => currentGroupOption.value?.name || '')
|
||||
/** 分类可管理(建/改名/删除):本组管理员、公司超管、平台超管(后端 scope 判)。 */
|
||||
const canManage = computed(() => currentGroupOption.value?.editable === true)
|
||||
/** 分组下拉只在能看多组时才渲染;只有一组(含无可见组)时按锁定态展示。 */
|
||||
const canSwitchGroup = computed(() => categoryScope.value.length > 1)
|
||||
const canCreate = computed(() => canManage.value && createName.value.trim().length > 0 && !creating.value && !saving.value)
|
||||
/** 空表文案分三种:不属于任何组 / 本组还没分类(可管理)/ 本组还没分类(只读)。 */
|
||||
const emptyListText = computed(() => {
|
||||
if (ownerGroupId.value <= 0) return '你还不属于任何数据权限分组'
|
||||
return canManage.value ? '本组暂无分类,先新建一个' : '本组暂无分类'
|
||||
})
|
||||
|
||||
async function loadScope(): Promise<void> {
|
||||
try {
|
||||
const scope = await fetchJdCategoryScope()
|
||||
categoryScope.value = scope.groups
|
||||
scopeDefaultGroupId.value = scope.defaultGroupId ?? 0
|
||||
} catch {
|
||||
categoryScope.value = []
|
||||
scopeDefaultGroupId.value = 0
|
||||
}
|
||||
const keep = categoryScope.value.some((group) => group.id === ownerGroupId.value)
|
||||
if (!keep) ownerGroupId.value = scopeDefaultGroupId.value
|
||||
await loadGroups()
|
||||
}
|
||||
|
||||
async function loadGroups(): Promise<void> {
|
||||
if (ownerGroupId.value <= 0) {
|
||||
groups.value = []
|
||||
loading.value = false
|
||||
loadFailure.value = ''
|
||||
errorText.value = ''
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
loadFailure.value = ''
|
||||
try {
|
||||
groups.value = await fetchJdProductGroups(ownerGroupId.value)
|
||||
} catch (error) {
|
||||
loadFailure.value = loadFailureMessage(error, '分类列表加载失败')
|
||||
groups.value = []
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 切换「分组」下拉:列表换成本组(跨组分类不可见,V203)。 */
|
||||
async function changeOwnerGroup(next: number): Promise<void> {
|
||||
if (next === ownerGroupId.value) return
|
||||
ownerGroupId.value = next
|
||||
cancelRename()
|
||||
createName.value = ''
|
||||
await loadGroups()
|
||||
}
|
||||
|
||||
async function submitCreate(): Promise<void> {
|
||||
const name = createName.value.trim()
|
||||
if (!name || creating.value || !canManage.value) return
|
||||
creating.value = true
|
||||
errorText.value = ''
|
||||
try {
|
||||
await createJdProductGroup({ name, sortOrder: 0, ownerGroupId: ownerGroupId.value })
|
||||
createName.value = ''
|
||||
showAdminFeedback(`已新建分类「${name}」`, 'success')
|
||||
await loadGroups()
|
||||
} catch (error) {
|
||||
errorText.value = requestErrorMessage(error) || '新建分类失败'
|
||||
} finally {
|
||||
creating.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function startRename(group: JdProductGroup): void {
|
||||
editingId.value = group.id
|
||||
editingName.value = group.name
|
||||
errorText.value = ''
|
||||
}
|
||||
|
||||
function cancelRename(): void {
|
||||
editingId.value = 0
|
||||
editingName.value = ''
|
||||
}
|
||||
|
||||
async function submitRename(group: JdProductGroup): Promise<void> {
|
||||
const name = editingName.value.trim()
|
||||
if (!name || saving.value) return
|
||||
saving.value = true
|
||||
errorText.value = ''
|
||||
try {
|
||||
await updateJdProductGroup(group.id, { name, sortOrder: group.sortOrder })
|
||||
groups.value = groups.value.map((item) => (item.id === group.id ? { ...item, name } : item))
|
||||
cancelRename()
|
||||
showAdminFeedback(`已把分类改名为「${name}」`, 'success')
|
||||
} catch (error) {
|
||||
errorText.value = requestErrorMessage(error) || '改名失败'
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 删除分类不删商品:只解挂本组归属行(商品回到未分类),后端 JdProductGroupService.delete。 */
|
||||
async function removeGroup(group: JdProductGroup): Promise<void> {
|
||||
const ok = await openAdminConfirm({ title: '删除分类', message: `确定删除分类「${group.name}」吗?删除后该分类下 ${group.productCount} 个商品回到未分类。`, confirmText: '确认删除', danger: true })
|
||||
if (!ok || saving.value) return
|
||||
saving.value = true
|
||||
errorText.value = ''
|
||||
try {
|
||||
await deleteJdProductGroup(group.id)
|
||||
showAdminFeedback(`已删除分类「${group.name}」`, 'success')
|
||||
await loadGroups()
|
||||
} catch (error) {
|
||||
errorText.value = requestErrorMessage(error) || '删除分类失败'
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void loadScope()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="jd-category-view">
|
||||
<section class="panel-box">
|
||||
<div class="jd-panel-head">
|
||||
<h3>京东分类管理</h3>
|
||||
</div>
|
||||
<p class="page-tip">
|
||||
分类按「数据权限分组」隔离(京东侧的分组,不同组看不到彼此的分类):当前组只组长/超管可维护;
|
||||
商品归类去「京东数据库」页勾选商品后「批量编辑分类」,删除分类不删商品(只解挂归属)。
|
||||
</p>
|
||||
|
||||
<div class="scope-row">
|
||||
<div class="form-group">
|
||||
<label>分组</label>
|
||||
<select
|
||||
v-if="canSwitchGroup"
|
||||
:value="ownerGroupId"
|
||||
aria-label="当前分组"
|
||||
@change="changeOwnerGroup(Number(($event.target as HTMLSelectElement).value))"
|
||||
>
|
||||
<option v-for="group in categoryScope" :key="group.id" :value="group.id">{{ group.label }}</option>
|
||||
</select>
|
||||
<span v-else-if="currentGroupName" class="group-locked" title="你的数据权限内只有这一个分组">{{ currentGroupName }}</span>
|
||||
<span v-else class="group-locked group-locked-empty">你还不属于任何数据权限分组</span>
|
||||
</div>
|
||||
<div v-if="canManage" class="group-create">
|
||||
<input v-model="createName" type="text" placeholder="输入新分类名称" @keyup.enter="submitCreate" />
|
||||
<button class="btn" type="button" :disabled="!canCreate" @click="submitCreate">新建</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="loadGroups" />
|
||||
<p v-if="errorText" class="group-error">{{ errorText }}</p>
|
||||
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>分类名称</th>
|
||||
<th style="width: 96px">商品数</th>
|
||||
<th v-if="canManage" style="width: 150px">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<template v-if="groups.length">
|
||||
<tr v-for="group in groups" :key="group.id">
|
||||
<td>
|
||||
<template v-if="editingId === group.id">
|
||||
<input v-model="editingName" class="rename-input" type="text" @keyup.enter="submitRename(group)" />
|
||||
<span class="row-actions">
|
||||
<button class="btn btn-sm" type="button" :disabled="saving" @click="submitRename(group)">保存</button>
|
||||
<button class="btn btn-sm btn-secondary" type="button" @click="cancelRename">取消</button>
|
||||
</span>
|
||||
</template>
|
||||
<template v-else>
|
||||
<span class="group-name" :title="group.name">{{ group.name }}</span>
|
||||
</template>
|
||||
</td>
|
||||
<td>{{ group.productCount }}</td>
|
||||
<td v-if="canManage" class="ops-cell">
|
||||
<button class="btn btn-sm" type="button" :disabled="saving" @click="startRename(group)">改名</button>
|
||||
<button class="btn btn-sm btn-danger" type="button" :disabled="saving" @click="removeGroup(group)">删除</button>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
<tr v-else-if="loading">
|
||||
<td :colspan="canManage ? 3 : 2" class="empty-tip">加载中...</td>
|
||||
</tr>
|
||||
<tr v-else>
|
||||
<td :colspan="canManage ? 3 : 2" class="empty-tip">{{ emptyListText }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.jd-category-view {
|
||||
font-family: inherit;
|
||||
color: var(--c-text, #24384d);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
}
|
||||
.panel-box {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
padding: 20px 22px 24px;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 14px;
|
||||
background: linear-gradient(145deg, #ffffff, #f9fbfd);
|
||||
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
|
||||
}
|
||||
.jd-panel-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.jd-panel-head h3 {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
font-weight: 650;
|
||||
color: #24384d;
|
||||
letter-spacing: 0.2px;
|
||||
}
|
||||
.page-tip {
|
||||
margin: 0 0 14px;
|
||||
color: #8293a5;
|
||||
font-size: 12.5px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.scope-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
align-items: flex-end;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 7px;
|
||||
min-width: 200px;
|
||||
}
|
||||
.form-group label {
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group select,
|
||||
.group-create input {
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13.5px;
|
||||
font-family: inherit;
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group select:hover,
|
||||
.group-create input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group select:focus,
|
||||
.group-create input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
}
|
||||
/* 与京东数据库页筛选行同款自绘箭头:appearance:none 后补 padding-right 给箭头留位。 */
|
||||
.form-group select {
|
||||
min-width: 220px;
|
||||
padding-right: 34px;
|
||||
background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' fill='none' stroke='%235b6f83' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
|
||||
background-repeat: no-repeat;
|
||||
background-position: right 12px center;
|
||||
appearance: none;
|
||||
-webkit-appearance: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
.group-create {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
.group-create input {
|
||||
width: 220px;
|
||||
}
|
||||
/* 只有一个可见分组时锁定的组名:与下拉同高同壳的静态芯片(京东数据库页同款)。 */
|
||||
.group-locked {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
min-height: 42px;
|
||||
padding: 0 12px;
|
||||
border: 1px solid #dbe5ee;
|
||||
border-radius: 9px;
|
||||
background: #f1f6fb;
|
||||
color: #4e6479;
|
||||
font-size: 13.5px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.group-locked-empty {
|
||||
color: #8293a5;
|
||||
}
|
||||
.group-error {
|
||||
margin: 0 0 10px;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid #f0c9c2;
|
||||
border-radius: 10px;
|
||||
background: #fdf1ef;
|
||||
color: #a04432;
|
||||
font-size: 13px;
|
||||
}
|
||||
.table-scroll {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
overflow-x: auto;
|
||||
border: 1px solid #dbe5ee;
|
||||
border-radius: 10px;
|
||||
background: #ffffff;
|
||||
}
|
||||
.table-scroll table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
table-layout: fixed;
|
||||
}
|
||||
.table-scroll th,
|
||||
.table-scroll td {
|
||||
padding: 10px 12px;
|
||||
text-align: left;
|
||||
font-size: 13.5px;
|
||||
line-height: 1.5;
|
||||
border-bottom: 1px solid #e0e8ef;
|
||||
vertical-align: middle;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.table-scroll th {
|
||||
background: #edf4fa;
|
||||
color: #4e6479;
|
||||
border-bottom-color: #d5e1eb;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.4px;
|
||||
}
|
||||
.table-scroll tbody tr:hover td {
|
||||
background: #f1f7fb;
|
||||
}
|
||||
.table-scroll tbody tr:last-child td {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.group-name {
|
||||
color: #24384d;
|
||||
}
|
||||
.rename-input {
|
||||
width: 200px;
|
||||
min-height: 32px;
|
||||
padding: 4px 10px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 8px;
|
||||
font-size: 13.5px;
|
||||
font-family: inherit;
|
||||
outline: none;
|
||||
}
|
||||
.rename-input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
}
|
||||
.row-actions {
|
||||
margin-left: 8px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.ops-cell {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
overflow: visible;
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
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;
|
||||
transition: background 160ms ease, box-shadow 160ms ease;
|
||||
}
|
||||
.btn:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.55;
|
||||
}
|
||||
.btn-sm {
|
||||
min-height: 28px;
|
||||
padding: 3px 10px;
|
||||
font-size: 12.5px;
|
||||
margin-right: 6px;
|
||||
}
|
||||
.btn-sm:last-child {
|
||||
margin-right: 0;
|
||||
}
|
||||
.btn-secondary {
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
border-color: #c7d7e5;
|
||||
}
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
color: #2f5d8b;
|
||||
border-color: #95b1cb;
|
||||
background: #edf5fb;
|
||||
}
|
||||
/* 危险动作与全站 .btn-danger 同形(实心红渐变+白字)。 */
|
||||
.btn-danger {
|
||||
background: linear-gradient(135deg, #c06d77, #b35f6a);
|
||||
border-color: #b35f6a;
|
||||
color: #ffffff;
|
||||
}
|
||||
.btn-danger:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #cb7c84, #b96570);
|
||||
}
|
||||
.empty-tip {
|
||||
padding: 44px 24px;
|
||||
text-align: center;
|
||||
color: #8293a5;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
</style>
|
||||
@@ -1,8 +1,9 @@
|
||||
<script setup lang="ts">
|
||||
/** 京东公共商品库:支持店铺分类和京麦类目组合筛选,分类管理在弹窗中完成。
|
||||
/** 京东公共商品库:支持分类和京麦类目组合筛选。
|
||||
* V203(2026-11-16 用户口径):分类按「数据权限分组」隔离——不同组看不到彼此的分类,
|
||||
* 组管理员可建/改/删分类并归类,同组普通号可开弹窗看但只读;平台超管全量可见可编辑;
|
||||
* 能看多组的人用筛选行「分组」下拉切换当前组(只有一组时锁定显示)。 */
|
||||
* 能看多组的人用筛选行「分组」下拉切换当前组(只有一组时锁定显示)。
|
||||
* 2026-11-17 用户口径:店铺分类弹窗下线(建/改名/删分类挪「京东分类管理」子菜单页);
|
||||
* 本页工具栏改「批量编辑分类」——勾选商品(翻页累计记忆)后选目标分类归入或移出。 */
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import {
|
||||
deleteJdProducts,
|
||||
@@ -20,7 +21,7 @@ import { createJdProductFilterState } from './jd-product-filter.ts'
|
||||
import JdProductDetailDrawer from './JdProductDetailDrawer.vue'
|
||||
import JdProductEditDrawer from './JdProductEditDrawer.vue'
|
||||
import JdCategoryCascader from './JdCategoryCascader.vue'
|
||||
import JdProductGroupDialog from './JdProductGroupDialog.vue'
|
||||
import JdBatchAssignDialog from './JdBatchAssignDialog.vue'
|
||||
import OldPagination from '@/components/OldPagination.vue'
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
import { openAdminConfirm } from '@/components/admin-confirm'
|
||||
@@ -52,7 +53,8 @@ const groupOptions = ref<JdProductGroup[]>([])
|
||||
const categoryOptions = ref<JdProductCategoryOption[]>([])
|
||||
const detailItem = ref<JdProductItem | null>(null)
|
||||
const detailVisible = ref(false)
|
||||
const groupDialogVisible = ref(false)
|
||||
/** 批量编辑分类对话框(2026-11-17 替代下线的店铺分类弹窗)。 */
|
||||
const batchEditVisible = ref(false)
|
||||
/** 行级编辑抽屉(2026-11-15 用户口径「每一条数据后面 需要编辑或者删除;编辑的话
|
||||
* 这里面都是可以编辑的」):删除走下面的 removeOne(同一条删除链),编辑走独立抽屉。 */
|
||||
const editItem = ref<JdProductItem | null>(null)
|
||||
@@ -64,6 +66,12 @@ const currentGroupOption = computed<JdCategoryGroupOption | null>(() =>
|
||||
const currentGroupName = computed(() => currentGroupOption.value?.name || '')
|
||||
/** 分类可管理(建/改名/删除/归类):本组管理员、公司超管、平台超管(后端 scope 判)。 */
|
||||
const canManageCategories = computed(() => currentGroupOption.value?.editable === true)
|
||||
/** 勾选列服务两类写:批量删除(只超管)+批量编辑分类(本组可写分类的管理员也要勾)。
|
||||
* 2026-11-17 弹窗下线后管理员失去弹窗右栏的勾选面 ⇒ 勾选列必须对「本组可写」放开,
|
||||
* 否则本组管理员没有归类入口。商品行按钮(编辑/删除/删除勾选)仍只归平台超管。 */
|
||||
const hasSelectionColumn = computed(() => isSuperAdmin.value || canManageCategories.value)
|
||||
/** 空态行 colspan:勾选列有无决定 5/6/7 列三种形状(超管含操作列)。 */
|
||||
const emptyColspan = computed(() => (isSuperAdmin.value ? 7 : hasSelectionColumn.value ? 6 : 5))
|
||||
/** 分组下拉只在能看多组时才渲染;只有一组(含无可见组)时按锁定态展示。 */
|
||||
const canSwitchGroup = computed(() => categoryScope.value.length > 1)
|
||||
|
||||
@@ -125,7 +133,9 @@ async function loadCategoryOptions(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
/** 切换「分组」下拉:分类筛选(属于上一组的分类)清空,分类选项换成本组,回第一页重取。 */
|
||||
/** 切换「分组」下拉:分类筛选(属于上一组的分类)清空,分类选项换成本组,回第一页重取。
|
||||
* 勾选集是按商品 id 记的(跨页累计),切组不清——归类的落点组随 ownerGroupId 走,
|
||||
* 误跨组批量归类由批量对话框里的组名标注防住。 */
|
||||
async function changeOwnerGroup(next: number): Promise<void> {
|
||||
if (next === ownerGroupId.value) return
|
||||
ownerGroupId.value = next
|
||||
@@ -135,11 +145,20 @@ async function changeOwnerGroup(next: number): Promise<void> {
|
||||
await load()
|
||||
}
|
||||
|
||||
/** 分类弹窗里做过变更:分类下拉与列表都刷新(删除分类后行集的 groupName 会变)。 */
|
||||
async function onGroupChanged(deletedGroupId?: number): Promise<void> {
|
||||
if (deletedGroupId && filter.groupId === String(deletedGroupId)) filter.groupId = ''
|
||||
/** 打开批量编辑分类:先刷一遍当前组分类(商品数徽标要新鲜),再亮对话框。 */
|
||||
async function openBatchEdit(): Promise<void> {
|
||||
await loadGroupOptions()
|
||||
page.value = 1
|
||||
batchEditVisible.value = true
|
||||
}
|
||||
|
||||
/** 批量归类完成(对话框已关):清勾选+重取列表(行集 groupName 变了)。
|
||||
* 移出分类 targetName 为 null;updated 是后端实际写入/解挂的归属行数。 */
|
||||
async function onBatchAssigned(updated: number, targetName: string | null): Promise<void> {
|
||||
showAdminFeedback(
|
||||
targetName ? `已把 ${updated} 个商品归入「${targetName}」` : `已把 ${updated} 个商品移出分类`,
|
||||
'success',
|
||||
)
|
||||
selectedIds.value = new Set()
|
||||
await load()
|
||||
}
|
||||
|
||||
@@ -161,8 +180,9 @@ async function load(): Promise<void> {
|
||||
rows.value = result.items
|
||||
total.value = result.total
|
||||
if (result.page >= 1) page.value = result.page
|
||||
// 重取后上一批勾选可能已不在本页(翻页/筛选变化):清空,防"看不见的勾选被一起删"。
|
||||
selectedIds.value = new Set()
|
||||
// 勾选跨页记忆(2026-11-17 用户口径「支持勾选翻页也要记住」):翻页/重取/改筛选都
|
||||
// 不清勾选集——批量编辑分类与批量删除都按累计 id 提交,操作前的确认弹窗点名数量,
|
||||
// 工具栏「清除勾选」给显式的反悔出口。
|
||||
} catch (error) {
|
||||
loadFailure.value = loadFailureMessage(error, '京东商品列表加载失败')
|
||||
showAdminFeedback(loadFailure.value, 'error')
|
||||
@@ -225,7 +245,8 @@ async function copyText(text: string): Promise<void> {
|
||||
|
||||
// ---------------- 删除(先删桶、全成功才删库行,语义在后端 JdProductDeleteService) ----------------
|
||||
|
||||
/** 本页勾选集(按行 id)。切页/重取后勾选清空——上一页勾的行不自动带到下一页。 */
|
||||
/** 勾选集(按商品 id,跨页累计记忆,2026-11-17 用户口径)。翻页/重取不清;显式出口
|
||||
* 是工具栏「清除勾选」,批量删除/批量归类成功后自动清。 */
|
||||
const selectedIds = ref<Set<number>>(new Set())
|
||||
const deleting = ref(false)
|
||||
|
||||
@@ -241,32 +262,41 @@ function toggleSelect(row: JdProductItem, checked: boolean): void {
|
||||
const allSelected = computed(() => rows.value.length > 0 && rows.value.every((row) => selectedIds.value.has(row.id)))
|
||||
|
||||
function toggleSelectAll(checked: boolean): void {
|
||||
selectedIds.value = checked ? new Set(rows.value.map((row) => row.id)) : new Set()
|
||||
const next = new Set(selectedIds.value)
|
||||
for (const row of rows.value) {
|
||||
if (checked) next.add(row.id)
|
||||
else next.delete(row.id)
|
||||
}
|
||||
selectedIds.value = next
|
||||
}
|
||||
|
||||
/** 显式清空勾选(跨页累计后用户需要一个看得见的反悔口)。 */
|
||||
function clearSelection(): void {
|
||||
selectedIds.value = new Set()
|
||||
}
|
||||
|
||||
/** 单行删除入口(行内按钮):确认弹窗点名商品编码与「桶内图片一并删除」。 */
|
||||
async function removeOne(row: JdProductItem): Promise<void> {
|
||||
await removeMany([row], `确定删除商品「${row.productCode || row.title}」吗?`)
|
||||
await removeMany([row.id], `确定删除商品「${row.productCode || row.title}」吗?`)
|
||||
}
|
||||
|
||||
/** 批量删除入口(勾选后点工具栏按钮):确认弹窗点名行数。 */
|
||||
/** 批量删除入口(工具栏按钮):按累计勾选 id 直删(跨页的行也在内),确认弹窗点名总数。 */
|
||||
async function removeSelected(): Promise<void> {
|
||||
const picked = rows.value.filter((row) => selectedIds.value.has(row.id))
|
||||
await removeMany(picked, `确定删除勾选的 ${picked.length} 个商品吗?`)
|
||||
await removeMany([...selectedIds.value], `确定删除勾选的 ${selectedIds.value.size} 个商品吗?`)
|
||||
}
|
||||
|
||||
/** 删除主流程:二次确认 → 先删桶、全成功才删库行(后端保证)→ 刷新列表并清勾选。 */
|
||||
async function removeMany(picked: JdProductItem[], message: string): Promise<void> {
|
||||
if (!picked.length || deleting.value) return
|
||||
async function removeMany(ids: number[], message: string): Promise<void> {
|
||||
if (!ids.length || deleting.value) return
|
||||
const ok = await openAdminConfirm({ title: '删除京东商品', message: `${message}删除后该商品的 SKU、图片登记与 jd-products 桶内图片文件一并删除(被其他商品共用的图片会保留);此操作不可恢复。`, confirmText: '确认删除', danger: true })
|
||||
if (!ok) return
|
||||
deleting.value = true
|
||||
try {
|
||||
const receipt = await deleteJdProducts(picked.map((row) => row.id))
|
||||
const receipt = await deleteJdProducts(ids)
|
||||
showAdminFeedback(`已删除 ${receipt.deleted} 个商品,清理 ${receipt.objectsDeleted} 个图片文件` +
|
||||
(receipt.objectsKept ? `(${receipt.objectsKept} 个共用图片保留)` : ''), 'success')
|
||||
selectedIds.value = new Set()
|
||||
if (picked.length >= rows.value.length && page.value > 1) page.value -= 1
|
||||
if (ids.length >= rows.value.length && page.value > 1) page.value -= 1
|
||||
await load()
|
||||
} catch (error) {
|
||||
const text = error instanceof Error && error.message ? error.message : '删除失败,请稍后重试'
|
||||
@@ -345,18 +375,33 @@ onMounted(async () => {
|
||||
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
|
||||
<div class="jd-toolbar">
|
||||
<span class="jd-summary">共 {{ total }} 条京东商品</span>
|
||||
<!-- 当前分组下拉 2026-11-16 用户口径「做成分组」上移进筛选行(带标签的表单控件),
|
||||
工具栏不再放裸下拉;分组语义(作用域非筛选条件、「重置」不清)不变。 -->
|
||||
<!-- 批量编辑分类(2026-11-17 用户口径「店铺分类弹窗删了,加个批量编辑分类」):
|
||||
只对当前分组可写档(本组管理员/公司超管/平台超管)渲染;勾选 0 时置灰(与
|
||||
删除勾选同款常显口径),打开后按累计勾选(跨页)提交归入/移出。 -->
|
||||
<button
|
||||
v-if="canManageCategories"
|
||||
class="btn btn-secondary"
|
||||
type="button"
|
||||
:disabled="!selectedCount"
|
||||
@click="openBatchEdit"
|
||||
>批量编辑分类</button>
|
||||
<!-- 商品行写只对平台超管;分类写由当前分组 editable 决定(本组管理员/公司超管/平台超管)。
|
||||
非超管看到只读提示,但「店铺分类」弹窗照常可开(同组普通号只读查看)。 -->
|
||||
<span v-if="!isSuperAdmin" class="jd-readonly-tip">只读:编辑/删除仅超级管理员可用;分类由本组管理员维护</span>
|
||||
<button class="btn btn-secondary" type="button" @click="groupDialogVisible = true">店铺分类</button>
|
||||
非超管看到只读提示,分类维护入口指向「京东分类管理」子菜单页(同组普通号在那页只读查看)。 -->
|
||||
<span v-if="!isSuperAdmin" class="jd-readonly-tip">只读:编辑/删除仅超级管理员可用;分类由本组管理员在「京东分类管理」维护</span>
|
||||
<select v-model="filter.groupId" aria-label="筛选店铺分类" @change="apply">
|
||||
<option value="">全部分类</option>
|
||||
<option v-for="group in groupOptions" :key="group.id" :value="String(group.id)">{{ group.name }}</option>
|
||||
</select>
|
||||
<!-- 清除勾选(2026-11-17 勾选跨页记忆的显式反悔口):只在有勾选时出现。 -->
|
||||
<button
|
||||
v-if="selectedCount"
|
||||
class="btn btn-secondary jd-clear-btn"
|
||||
type="button"
|
||||
@click="clearSelection"
|
||||
>清除勾选</button>
|
||||
<!-- 批量删除 2026-11-16 客户口径「不要勾选后才显示」:常显,勾选 0 时置灰。
|
||||
同日写权限收窄到超管:非超管整颗按钮不渲染(勾选列同窗隐藏)。 -->
|
||||
同日写权限收窄到超管:非超管整颗按钮不渲染(勾选列 2026-11-17 起对本组可写
|
||||
分类管理员开放,服务批量归类)。 -->
|
||||
<button
|
||||
v-if="isSuperAdmin"
|
||||
class="btn btn-danger jd-delete-btn"
|
||||
@@ -371,7 +416,7 @@ onMounted(async () => {
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th v-if="isSuperAdmin" style="width: 42px"><input type="checkbox" :checked="allSelected" @change="toggleSelectAll(($event.target as HTMLInputElement).checked)" /></th>
|
||||
<th v-if="hasSelectionColumn" style="width: 42px"><input type="checkbox" :checked="allSelected" @change="toggleSelectAll(($event.target as HTMLInputElement).checked)" /></th>
|
||||
<th style="width: 92px">分类</th>
|
||||
<th style="width: 520px">商品信息</th>
|
||||
<th style="width: 76px">总库存</th>
|
||||
@@ -385,7 +430,7 @@ onMounted(async () => {
|
||||
<tbody>
|
||||
<template v-if="rows.length">
|
||||
<tr v-for="row in rows" :key="row.id" class="jd-row" @click="openDetail(row)">
|
||||
<td v-if="isSuperAdmin" @click.stop><input type="checkbox" :checked="selectedIds.has(row.id)" @change="toggleSelect(row, ($event.target as HTMLInputElement).checked)" /></td>
|
||||
<td v-if="hasSelectionColumn" @click.stop><input type="checkbox" :checked="selectedIds.has(row.id)" @change="toggleSelect(row, ($event.target as HTMLInputElement).checked)" /></td>
|
||||
<td :title="row.groupName || ''">{{ row.groupName || '未分类' }}</td>
|
||||
<td class="jd-info-cell">
|
||||
<div class="jd-info-wrap">
|
||||
@@ -422,10 +467,10 @@ onMounted(async () => {
|
||||
</tr>
|
||||
</template>
|
||||
<tr v-else-if="loading">
|
||||
<td :colspan="isSuperAdmin ? 7 : 5" class="empty-tip">加载中...</td>
|
||||
<td :colspan="emptyColspan" class="empty-tip">加载中...</td>
|
||||
</tr>
|
||||
<tr v-else>
|
||||
<td :colspan="isSuperAdmin ? 7 : 5" class="empty-tip">暂无京东商品数据</td>
|
||||
<td :colspan="emptyColspan" class="empty-tip">暂无京东商品数据</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -434,15 +479,14 @@ onMounted(async () => {
|
||||
<OldPagination :total="total" :page="page" :page-size="pageSize" @change="changePage" @size-change="changeSize" />
|
||||
</section>
|
||||
|
||||
<JdProductGroupDialog
|
||||
:visible="groupDialogVisible"
|
||||
:category-options="categoryOptions"
|
||||
<JdBatchAssignDialog
|
||||
:visible="batchEditVisible"
|
||||
:owner-group-id="ownerGroupId"
|
||||
:owner-group-name="currentGroupName"
|
||||
:can-manage="canManageCategories"
|
||||
:can-assign="canManageCategories"
|
||||
@close="groupDialogVisible = false"
|
||||
@changed="onGroupChanged"
|
||||
:categories="groupOptions"
|
||||
:selected-ids="[...selectedIds]"
|
||||
@close="batchEditVisible = false"
|
||||
@done="onBatchAssigned"
|
||||
/>
|
||||
<JdProductDetailDrawer
|
||||
:item="detailItem"
|
||||
|
||||
@@ -1,454 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
/** 店铺分类弹窗右栏:按京麦类目和标题筛选商品,勾选后归入左侧目标或移出分类。
|
||||
* V203(2026-11-16 用户口径):归类写「本组」的归属行(biz_jd_product_group_assign,
|
||||
* 一组一商品一行),行集与归入/移出都带当前分组 ownerGroupId,同一商品在其他组可另归一类;
|
||||
* 归类不再置人工编辑锁(采集照常更新价格/库存)。`canAssign=false`(同组普通号只读)
|
||||
* 时勾选列与底部两个写按钮都不渲染,只留行集浏览。 */
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import JdCategoryCascader from './JdCategoryCascader.vue'
|
||||
import { batchAssignJdProductGroup, fetchJdProductList } from './jd-product-api.ts'
|
||||
import type { JdProductCategoryOption, JdProductGroup } from './jd-product-api.ts'
|
||||
import type { JdProductItem } from './jd-product-model.ts'
|
||||
import OldPagination from '@/components/OldPagination.vue'
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
import { requestErrorMessage } from '../../api/envelope.ts'
|
||||
|
||||
const props = defineProps<{
|
||||
/** 左栏点亮的分类=归类目标;null=尚未点亮(「归入」按钮置灰)。 */
|
||||
selectedGroup: JdProductGroup | null
|
||||
categoryOptions: JdProductCategoryOption[]
|
||||
refreshVersion: number
|
||||
/** 当前数据权限分组:行集的分类列与归类落点都以它为作用域。 */
|
||||
ownerGroupId: number
|
||||
/** 本账号可归类(本组管理员/公司超管/平台超管);false=只读浏览。 */
|
||||
canAssign: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{ (event: 'changed'): void }>()
|
||||
|
||||
const category = ref('')
|
||||
const keyword = ref('')
|
||||
const PRODUCT_PAGE_SIZE = 20
|
||||
const products = ref<JdProductItem[]>([])
|
||||
const productTotal = ref(0)
|
||||
const productPage = ref(1)
|
||||
const productsLoading = ref(false)
|
||||
const productsError = ref('')
|
||||
/** 本页勾选集(按行 id):切范围/翻页/重取后清空,防「看不见的勾选被一起归类」。 */
|
||||
const selectedProductIds = ref<Set<number>>(new Set())
|
||||
const assigning = ref(false)
|
||||
|
||||
const selectedCount = computed(() => selectedProductIds.value.size)
|
||||
/** 归入所选分类:必须先在左侧点亮一个分类且有勾选行。 */
|
||||
const removableIds = computed(() => products.value.filter(row => selectedProductIds.value.has(row.id) && row.groupId != null && row.groupId > 0).map(row => row.id))
|
||||
/** 可提交「归入」(props.canAssign 是权限,这里的名字避开与 prop 同名)。 */
|
||||
const canSubmitAssign = computed(() => props.canAssign && !!props.selectedGroup && selectedCount.value > 0 && !assigning.value && !productsLoading.value)
|
||||
const canRemove = computed(() => props.canAssign && removableIds.value.length > 0 && !assigning.value && !productsLoading.value)
|
||||
const allSelected = computed(() =>
|
||||
products.value.length > 0 && products.value.every((row) => selectedProductIds.value.has(row.id)))
|
||||
|
||||
let requestVersion = 0
|
||||
async function loadProducts(): Promise<void> {
|
||||
const request = ++requestVersion
|
||||
selectedProductIds.value = new Set()
|
||||
productsLoading.value = true
|
||||
productsError.value = ''
|
||||
try {
|
||||
const result = await fetchJdProductList({
|
||||
page: productPage.value,
|
||||
pageSize: PRODUCT_PAGE_SIZE,
|
||||
titleKeyword: keyword.value.trim(),
|
||||
category: category.value,
|
||||
ownerGroupId: props.ownerGroupId,
|
||||
})
|
||||
if (request !== requestVersion) return
|
||||
products.value = result.items
|
||||
productTotal.value = result.total
|
||||
if (result.page >= 1) productPage.value = result.page
|
||||
selectedProductIds.value = new Set()
|
||||
} catch (error) {
|
||||
if (request !== requestVersion) return
|
||||
productsError.value = requestErrorMessage(error) || '商品列表加载失败'
|
||||
products.value = []
|
||||
productTotal.value = 0
|
||||
selectedProductIds.value = new Set()
|
||||
} finally {
|
||||
if (request === requestVersion) productsLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
watch(() => props.refreshVersion, () => { void loadProducts() })
|
||||
|
||||
function pickCategory(next: string): void {
|
||||
category.value = next
|
||||
productPage.value = 1
|
||||
void loadProducts()
|
||||
}
|
||||
|
||||
function searchProducts(): void {
|
||||
productPage.value = 1
|
||||
void loadProducts()
|
||||
}
|
||||
|
||||
function changeProductPage(next: number): void {
|
||||
if (next < 1 || next === productPage.value) return
|
||||
productPage.value = next
|
||||
void loadProducts()
|
||||
}
|
||||
|
||||
function toggleSelect(row: JdProductItem, checked: boolean): void {
|
||||
const next = new Set(selectedProductIds.value)
|
||||
if (checked) next.add(row.id)
|
||||
else next.delete(row.id)
|
||||
selectedProductIds.value = next
|
||||
}
|
||||
|
||||
function toggleSelectAll(checked: boolean): void {
|
||||
selectedProductIds.value = checked ? new Set(products.value.map((row) => row.id)) : new Set()
|
||||
}
|
||||
|
||||
/** 勾选行 → 归入左栏点亮的分类(写本组归属行)。成功后分类商品数(父件)与右栏行集都刷新
|
||||
* (归类过的行离开「未分类」)。 */
|
||||
async function assignToSelected(): Promise<void> {
|
||||
const target = props.selectedGroup
|
||||
if (!target || !canSubmitAssign.value) return
|
||||
assigning.value = true
|
||||
productsError.value = ''
|
||||
try {
|
||||
const updated = await batchAssignJdProductGroup([...selectedProductIds.value], target.id, props.ownerGroupId)
|
||||
showAdminFeedback(`已把 ${updated} 个商品归入「${target.name}」`, 'success')
|
||||
emit('changed')
|
||||
await loadProducts()
|
||||
} catch (error) {
|
||||
productsError.value = requestErrorMessage(error) || '归类失败,请稍后重试'
|
||||
} finally {
|
||||
assigning.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 勾选行 → 移出本组分类(删本组归属行,商品回到未分类;别组的归类不受影响)。 */
|
||||
async function removeFromCategory(): Promise<void> {
|
||||
if (!canRemove.value) return
|
||||
assigning.value = true
|
||||
productsError.value = ''
|
||||
try {
|
||||
const updated = await batchAssignJdProductGroup(removableIds.value, null, props.ownerGroupId)
|
||||
showAdminFeedback(`已把 ${updated} 个商品移出分类`, 'success')
|
||||
emit('changed')
|
||||
await loadProducts()
|
||||
} catch (error) {
|
||||
productsError.value = requestErrorMessage(error) || '移出分类失败,请稍后重试'
|
||||
} finally {
|
||||
assigning.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void loadProducts()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="right-pane">
|
||||
<div class="product-toolbar">
|
||||
<JdCategoryCascader class="assign-category" :model-value="category" :options="categoryOptions" tree-only @change="pickCategory" />
|
||||
<input v-model="keyword" type="text" class="keyword-input" placeholder="标题关键字" @keyup.enter="searchProducts" />
|
||||
<button class="btn btn-small" type="button" @click="searchProducts">查询</button>
|
||||
</div>
|
||||
<p v-if="productsError" class="pane-error">
|
||||
{{ productsError }}
|
||||
<button class="btn btn-secondary btn-mini" type="button" @click="loadProducts">重试</button>
|
||||
</p>
|
||||
|
||||
<div class="product-list">
|
||||
<table v-if="products.length">
|
||||
<thead>
|
||||
<tr>
|
||||
<th v-if="canAssign" class="col-check"><input type="checkbox" :disabled="productsLoading || assigning" :checked="allSelected" @change="toggleSelectAll(($event.target as HTMLInputElement).checked)" /></th>
|
||||
<th>商品信息</th>
|
||||
<th class="col-group">当前分类</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="row in products" :key="row.id">
|
||||
<td v-if="canAssign" class="col-check">
|
||||
<input
|
||||
type="checkbox"
|
||||
:disabled="productsLoading || assigning"
|
||||
:checked="selectedProductIds.has(row.id)"
|
||||
@change="toggleSelect(row, ($event.target as HTMLInputElement).checked)"
|
||||
/>
|
||||
</td>
|
||||
<td>
|
||||
<div class="product-cell">
|
||||
<img v-if="row.mainImageUrl" class="product-thumb" :src="row.mainImageUrl" alt="" loading="lazy" />
|
||||
<span v-else class="product-thumb product-thumb-empty">无图</span>
|
||||
<div class="product-body">
|
||||
<div class="product-title" :title="row.title">{{ row.title || '-' }}</div>
|
||||
<div class="product-meta">商品编码:{{ row.productCode || '-' }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="col-group" :title="row.groupName || ''">{{ row.groupName || '未分类' }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p v-else-if="productsLoading" class="pane-tip">加载中...</p>
|
||||
<p v-else-if="!productsError" class="pane-tip">没有符合条件的商品</p>
|
||||
</div>
|
||||
|
||||
<div v-if="canAssign" class="product-footer">
|
||||
<span class="pick-summary">已勾选 {{ selectedCount }} 个商品</span>
|
||||
<div class="footer-actions">
|
||||
<button class="btn btn-small" type="button" :disabled="!canSubmitAssign" @click="assignToSelected">
|
||||
{{ assigning ? '归类中...' : selectedGroup ? `归入「${selectedGroup.name}」` : '归入所选分类' }}
|
||||
</button>
|
||||
<button class="btn btn-danger btn-small" type="button" :disabled="!canRemove" @click="removeFromCategory">移出分类</button>
|
||||
</div>
|
||||
</div>
|
||||
<OldPagination
|
||||
:total="productTotal"
|
||||
:page="productPage"
|
||||
:page-size="PRODUCT_PAGE_SIZE"
|
||||
:sizes="[PRODUCT_PAGE_SIZE]"
|
||||
:jump="false"
|
||||
@change="changeProductPage"
|
||||
/>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.right-pane {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding-left: 14px;
|
||||
}
|
||||
.product-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.assign-category {
|
||||
flex: 0 0 190px;
|
||||
}
|
||||
.scope-tabs {
|
||||
display: flex;
|
||||
border: 1px solid #c7d7e5;
|
||||
border-radius: 9px;
|
||||
overflow: hidden;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.scope-tabs button {
|
||||
min-height: 34px;
|
||||
padding: 5px 14px;
|
||||
border: 0;
|
||||
border-right: 1px solid #e7eef5;
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
font-family: inherit;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.scope-tabs button:last-child {
|
||||
border-right: 0;
|
||||
}
|
||||
.scope-tabs button:hover:not(:disabled):not(.on) {
|
||||
background: #edf5fb;
|
||||
color: #2f5d8b;
|
||||
}
|
||||
.scope-tabs button.on {
|
||||
background: #4f78a5;
|
||||
color: #ffffff;
|
||||
}
|
||||
.scope-tabs button:disabled {
|
||||
color: #9baaba;
|
||||
background: #eef3f7;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.keyword-input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
min-height: 36px;
|
||||
padding: 6px 12px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13.5px;
|
||||
font-family: inherit;
|
||||
outline: none;
|
||||
}
|
||||
.keyword-input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
}
|
||||
.pane-error {
|
||||
margin: 0 0 8px;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid #f0c9c2;
|
||||
border-radius: 10px;
|
||||
background: #fdf1ef;
|
||||
color: #a04432;
|
||||
font-size: 13px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
/* 错误条右缘的重试入口:一条真能办成事的出口(重试绑页内 loadProducts,守卫 load-failure-visibility 钉)。 */
|
||||
.pane-error .btn {
|
||||
margin-left: auto;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.pane-tip {
|
||||
margin: 10px 2px;
|
||||
color: #8293a5;
|
||||
font-size: 13px;
|
||||
}
|
||||
.product-list {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
border: 1px solid #dbe5ee;
|
||||
border-radius: 10px;
|
||||
background: #ffffff;
|
||||
}
|
||||
.product-list table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
.product-list th,
|
||||
.product-list td {
|
||||
padding: 8px 12px;
|
||||
text-align: left;
|
||||
font-size: 13px;
|
||||
line-height: 1.45;
|
||||
border-bottom: 1px solid #e7eef5;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.product-list th {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
background: #edf4fa;
|
||||
color: #4e6479;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.4px;
|
||||
}
|
||||
.product-list tbody tr:hover td {
|
||||
background: #f1f7fb;
|
||||
}
|
||||
.product-list tbody tr:last-child td {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.col-check {
|
||||
width: 42px;
|
||||
}
|
||||
.col-check input {
|
||||
margin: 0;
|
||||
}
|
||||
.col-group {
|
||||
width: 140px;
|
||||
color: #7b8a99;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.product-cell {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 10px;
|
||||
min-width: 0;
|
||||
}
|
||||
.product-thumb {
|
||||
flex-shrink: 0;
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
object-fit: cover;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 6px;
|
||||
background: #f2f7fb;
|
||||
}
|
||||
.product-thumb-empty {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #8293a5;
|
||||
font-size: 12px;
|
||||
}
|
||||
.product-body {
|
||||
min-width: 0;
|
||||
}
|
||||
.product-title {
|
||||
color: #24384d;
|
||||
font-size: 13px;
|
||||
line-height: 1.4;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
word-break: break-all;
|
||||
}
|
||||
.product-meta {
|
||||
margin-top: 2px;
|
||||
color: #7b8a99;
|
||||
font-size: 12px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.product-footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
.pick-summary {
|
||||
color: #5b6f83;
|
||||
font-size: 13px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.footer-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-left: auto;
|
||||
}
|
||||
.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-small {
|
||||
min-height: 34px;
|
||||
padding: 5px 13px;
|
||||
font-size: 12.5px;
|
||||
}
|
||||
.btn-danger {
|
||||
background: #ffffff;
|
||||
color: #a04432;
|
||||
border-color: #e4b3a8;
|
||||
}
|
||||
.btn-danger:hover:not(:disabled) {
|
||||
background: #fdf1ef;
|
||||
border-color: #d08a7b;
|
||||
}
|
||||
/* 弹窗里的分页贴右、收紧行高(页内版式在弹窗内偏大)。 */
|
||||
:deep(.old-pagination) {
|
||||
margin-top: 10px;
|
||||
}
|
||||
</style>
|
||||
@@ -1,488 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
/** 店铺分类弹窗:左侧管理当前分组的分类并选择归类目标,右侧按京麦类目筛选商品并批量归类。
|
||||
* V203(2026-11-16 用户口径):分类按「数据权限分组」隔离——弹窗只显示当前分组的分类;
|
||||
* `canManage=false`(同组普通号)可打开看,但新建行、改名/删除按钮与归类入口都不渲染;
|
||||
* 归类写归属表(biz_jd_product_group_assign),不置人工编辑锁(采集照常更新商品行)。 */
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import {
|
||||
createJdProductGroup,
|
||||
deleteJdProductGroup,
|
||||
fetchJdProductGroups,
|
||||
updateJdProductGroup,
|
||||
type JdProductGroup,
|
||||
type JdProductCategoryOption,
|
||||
} from './jd-product-api.ts'
|
||||
import JdProductAssignPane from './JdProductAssignPane.vue'
|
||||
import { openAdminConfirm } from '@/components/admin-confirm'
|
||||
import { requestErrorMessage } from '../../api/envelope.ts'
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean
|
||||
categoryOptions: JdProductCategoryOption[]
|
||||
/** 当前数据权限分组(分类的归属与可见范围);0=没有可管理/可见的组。 */
|
||||
ownerGroupId: number
|
||||
ownerGroupName: string
|
||||
/** 本账号对当前分组分类可写(建/改名/删除);缺省 false=只读查看。 */
|
||||
canManage: boolean
|
||||
/** 可归类(本组管理员/公司超管/平台超管);与 canManage 同源,但分开传便于后续细分。 */
|
||||
canAssign: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{ (event: 'close'): void; (event: 'changed', deletedGroupId?: number): void }>()
|
||||
|
||||
// ---------------- 左栏:分类管理(当前分组一份,界面措辞「分类」) ----------------
|
||||
|
||||
const loading = ref(false)
|
||||
const errorText = ref('')
|
||||
const groups = ref<JdProductGroup[]>([])
|
||||
/** 新建:只收名称(排序输入 2026-11-15 客户口径下线,sortOrder 恒 0,后端契约不变)。 */
|
||||
const createName = ref('')
|
||||
const creating = ref(false)
|
||||
/** 改名:正在编辑的分类 id 与草稿名。 */
|
||||
const editingId = ref(0)
|
||||
const editingName = ref('')
|
||||
const saving = ref(false)
|
||||
const paneRefreshVersion = ref(0)
|
||||
/** 左侧点亮的分类=右栏「归入所选分类」的归类目标;删除后自动清掉。 */
|
||||
const selectedGroupId = ref(0)
|
||||
|
||||
const canCreate = computed(() => props.canManage && createName.value.trim().length > 0 && !creating.value && !saving.value)
|
||||
const selectedGroup = computed(() => groups.value.find((group) => group.id === selectedGroupId.value) || null)
|
||||
/** 标题带当前分组名(跨组同名分类靠它区分)。 */
|
||||
const dialogTitle = computed(() => props.ownerGroupName ? `店铺分类 · ${props.ownerGroupName}` : '店铺分类')
|
||||
/** 空列表文案分三种:不属于任何组 / 本组还没分类(可管理)/ 本组还没分类(只读)。 */
|
||||
const emptyListText = computed(() => {
|
||||
if (props.ownerGroupId <= 0) return '你还不属于任何数据权限分组'
|
||||
return props.canManage ? '本组暂无分类,先新建一个' : '本组暂无分类'
|
||||
})
|
||||
|
||||
async function loadGroups(): Promise<void> {
|
||||
if (props.ownerGroupId <= 0) {
|
||||
groups.value = []
|
||||
loading.value = false
|
||||
errorText.value = ''
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
errorText.value = ''
|
||||
try {
|
||||
groups.value = await fetchJdProductGroups(props.ownerGroupId)
|
||||
} catch (error) {
|
||||
errorText.value = requestErrorMessage(error) || '分类列表加载失败'
|
||||
groups.value = []
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function sortGroups(list: JdProductGroup[]): JdProductGroup[] {
|
||||
return [...list].sort((a, b) => a.sortOrder - b.sortOrder || a.id - b.id)
|
||||
}
|
||||
|
||||
/** 变更后统一收口:刷新左栏商品数徽标+上抛页面(分组下拉与行集都依赖它)。 */
|
||||
async function refreshAfterChange(deletedGroupId?: number, refreshPane = false): Promise<void> {
|
||||
emit('changed', deletedGroupId)
|
||||
if (refreshPane) paneRefreshVersion.value++
|
||||
try {
|
||||
groups.value = sortGroups(await fetchJdProductGroups(props.ownerGroupId))
|
||||
} catch (error) {
|
||||
errorText.value = `操作已成功,分类列表刷新失败:${requestErrorMessage(error) || '请重试'}`
|
||||
}
|
||||
}
|
||||
|
||||
async function submitCreate(): Promise<void> {
|
||||
const name = createName.value.trim()
|
||||
if (!name || creating.value || !props.canManage) return
|
||||
creating.value = true
|
||||
errorText.value = ''
|
||||
try {
|
||||
await createJdProductGroup({ name, sortOrder: 0, ownerGroupId: props.ownerGroupId })
|
||||
createName.value = ''
|
||||
await refreshAfterChange()
|
||||
} catch (error) {
|
||||
errorText.value = requestErrorMessage(error) || '新建分类失败'
|
||||
} finally {
|
||||
creating.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function startRename(group: JdProductGroup): void {
|
||||
editingId.value = group.id
|
||||
editingName.value = group.name
|
||||
errorText.value = ''
|
||||
}
|
||||
|
||||
function cancelRename(): void {
|
||||
editingId.value = 0
|
||||
editingName.value = ''
|
||||
}
|
||||
|
||||
async function submitRename(group: JdProductGroup): Promise<void> {
|
||||
const name = editingName.value.trim()
|
||||
if (!name || saving.value) return
|
||||
saving.value = true
|
||||
errorText.value = ''
|
||||
try {
|
||||
await updateJdProductGroup(group.id, { name, sortOrder: group.sortOrder })
|
||||
groups.value = groups.value.map(item => item.id === group.id ? { ...item, name } : item)
|
||||
cancelRename()
|
||||
await refreshAfterChange(undefined, true)
|
||||
} catch (error) {
|
||||
errorText.value = requestErrorMessage(error) || '改名失败'
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function removeGroup(group: JdProductGroup): Promise<void> {
|
||||
const ok = await openAdminConfirm({ title: '删除分类', message: `确定删除分类「${group.name}」吗?删除后该分类下 ${group.productCount} 个商品回到未分类。`, confirmText: '确认删除', danger: true })
|
||||
if (!ok || saving.value) return
|
||||
saving.value = true
|
||||
errorText.value = ''
|
||||
try {
|
||||
await deleteJdProductGroup(group.id)
|
||||
// 删掉当前归类目标时清除选中状态。
|
||||
if (selectedGroupId.value === group.id) {
|
||||
selectedGroupId.value = 0
|
||||
}
|
||||
groups.value = groups.value.filter(item => item.id !== group.id)
|
||||
await refreshAfterChange(group.id, true)
|
||||
} catch (error) {
|
||||
errorText.value = requestErrorMessage(error) || '删除分类失败'
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 左侧点亮分类作为右栏归类目标(只读账号没有归类入口,点亮无意义 ⇒ 直接不响应)。 */
|
||||
function pickGroup(group: JdProductGroup): void {
|
||||
if (saving.value || !props.canAssign) return
|
||||
selectedGroupId.value = group.id
|
||||
}
|
||||
|
||||
// 打开即拉一次分类列表;右栏行集由 JdProductAssignPane 挂载时自取。
|
||||
watch(
|
||||
() => props.visible,
|
||||
(visible) => {
|
||||
if (visible) {
|
||||
cancelRename()
|
||||
createName.value = ''
|
||||
errorText.value = ''
|
||||
selectedGroupId.value = 0
|
||||
void loadGroups()
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
/** 右栏归类成功:分类商品数变化+页面行集的 groupName 都要刷。 */
|
||||
function onPaneChanged(): void {
|
||||
void refreshAfterChange()
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible" class="modal-mask" @click.self="emit('close')">
|
||||
<div class="group-modal">
|
||||
<div class="modal-head">
|
||||
<h3>{{ dialogTitle }}</h3>
|
||||
<button class="modal-close" type="button" aria-label="关闭" @click="emit('close')">×</button>
|
||||
</div>
|
||||
<p class="modal-tip">
|
||||
<template v-if="canAssign">左侧管理本组分类并点选目标分类;右侧勾选商品后「归入所选分类」或「移出分类」。归类只记在分类归属上,不影响采集对价格/库存的更新。</template>
|
||||
<template v-else>左侧是本组分类(只读);分类的新建/改名/删除与商品归类由本组管理员操作。</template>
|
||||
</p>
|
||||
<p v-if="errorText" class="group-error">{{ errorText }}</p>
|
||||
|
||||
<div class="split-body">
|
||||
<!-- 左栏:分类管理(只读账号不渲染新建行,改名/删除按钮逐行隐藏) -->
|
||||
<aside class="left-pane">
|
||||
<div v-if="canManage" class="group-create">
|
||||
<input
|
||||
v-model="createName"
|
||||
type="text"
|
||||
placeholder="输入新分类名称"
|
||||
@keyup.enter="submitCreate"
|
||||
/>
|
||||
<!-- 新建=输入行尾「+」图标(2026-11-15 客户口径:原第二行文字按钮收成图标上移,
|
||||
排序数字输入下线——sortOrder 恒 0,后端契约不变)。 -->
|
||||
<button
|
||||
class="create-icon-btn"
|
||||
type="button"
|
||||
title="新建分类"
|
||||
aria-label="新建分类"
|
||||
:disabled="!canCreate"
|
||||
@click="submitCreate"
|
||||
>+</button>
|
||||
</div>
|
||||
<p v-if="loading" class="pane-tip">加载中...</p>
|
||||
<ul class="group-list">
|
||||
<li
|
||||
v-for="group in groups"
|
||||
:key="group.id"
|
||||
class="group-row"
|
||||
:class="{ active: selectedGroupId === group.id }"
|
||||
@click="pickGroup(group)"
|
||||
>
|
||||
<template v-if="editingId === group.id">
|
||||
<input v-model="editingName" type="text" @keyup.enter="submitRename(group)" />
|
||||
<span class="group-actions" @click.stop>
|
||||
<button class="btn btn-mini" type="button" :disabled="saving" @click="submitRename(group)">保存</button>
|
||||
<button class="btn btn-secondary btn-mini" type="button" @click="cancelRename">取消</button>
|
||||
</span>
|
||||
</template>
|
||||
<template v-else>
|
||||
<span class="group-name" :title="group.name">{{ group.name }}</span>
|
||||
<span class="group-meta">{{ group.productCount }}</span>
|
||||
<span v-if="canManage" class="group-actions" @click.stop>
|
||||
<button class="btn btn-secondary btn-mini" type="button" @click="startRename(group)">改名</button>
|
||||
<button class="btn btn-danger btn-mini" type="button" :disabled="saving" @click="removeGroup(group)">删除</button>
|
||||
</span>
|
||||
</template>
|
||||
</li>
|
||||
<li v-if="!loading && !groups.length && !errorText" class="pane-tip">{{ emptyListText }}</li>
|
||||
</ul>
|
||||
</aside>
|
||||
|
||||
<!-- 右栏:商品人工归类(独立件,行集/勾选/批量归类都在那里;只读账号不含写入口) -->
|
||||
<JdProductAssignPane
|
||||
:selected-group="selectedGroup"
|
||||
:category-options="categoryOptions"
|
||||
:refresh-version="paneRefreshVersion"
|
||||
:owner-group-id="ownerGroupId"
|
||||
:can-assign="canAssign"
|
||||
@changed="onPaneChanged"
|
||||
/>
|
||||
</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);
|
||||
}
|
||||
.group-modal {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: min(1080px, 100%);
|
||||
max-height: 86vh;
|
||||
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-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;
|
||||
}
|
||||
.split-body {
|
||||
display: flex;
|
||||
gap: 0;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
/* 左栏(分类管理):固定宽,独立滚动。 */
|
||||
.left-pane {
|
||||
flex: 0 0 248px;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border-right: 1px solid #e7eef5;
|
||||
padding-right: 14px;
|
||||
}
|
||||
.group-create {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.group-create input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
min-height: 36px;
|
||||
padding: 6px 12px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13.5px;
|
||||
font-family: inherit;
|
||||
outline: none;
|
||||
}
|
||||
.group-create input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
}
|
||||
/* 新建「+」图标按钮:与输入同行(原第二行文字按钮上移收成图标)。 */
|
||||
.create-icon-btn {
|
||||
flex: none;
|
||||
width: 36px;
|
||||
min-height: 36px;
|
||||
padding: 0;
|
||||
border: 1px solid #4f78a5;
|
||||
border-radius: 9px;
|
||||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||||
color: #ffffff;
|
||||
font-size: 18px;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
}
|
||||
.create-icon-btn:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.6;
|
||||
}
|
||||
.group-list {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
border-top: 1px solid #e7eef5;
|
||||
}
|
||||
.group-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 8px 6px;
|
||||
border-bottom: 1px solid #e7eef5;
|
||||
font-size: 13.5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.group-row:hover {
|
||||
background: #f1f7fb;
|
||||
}
|
||||
/* 左侧点亮=归类目标:右侧「归入所选分类」就落在这一行。 */
|
||||
.group-row.active {
|
||||
background: #e8f1fa;
|
||||
box-shadow: inset 3px 0 0 #4f78a5;
|
||||
}
|
||||
.group-row input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
min-height: 32px;
|
||||
padding: 4px 10px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 8px;
|
||||
font-size: 13.5px;
|
||||
font-family: inherit;
|
||||
}
|
||||
.group-name {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
color: #24384d;
|
||||
}
|
||||
.group-meta {
|
||||
flex: none;
|
||||
min-width: 22px;
|
||||
padding: 1px 7px;
|
||||
border-radius: 9px;
|
||||
background: #eef4fa;
|
||||
color: #4e6479;
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.group-actions {
|
||||
flex: none;
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
}
|
||||
.pane-tip {
|
||||
margin: 10px 2px;
|
||||
color: #8293a5;
|
||||
font-size: 13px;
|
||||
}
|
||||
.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-mini {
|
||||
min-height: 28px;
|
||||
padding: 3px 9px;
|
||||
font-size: 12px;
|
||||
}
|
||||
.btn-secondary {
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
border-color: #c7d7e5;
|
||||
}
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
color: #2f5d8b;
|
||||
border-color: #95b1cb;
|
||||
background: #edf5fb;
|
||||
}
|
||||
.btn-danger {
|
||||
background: #ffffff;
|
||||
color: #a04432;
|
||||
border-color: #e4b3a8;
|
||||
}
|
||||
.btn-danger:hover:not(:disabled) {
|
||||
background: #fdf1ef;
|
||||
border-color: #d08a7b;
|
||||
}
|
||||
</style>
|
||||
@@ -164,10 +164,14 @@ h3 {
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
}
|
||||
/* 危险动作(删除勾选)推到行尾:留在「店铺分类/分类筛选」旁边会被读成同一组动作。 */
|
||||
/* 危险动作(删除勾选)推到行尾:留在「批量编辑分类/分类筛选」旁边会被读成同一组动作。 */
|
||||
.jd-delete-btn {
|
||||
margin-left: auto;
|
||||
}
|
||||
/* 清除勾选(勾选跨页记忆的显式反悔口):贴着删除勾选(同一组勾选管理动作)。 */
|
||||
.jd-clear-btn {
|
||||
margin-left: 6px;
|
||||
}
|
||||
/* 危险动作(删除勾选):与全站 .btn-danger 同形——实心红渐变+白字。
|
||||
旧版是白底红字描边,落在工具栏里看着像「未激活的次要按钮」,与打卡/分组等页不统一。 */
|
||||
.btn-danger {
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
/** 批量移除分类的纯逻辑(2026-11-16 用户截图反馈):勾选中「已分类」的行才参与——未分类行
|
||||
* 没有分类可移,参与只会白吃一次人工锁(manual_locked=1,价格/库存随锁停更,与编辑保存
|
||||
* 同口径)。确认文案也在此出(点名数量与后果),页面只管确认弹窗、调用与刷新;
|
||||
* 独立成件也让 JdDatabasePage.vue 守得住可读棘轮的 800 行报警线(AssignPane 同款理由)。
|
||||
* node --test 可直测(零依赖、不碰 http/Pinia)。 */
|
||||
import type { JdProductItem } from './jd-product-model.ts'
|
||||
|
||||
/** 勾选中「已分类」的行(groupName 非空=group_id 已挂分类)。 */
|
||||
export function removableGroupPicks(rows: JdProductItem[], selectedIds: ReadonlySet<number>): JdProductItem[] {
|
||||
return rows.filter((row) => selectedIds.has(row.id) && !!row.groupName)
|
||||
}
|
||||
|
||||
/** 移除分类确认弹窗文案(点名数量与人工编辑锁后果,用户点确认前看得见代价)。 */
|
||||
export function removeGroupConfirmMessage(count: number): string {
|
||||
return `确定把勾选的 ${count} 个商品移出分类吗?移出后回到「未分类」;分类操作会置人工编辑锁,这些行的价格/库存不再随采集自动更新(与编辑保存同口径)。`
|
||||
}
|
||||
@@ -78,7 +78,7 @@ export async function deleteJdProducts(
|
||||
/** 编辑提交负载(PUT /api/admin/jd-products/{id} body,后端 JdProductUpdateRequest):
|
||||
* 主字段全量提交;attrGroups/skus/deleteImageIds 可选——null=不修改该块
|
||||
* (后端对 null 块零触碰)。分类不在本负载里(V203:分类按数据权限分组归属存
|
||||
* biz_jd_product_group_assign,编辑面不写 group_id,归类只走「店铺分类」弹窗)。 */
|
||||
* biz_jd_product_group_assign,编辑面不写 group_id,归类只走列表页「批量编辑分类」)。 */
|
||||
export interface JdProductUpdatePayload {
|
||||
title: string
|
||||
brand: string | null
|
||||
@@ -208,8 +208,8 @@ export async function fetchJdProductGroups(ownerGroupId?: number | null): Promis
|
||||
}
|
||||
|
||||
/** 分类作用域(GET /scope):本账号可见的数据权限分组 + 每组可写标记。
|
||||
* 页面用它渲染「分组」下拉、按 editable 渲染分类写入口;失败由页面自己兜(回空作用域=
|
||||
* 分类列全空、弹窗提示不属于任何分组,但商品列表照常可用)。 */
|
||||
* 页面用它渲染「分组」下拉并按 editable 渲染分类写入口;失败由页面自己兜(回空作用域=
|
||||
* 分类列全空、分类管理页提示不属于任何分组,但商品列表照常可用)。 */
|
||||
export async function fetchJdCategoryScope(): Promise<JdCategoryScope> {
|
||||
const { data } = await http.get<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/scope`)
|
||||
const core = groupDataOf<unknown>(data)
|
||||
@@ -287,12 +287,13 @@ export async function deleteJdProductGroup(id: number): Promise<void> {
|
||||
groupDataOf<unknown>(data)
|
||||
}
|
||||
|
||||
/** 批量人工归类(店铺分类弹窗 2026-11-15 + 京东数据库页工具栏「移除分类」2026-11-16):
|
||||
* 勾选商品行 → 归入当前分组(ownerGroupId)的指定分类或移出分类(V203:归属写
|
||||
/** 批量人工归类(2026-11-17 起唯一入口=京东数据库页工具栏「批量编辑分类」;
|
||||
* 旧「店铺分类弹窗+工具栏移除分类」已随同日口径下线):勾选商品行(跨页累计)
|
||||
* → 归入当前分组(ownerGroupId)的指定分类或移出分类(V203:归属写
|
||||
* biz_jd_product_group_assign 的 (product_id, owner_group_id) 一行,同一商品各组可各自归类)。
|
||||
* groupId 传 null=移出本组分类;返回实际写入/解挂的归属行数。
|
||||
* 归类<b>不再置人工编辑锁</b>(2026-11-16 用户拍板):分类不在商品行上,采集冲不掉它。
|
||||
* 业务失败(分类不存在/不属于当前分组)把中文文案抛回,弹窗红条原样展示。 */
|
||||
* 业务失败(分类不存在/不属于当前分组)把中文文案抛回,对话框红条原样展示。 */
|
||||
export async function batchAssignJdProductGroup(
|
||||
ids: number[],
|
||||
groupId: number | null,
|
||||
|
||||
@@ -47,6 +47,9 @@ export const adminPages: AdminPageDef[] = [
|
||||
{ path: 'patent-center/clean-items', menuKey: 'admin_appearance_patent_clean_items', title: '外观专利数据库', companyScoped: true, load: () => import('@/pages/patent/AppearancePatentCleanItemsPage.vue') },
|
||||
// 京东数据库 2026-11-16 退出公司 tab(参考品牌数据库先例):数据全平台公共,不按公司取数。
|
||||
{ path: 'jd-center/database', menuKey: 'admin_jd_database', title: '京东数据库', companyScoped: false, load: () => import('@/pages/jd/JdDatabasePage.vue') },
|
||||
// 京东分类管理 2026-11-17(用户口径「店铺分类弹窗下线,加个京东分类管理的子菜单维护 CRUD」):
|
||||
// 分类建/改名/删除独立成页(V204 菜单行同 key),归类在京东数据库页「批量编辑分类」。
|
||||
{ path: 'jd-center/categories', menuKey: 'admin_jd_category_manage', title: '京东分类管理', companyScoped: false, load: () => import('@/pages/jd/JdCategoryManagerPage.vue') },
|
||||
]
|
||||
|
||||
export function routeOf(page: AdminPageDef): RouteRecordRaw {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"note": "readSource 钉子逐文件基线。两把尺子:pins=落在用例体内的读盘,reads=全文读点总数(含模块级夹具与 helper)。都只许减;pins 下降而 reads 没同步下降=把读盘挪出体内,不算改进。由 tests/source-pin-ratchet.test.ts 生成。",
|
||||
"totals": {
|
||||
"files": 254,
|
||||
"cases": 1778,
|
||||
"files": 262,
|
||||
"cases": 1824,
|
||||
"pins": 458,
|
||||
"reads": 656
|
||||
},
|
||||
@@ -187,6 +187,11 @@
|
||||
"pins": 3,
|
||||
"reads": 3
|
||||
},
|
||||
"appearance-patent-clean-filter.test.ts": {
|
||||
"cases": 3,
|
||||
"pins": 0,
|
||||
"reads": 0
|
||||
},
|
||||
"brand-gating-model.test.ts": {
|
||||
"cases": 5,
|
||||
"pins": 0,
|
||||
@@ -297,6 +302,31 @@
|
||||
"pins": 1,
|
||||
"reads": 1
|
||||
},
|
||||
"jd-category-cascader-position.test.ts": {
|
||||
"cases": 4,
|
||||
"pins": 0,
|
||||
"reads": 0
|
||||
},
|
||||
"jd-category-tree.test.ts": {
|
||||
"cases": 6,
|
||||
"pins": 0,
|
||||
"reads": 0
|
||||
},
|
||||
"jd-database-page.test.ts": {
|
||||
"cases": 7,
|
||||
"pins": 0,
|
||||
"reads": 0
|
||||
},
|
||||
"jd-product-group.test.ts": {
|
||||
"cases": 6,
|
||||
"pins": 0,
|
||||
"reads": 0
|
||||
},
|
||||
"jd-publish-quota-edit.test.ts": {
|
||||
"cases": 1,
|
||||
"pins": 0,
|
||||
"reads": 0
|
||||
},
|
||||
"keyword-usage-model.test.ts": {
|
||||
"cases": 6,
|
||||
"pins": 0,
|
||||
@@ -362,6 +392,11 @@
|
||||
"pins": 5,
|
||||
"reads": 6
|
||||
},
|
||||
"platform-menu-filter.test.ts": {
|
||||
"cases": 7,
|
||||
"pins": 0,
|
||||
"reads": 0
|
||||
},
|
||||
"shop-key-filter-params.test.ts": {
|
||||
"cases": 7,
|
||||
"pins": 4,
|
||||
@@ -1272,6 +1307,11 @@
|
||||
"pins": 0,
|
||||
"reads": 1
|
||||
},
|
||||
"密钥余额列读数.test.ts": {
|
||||
"cases": 12,
|
||||
"pins": 0,
|
||||
"reads": 0
|
||||
},
|
||||
"密钥货源标签与代理脱敏.test.ts": {
|
||||
"cases": 19,
|
||||
"pins": 1,
|
||||
|
||||
@@ -17,6 +17,8 @@ const KEYWORD_USAGE_MIGRATION = join(process.cwd(), '..', 'backend-java', 'src',
|
||||
'V175__move_gating_and_add_keyword_usage_menu.sql')
|
||||
const JD_DATABASE_MIGRATION = join(process.cwd(), '..', 'backend-java', 'src', 'main', 'resources', 'db',
|
||||
'V196__jd_database_menu.sql')
|
||||
const JD_CATEGORY_MANAGE_MIGRATION = join(process.cwd(), '..', 'backend-java', 'src', 'main', 'resources', 'db',
|
||||
'V204__jd_category_manage_menu.sql')
|
||||
|
||||
interface MigrationMenu {
|
||||
name: string
|
||||
@@ -121,3 +123,24 @@ test('V196 新增的京东数据库菜单 key 必须在路由注册表登记', (
|
||||
assert.ok(/'京东数据库', 'admin_jd_database', 'admin', 'jd-center\/database', 68/.test(sql), '京东数据库排序应为 68')
|
||||
assert.ok(!sql.includes('user_column_permission'), 'V196 不得预插授权行(默认仅超管可见)')
|
||||
})
|
||||
|
||||
test('V204 新增的京东分类管理菜单 key 必须在路由注册表登记(2026-11-17 弹窗下线、CRUD 挪子菜单页)', () => {
|
||||
const sql = readFileSync(JD_CATEGORY_MANAGE_MIGRATION, 'utf8')
|
||||
const menus = menusInsertedBy(sql)
|
||||
const insertCount = (sql.match(/INSERT INTO `columns`/g) || []).length
|
||||
assert.ok(menus.length > 0, 'V204 应当插入后台菜单,一条都没解析出来说明正则失效')
|
||||
assert.equal(menus.length, insertCount, `解析到 ${menus.length} 条,但迁移有 ${insertCount} 条 INSERT INTO columns`)
|
||||
|
||||
const menu = menus.find((item) => item.columnKey === 'admin_jd_category_manage')
|
||||
assert.ok(menu, 'V204 必须插入 admin_jd_category_manage 菜单')
|
||||
const page = adminPages.find((item) => item.menuKey === 'admin_jd_category_manage')
|
||||
assert.ok(page, 'routes.ts 必须有 admin_jd_category_manage 页面,否则菜单点进去 404')
|
||||
assert.equal(page.path, menu.routePath, '库里的 route_path 应与注册表路径一致')
|
||||
assert.equal(page.title, menu.name, '页面标题应与菜单名一致')
|
||||
assert.equal(page.companyScoped, false, '分类按数据权限分组隔离(V203),不按公司 tab 取数')
|
||||
|
||||
// 每公司一套树,挂数据管理组、排序 69(V196 京东数据库占 68)。
|
||||
assert.ok(sql.includes("grp.`column_key` = 'admin_group_data'"), 'V204 必须把京东分类管理挂到数据管理组')
|
||||
assert.ok(/'京东分类管理', 'admin_jd_category_manage', 'admin', 'jd-center\/categories', 69/.test(sql), '京东分类管理排序应为 69')
|
||||
assert.ok(!sql.includes('user_column_permission'), 'V204 不得预插授权行(默认仅超管可见)')
|
||||
})
|
||||
|
||||
@@ -32,6 +32,16 @@ test('routes 注册表出现京东数据库页面且退出公司 tab(2026-11-1
|
||||
assert.equal(page.companyScoped, false, '京东数据库全平台公共,不画公司 tab(AC-6 已被 11-15/11-16 口径推翻)')
|
||||
})
|
||||
|
||||
/** 2026-11-17 用户口径「店铺分类弹窗删了,加个京东分类管理的子菜单维护 CRUD」(V204):
|
||||
* 分类建/改名/删除独立成页,与京东数据库页同在京东平台侧(platform-scope 用例另钉)。 */
|
||||
test('routes 注册表出现京东分类管理页面(V204 子菜单),与京东数据库并排退出公司 tab', () => {
|
||||
const page = adminPages.find((item) => item.menuKey === 'admin_jd_category_manage')
|
||||
assert.ok(page, 'routes.ts 缺 menuKey=admin_jd_category_manage 的注册行')
|
||||
assert.equal(page.path, 'jd-center/categories', 'route_path 必须与 V204 菜单一侧一致')
|
||||
assert.equal(page.title, '京东分类管理', '菜单标题以「京东分类管理」为准')
|
||||
assert.equal(page.companyScoped, false, '分类按数据权限分组隔离(V203),不画公司 tab')
|
||||
})
|
||||
|
||||
/** 详情面的 SKU 矩阵解析(V198):后端下发 camelCase,snake 容错;坏行不炸整块。 */
|
||||
test('详情负载的 skus 归一化成矩阵行:skuId 为身份、销售属性维度按首次出现排序', () => {
|
||||
const detail = parseJdProductDetail({
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { removableGroupPicks, removeGroupConfirmMessage } from '../src/pages/jd/jd-group-remove.ts'
|
||||
import { toJdProductItem } from '../src/pages/jd/jd-product-model.ts'
|
||||
|
||||
/** 「移除分类」纯逻辑契约(2026-11-16 页工具栏):勾选里只挑已分类行+确认文案点名后果。
|
||||
* 挂载侧行为(按钮置灰/发送名单/清勾选)由 tests/mount/jd-database-page.mount.test.ts 钉。 */
|
||||
|
||||
function row(id: number, groupName: string | null) {
|
||||
return toJdProductItem({ id, product_code: `JD-${id}`, group_name: groupName })!
|
||||
}
|
||||
|
||||
test('removableGroupPicks 只挑勾选中已分类的行(未分类行没有分类可移,不参与=不白吃人工锁)', () => {
|
||||
const rows = [row(1, '甲组'), row(2, null), row(3, '乙组'), row(4, '')]
|
||||
const picks = removableGroupPicks(rows, new Set([2, 3, 4]))
|
||||
assert.deepEqual(picks.map((r) => r.id), [3], '未分类(null/空名)行一律排除')
|
||||
assert.deepEqual(removableGroupPicks(rows, new Set()).map((r) => r.id), [], '空勾选回空')
|
||||
})
|
||||
|
||||
test('确认文案点名数量与人工编辑锁后果(用户点确认前看得见代价)', () => {
|
||||
const message = removeGroupConfirmMessage(2)
|
||||
assert.ok(message.includes('2 个商品'), '文案点名数量')
|
||||
assert.ok(message.includes('人工编辑锁'), '文案点名人工锁后果')
|
||||
assert.ok(message.includes('未分类'), '文案说明移出后的去向')
|
||||
})
|
||||
@@ -0,0 +1,172 @@
|
||||
/**
|
||||
* 京东分类管理页(V204,2026-11-17 用户口径「店铺分类弹窗删了,加个京东分类管理的子菜单
|
||||
* 维护 CRUD」)的挂载契约:当前数据权限分组的分类建/改名/删除独立成页;分组作用域与
|
||||
* 京东数据库页同一套(京东侧分组,非亚马逊——platform-scope JD_MENU_KEYS);
|
||||
* 商品归类不在这里(去京东数据库页「批量编辑分类」)。
|
||||
*
|
||||
* 跑法:`npx vitest run tests/mount/jd-category-manager-page.mount.test.ts`
|
||||
*/
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { createPinia, setActivePinia, type Pinia } from 'pinia'
|
||||
|
||||
import JdCategoryManagerPage from '@/pages/jd/JdCategoryManagerPage.vue'
|
||||
|
||||
const jdApi = vi.hoisted(() => ({
|
||||
fetchJdCategoryScope: vi.fn(),
|
||||
fetchJdProductGroups: vi.fn(),
|
||||
createJdProductGroup: vi.fn(),
|
||||
updateJdProductGroup: vi.fn(),
|
||||
deleteJdProductGroup: vi.fn(),
|
||||
}))
|
||||
|
||||
const confirmMock = vi.hoisted(() => vi.fn())
|
||||
|
||||
vi.mock('@/pages/jd/jd-product-api.ts', () => jdApi)
|
||||
vi.mock('@/components/admin-confirm', () => ({ openAdminConfirm: confirmMock }))
|
||||
|
||||
/** 分组 id 常量:默认作用域就这一个可见且可写的组(组长档形状)。 */
|
||||
const GROUP_A = 11
|
||||
|
||||
function singleGroupScope(editable = true) {
|
||||
return {
|
||||
platformSuperAdmin: false,
|
||||
defaultGroupId: GROUP_A,
|
||||
groups: [{ id: GROUP_A, name: '甲组', label: '甲组', editable }],
|
||||
}
|
||||
}
|
||||
|
||||
function group(id: number, name: string, productCount = 0, sortOrder = 0) {
|
||||
return { id, name, ownerGroupId: GROUP_A, sortOrder, productCount }
|
||||
}
|
||||
|
||||
let pinia: Pinia
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
pinia = createPinia()
|
||||
setActivePinia(pinia)
|
||||
jdApi.fetchJdCategoryScope.mockResolvedValue(singleGroupScope())
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([])
|
||||
confirmMock.mockResolvedValue(true)
|
||||
})
|
||||
|
||||
async function mountPage(): Promise<ReturnType<typeof mount>> {
|
||||
const wrapper = mount(JdCategoryManagerPage, { global: { plugins: [pinia] } })
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
return wrapper
|
||||
}
|
||||
|
||||
describe('京东分类管理(V204 子菜单页)', () => {
|
||||
it('首屏按默认组取分类;多组可见出「分组」下拉,切组重取', async () => {
|
||||
jdApi.fetchJdCategoryScope.mockResolvedValue({
|
||||
platformSuperAdmin: true,
|
||||
defaultGroupId: GROUP_A,
|
||||
groups: [
|
||||
{ id: GROUP_A, name: 'A组', label: '甲公司 / A组', editable: true },
|
||||
{ id: 12, name: 'B组', label: '甲公司 / B组', editable: false },
|
||||
],
|
||||
})
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([group(7, '裙装', 3)])
|
||||
const wrapper = await mountPage()
|
||||
expect(jdApi.fetchJdProductGroups).toHaveBeenCalledWith(GROUP_A)
|
||||
const picker = wrapper.get('[aria-label="当前分组"]')
|
||||
expect((picker.element as HTMLSelectElement).closest('.form-group')?.querySelector('label')?.textContent).toBe('分组',
|
||||
'分组是带标签的表单控件(与京东数据库页筛选行同口径)')
|
||||
expect(picker.findAll('option').map((o) => o.text())).toEqual(['甲公司 / A组', '甲公司 / B组'])
|
||||
|
||||
await picker.setValue('12')
|
||||
await flushPromises()
|
||||
// 切组后分类按新组重取(跨组不可见,V203)。
|
||||
expect(jdApi.fetchJdProductGroups).toHaveBeenLastCalledWith(12)
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('新建分类:落当前分组归属(ownerGroupId 必带),成功后清输入并重取', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([group(7, '裙装', 3)])
|
||||
const wrapper = await mountPage()
|
||||
await wrapper.get('.group-create input').setValue('上新区')
|
||||
await wrapper.findAll('button').find((b) => b.text() === '新建')!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.createJdProductGroup).toHaveBeenCalledWith({ name: '上新区', sortOrder: 0, ownerGroupId: GROUP_A })
|
||||
expect((wrapper.get('.group-create input').element as HTMLInputElement).value).toBe('')
|
||||
expect(jdApi.fetchJdProductGroups).toHaveBeenCalledTimes(2, '成功后重取分类列表')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('改名:行内编辑后按 (id, {name, sortOrder}) 提交', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([group(7, '裙装', 3)])
|
||||
const wrapper = await mountPage()
|
||||
await wrapper.findAll('button').find((b) => b.text() === '改名')!.trigger('click')
|
||||
await wrapper.get('.rename-input').setValue('长裙')
|
||||
await wrapper.findAll('button').find((b) => b.text() === '保存')!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.updateJdProductGroup).toHaveBeenCalledWith(7, { name: '长裙', sortOrder: 0 })
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('删除:二次确认文案点名商品数(删除不删商品,只解挂归属),确认后调端点重取', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([group(7, '裙装', 3)])
|
||||
const wrapper = await mountPage()
|
||||
await wrapper.findAll('button').find((b) => b.text() === '删除')!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(confirmMock).toHaveBeenCalledTimes(1)
|
||||
const options = confirmMock.mock.calls[0][0]
|
||||
expect(options.title).toBe('删除分类')
|
||||
expect(options.message).toContain('确定删除分类「裙装」吗')
|
||||
expect(options.message).toContain('3 个商品回到未分类', '文案点名该分类下的商品数')
|
||||
expect(options.danger).toBe(true)
|
||||
expect(jdApi.deleteJdProductGroup).toHaveBeenCalledWith(7)
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('只读档(editable=false):无新建行、无改名/删除按钮,空表文案不带「先新建」', async () => {
|
||||
jdApi.fetchJdCategoryScope.mockResolvedValue(singleGroupScope(false))
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([])
|
||||
const wrapper = await mountPage()
|
||||
expect(wrapper.find('.group-create').exists()).toBe(false, '只读账号不渲染新建行')
|
||||
expect(wrapper.findAll('button').some((b) => b.text() === '改名')).toBe(false)
|
||||
expect(wrapper.findAll('button').some((b) => b.text() === '删除')).toBe(false)
|
||||
expect(wrapper.find('thead').text()).not.toContain('操作', '只读档连操作列表头都不渲染')
|
||||
expect(wrapper.find('.empty-tip').text()).toBe('本组暂无分类')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('不属于任何数据权限分组:锁定芯片直说空态,不出下拉与新建行', async () => {
|
||||
jdApi.fetchJdCategoryScope.mockResolvedValue({ platformSuperAdmin: false, defaultGroupId: null, groups: [] })
|
||||
const wrapper = await mountPage()
|
||||
expect(wrapper.find('[aria-label="当前分组"]').exists()).toBe(false)
|
||||
expect(wrapper.get('.group-locked').text()).toBe('你还不属于任何数据权限分组')
|
||||
expect(wrapper.find('.group-create').exists()).toBe(false)
|
||||
expect(wrapper.find('.empty-tip').text()).toBe('你还不属于任何数据权限分组')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('加载失败:红条可见且重试真能重跑(取数页硬规矩),切组后重取成功即清', async () => {
|
||||
jdApi.fetchJdProductGroups.mockRejectedValueOnce(new Error('上游 502'))
|
||||
const wrapper = mount(JdCategoryManagerPage, { global: { plugins: [pinia] } })
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
const bar = wrapper.find('.load-failure-bar')
|
||||
expect(bar.exists()).toBe(true, '失败态必须可见(不是一闪而过的 toast)')
|
||||
expect(bar.text()).toContain('分类列表加载失败')
|
||||
expect(bar.text()).toContain('上游 502', '后端/网络原因要进文案')
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([group(7, '裙装', 3)])
|
||||
await bar.find('button').trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
expect(wrapper.find('.load-failure-bar').exists()).toBe(false, '重试成功后红条消失')
|
||||
expect(wrapper.text()).toContain('裙装')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('页面职责边界(反向钉):归类不在本页——页面不出现批量归类/商品列表入口', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([group(7, '裙装', 3)])
|
||||
const wrapper = await mountPage()
|
||||
expect(wrapper.findAll('button').some((b) => b.text() === '批量编辑分类')).toBe(false, '归类入口在京东数据库页')
|
||||
expect(wrapper.text()).toContain('京东数据库', '页内提示指路「京东数据库」页')
|
||||
expect(jdApi.deleteJdProductGroup).not.toHaveBeenCalled()
|
||||
wrapper.unmount()
|
||||
})
|
||||
})
|
||||
@@ -2,8 +2,10 @@
|
||||
* 京东数据库页(v1.4 Phase 5)的挂载契约。
|
||||
*
|
||||
* 形态:panel-box + 筛选行(商品编码/标题关键字/类目/分组/同步起止 date 对)+
|
||||
* 查询/重置/店铺分类 + 自绘明细表(点行开详情抽屉)+ OldPagination;
|
||||
* 查询/重置 + 自绘明细表(点行开详情抽屉)+ OldPagination;
|
||||
* 分组下拉 2026-11-16 用户口径「做成分组」上移进筛选行=带标签的表单控件(不再是工具栏裸下拉);
|
||||
* 店铺分类弹窗 2026-11-17 用户口径下线:工具栏改「批量编辑分类」(勾选跨页累计+归入/移出),
|
||||
* 分类建/改名/删除挪「京东分类管理」子菜单页(V204,另见 jd-category-manager-page.mount.test.ts)。
|
||||
* 公司维度 2026-11-16 整页摘除(「删除掉公司 tab,参考品牌数据库」):页面不消费公司 tab
|
||||
* store、列表/类目下拉不带 company_id(反向钉在 company-tab-wiring「公司维度不得回流」)。
|
||||
* 商品状态筛选/列与导出按钮已随 2026-11-15 客户口径从前端下线(后端端点保留);
|
||||
@@ -108,176 +110,123 @@ async function mountWith(payload: unknown): Promise<VueWrapper<Element>> {
|
||||
return wrapper
|
||||
}
|
||||
|
||||
describe('店铺分类弹窗', () => {
|
||||
it('外层店铺分类与京麦类目独立组合,选全部立即清除分组', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 1 }])
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
const select = wrapper.get('[aria-label="筛选店铺分类"]')
|
||||
await select.setValue('7')
|
||||
/** 批量编辑分类(2026-11-17 用户口径「店铺分类弹窗删了,加个批量编辑分类」):
|
||||
* 勾选跨页累计记忆(翻页/重取不清)→ 对话框选目标分类归入或移出 → 按 (ids, groupId,
|
||||
* ownerGroupId) 提交;成功后清勾选并重取。旧弹窗的「勾选翻页即清」口径同日废止。 */
|
||||
describe('批量编辑分类(店铺分类弹窗 2026-11-17 下线后的替代入口)', () => {
|
||||
it('勾选跨页记忆:第 1 页勾 1 行翻到第 2 页再勾 1 行,删除按累计 2 行提交,清除勾选可显式清零', async () => {
|
||||
jdApi.fetchJdProductList
|
||||
.mockImplementationOnce(() => Promise.resolve({ items: [item(1)], total: 40, page: 1, pageSize: 20 }))
|
||||
.mockImplementation(() => Promise.resolve({ items: [item(2)], total: 40, page: 2, pageSize: 20 }))
|
||||
const wrapper = mount(JdDatabasePage, { global: { plugins: [pinia] } })
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7', page: 1 })
|
||||
await wrapper.get('.cat-trigger').trigger('click')
|
||||
expect(wrapper.find('.cat-custom').exists()).toBe(false)
|
||||
await wrapper.get('.cat-search').setValue('艺考')
|
||||
await wrapper.get('.cat-col-search .cat-row').trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7', category: '艺考形体服', page: 1 })
|
||||
await select.setValue('')
|
||||
const deleteBtn = () => wrapper.get('.jd-delete-btn')
|
||||
const clearBtn = () => wrapper.findAll('button').find((b) => b.text() === '清除勾选')
|
||||
|
||||
await wrapper.findAll('tbody input[type="checkbox"]')[0].setValue(true)
|
||||
expect(deleteBtn().text()).toContain('删除勾选(1)')
|
||||
|
||||
// 翻页:勾选不清(2026-11-17 口径「支持勾选翻页也要记住」)。
|
||||
await wrapper.findAll('button').find((b) => b.text() === '下一页')!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '', category: '艺考形体服', page: 1 })
|
||||
expect(wrapper.get('.jd-toolbar').text()).not.toMatch(/归入分类|移除分类/)
|
||||
wrapper.unmount()
|
||||
})
|
||||
it('入口恢复,按京麦类目筛选并将商品归入或移出左侧目标', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 1 }])
|
||||
jdApi.fetchJdProductCategories.mockResolvedValue([{ name: '历史京麦类目', productCount: 1 }])
|
||||
jdApi.batchAssignJdProductGroup.mockResolvedValue(1)
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
await wrapper.findAll('button').find(b => b.text() === '店铺分类')!.trigger('click')
|
||||
expect(deleteBtn().text()).toContain('删除勾选(1)', '翻页后第 1 页的勾选仍在累计集里')
|
||||
await wrapper.findAll('tbody input[type="checkbox"]')[0].setValue(true)
|
||||
expect(deleteBtn().text()).toContain('删除勾选(2)', '第 2 页再勾 1 行,累计 2 行')
|
||||
expect(clearBtn(), '有勾选时「清除勾选」出现').toBeTruthy()
|
||||
|
||||
// 累计勾选直达删除:跨页的行一起删(确认弹窗点名总数)。
|
||||
jdApi.deleteJdProducts.mockResolvedValueOnce({ deleted: 2, imagesDeleted: 0, objectsDeleted: 0, objectsKept: 0, objectsSkipped: 0 })
|
||||
await deleteBtn().trigger('click')
|
||||
await flushPromises()
|
||||
const modal = wrapper.get('.group-modal')
|
||||
expect(modal.text()).toContain('不影响采集对价格/库存的更新', 'V203 归类不再置人工编辑锁,文案不得再说「停更」')
|
||||
expect(modal.text()).not.toContain('停更', '旧「价格/库存等字段停更」口径已废(归类不再置锁)')
|
||||
expect(modal.text()).toContain('甲组', '标题带当前分组名(跨组同名分类靠它区分)')
|
||||
expect(modal.find('.scope-tabs').exists()).toBe(false)
|
||||
await modal.get('.group-row').trigger('click')
|
||||
await modal.get('.cat-trigger').trigger('click')
|
||||
expect(modal.find('.cat-custom').exists()).toBe(false)
|
||||
await modal.get('.cat-search').setValue('历史京麦类目')
|
||||
await modal.findAll('.cat-row').find(row => row.text().includes('历史京麦类目'))!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ category: '历史京麦类目', page: 1 })
|
||||
await modal.get('tbody input[type="checkbox"]').setValue(true)
|
||||
await modal.findAll('button').find(b => b.text().includes('归入「甲组」'))!.trigger('click')
|
||||
await flushPromises()
|
||||
// 归类落点是「本组」的归属行:第三个参数必须是当前分组(V203 一组一商品一行)。
|
||||
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1], 7, GROUP_A)
|
||||
await modal.get('tbody input[type="checkbox"]').setValue(true)
|
||||
await modal.findAll('button').find(b => b.text() === '移出分类')!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1], null, GROUP_A)
|
||||
await modal.get('.modal-close').trigger('click')
|
||||
expect(wrapper.find('.group-modal').exists()).toBe(false)
|
||||
expect(confirmMock.mock.calls.at(-1)![0].message).toContain('确定删除勾选的 2 个商品吗', '确认文案点名累计总数')
|
||||
// 跨页累计的 id 一起提交。
|
||||
expect(jdApi.deleteJdProducts).toHaveBeenLastCalledWith([1, 2])
|
||||
|
||||
// 显式反悔口:清除勾选后按钮回置灰。
|
||||
await wrapper.findAll('tbody input[type="checkbox"]')[0].setValue(true)
|
||||
await clearBtn()!.trigger('click')
|
||||
expect(deleteBtn().text()).toContain('删除勾选(0)')
|
||||
expect(wrapper.findAll('button').some((b) => b.text() === '清除勾选')).toBe(false, '勾选 0 时清除按钮消失')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('加载期间立即清除勾选并阻止操作,旧请求不能覆盖新结果', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 1 }])
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
await wrapper.findAll('button').find(b => b.text() === '店铺分类')!.trigger('click')
|
||||
await flushPromises()
|
||||
const modal = wrapper.get('.group-modal')
|
||||
await modal.get('.group-row').trigger('click')
|
||||
await modal.get('tbody input').setValue(true)
|
||||
let resolveOld!: (value: unknown) => void
|
||||
let resolveNew!: (value: unknown) => void
|
||||
jdApi.fetchJdProductList.mockImplementationOnce(() => new Promise(resolve => { resolveOld = resolve }))
|
||||
.mockImplementationOnce(() => new Promise(resolve => { resolveNew = resolve }))
|
||||
await modal.get('.keyword-input').setValue('旧')
|
||||
await modal.get('.keyword-input').trigger('keyup.enter')
|
||||
expect(modal.text()).toContain('已勾选 0 个商品')
|
||||
expect(modal.findAll('button').find(b => b.text().includes('归入「甲组」'))!.attributes('disabled')).toBeDefined()
|
||||
expect(modal.findAll('button').find(b => b.text() === '移出分类')!.attributes('disabled')).toBeDefined()
|
||||
await modal.get('.keyword-input').setValue('新')
|
||||
await modal.get('.keyword-input').trigger('keyup.enter')
|
||||
resolveNew({ items: [item(2, { title: '新结果' })], total: 1, page: 1, pageSize: 20 })
|
||||
await flushPromises()
|
||||
resolveOld({ items: [item(1, { title: '旧结果' })], total: 1, page: 1, pageSize: 20 })
|
||||
await flushPromises()
|
||||
expect(modal.text()).toContain('新结果')
|
||||
expect(modal.text()).not.toContain('旧结果')
|
||||
wrapper.unmount()
|
||||
})
|
||||
it('批量归入:未勾选时入口置灰,勾选后打开对话框选目标分类,按 (ids, groupId, ownerGroupId) 提交并清勾选重取', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([
|
||||
{ id: 7, name: '甲组', sortOrder: 0, productCount: 3 },
|
||||
{ id: 8, name: '乙组', sortOrder: 1, productCount: 1 },
|
||||
])
|
||||
jdApi.batchAssignJdProductGroup.mockResolvedValue(2)
|
||||
const wrapper = await mountWith({ items: [item(1), item(2)], total: 2, page: 1, pageSize: 20 })
|
||||
const editBtn = () => wrapper.findAll('button').find((b) => b.text() === '批量编辑分类')!
|
||||
|
||||
it('翻页开始时清除勾选且禁止批量操作', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 1 }])
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 40, page: 1, pageSize: 20 })
|
||||
await wrapper.findAll('button').find(b => b.text() === '店铺分类')!.trigger('click')
|
||||
await flushPromises()
|
||||
const modal = wrapper.get('.group-modal')
|
||||
await modal.get('.group-row').trigger('click')
|
||||
await modal.get('tbody input').setValue(true)
|
||||
let resolvePage!: (value: unknown) => void
|
||||
jdApi.fetchJdProductList.mockImplementationOnce(() => new Promise(resolve => { resolvePage = resolve }))
|
||||
modal.getComponent(OldPagination).vm.$emit('change', 2)
|
||||
await wrapper.vm.$nextTick()
|
||||
expect(modal.text()).toContain('已勾选 0 个商品')
|
||||
expect(modal.findAll('button').find(b => b.text().includes('归入「甲组」'))!.attributes('disabled')).toBeDefined()
|
||||
resolvePage({ items: [item(2)], total: 40, page: 2, pageSize: 20 })
|
||||
await flushPromises()
|
||||
expect(modal.text()).toContain('JD-1002')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('移出只提交已分类商品,未分类商品不会被锁', async () => {
|
||||
jdApi.batchAssignJdProductGroup.mockResolvedValue(1)
|
||||
const wrapper = await mountWith({ items: [item(1), item(2, { groupId: null, groupName: '' })], total: 2, page: 1, pageSize: 20 })
|
||||
await wrapper.findAll('button').find(b => b.text() === '店铺分类')!.trigger('click')
|
||||
await flushPromises()
|
||||
const modal = wrapper.get('.group-modal')
|
||||
await modal.get('thead input').setValue(true)
|
||||
await modal.findAll('button').find(b => b.text() === '移出分类')!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1], null, GROUP_A)
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('删除当前筛选分类后刷新两侧并清除主页面筛选,即使分类列表刷新失败', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 1 }])
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
await wrapper.get('[aria-label="筛选店铺分类"]').setValue('7')
|
||||
await flushPromises()
|
||||
await wrapper.findAll('button').find(b => b.text() === '店铺分类')!.trigger('click')
|
||||
await flushPromises()
|
||||
const modal = wrapper.get('.group-modal')
|
||||
expect(editBtn().attributes('disabled')).toBeDefined('勾选 0 时置灰(与删除勾选同款常显口径)')
|
||||
const boxes = wrapper.findAll('tbody input[type="checkbox"]')
|
||||
await boxes[0].setValue(true)
|
||||
await boxes[1].setValue(true)
|
||||
expect(editBtn().attributes('disabled')).toBeUndefined()
|
||||
const callsBefore = jdApi.fetchJdProductList.mock.calls.length
|
||||
jdApi.fetchJdProductGroups.mockRejectedValue(new Error('网络中断'))
|
||||
await modal.findAll('button').find(b => b.text() === '删除')!.trigger('click')
|
||||
await editBtn().trigger('click')
|
||||
await flushPromises()
|
||||
expect(modal.text()).toContain('操作已成功,分类列表刷新失败')
|
||||
expect(modal.text()).not.toContain('删除分类失败')
|
||||
const calls = jdApi.fetchJdProductList.mock.calls.slice(callsBefore).map(call => call[0])
|
||||
expect(calls.some(call => call.groupId === '')).toBe(true)
|
||||
expect(calls.some(call => call.category === '' && !('groupId' in call))).toBe(true)
|
||||
const modal = wrapper.get('.batch-modal')
|
||||
expect(modal.text()).toContain('批量编辑分类')
|
||||
expect(modal.text()).toContain('已勾选 2 个商品(翻页累计)', '对话框点名累计勾选数')
|
||||
expect(modal.text()).toContain('甲组', '标题/上下文带当前分组名')
|
||||
expect(modal.findAll('.option-row')).toHaveLength(3, '两个分类+一个移出选项')
|
||||
|
||||
await modal.findAll('.option-row')[0].trigger('click')
|
||||
const confirmBtn = modal.findAll('button').find((b) => b.text() === '归入「甲组」')
|
||||
expect(confirmBtn, '确认按钮文案带目标分类名').toBeTruthy()
|
||||
await confirmBtn!.trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1, 2], 7, GROUP_A)
|
||||
expect(document.body.textContent).toContain('已把 2 个商品归入「甲组」')
|
||||
expect(wrapper.find('.batch-modal').exists()).toBe(false, '成功后对话框自动关闭')
|
||||
expect(jdApi.fetchJdProductList.mock.calls.length).toBeGreaterThan(callsBefore, '成功后重取列表(groupName 变了)')
|
||||
expect(wrapper.get('.jd-delete-btn').text()).toContain('删除勾选(0)', '成功后清勾选')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('改名后重新加载弹窗商品行', async () => {
|
||||
it('移出分类:选「移出分类」确认 → groupId 传 null(后端只解挂本组归属行)', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 3 }])
|
||||
jdApi.batchAssignJdProductGroup.mockResolvedValue(1)
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
await wrapper.findAll('tbody input[type="checkbox"]')[0].setValue(true)
|
||||
await wrapper.findAll('button').find((b) => b.text() === '批量编辑分类')!.trigger('click')
|
||||
await flushPromises()
|
||||
const modal = wrapper.get('.batch-modal')
|
||||
await modal.find('.option-detach').trigger('click')
|
||||
await modal.findAll('button').find((b) => b.text() === '移出分类')!.trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1], null, GROUP_A)
|
||||
expect(document.body.textContent).toContain('已把 1 个商品移出分类')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('本组暂无分类:对话框只留提示不给提交(移出对未分类行是无谓操作),引导去分类管理页', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([])
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
await wrapper.findAll('tbody input[type="checkbox"]')[0].setValue(true)
|
||||
await wrapper.findAll('button').find((b) => b.text() === '批量编辑分类')!.trigger('click')
|
||||
await flushPromises()
|
||||
const modal = wrapper.get('.batch-modal')
|
||||
expect(modal.text()).toContain('本组暂无分类')
|
||||
expect(modal.text()).toContain('京东分类管理', '空态把维护入口指向「京东分类管理」')
|
||||
expect(modal.findAll('button').some((b) => b.text() === '移出分类' && b.attributes('disabled') === undefined)).toBe(false,
|
||||
'无分类时移出不可提交')
|
||||
expect(jdApi.batchAssignJdProductGroup).not.toHaveBeenCalled()
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('店铺分类弹窗已下线(反向钉):入口按钮与 .group-modal 都不再存在,分类筛选照常', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 1 }])
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
await wrapper.findAll('button').find(b => b.text() === '店铺分类')!.trigger('click')
|
||||
await flushPromises()
|
||||
const modal = wrapper.get('.group-modal')
|
||||
const before = jdApi.fetchJdProductList.mock.calls.length
|
||||
await modal.findAll('button').find(b => b.text() === '改名')!.trigger('click')
|
||||
await modal.get('.group-row input').setValue('新名称')
|
||||
await modal.findAll('button').find(b => b.text() === '保存')!.trigger('click')
|
||||
await flushPromises()
|
||||
const calls = jdApi.fetchJdProductList.mock.calls.slice(before).map(call => call[0])
|
||||
expect(calls.some(call => call.category === '' && !('groupId' in call))).toBe(true)
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('左侧支持新增、改名和确认删除', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 1 }])
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
|
||||
await wrapper.findAll('button').find(b => b.text() === '店铺分类')!.trigger('click')
|
||||
await flushPromises()
|
||||
const modal = wrapper.get('.group-modal')
|
||||
await modal.get('.group-create input').setValue('新分类')
|
||||
await modal.get('.create-icon-btn').trigger('click')
|
||||
await flushPromises()
|
||||
// 新建落当前分组的归属(V203 跨组不可见:不带 ownerGroupId 会落到后端默认组)。
|
||||
expect(jdApi.createJdProductGroup).toHaveBeenCalledWith({ name: '新分类', sortOrder: 0, ownerGroupId: GROUP_A })
|
||||
await modal.findAll('button').find(b => b.text() === '改名')!.trigger('click')
|
||||
await modal.get('.group-row input').setValue('改名后')
|
||||
await modal.findAll('button').find(b => b.text() === '保存')!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.updateJdProductGroup).toHaveBeenCalledWith(7, { name: '改名后', sortOrder: 0 })
|
||||
await modal.findAll('button').find(b => b.text() === '删除')!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(confirmMock).toHaveBeenCalled()
|
||||
expect(jdApi.deleteJdProductGroup).toHaveBeenCalledWith(7)
|
||||
expect(wrapper.findAll('button').some((b) => b.text() === '店铺分类')).toBe(false, '「店铺分类」入口已删')
|
||||
expect(wrapper.find('.group-modal').exists()).toBe(false)
|
||||
expect(wrapper.get('[aria-label="筛选店铺分类"]').exists()).toBe(true, '分类筛选下拉是读面,保留')
|
||||
wrapper.unmount()
|
||||
})
|
||||
})
|
||||
@@ -529,11 +478,12 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].category).toBe('')
|
||||
})
|
||||
|
||||
it('不再显示独立分类与分类状态筛选', async () => {
|
||||
it('不再显示独立分类与分类状态筛选;工具栏入口是「批量编辑分类」(弹窗 2026-11-17 下线)', async () => {
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
|
||||
expect(wrapper.find('.jd-filter-row').text()).not.toContain('分类状态')
|
||||
expect(wrapper.find('.jd-filter-row select').exists()).toBe(false)
|
||||
expect(wrapper.findAll('button').some(button => button.text() === '店铺分类')).toBe(true)
|
||||
expect(wrapper.findAll('button').some(button => button.text() === '批量编辑分类')).toBe(true)
|
||||
expect(wrapper.findAll('button').some(button => button.text() === '店铺分类')).toBe(false, '「店铺分类」入口已删')
|
||||
})
|
||||
|
||||
it('重置把筛选面回空并回第一页重取', async () => {
|
||||
@@ -748,13 +698,13 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
})
|
||||
})
|
||||
|
||||
/** 写权限分档(2026-11-16 用户口径):
|
||||
* 商品行写(编辑/删除/勾选批量删)只对平台超管渲染;
|
||||
* 分类写由 scope 的每组 editable 决定(本组管理员/公司超管/平台超管)——同组普通号
|
||||
* 能打开「店铺分类」弹窗看(用户原话「可以进弹窗里看 但是不能添加删除分类」),
|
||||
* 但新建/改名/删除与归类入口都不渲染,后端同口径 403 兜底。 */
|
||||
/** 写权限分档(2026-11-16 用户口径收窄商品行写;2026-11-17 弹窗下线后更新):
|
||||
* 商品行写(编辑/删除/勾选批量删)只对平台超管渲染;分类写(批量编辑分类)由 scope 的
|
||||
* 每组 editable 决定(本组管理员/公司超管/平台超管)——同组普通号在本页只读,
|
||||
* 只读查看入口在「京东分类管理」子菜单页(V204)。勾选列 2026-11-17 起对本组可写
|
||||
* 分类管理员开放(服务批量归类),商品行按钮仍只归平台超管。 */
|
||||
describe('京东数据库写权限分档(商品行写=平台超管;分类写=本组 editable)', () => {
|
||||
it('非超管只读:无勾选列、无操作列、无删除勾选;列表/筛选/详情照常,弹窗可看不可改', async () => {
|
||||
it('非超管且本组不可写:无勾选列、无操作列、无删除勾选、无批量编辑分类;列表/筛选/详情照常', async () => {
|
||||
useAdminSessionStore().user = { id: 2, username: 'ops', role: 'admin' }
|
||||
// 同组普通号:可见但不可写(editable=false)。
|
||||
jdApi.fetchJdCategoryScope.mockResolvedValue(singleGroupScope(false))
|
||||
@@ -764,43 +714,25 @@ describe('京东数据库写权限分档(商品行写=平台超管;分类
|
||||
)
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
|
||||
expect(wrapper.findAll('tbody input[type="checkbox"]')).toHaveLength(0, '非超管不渲染勾选列(勾选只为批量删除服务)')
|
||||
expect(wrapper.findAll('tbody input[type="checkbox"]')).toHaveLength(0, '不可写分类的普通号没有勾选列')
|
||||
expect(wrapper.find('.jd-delete-btn').exists()).toBe(false, '批量删除按钮不渲染')
|
||||
expect(wrapper.findAll('button').some((b) => b.text() === '批量编辑分类')).toBe(false, '分类写入口不渲染(本组不可写)')
|
||||
expect(wrapper.find('thead').text()).not.toContain('操作', '操作列(编辑/删除)不渲染')
|
||||
expect(wrapper.text()).toContain('只读:编辑/删除仅超级管理员可用;分类由本组管理员维护', '只读提示必须看得见并区分两类写权限')
|
||||
expect(wrapper.text()).toContain('只读:编辑/删除仅超级管理员可用', '只读提示必须看得见并区分两类写权限')
|
||||
expect(wrapper.text()).toContain('京东分类管理', '提示把分类维护入口指向「京东分类管理」子菜单页')
|
||||
|
||||
// 读面不受影响:筛选下拉、列表行、点行开详情都还在。
|
||||
expect(wrapper.get('[aria-label="筛选店铺分类"]').exists()).toBe(true, '分类筛选是读面,保留')
|
||||
const cells = wrapper.findAll('tbody tr')[0].findAll('td')
|
||||
expect(cells).toHaveLength(5, '非超管列表 5 列:分类/商品信息/总库存/价格/同步时间')
|
||||
expect(wrapper.findAll('tbody tr')[0].findAll('td')).toHaveLength(5, '普通号列表 5 列:分类/商品信息/总库存/价格/同步时间')
|
||||
await wrapper.findAll('tbody tr')[0].trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
expect(wrapper.find('.drawer-mask').exists()).toBe(true, '点行仍可开只读详情抽屉')
|
||||
expect(jdApi.fetchJdProductDetail).toHaveBeenCalledWith(1)
|
||||
await wrapper.find('.drawer-mask').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
// 「店铺分类」弹窗对所有有本页菜单权限的人可见(可以进弹窗里看)……
|
||||
const dialogButton = wrapper.findAll('button').find((b) => b.text() === '店铺分类')
|
||||
expect(dialogButton, '同组普通号也能打开分类弹窗(只读查看)').toBeTruthy()
|
||||
await dialogButton!.trigger('click')
|
||||
await flushPromises()
|
||||
const modal = wrapper.get('.group-modal')
|
||||
expect(modal.text()).toContain('本组分类(只读)', '弹窗文案点名只读')
|
||||
expect(modal.text()).toContain('甲组', '看得到本组分类')
|
||||
// ……但没有建/改/删与归类入口(用户原话「不能添加删除分类」)。
|
||||
expect(modal.find('.group-create').exists()).toBe(false, '只读账号不渲染新建输入行')
|
||||
expect(modal.findAll('button').some((b) => b.text() === '改名')).toBe(false, '无改名入口')
|
||||
expect(modal.findAll('button').some((b) => b.text() === '删除')).toBe(false, '无删除入口')
|
||||
expect(modal.find('tbody input[type="checkbox"]').exists()).toBe(false, '右栏无勾选列(没有归类写入口)')
|
||||
expect(modal.findAll('button').some((b) => b.text().includes('归入') || b.text() === '移出分类')).toBe(false,
|
||||
'无归入/移出入口')
|
||||
expect(jdApi.batchAssignJdProductGroup).not.toHaveBeenCalled()
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('超管保留全部写入口(勾选列+操作列+删除勾选+店铺分类),且不显示只读提示', async () => {
|
||||
it('超管保留全部写入口(勾选列+操作列+删除勾选+批量编辑分类),且不显示只读提示', async () => {
|
||||
// beforeEach 默认 super_admin;这里显式再钉一次,防默认值漂移把这条闸门变成恒绿。
|
||||
useAdminSessionStore().user = { id: 1, username: 'root', role: 'super_admin' }
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
@@ -808,29 +740,39 @@ describe('京东数据库写权限分档(商品行写=平台超管;分类
|
||||
expect(wrapper.findAll('tbody input[type="checkbox"]')).toHaveLength(1)
|
||||
expect(wrapper.findAll('tbody tr')[0].findAll('td')).toHaveLength(7)
|
||||
expect(wrapper.find('.jd-delete-btn').exists()).toBe(true)
|
||||
expect(wrapper.findAll('button').some((b) => b.text() === '店铺分类')).toBe(true)
|
||||
expect(wrapper.findAll('button').some((b) => b.text() === '批量编辑分类')).toBe(true)
|
||||
expect(wrapper.text()).not.toContain('只读:')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('本组管理员(非平台超管):商品行仍只读,但分类弹窗有建/改/删与归类入口', async () => {
|
||||
it('本组管理员(非平台超管):商品行按钮仍无,但勾选列随批量编辑分类放开(6 列形状)', async () => {
|
||||
useAdminSessionStore().user = { id: 3, username: 'leader', role: 'admin' }
|
||||
// 组长档形状:可见组可写 ⇒ editable=true,商品行写仍按 isSuperAdmin 判(不受 editable 影响)。
|
||||
// 组长档形状:可见组可写 ⇒ editable=true;商品行写仍按 isSuperAdmin 判(不受 editable 影响)。
|
||||
jdApi.fetchJdCategoryScope.mockResolvedValue(singleGroupScope(true))
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 1 }])
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
expect(wrapper.findAll('tbody input[type="checkbox"]')).toHaveLength(0, '组管理员也不动商品行(编辑/删除只归平台超管)')
|
||||
await wrapper.findAll('button').find((b) => b.text() === '店铺分类')!.trigger('click')
|
||||
expect(wrapper.findAll('tbody tr')[0].findAll('td')).toHaveLength(6, '管理员 6 列:勾选/分类/商品信息/总库存/价格/同步时间(无操作列)')
|
||||
expect(wrapper.find('.jd-delete-btn').exists()).toBe(false, '批量删除(商品行写)仍只归平台超管')
|
||||
expect(wrapper.find('thead').text()).not.toContain('操作')
|
||||
const editBtn = wrapper.findAll('button').find((b) => b.text() === '批量编辑分类')
|
||||
expect(editBtn, '本组管理员有批量编辑分类入口').toBeTruthy()
|
||||
|
||||
// 管理员可勾选并走一遍归类(2026-11-17 弹窗下线后唯一的归类路径)。
|
||||
jdApi.batchAssignJdProductGroup.mockResolvedValue(1)
|
||||
await wrapper.findAll('tbody input[type="checkbox"]')[0].setValue(true)
|
||||
expect(editBtn!.attributes('disabled')).toBeUndefined('勾选后可点')
|
||||
await editBtn!.trigger('click')
|
||||
await flushPromises()
|
||||
const modal = wrapper.get('.group-modal')
|
||||
expect(modal.find('.group-create').exists()).toBe(true, '本组管理员能新建分类')
|
||||
expect(modal.findAll('button').some((b) => b.text() === '删除')).toBe(true, '能删除分类')
|
||||
expect(modal.find('tbody input[type="checkbox"]').exists()).toBe(true, '能勾选商品归类')
|
||||
const modal = wrapper.get('.batch-modal')
|
||||
await modal.findAll('.option-row')[0].trigger('click')
|
||||
await modal.findAll('button').find((b) => b.text() === '归入「甲组」')!.trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1], 7, GROUP_A)
|
||||
wrapper.unmount()
|
||||
})
|
||||
})
|
||||
|
||||
/** 分组作用域(V203):不同组看不到彼此的分类;能看多组的人用「分组」下拉切换。 */
|
||||
describe('京东数据库分类按数据权限分组隔离(V203)', () => {
|
||||
it('多组可见:筛选行出带标签的「分组」下拉,切换后分类下拉与列表一并用新组取', async () => {
|
||||
jdApi.fetchJdCategoryScope.mockResolvedValue({
|
||||
@@ -892,16 +834,14 @@ describe('京东数据库分类按数据权限分组隔离(V203)', () => {
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('不属于任何数据权限分组:分类全空、不给切换,弹窗直说「你还不属于任何数据权限分组」', async () => {
|
||||
it('不属于任何数据权限分组:分类全空、不给切换也不给批量归类入口(空态兜底在「京东分类管理」页)', async () => {
|
||||
jdApi.fetchJdCategoryScope.mockResolvedValue({ platformSuperAdmin: false, defaultGroupId: null, groups: [] })
|
||||
const wrapper = await mountWith({ items: [item(1, { groupId: null, groupName: '' })], total: 1, page: 1, pageSize: 20 })
|
||||
expect(wrapper.find('[aria-label="当前分组"]').exists()).toBe(false)
|
||||
expect(wrapper.find('.jd-group-locked').exists()).toBe(false, '没有分组就没有可锁定的组名')
|
||||
expect(wrapper.find('[aria-label="筛选店铺分类"]').text()).toContain('全部分类', '分类筛选只剩「全部分类」')
|
||||
expect(wrapper.findAll('tbody tr')[0].findAll('td')[1].text()).toBe('未分类')
|
||||
await wrapper.findAll('button').find((b) => b.text() === '店铺分类')!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper.get('.group-modal').text()).toContain('你还不属于任何数据权限分组')
|
||||
expect(wrapper.findAll('button').some((b) => b.text() === '批量编辑分类')).toBe(false, '没有分组就没有可写的分类面')
|
||||
expect(jdApi.batchAssignJdProductGroup).not.toHaveBeenCalled()
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
@@ -36,6 +36,8 @@ const OPS_MIN_COL_PX: Record<string, number> = {
|
||||
'src/pages/asin/ProductCategoryPage.vue': 138,
|
||||
'src/pages/asin/QueryAsinPage.vue': 138,
|
||||
'src/pages/asin/SkipPricePage.vue': 138,
|
||||
// 京东分类管理(V204):改名/删除两颗 btn-sm(两字 53×2+gap+左右 padding 24)。
|
||||
'src/pages/jd/JdCategoryManagerPage.vue': 138,
|
||||
'src/pages/records/DeviceLogsPage.vue': 138,
|
||||
'src/pages/records/RecordsDigitalHumanVersionPage.vue': 287,
|
||||
'src/pages/records/RecordsSoftwareVersionPage.vue': 77,
|
||||
|
||||
@@ -33,6 +33,7 @@ const TREE: AdminMenuNode[] = [
|
||||
node('admin_query_asin', '查询ASIN', '/asin-center/query'),
|
||||
node('admin_appearance_patent_clean_items', '外观专利数据库', '/patent-center/clean-items'),
|
||||
node('admin_jd_database', '京东数据库', '/jd-center/database'),
|
||||
node('admin_jd_category_manage', '京东分类管理', '/jd-center/categories'),
|
||||
node('admin_product_categories', '商品类目', '/asin-center/categories'),
|
||||
]),
|
||||
]
|
||||
@@ -51,15 +52,21 @@ test('menuKey 平台归属:京东清单四项即 jd,其余(含分组 key
|
||||
assert.equal(platformOfMenuKey(''), 'amazon')
|
||||
})
|
||||
|
||||
test('京东 tab:账号与权限只余圈定三项,数据管理只余京东数据库;顺序与 route 原样透传', () => {
|
||||
test('京东 tab:账号与权限只余圈定三项,数据管理只余京东两页(数据库+分类管理);顺序与 route 原样透传', () => {
|
||||
const filtered = filterMenuTreeByPlatform(TREE, 'jd')
|
||||
assert.deepEqual(filtered.map((item) => item.key), ['admin_group_account', 'admin_group_data'])
|
||||
assert.deepEqual(groupChildKeys(filtered, 'admin_group_account'),
|
||||
['admin_users', 'admin_group_manage', 'admin_companies'])
|
||||
assert.deepEqual(groupChildKeys(filtered, 'admin_group_data'), ['admin_jd_database'])
|
||||
// 2026-11-17 用户口径「这边分组是京东的分组管理的而不是亚马逊的」:分类管理子菜单
|
||||
// 归京东侧(JD_MENU_KEYS),亚马逊 tab 侧看不到它(亚马逊用例反向钉住)。
|
||||
assert.deepEqual(groupChildKeys(filtered, 'admin_group_data'),
|
||||
['admin_jd_database', 'admin_jd_category_manage'])
|
||||
const jd = filtered[1].children![0]
|
||||
assert.equal(jd.route, '/jd-center/database')
|
||||
assert.equal(jd.name, '京东数据库')
|
||||
const categoryManage = filtered[1].children![1]
|
||||
assert.equal(categoryManage.route, '/jd-center/categories', 'V204 菜单行的 route_path 与注册表一致')
|
||||
assert.equal(categoryManage.name, '京东分类管理')
|
||||
})
|
||||
|
||||
test('亚马逊 tab:其余菜单全数保留且分组结构不变', () => {
|
||||
@@ -109,7 +116,8 @@ test('平台 tab 定义与京东清单钉死(2026-11-16 用户圈定口径,
|
||||
{ id: 'amazon', label: '亚马逊' },
|
||||
{ id: 'jd', label: '京东' },
|
||||
])
|
||||
assert.deepEqual([...JD_MENU_KEYS].sort(), ['admin_companies', 'admin_group_manage', 'admin_jd_database', 'admin_users'])
|
||||
assert.deepEqual([...JD_MENU_KEYS].sort(),
|
||||
['admin_companies', 'admin_group_manage', 'admin_jd_category_manage', 'admin_jd_database', 'admin_users'])
|
||||
})
|
||||
|
||||
test('JD_MENU_KEYS 每一条都必须在路由注册表登记(同 company-menu-route 护栏形状:少登记=看得见点进去404)', () => {
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
-- 迁移 V204:后管菜单「京东分类管理」(2026-11-17 用户口径「店铺分类弹窗下线,
|
||||
-- 加个京东分类管理的子菜单维护 CRUD」)
|
||||
-- =============================================================
|
||||
-- 1. 变更目的:店铺分类弹窗从京东数据库页下线后,分类的建/改名/删除挪到独立子页
|
||||
-- (jd-center/categories)。只新增 columns 菜单行,不插任何授权行(user→column
|
||||
-- 勾授表零写入)⇒ 默认仅 super_admin 可见可访问(V196 惯例);其余角色由超管
|
||||
-- 在权限页手工勾授后才可见。接口层无新端点:页面复用 /api/admin/jd-product-groups
|
||||
-- 既有读写端点,其鉴权锚在 admin_jd_database(与本菜单行互不影响——没勾本菜单
|
||||
-- 但勾了京东数据库的超管仍能走接口,前端入口由菜单树裁剪)。
|
||||
--
|
||||
-- 2. 形状口径(V196 逐形,每公司一套树):
|
||||
-- - company_id=1 为模板行,其余公司(含停用公司)逐家复制;子行 parent_id 必须
|
||||
-- 认本公司 admin_group_data 组行,严禁跨公司认父(V185 实录:company_id NOT NULL
|
||||
-- 无默认值,漏写直接 1364)。
|
||||
-- - 挂「数据管理」组(admin_group_data),排序 69(V196 京东数据库占 68)。
|
||||
-- - route_path='jd-center/categories' 为前端 History 路由(V109 形状),
|
||||
-- column_key='admin_jd_category_manage' 为稳定权限标识;前端 routes.ts 以
|
||||
-- menuKey=admin_jd_category_manage 登记同一路径,且进 platform-scope 的
|
||||
-- JD_MENU_KEYS(京东平台 tab 侧,2026-11-16「亚马逊/京东不混一起」)。
|
||||
-- - 幂等守卫按 (company_id, column_key) 判存,同时防
|
||||
-- uk_company_menu_type_route_path(company_id, menu_type, route_path) 撞行。
|
||||
--
|
||||
-- 3. 影响表与数据量:columns 新增 N 行(N=公司数),字典小表,毫秒级。
|
||||
--
|
||||
-- 4. 可重跑性:两段 INSERT 都带 NOT EXISTS 守卫,重跑逐条 no-op;自检闸门只读。
|
||||
--
|
||||
-- 5. 回滚(人工补丁,写成注释以免落在 Flyway 扫描路径里被当迁移执行):
|
||||
-- DELETE FROM columns WHERE column_key='admin_jd_category_manage';
|
||||
-- DELETE FROM flyway_schema_history WHERE version='204';
|
||||
-- (授权过的行随 columns 外键 ON DELETE CASCADE 一并清,无需单独处理。)
|
||||
-- =============================================================
|
||||
|
||||
-- ---------- 1. 公司 1 模板行:京东分类管理 ----------
|
||||
INSERT INTO `columns` (`name`, `column_key`, `menu_type`, `route_path`, `sort_order`, `parent_id`, `company_id`)
|
||||
SELECT '京东分类管理', 'admin_jd_category_manage', 'admin', 'jd-center/categories', 69, grp.`id`, 1
|
||||
FROM `columns` grp
|
||||
WHERE grp.`company_id` = 1 AND grp.`column_key` = 'admin_group_data'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM `columns`
|
||||
WHERE `company_id` = 1
|
||||
AND (`column_key` = 'admin_jd_category_manage'
|
||||
OR (`menu_type` = 'admin' AND `route_path` = 'jd-center/categories'))
|
||||
);
|
||||
|
||||
-- ---------- 2. 复制到其余公司(含停用公司),各自认本公司数据管理组行 ----------
|
||||
INSERT INTO `columns` (`name`, `column_key`, `menu_type`, `route_path`, `sort_order`, `parent_id`, `company_id`)
|
||||
SELECT '京东分类管理', 'admin_jd_category_manage', 'admin', 'jd-center/categories', 69, grp.`id`, c.`id`
|
||||
FROM `company` c
|
||||
JOIN `columns` grp ON grp.`company_id` = c.`id` AND grp.`column_key` = 'admin_group_data'
|
||||
WHERE c.`id` <> 1
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM `columns` col
|
||||
WHERE col.`company_id` = c.`id`
|
||||
AND (col.`column_key` = 'admin_jd_category_manage'
|
||||
OR (col.`menu_type` = 'admin' AND col.`route_path` = 'jd-center/categories'))
|
||||
);
|
||||
|
||||
-- ---------- 3. 自检闸门:不为 0 就抛 1048(列 must_be_zero NOT NULL) ----------
|
||||
CREATE TEMPORARY TABLE IF NOT EXISTS `_v204_gate` (`must_be_zero` INT NOT NULL);
|
||||
|
||||
-- 闸门 1:每家公司恰好一行,且父必须是本公司数据管理组、排序 69
|
||||
INSERT INTO `_v204_gate`
|
||||
SELECT IF(COUNT(*) = 0, 0, NULL)
|
||||
FROM (
|
||||
SELECT c.`id`
|
||||
FROM `company` c
|
||||
LEFT JOIN `columns` col ON col.`company_id` = c.`id`
|
||||
AND col.`column_key` = 'admin_jd_category_manage'
|
||||
LEFT JOIN `columns` grp ON grp.`id` = col.`parent_id`
|
||||
AND grp.`company_id` = c.`id` AND grp.`column_key` = 'admin_group_data'
|
||||
GROUP BY c.`id`
|
||||
HAVING COUNT(col.`id`) <> 1 OR COUNT(grp.`id`) <> 1 OR MAX(col.`sort_order`) <> 69
|
||||
) bad;
|
||||
|
||||
-- 闸门 2:该路由不允许被别的 column_key 占行(防 uk_company_menu_type_route_path 语义被顶)
|
||||
INSERT INTO `_v204_gate`
|
||||
SELECT IF(COUNT(*) = 0, 0, NULL)
|
||||
FROM `columns` col
|
||||
WHERE col.`menu_type` = 'admin'
|
||||
AND col.`route_path` = 'jd-center/categories'
|
||||
AND col.`column_key` <> 'admin_jd_category_manage';
|
||||
|
||||
DROP TEMPORARY TABLE `_v204_gate`;
|
||||
Reference in New Issue
Block a user