feat(jd): 整合自定义分类并保护商品数据
This commit is contained in:
@@ -25,9 +25,28 @@ const props = defineProps<{
|
||||
options?: { name: string; productCount: number }[]
|
||||
/** 当前选中末级类目名;'' = 全部类目。 */
|
||||
modelValue: string
|
||||
groups?: { id: number; name: string; productCount: number }[]
|
||||
groupId?: string
|
||||
createVersion?: number
|
||||
busy?: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{ (event: 'change', value: string): void }>()
|
||||
const emit = defineEmits<{
|
||||
(event: 'change', value: string): void
|
||||
(event: 'group', value: string): void
|
||||
(event: 'create-group', value: string): void
|
||||
(event: 'delete-group', id: number): void
|
||||
}>()
|
||||
const newGroupName = ref('')
|
||||
watch(() => props.createVersion, () => { newGroupName.value = '' })
|
||||
function createGroup(): void {
|
||||
const name = newGroupName.value.trim()
|
||||
if (name) emit('create-group', name)
|
||||
}
|
||||
function pickGroup(id: number): void {
|
||||
emit('group', String(id))
|
||||
close()
|
||||
}
|
||||
|
||||
const open = ref(false)
|
||||
/** 已下钻的节点名路径(非末级行点击推进)。 */
|
||||
@@ -143,12 +162,12 @@ function clear(): void {
|
||||
<button
|
||||
class="cat-trigger"
|
||||
type="button"
|
||||
:class="{ open, filled: !!modelValue }"
|
||||
:class="{ open, filled: !!modelValue || !!groupId }"
|
||||
@click="toggle"
|
||||
>
|
||||
<span class="cat-trigger-text" :title="modelValue || ''">{{ modelValue || '全部类目' }}</span>
|
||||
<span class="cat-trigger-text" :title="modelValue || ''">{{ groups?.find(group => String(group.id) === groupId)?.name || modelValue || '全部类目' }}</span>
|
||||
<span
|
||||
v-if="modelValue"
|
||||
v-if="modelValue || groupId"
|
||||
class="cat-clear"
|
||||
role="button"
|
||||
aria-label="清除类目"
|
||||
@@ -160,9 +179,21 @@ function clear(): void {
|
||||
<!-- 面板外点透明遮罩关闭(零 document 监听器,无泄漏面)。 -->
|
||||
<div v-if="open" class="cat-mask" @click="close"></div>
|
||||
<div v-if="open" ref="panelRef" class="cat-panel" :style="{ left: `${panelOffsetX}px` }">
|
||||
<div class="cat-custom cat-col-custom">
|
||||
<div class="cat-seg">自定义分类</div>
|
||||
<form class="cat-create" @submit.prevent="createGroup">
|
||||
<input v-model="newGroupName" class="cat-search" placeholder="新建分类" aria-label="新建分类名称" />
|
||||
<button type="submit" :disabled="busy || !newGroupName.trim()">添加</button>
|
||||
</form>
|
||||
<div v-for="group in groups || []" :key="group.id" class="cat-row" :class="{ active: groupId === String(group.id) }">
|
||||
<button type="button" class="cat-group-pick" :title="group.name" @click="pickGroup(group.id)">{{ group.name }}({{ group.productCount }})</button>
|
||||
<button type="button" :aria-label="`删除分类 ${group.name}`" @click.stop="emit('delete-group', group.id)">删除</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 搜索态:树内末级命中+树外兜底段(扁平列表,行 title 带全路径)。 -->
|
||||
<template v-if="searching">
|
||||
<div class="cat-col cat-col-search">
|
||||
<div class="cat-search-row"><input v-model="searchText" type="text" class="cat-search" placeholder="搜索类目" /></div>
|
||||
<template v-if="searchLeaves.length || fallbackOptions.length">
|
||||
<div
|
||||
v-for="leaf in searchLeaves"
|
||||
@@ -233,6 +264,10 @@ function clear(): void {
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.cat-custom { flex: none; width: 200px; max-height: 340px; overflow-y: auto; border-right: 1px solid #e7eef5; }
|
||||
.cat-create { display: flex; gap: 4px; padding: 6px 8px; }
|
||||
.cat-create input { min-width: 0; }
|
||||
.cat-group-pick { flex: 1; min-width: 0; text-align: left; border: 0; background: transparent; color: inherit; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.cat-cascader {
|
||||
position: relative;
|
||||
min-width: 0;
|
||||
@@ -321,9 +356,11 @@ function clear(): void {
|
||||
border-radius: 10px;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 16px 44px rgba(39, 67, 94, 0.18);
|
||||
overflow: hidden;
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
}
|
||||
.cat-col {
|
||||
flex: none;
|
||||
width: 200px;
|
||||
max-height: 340px;
|
||||
overflow-y: auto;
|
||||
|
||||
@@ -1,33 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
/** 京东数据库页(v1.4 Phase 5):公共的京东商品库(2026-11-15 用户定案「不区分公司、属于
|
||||
* 公共的」,分类同亚马逊口径全平台一份),筛选行(商品编码/标题关键字/分类/分类状态/
|
||||
* 类目/同步起止 date 对)+查询/重置/店铺分类 + 自绘明细表(勾选列+点行开详情抽屉)
|
||||
* + 删除(单行/批量,先删桶对象、全成功才删库行,确认弹窗点名数量)+ OldPagination。
|
||||
* 公司维度 2026-11-16 整页摘除(用户定案「删除掉公司 tab,参考品牌数据库」=品牌库
|
||||
* 2026-10-06 先例同形):页面不再消费公司 tab store、列表/类目下拉不再下传 company_id
|
||||
* (后端读侧 company_id 谓词同窗摘,行 company_id 列仍作同步来源标记留在详情里);
|
||||
* 每个管理员看到同一份公共全量。反向钉在 company-tab-wiring「公司维度不得回流」清单。
|
||||
* 列表按京麦商品列表样式(2026-11-15 用户口径):分类前置为第 1 列;商品信息列=京麦同款
|
||||
* 合并布局(主图+图下信息分+标题两行+商品编码/货号+SKU 数标签,编码带一键复制);类目/上架
|
||||
* 时间/京东创建/修改时间仍收详情抽屉基本信息(B104「详情显示全部属性」口径不变)。
|
||||
* 商品状态筛选框与导出按钮随 2026-11-15 客户口径「这两个不要/导出也不用」从前端下线
|
||||
* (后端 sale_status 参数与 /export 端点保留);店铺筛选与店铺列同日客户口径「店铺不需要」
|
||||
* 下线(后端 shop_name 参数同窗撤);店铺仍收详情抽屉。
|
||||
* 2026-11-16 三笔(用户截图反馈):① 创建/修改/同步三个时间列按「时间移动到最后去」移到
|
||||
* 操作列之后收尾;② 价格列修「采集到了却全显示 -」=模型解析层 text() 丢掉后端 BigDecimal
|
||||
* 的 JSON number 形状(生产库 273/273 行 price_min 全有值,jd-product-model.ts decimalText 收口);
|
||||
* ③ 「上架时间 / 商品状态」合并列整列下线(「不需要采集」口径,jd_online_at/sale_status 仍收
|
||||
* 详情抽屉),操作列随 2026-11-16「操作放最后一列」口径置末;④ 创建/修改两列同口径「不要」
|
||||
* 下线(jd_created_at/jd_updated_at 仍收详情抽屉),列表时间列只剩同步时间收尾;
|
||||
* ⑤ 工具栏加「移除分类」批量按钮(batch-assign-group 的 groupId=null 口径,勾选里只算已分类行)。
|
||||
* 骨架像素复刻「外观专利数据库」页(panel-box + LoadFailureBar + 自绘 table + 旧式分页);
|
||||
* 日期对护栏:起侧 max=止侧、止侧 min=起侧、两侧 @change 用 orderedPair 把倒挂交换回来
|
||||
* (clampJdSyncedRange 照 clampDatePair)。
|
||||
* 日期初值故意留空:同步数据是累计集,默认当天会让首屏只剩今天同步的行
|
||||
* (date-filter-default-today 护栏 EXEMPT 口径,外观专利页同款)。 */
|
||||
/** 京东公共商品库:类目面板提供京麦树与自定义分类筛选、增删;
|
||||
* 商品支持勾选归入或移除分类,删除分类保留商品。列表、详情和编辑共用现有接口。 */
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import {
|
||||
batchAssignJdProductGroup,
|
||||
createJdProductGroup,
|
||||
deleteJdProductGroup,
|
||||
deleteJdProducts,
|
||||
fetchJdProductCategories,
|
||||
fetchJdProductGroups,
|
||||
@@ -41,7 +19,6 @@ import { createJdProductFilterState } from './jd-product-filter.ts'
|
||||
import { removableGroupPicks, removeGroupConfirmMessage } from './jd-group-remove.ts'
|
||||
import JdProductDetailDrawer from './JdProductDetailDrawer.vue'
|
||||
import JdProductEditDrawer from './JdProductEditDrawer.vue'
|
||||
import JdProductGroupDialog from './JdProductGroupDialog.vue'
|
||||
import JdCategoryCascader from './JdCategoryCascader.vue'
|
||||
import OldPagination from '@/components/OldPagination.vue'
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
@@ -62,8 +39,6 @@ const filter = reactive(createJdProductFilterState())
|
||||
const groupOptions = ref<JdProductGroup[]>([])
|
||||
/** 类目下拉选项(京麦末级类目):与当前行集同源(公共库全量);失败静默回空。 */
|
||||
const categoryOptions = ref<JdProductCategoryOption[]>([])
|
||||
/** 分组管理弹窗与详情抽屉。 */
|
||||
const groupDialogVisible = ref(false)
|
||||
const detailItem = ref<JdProductItem | null>(null)
|
||||
const detailVisible = ref(false)
|
||||
/** 行级编辑抽屉(2026-11-15 用户口径「每一条数据后面 需要编辑或者删除;编辑的话
|
||||
@@ -131,7 +106,6 @@ async function load(): Promise<void> {
|
||||
titleKeyword: filter.titleKeyword,
|
||||
category: filter.category,
|
||||
groupId: filter.groupId,
|
||||
groupScope: filter.groupScope,
|
||||
syncedFrom: filter.syncedFrom,
|
||||
syncedTo: filter.syncedTo,
|
||||
})
|
||||
@@ -157,9 +131,66 @@ function apply(): void {
|
||||
* 点「全部类目」/触发框 × = 清选重查。 */
|
||||
function onCategoryPicked(name: string): void {
|
||||
filter.category = name
|
||||
filter.groupId = ''
|
||||
apply()
|
||||
}
|
||||
|
||||
function onGroupPicked(id: string): void {
|
||||
filter.groupId = id
|
||||
filter.category = ''
|
||||
apply()
|
||||
}
|
||||
|
||||
const groupBusy = ref(false)
|
||||
const groupCreateVersion = ref(0)
|
||||
async function createGroup(name: string): Promise<void> {
|
||||
if (groupBusy.value) return
|
||||
groupBusy.value = true
|
||||
try {
|
||||
await createJdProductGroup({ name, sortOrder: 0 })
|
||||
groupCreateVersion.value++
|
||||
await loadGroupOptions()
|
||||
showAdminFeedback('分类已添加', 'success')
|
||||
} catch (error) {
|
||||
showAdminFeedback(error instanceof Error && error.message ? error.message : '添加分类失败', 'error')
|
||||
} finally { groupBusy.value = false }
|
||||
}
|
||||
|
||||
async function deleteGroup(id: number): Promise<void> {
|
||||
const group = groupOptions.value.find(item => item.id === id)
|
||||
if (!group || groupBusy.value) return
|
||||
const ok = await openAdminConfirm({ title: '删除分类', message: `确定删除分类「${group.name}」吗?分类下 ${group.productCount} 个商品将保留并回到未分类。`, confirmText: '确认删除', danger: true })
|
||||
if (!ok || groupBusy.value) return
|
||||
groupBusy.value = true
|
||||
try {
|
||||
await deleteJdProductGroup(id)
|
||||
if (filter.groupId === String(id)) filter.groupId = ''
|
||||
await onGroupChanged()
|
||||
showAdminFeedback('分类已删除,商品已保留', 'success')
|
||||
} catch (error) {
|
||||
showAdminFeedback(error instanceof Error && error.message ? error.message : '删除分类失败', 'error')
|
||||
} finally { groupBusy.value = false }
|
||||
}
|
||||
|
||||
const assignGroupId = ref('')
|
||||
async function assignSelectedGroup(): Promise<void> {
|
||||
const id = Number(assignGroupId.value)
|
||||
const picked = rows.value.filter(row => selectedIds.value.has(row.id))
|
||||
if (!id || !picked.length || groupBusy.value || removingGroup.value || deleting.value) return
|
||||
const group = groupOptions.value.find(item => item.id === id)
|
||||
if (!group) return
|
||||
const ok = await openAdminConfirm({ title: '归入分类', message: `确定将勾选的 ${picked.length} 个商品归入「${group.name}」吗?归类会设置人工编辑锁,商品不再被采集自动覆盖,价格和库存等字段也将停止自动更新。`, confirmText: '确认归类', danger: false })
|
||||
if (!ok || groupBusy.value || removingGroup.value || deleting.value) return
|
||||
groupBusy.value = true
|
||||
try {
|
||||
const updated = await batchAssignJdProductGroup(picked.map(row => row.id), id)
|
||||
showAdminFeedback(`已将 ${updated} 个商品归入分类`, 'success')
|
||||
await onGroupChanged()
|
||||
} catch (error) {
|
||||
showAdminFeedback(error instanceof Error && error.message ? error.message : '归入分类失败', 'error')
|
||||
} finally { groupBusy.value = false }
|
||||
}
|
||||
|
||||
/** 重置:筛选面回出厂空态,回第一页重取。 */
|
||||
function reset(): void {
|
||||
Object.assign(filter, createJdProductFilterState())
|
||||
@@ -267,6 +298,7 @@ async function removeSelectedGroup(): Promise<void> {
|
||||
const updated = await batchAssignJdProductGroup(picked.map((row) => row.id), null)
|
||||
showAdminFeedback(`已把 ${updated} 个商品移出分类`, 'success')
|
||||
selectedIds.value = new Set()
|
||||
await loadGroupOptions()
|
||||
await load()
|
||||
} catch (error) {
|
||||
const text = error instanceof Error && error.message ? error.message : '移除分类失败,请稍后重试'
|
||||
@@ -288,7 +320,6 @@ onMounted(() => {
|
||||
<section class="panel-box">
|
||||
<div class="jd-panel-head">
|
||||
<h3>京东数据库</h3>
|
||||
<button class="btn btn-secondary" type="button" @click="groupDialogVisible = true">店铺分类</button>
|
||||
</div>
|
||||
|
||||
<div class="jd-filter-row">
|
||||
@@ -300,26 +331,6 @@ onMounted(() => {
|
||||
<label>标题关键字</label>
|
||||
<input v-model="filter.titleKeyword" type="text" placeholder="输入标题关键字" @keyup.enter="apply" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>分类</label>
|
||||
<!-- 分类选中即查:选完立刻按该分类过滤刷新(回第一页),不必再点查询。
|
||||
(2026-11-15「分组管理」改「店铺分类」:同一 group 实体,只改界面措辞。) -->
|
||||
<select v-model="filter.groupId" @change="apply">
|
||||
<option value="">全部分类</option>
|
||||
<option v-for="group in groupOptions" :key="group.id" :value="String(group.id)">{{ group.name }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>分类状态</label>
|
||||
<!-- 分类状态(2026-11-15 客户口径「查询已分类的跟未分类,分类好的可以不显示」):
|
||||
选中即查,同分组/类目口径;与上方「分类」(具体分组等值过滤)正交——
|
||||
这里只按 group_id 是否为空分档。 -->
|
||||
<select v-model="filter.groupScope" @change="apply">
|
||||
<option value="">全部</option>
|
||||
<option value="grouped">已分类</option>
|
||||
<option value="ungrouped">未分类</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>类目</label>
|
||||
<!-- 类目(京麦末级类目)京麦同款级联面板(2026-11-16 客户口径):一/二级为静态导航
|
||||
@@ -327,7 +338,14 @@ onMounted(() => {
|
||||
<JdCategoryCascader
|
||||
:options="categoryOptions"
|
||||
:model-value="filter.category"
|
||||
:groups="groupOptions"
|
||||
:group-id="filter.groupId"
|
||||
:create-version="groupCreateVersion"
|
||||
:busy="groupBusy"
|
||||
@change="onCategoryPicked"
|
||||
@group="onGroupPicked"
|
||||
@create-group="createGroup"
|
||||
@delete-group="deleteGroup"
|
||||
/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@@ -347,8 +365,15 @@ onMounted(() => {
|
||||
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
|
||||
<div class="jd-toolbar">
|
||||
<span class="jd-summary">共 {{ total }} 条京东商品</span>
|
||||
<select v-model="assignGroupId" aria-label="选择归入的分类">
|
||||
<option value="">选择分类</option>
|
||||
<option v-for="group in groupOptions" :key="group.id" :value="String(group.id)">{{ group.name }}</option>
|
||||
</select>
|
||||
<button class="btn" type="button" :disabled="!selectedCount || !assignGroupId || groupBusy || removingGroup || deleting" @click="assignSelectedGroup">归入分类({{ selectedCount }})</button>
|
||||
<!-- 「移除分类」是次要批量动作:改用全站统一的次要按钮(白底灰蓝字),
|
||||
主蓝只留给「归入分类」,与打卡/分组等页的工具栏层级一致。 -->
|
||||
<button
|
||||
class="btn jd-remove-btn" type="button"
|
||||
class="btn btn-secondary jd-remove-btn" type="button"
|
||||
:disabled="removingGroup || !removablePicked.length"
|
||||
:title="removablePicked.length ? `移出勾选的 ${removablePicked.length} 个已分类商品` : '勾选中没有已分类的商品'"
|
||||
@click="removeSelectedGroup"
|
||||
@@ -370,8 +395,8 @@ onMounted(() => {
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 42px"><input type="checkbox" :checked="allSelected" @change="toggleSelectAll(($event.target as HTMLInputElement).checked)" /></th>
|
||||
<th style="width: 96px">分类</th>
|
||||
<th>商品信息</th>
|
||||
<th style="width: 92px">分类</th>
|
||||
<th style="width: 520px">商品信息</th>
|
||||
<th style="width: 76px">总库存</th>
|
||||
<th style="width: 120px">价格</th>
|
||||
<!-- 同步时间收尾(创建/修改两列 2026-11-16 客户口径「不要」下线,仍收详情抽屉);
|
||||
@@ -442,350 +467,7 @@ onMounted(() => {
|
||||
@close="closeEdit"
|
||||
@saved="onEditSaved"
|
||||
/>
|
||||
<JdProductGroupDialog
|
||||
:visible="groupDialogVisible"
|
||||
@close="groupDialogVisible = false"
|
||||
@changed="onGroupChanged"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* 像素复刻「外观专利数据库」页样式(panel-box + 自绘表格 + 旧式分页);列表只摆部分字段,全量属性在详情抽屉。 */
|
||||
.jd-database-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);
|
||||
}
|
||||
h3 {
|
||||
margin: 0 0 16px;
|
||||
font-size: 15px;
|
||||
font-weight: 650;
|
||||
color: #24384d;
|
||||
letter-spacing: 0.2px;
|
||||
}
|
||||
.jd-panel-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.jd-panel-head h3 {
|
||||
margin: 0;
|
||||
}
|
||||
.jd-filter-row {
|
||||
/* 可换行流式布局:固定 6 列 minmax(140px) 的网格在窄面板下最小宽超出容器,
|
||||
把查询/重置挤出面板右缘(与「管理分组」重叠)。flex-wrap 让放不下的项自然折行。 */
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
align-items: flex-end;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.jd-filter-row .form-group {
|
||||
flex: 1 1 160px;
|
||||
min-width: 150px;
|
||||
max-width: 260px;
|
||||
}
|
||||
.jd-filter-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 7px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.form-group label {
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13.5px;
|
||||
font-family: inherit;
|
||||
color-scheme: light;
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover,
|
||||
.form-group select:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
}
|
||||
.form-group input[type="date"] {
|
||||
color-scheme: light;
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
min-height: 42px;
|
||||
padding: 9px 18px;
|
||||
border: 1px solid #4f78a5;
|
||||
border-radius: 9px;
|
||||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||||
color: #ffffff;
|
||||
font-family: inherit;
|
||||
font-size: 13.5px;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
|
||||
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
|
||||
}
|
||||
.btn:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #7094ba, #5d83ac);
|
||||
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
|
||||
}
|
||||
.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;
|
||||
}
|
||||
.jd-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
/* 工具栏右侧两个批量按钮:推右的 margin 由移除分类带,删除跟排。 */
|
||||
.jd-remove-btn {
|
||||
margin-left: auto;
|
||||
}
|
||||
.btn-danger {
|
||||
background: #ffffff;
|
||||
color: #a04432;
|
||||
border-color: #e4b3a8;
|
||||
}
|
||||
.btn-danger:hover:not(:disabled) {
|
||||
background: #fdf1ef;
|
||||
border-color: #d08a7b;
|
||||
}
|
||||
.jd-summary {
|
||||
color: #5b6f83;
|
||||
font-size: 13px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.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;
|
||||
}
|
||||
.jd-table-scroll > table {
|
||||
min-width: 1500px;
|
||||
}
|
||||
/* 操作列(编辑/删除):双小按钮需 138px(ops-cell-must-wrap 实测口径:两字按钮 53×2+24 padding)。
|
||||
overflow 显式放开:td 全局是 overflow:hidden(611 行),压线时第二颗(删除)会被裁成
|
||||
「编辑+…」的形状——2026-11-16 用户报「删除没了」的真因,列宽 120px < 实测 138px。 */
|
||||
.jd-ops-cell {
|
||||
white-space: nowrap;
|
||||
text-overflow: clip;
|
||||
overflow: visible;
|
||||
}
|
||||
.btn-sm {
|
||||
min-height: 28px;
|
||||
padding: 3px 10px;
|
||||
font-size: 12.5px;
|
||||
margin-right: 6px;
|
||||
}
|
||||
.btn-sm:last-child {
|
||||
margin-right: 0;
|
||||
}
|
||||
.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;
|
||||
}
|
||||
/* 首列勾选格:checkbox 的 UA 默认 margin(3px 3px 3px 4px)使其 margin-box 溢出
|
||||
42px 格的内容盒(42−24 padding=18px),配合上面的 overflow:hidden,Chromium 在
|
||||
首次渲染时会把被裁的 checkbox 碎片留在裁剪边缘,看起来像格子右边多出 ".."。
|
||||
margin 归零后 margin-box 收进内容盒,首渲染即干净(playwright 三次冷加载已验)。 */
|
||||
.table-scroll th:first-child input,
|
||||
.table-scroll td:first-child input {
|
||||
margin: 0;
|
||||
}
|
||||
.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;
|
||||
}
|
||||
/* 点行开详情抽屉:行级 hover 已有底色反馈,光标再点一下提示可点。 */
|
||||
.jd-row {
|
||||
cursor: pointer;
|
||||
}
|
||||
.jd-thumb {
|
||||
display: block;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
object-fit: cover;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 6px;
|
||||
background: #f2f7fb;
|
||||
}
|
||||
/* 商品信息列=京麦同款合并布局:td 的全局 nowrap/ellipsis 与多行内容冲突,本列放开换行,
|
||||
截断交给内部各行(标题两行 line-clamp、编码/货号单行 ellipsis)。 */
|
||||
.jd-info-cell {
|
||||
white-space: normal;
|
||||
text-overflow: clip;
|
||||
}
|
||||
.jd-info-wrap {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 10px;
|
||||
min-width: 0;
|
||||
}
|
||||
.jd-info-figure {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 3px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.jd-thumb-empty {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #8293a5;
|
||||
font-size: 12px;
|
||||
}
|
||||
.jd-health {
|
||||
color: #2e9e6b;
|
||||
font-size: 11px;
|
||||
line-height: 1.2;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.jd-info-body {
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 3px;
|
||||
}
|
||||
.jd-info-title {
|
||||
color: #24384d;
|
||||
font-size: 13.5px;
|
||||
font-weight: 500;
|
||||
line-height: 1.45;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
word-break: break-all;
|
||||
}
|
||||
.jd-info-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
color: #7b8a99;
|
||||
font-size: 12px;
|
||||
line-height: 1.4;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
}
|
||||
.jd-info-code {
|
||||
font-family: "Cascadia Mono", "SF Mono", Consolas, "Courier New", monospace;
|
||||
color: #4e6479;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.jd-copy-btn {
|
||||
flex-shrink: 0;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: #8aa5bf;
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
padding: 0 2px;
|
||||
line-height: 1;
|
||||
}
|
||||
.jd-copy-btn:hover {
|
||||
color: #3b82c4;
|
||||
}
|
||||
.jd-info-tags {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
margin-top: 2px;
|
||||
}
|
||||
/* 品牌·类目行(京麦列表同款深色文字):信息 meta 是灰色,这行按京麦用主文字色。 */
|
||||
.jd-brand-cat {
|
||||
color: #3d5368;
|
||||
font-weight: 550;
|
||||
}
|
||||
.jd-tag {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
height: 18px;
|
||||
padding: 0 6px;
|
||||
border: 1px solid #cfe3f5;
|
||||
border-radius: 3px;
|
||||
background: #eef5fc;
|
||||
color: #3b82c4;
|
||||
font-size: 11.5px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.empty-tip {
|
||||
padding: 44px 24px;
|
||||
text-align: center;
|
||||
color: #8293a5;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
</style>
|
||||
<style scoped src="./jd-database-page.css"></style>
|
||||
|
||||
@@ -1,468 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
/** 京东店铺分类弹窗右栏:商品人工归类面板(2026-11-15 从 JdProductGroupDialog 拆出,
|
||||
* 独立件也守可读棘轮的 800 行报警线)。范围切换(全部/未分类/当前分类)+标题关键字搜索
|
||||
* +勾选行 →「归入所选分类」/「移出分类」。归类走批量端点
|
||||
* POST /api/admin/jd-products/batch-assign-group:后端与单行编辑同口径置 manual_locked=1
|
||||
* (归类即人工干预,采集 upsert/覆盖清理不再碰该行,分类永不丢;代价是该行价格/库存随锁
|
||||
* 停更——弹窗提示语点名这个后果)。取数复用 fetchJdProductList(不带公司维度,全平台一份);
|
||||
* 「未分类」走 ungrouped 参数。
|
||||
* 归类目标(selectedGroup)由左栏(父件)点亮下发;弹窗壳 v-if 整树重建 ⇒ 每次打开即本件
|
||||
* 重挂载、onMounted 自取首屏行集。成功后 emit('changed') 让父件刷新分类商品数并上抛页面;
|
||||
* 业务失败把后端中文文案展示在本面板红条内。 */
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { batchAssignJdProductGroup, fetchJdProductList } from './jd-product-api.ts'
|
||||
import type { 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
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{ (event: 'changed'): void }>()
|
||||
|
||||
type Scope = 'all' | 'ungrouped' | 'current'
|
||||
const scope = ref<Scope>('all')
|
||||
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 canAssign = computed(() => !!props.selectedGroup && selectedCount.value > 0 && !assigning.value)
|
||||
const canRemove = computed(() => selectedCount.value > 0 && !assigning.value)
|
||||
const allSelected = computed(() =>
|
||||
products.value.length > 0 && products.value.every((row) => selectedProductIds.value.has(row.id)))
|
||||
|
||||
async function loadProducts(): Promise<void> {
|
||||
productsLoading.value = true
|
||||
productsError.value = ''
|
||||
try {
|
||||
const result = await fetchJdProductList({
|
||||
page: productPage.value,
|
||||
pageSize: PRODUCT_PAGE_SIZE,
|
||||
titleKeyword: keyword.value.trim(),
|
||||
groupId: scope.value === 'current' && props.selectedGroup ? String(props.selectedGroup.id) : '',
|
||||
ungrouped: scope.value === 'ungrouped',
|
||||
})
|
||||
products.value = result.items
|
||||
productTotal.value = result.total
|
||||
if (result.page >= 1) productPage.value = result.page
|
||||
selectedProductIds.value = new Set()
|
||||
} catch (error) {
|
||||
productsError.value = requestErrorMessage(error) || '商品列表加载失败'
|
||||
products.value = []
|
||||
productTotal.value = 0
|
||||
selectedProductIds.value = new Set()
|
||||
} finally {
|
||||
productsLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function pickScope(next: Scope): void {
|
||||
if (next === 'current' && !props.selectedGroup) return
|
||||
if (scope.value === next) return
|
||||
scope.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 || !canAssign.value) return
|
||||
assigning.value = true
|
||||
productsError.value = ''
|
||||
try {
|
||||
const updated = await batchAssignJdProductGroup([...selectedProductIds.value], target.id)
|
||||
showAdminFeedback(`已把 ${updated} 个商品归入「${target.name}」`, 'success')
|
||||
emit('changed')
|
||||
await loadProducts()
|
||||
} catch (error) {
|
||||
productsError.value = requestErrorMessage(error) || '归类失败,请稍后重试'
|
||||
} finally {
|
||||
assigning.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 勾选行 → 移出分类(group_id 置 NULL,回到未分类)。 */
|
||||
async function removeFromCategory(): Promise<void> {
|
||||
if (!canRemove.value) return
|
||||
assigning.value = true
|
||||
productsError.value = ''
|
||||
try {
|
||||
const updated = await batchAssignJdProductGroup([...selectedProductIds.value], null)
|
||||
showAdminFeedback(`已把 ${updated} 个商品移出分类`, 'success')
|
||||
emit('changed')
|
||||
await loadProducts()
|
||||
} catch (error) {
|
||||
productsError.value = requestErrorMessage(error) || '移出分类失败,请稍后重试'
|
||||
} finally {
|
||||
assigning.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 目标分类变化(左栏点亮/删除):右栏停在「当前分类」页签时随点亮对象换行集;
|
||||
// 目标被删(null)=「当前分类」没了,拉回全量页签,不留在空集页签里。
|
||||
watch(
|
||||
() => props.selectedGroup,
|
||||
(group) => {
|
||||
if (scope.value !== 'current') return
|
||||
if (group && group.id > 0) {
|
||||
productPage.value = 1
|
||||
void loadProducts()
|
||||
} else {
|
||||
scope.value = 'all'
|
||||
productPage.value = 1
|
||||
void loadProducts()
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
onMounted(() => {
|
||||
void loadProducts()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="right-pane">
|
||||
<div class="product-toolbar">
|
||||
<div class="scope-tabs">
|
||||
<button type="button" :class="{ on: scope === 'all' }" @click="pickScope('all')">全部</button>
|
||||
<button type="button" :class="{ on: scope === 'ungrouped' }" @click="pickScope('ungrouped')">未分类</button>
|
||||
<button
|
||||
type="button"
|
||||
:class="{ on: scope === 'current' }"
|
||||
:disabled="!selectedGroup"
|
||||
:title="selectedGroup ? `只看「${selectedGroup.name}」下的商品` : '先在左侧点选一个分类'"
|
||||
@click="pickScope('current')"
|
||||
>当前分类</button>
|
||||
</div>
|
||||
<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 class="col-check"><input type="checkbox" :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 class="col-check">
|
||||
<input
|
||||
type="checkbox"
|
||||
: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 class="product-footer">
|
||||
<span class="pick-summary">已勾选 {{ selectedCount }} 个商品</span>
|
||||
<div class="footer-actions">
|
||||
<button class="btn btn-small" type="button" :disabled="!canAssign" @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;
|
||||
}
|
||||
.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,456 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
/** 京东商品「店铺分类」弹窗(2026-11-15 由「分组管理」小弹窗重做):左右分栏——左栏分类管理
|
||||
* (新建=输入行尾「+」图标,排序数字输入 2026-11-15 客户口径下线、sortOrder 恒 0;
|
||||
* 改名/删除;分组全平台一份、措辞「分类」),右栏商品人工归类(独立件
|
||||
* JdProductAssignPane:范围切换+搜索+勾选 →「归入所选分类」/「移出分类」,批量端点
|
||||
* batch-assign-group 与单行编辑同口径置 manual_locked=1——归类即人工干预,采集不再覆盖/
|
||||
* 清理该行)。左栏点亮的分类=右栏归类目标;目标被删时右栏自动拉回全量页签。
|
||||
* 重名等业务失败把后端返回的中文文案原样展示在弹窗内(envelope code 非 0 → errorTextOf);
|
||||
* 删除分类前 openAdminConfirm 二次确认;变更成功后 emit('changed'),由页面刷新分组下拉与
|
||||
* 列表。弹窗壳 v-if 整树重建 ⇒ 每次打开即两个面板都重新拉数据,无需手动重置。 */
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import {
|
||||
createJdProductGroup,
|
||||
deleteJdProductGroup,
|
||||
fetchJdProductGroups,
|
||||
updateJdProductGroup,
|
||||
type JdProductGroup,
|
||||
} 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
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{ (event: 'close'): void; (event: 'changed'): 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 selectedGroupId = ref(0)
|
||||
|
||||
const canCreate = computed(() => createName.value.trim().length > 0 && !creating.value && !saving.value)
|
||||
const selectedGroup = computed(() => groups.value.find((group) => group.id === selectedGroupId.value) || null)
|
||||
|
||||
async function loadGroups(): Promise<void> {
|
||||
loading.value = true
|
||||
errorText.value = ''
|
||||
try {
|
||||
groups.value = await fetchJdProductGroups()
|
||||
} 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(): Promise<void> {
|
||||
groups.value = sortGroups(await fetchJdProductGroups())
|
||||
emit('changed')
|
||||
}
|
||||
|
||||
async function submitCreate(): Promise<void> {
|
||||
const name = createName.value.trim()
|
||||
if (!name || creating.value) return
|
||||
creating.value = true
|
||||
errorText.value = ''
|
||||
try {
|
||||
await createJdProductGroup({ name, sortOrder: 0 })
|
||||
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 })
|
||||
cancelRename()
|
||||
await refreshAfterChange()
|
||||
} 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)
|
||||
// 删掉的是当前归类目标:清点亮,右栏自己会拉回全量页签(watch selectedGroup)。
|
||||
if (selectedGroupId.value === group.id) {
|
||||
selectedGroupId.value = 0
|
||||
}
|
||||
await refreshAfterChange()
|
||||
} catch (error) {
|
||||
errorText.value = requestErrorMessage(error) || '删除分类失败'
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 左侧点亮分类=归类目标(右栏「当前分类」页签随点亮对象换行集)。 */
|
||||
function pickGroup(group: JdProductGroup): void {
|
||||
if (saving.value) 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>店铺分类</h3>
|
||||
<button class="modal-close" type="button" aria-label="关闭" @click="emit('close')">×</button>
|
||||
</div>
|
||||
<p class="modal-tip">
|
||||
左侧管理分类并点选目标分类;右侧勾选商品后「归入所选分类」或「移出分类」。
|
||||
人工归类过的商品不再被采集自动覆盖(价格/库存等字段停更)。
|
||||
</p>
|
||||
<p v-if="errorText" class="group-error">{{ errorText }}</p>
|
||||
|
||||
<div class="split-body">
|
||||
<!-- 左栏:分类管理 -->
|
||||
<aside class="left-pane">
|
||||
<div 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 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">暂无分类,先新建一个</li>
|
||||
</ul>
|
||||
</aside>
|
||||
|
||||
<!-- 右栏:商品人工归类(独立件,行集/勾选/批量归类都在那里) -->
|
||||
<JdProductAssignPane :selected-group="selectedGroup" @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>
|
||||
@@ -0,0 +1,342 @@
|
||||
/* 像素复刻「外观专利数据库」页样式(panel-box + 自绘表格 + 旧式分页);列表只摆部分字段,全量属性在详情抽屉。 */
|
||||
.jd-database-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);
|
||||
}
|
||||
h3 {
|
||||
margin: 0 0 16px;
|
||||
font-size: 15px;
|
||||
font-weight: 650;
|
||||
color: #24384d;
|
||||
letter-spacing: 0.2px;
|
||||
}
|
||||
.jd-panel-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.jd-panel-head h3 {
|
||||
margin: 0;
|
||||
}
|
||||
.jd-filter-row {
|
||||
/* 可换行流式布局:固定 6 列 minmax(140px) 的网格在窄面板下最小宽超出容器,
|
||||
把查询/重置挤出面板右缘(与「管理分组」重叠)。flex-wrap 让放不下的项自然折行。 */
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
align-items: flex-end;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.jd-filter-row .form-group {
|
||||
flex: 1 1 160px;
|
||||
min-width: 150px;
|
||||
max-width: 260px;
|
||||
}
|
||||
.jd-filter-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 7px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.form-group label {
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13.5px;
|
||||
font-family: inherit;
|
||||
color-scheme: light;
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover,
|
||||
.form-group select:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
}
|
||||
.form-group input[type="date"] {
|
||||
color-scheme: light;
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
min-height: 42px;
|
||||
padding: 9px 18px;
|
||||
border: 1px solid #4f78a5;
|
||||
border-radius: 9px;
|
||||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||||
color: #ffffff;
|
||||
font-family: inherit;
|
||||
font-size: 13.5px;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
|
||||
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
|
||||
}
|
||||
.btn:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #7094ba, #5d83ac);
|
||||
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
|
||||
}
|
||||
.btn:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.55;
|
||||
}
|
||||
.btn-secondary {
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
border-color: #c7d7e5;
|
||||
}
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
color: #2f5d8b;
|
||||
border-color: #95b1cb;
|
||||
background: #edf5fb;
|
||||
}
|
||||
.jd-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
/* 工具栏右侧两个批量按钮:推右的 margin 由移除分类带,删除跟排。 */
|
||||
.jd-remove-btn {
|
||||
margin-left: auto;
|
||||
}
|
||||
/* 危险动作(删除勾选):与全站 .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);
|
||||
}
|
||||
.jd-summary {
|
||||
color: #5b6f83;
|
||||
font-size: 13px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.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;
|
||||
}
|
||||
/* 列宽收口(2026-11-16 用户口径「列表间距有点大」):1500px 的 min-width 让宽屏下
|
||||
唯一的弹性列(商品信息)独吞剩余宽度,标题右侧留出近 800px 空白,价格/库存被推到最右。
|
||||
商品信息改固定 520px 后各列按比例分摊余量,min-width 降到 1180px 即可无横向滚动。 */
|
||||
.jd-table-scroll > table {
|
||||
min-width: 1180px;
|
||||
}
|
||||
/* 操作列(编辑/删除):双小按钮需 138px(ops-cell-must-wrap 实测口径:两字按钮 53×2+24 padding)。
|
||||
overflow 显式放开:td 全局是 overflow:hidden(611 行),压线时第二颗(删除)会被裁成
|
||||
「编辑+…」的形状——2026-11-16 用户报「删除没了」的真因,列宽 120px < 实测 138px。 */
|
||||
.jd-ops-cell {
|
||||
white-space: nowrap;
|
||||
text-overflow: clip;
|
||||
overflow: visible;
|
||||
}
|
||||
.btn-sm {
|
||||
min-height: 28px;
|
||||
padding: 3px 10px;
|
||||
font-size: 12.5px;
|
||||
margin-right: 6px;
|
||||
}
|
||||
.btn-sm:last-child {
|
||||
margin-right: 0;
|
||||
}
|
||||
.table-scroll th,
|
||||
.table-scroll td {
|
||||
/* 单元格左右内距 12→10px(同上「间距有点大」):列与列之间少 4px,行内更紧凑。 */
|
||||
padding: 10px 10px;
|
||||
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;
|
||||
}
|
||||
/* 首列勾选格:checkbox 的 UA 默认 margin(3px 3px 3px 4px)使其 margin-box 溢出
|
||||
42px 格的内容盒(42−24 padding=18px),配合上面的 overflow:hidden,Chromium 在
|
||||
首次渲染时会把被裁的 checkbox 碎片留在裁剪边缘,看起来像格子右边多出 ".."。
|
||||
margin 归零后 margin-box 收进内容盒,首渲染即干净(playwright 三次冷加载已验)。 */
|
||||
.table-scroll th:first-child input,
|
||||
.table-scroll td:first-child input {
|
||||
margin: 0;
|
||||
}
|
||||
.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;
|
||||
}
|
||||
/* 点行开详情抽屉:行级 hover 已有底色反馈,光标再点一下提示可点。 */
|
||||
.jd-row {
|
||||
cursor: pointer;
|
||||
}
|
||||
.jd-thumb {
|
||||
display: block;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
object-fit: cover;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 6px;
|
||||
background: #f2f7fb;
|
||||
}
|
||||
/* 商品信息列=京麦同款合并布局:td 的全局 nowrap/ellipsis 与多行内容冲突,本列放开换行,
|
||||
截断交给内部各行(标题两行 line-clamp、编码/货号单行 ellipsis)。 */
|
||||
.jd-info-cell {
|
||||
white-space: normal;
|
||||
text-overflow: clip;
|
||||
}
|
||||
.jd-info-wrap {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 10px;
|
||||
min-width: 0;
|
||||
}
|
||||
.jd-info-figure {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 3px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.jd-thumb-empty {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #8293a5;
|
||||
font-size: 12px;
|
||||
}
|
||||
.jd-health {
|
||||
color: #2e9e6b;
|
||||
font-size: 11px;
|
||||
line-height: 1.2;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.jd-info-body {
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 3px;
|
||||
}
|
||||
.jd-info-title {
|
||||
color: #24384d;
|
||||
font-size: 13.5px;
|
||||
font-weight: 500;
|
||||
line-height: 1.45;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
word-break: break-all;
|
||||
}
|
||||
.jd-info-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
color: #7b8a99;
|
||||
font-size: 12px;
|
||||
line-height: 1.4;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
}
|
||||
.jd-info-code {
|
||||
font-family: "Cascadia Mono", "SF Mono", Consolas, "Courier New", monospace;
|
||||
color: #4e6479;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.jd-copy-btn {
|
||||
flex-shrink: 0;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: #8aa5bf;
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
padding: 0 2px;
|
||||
line-height: 1;
|
||||
}
|
||||
.jd-copy-btn:hover {
|
||||
color: #3b82c4;
|
||||
}
|
||||
.jd-info-tags {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
margin-top: 2px;
|
||||
}
|
||||
/* 品牌·类目行(京麦列表同款深色文字):信息 meta 是灰色,这行按京麦用主文字色。 */
|
||||
.jd-brand-cat {
|
||||
color: #3d5368;
|
||||
font-weight: 550;
|
||||
}
|
||||
.jd-tag {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
height: 18px;
|
||||
padding: 0 6px;
|
||||
border: 1px solid #cfe3f5;
|
||||
border-radius: 3px;
|
||||
background: #eef5fc;
|
||||
color: #3b82c4;
|
||||
font-size: 11.5px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.empty-tip {
|
||||
padding: 44px 24px;
|
||||
text-align: center;
|
||||
color: #8293a5;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
@@ -29,15 +29,12 @@ export async function fetchJdProductList(
|
||||
titleKeyword: params.titleKeyword ?? '',
|
||||
category: params.category ?? '',
|
||||
groupId: params.groupId ?? '',
|
||||
groupScope: params.groupScope ?? '',
|
||||
syncedFrom: params.syncedFrom ?? '',
|
||||
syncedTo: params.syncedTo ?? '',
|
||||
},
|
||||
params.page,
|
||||
params.pageSize,
|
||||
)
|
||||
// 未分类范围(店铺分类弹窗「未分类」页签):由发送口直传,构造器不认识它。
|
||||
if (params.ungrouped) query.ungrouped = true
|
||||
const { data } = await http.get<unknown>(JD_PRODUCT_ENDPOINT, { params: query })
|
||||
return parseJdProductPage(data)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
/** 京东数据库页筛选纯函数(v1.4 Phase 5):商品编码/标题关键字/类目/分组/分类状态/同步起止 + snake 分页参数。
|
||||
* 产出与后端契约 §列表 query 逐字对撞:`page`/`page_size`(默认 20、上限 100)、
|
||||
* `product_code`、`title_keyword`、`category`(京麦末级类目等值过滤,2026-11-15 增)、
|
||||
* `group_id`、`grouped`(只看已分类,2026-11-15 客户口径「查询已分类的跟未分类,分类好的
|
||||
* 可以不显示」增)、`ungrouped`(只看未分类,页面「分类状态」档与店铺分类弹窗共用)、
|
||||
* `group_id`、
|
||||
* `synced_from`/`synced_to`(ISO yyyy-MM-dd;空白不下发)。
|
||||
* 商品状态筛选与导出(2026-11-15 客户口径「这两个不要/导出也不用」)已从前端下线;
|
||||
* 店铺筛选同日客户口径「店铺不需要」从前端下线(后端 shop_name 参数同窗撤,DB 列与详情不动)。
|
||||
@@ -30,9 +29,6 @@ export interface JdProductFilterState {
|
||||
category: string
|
||||
/** 分组 id 文本(分组管理里那一行),空串=全部分组。 */
|
||||
groupId: string
|
||||
/** 分类状态(2026-11-15 客户口径「查询已分类的跟未分类」):''=全部、
|
||||
* 'grouped'=只看已分类(group_id 非空)、'ungrouped'=只看未分类(group_id 为空)。 */
|
||||
groupScope: '' | 'grouped' | 'ungrouped'
|
||||
/** 同步开始日期(ISO yyyy-MM-dd;空串不限)。 */
|
||||
syncedFrom: string
|
||||
/** 同步结束日期(ISO yyyy-MM-dd;空串不限)。 */
|
||||
@@ -40,7 +36,7 @@ export interface JdProductFilterState {
|
||||
}
|
||||
|
||||
export function createJdProductFilterState(): JdProductFilterState {
|
||||
return { productCode: '', titleKeyword: '', category: '', groupId: '', groupScope: '', syncedFrom: '', syncedTo: '' }
|
||||
return { productCode: '', titleKeyword: '', category: '', groupId: '', syncedFrom: '', syncedTo: '' }
|
||||
}
|
||||
|
||||
/** 是否有任一激活筛选条件。 */
|
||||
@@ -49,7 +45,6 @@ export function jdProductFilterActive(state: JdProductFilterState): boolean {
|
||||
if ((state.titleKeyword || '').trim()) return true
|
||||
if ((state.category || '').trim()) return true
|
||||
if ((state.groupId || '').trim()) return true
|
||||
if ((state.groupScope || '').trim()) return true
|
||||
if (validIsoDateOrUndefined(state.syncedFrom) || validIsoDateOrUndefined(state.syncedTo)) return true
|
||||
return false
|
||||
}
|
||||
@@ -63,11 +58,6 @@ export interface JdProductQuery {
|
||||
/** 京麦末级类目等值过滤(后端 JdProductQueryService.Filter.category)。 */
|
||||
category?: string
|
||||
group_id?: number
|
||||
/** 未分类过滤(店铺分类弹窗「未分类」范围):true=只看 group_id 为空的行。
|
||||
* 同 group_id 一样由 api 发送口下传——构造器不认识它(弹窗的取数不走筛选态)。 */
|
||||
ungrouped?: boolean
|
||||
/** 已分类过滤(页面筛选行「分类状态」=已分类):true=只看 group_id 非空的行。 */
|
||||
grouped?: boolean
|
||||
synced_from?: string
|
||||
synced_to?: string
|
||||
}
|
||||
@@ -80,10 +70,6 @@ export interface JdProductListParams {
|
||||
titleKeyword?: string
|
||||
category?: string
|
||||
groupId?: string
|
||||
/** 分类状态档(''=全部 | 'grouped' | 'ungrouped');页面筛选行传,弹窗不传。 */
|
||||
groupScope?: '' | 'grouped' | 'ungrouped'
|
||||
/** 未分类范围(true=只看未分类行);仅店铺分类弹窗右栏传,页面筛选行不用。 */
|
||||
ungrouped?: boolean
|
||||
syncedFrom?: string
|
||||
syncedTo?: string
|
||||
}
|
||||
@@ -99,10 +85,6 @@ function toJdProductFilterQuery(state: JdProductFilterState): Omit<JdProductQuer
|
||||
if (category) query.category = category
|
||||
const groupId = Number.parseInt((state.groupId || '').trim(), 10)
|
||||
if (Number.isFinite(groupId) && groupId > 0) query.group_id = groupId
|
||||
// 分类状态档:未分类走既有 ungrouped 参数(与店铺分类弹窗同一后端谓词),
|
||||
// 已分类走 grouped;''(全部)不下发。
|
||||
if (state.groupScope === 'ungrouped') query.ungrouped = true
|
||||
if (state.groupScope === 'grouped') query.grouped = true
|
||||
const syncedFrom = validIsoDateOrUndefined(state.syncedFrom)
|
||||
if (syncedFrom) query.synced_from = syncedFrom
|
||||
const syncedTo = validIsoDateOrUndefined(state.syncedTo)
|
||||
|
||||
@@ -101,22 +101,10 @@ test('类目筛选参数序列化:空串不下发、非空下发 category(
|
||||
assert.equal(jdProductFilterActive(filtered), true, '选中类目算激活筛选')
|
||||
})
|
||||
|
||||
/** 分类状态筛选(2026-11-15 客户口径「查询已分类的跟未分类,分类好的可以不显示」):
|
||||
* 全部不下发、已分类下发 grouped、未分类下发 ungrouped(与店铺分类弹窗同一后端谓词)。 */
|
||||
test('分类状态筛选参数序列化:全部不下发、已分类 grouped、未分类 ungrouped', async () => {
|
||||
const { createJdProductFilterState, toJdProductListParams, jdProductFilterActive } =
|
||||
await import('../src/pages/jd/jd-product-filter.ts')
|
||||
const empty = createJdProductFilterState()
|
||||
assert.equal('grouped' in toJdProductListParams(empty, 1, 20), false, '全部不下发 grouped')
|
||||
assert.equal('ungrouped' in toJdProductListParams(empty, 1, 20), false, '全部不下发 ungrouped')
|
||||
|
||||
const grouped = { ...empty, groupScope: 'grouped' as const }
|
||||
assert.equal(toJdProductListParams(grouped, 1, 20).grouped, true, '已分类档下发 grouped=true')
|
||||
assert.equal('ungrouped' in toJdProductListParams(grouped, 1, 20), false, '已分类档不下发 ungrouped')
|
||||
assert.equal(jdProductFilterActive(grouped), true, '选中已分类算激活筛选')
|
||||
|
||||
const ungrouped = { ...empty, groupScope: 'ungrouped' as const }
|
||||
assert.equal(toJdProductListParams(ungrouped, 1, 20).ungrouped, true, '未分类档下发 ungrouped=true')
|
||||
assert.equal('grouped' in toJdProductListParams(ungrouped, 1, 20), false, '未分类档不下发 grouped')
|
||||
assert.equal(jdProductFilterActive(ungrouped), true, '选中未分类算激活筛选')
|
||||
test('自定义分类使用 group_id,不发送分类状态参数', async () => {
|
||||
const { createJdProductFilterState, toJdProductListParams } = await import('../src/pages/jd/jd-product-filter.ts')
|
||||
const query = toJdProductListParams({ ...createJdProductFilterState(), groupId: '7' }, 1, 20)
|
||||
assert.equal(query.group_id, 7)
|
||||
assert.equal('grouped' in query, false)
|
||||
assert.equal('ungrouped' in query, false)
|
||||
})
|
||||
|
||||
@@ -24,8 +24,8 @@ import {
|
||||
toJdProductListParams,
|
||||
} from '../src/pages/jd/jd-product-filter.ts'
|
||||
import {
|
||||
jdCategoryNavChildren,
|
||||
jdCategoryNavRoots,
|
||||
jdCategoryChildren,
|
||||
jdCategoryRoots,
|
||||
} from '../src/pages/jd/jd-category-tree.ts'
|
||||
import {
|
||||
jdPriceRange,
|
||||
@@ -36,15 +36,14 @@ import {
|
||||
|
||||
test('类目级联静态导航树——服饰内衣二级与京麦面板样本逐字同源,一级集非空且无重名', () => {
|
||||
// 京麦面板真机样本(2026-11-16 客户截图):服饰内衣下就是这五个二级,改名即红。
|
||||
assert.deepEqual(jdCategoryNavChildren('服饰内衣'), ['服饰配件', '内衣', '女装', '男装', '定制服装/工装'])
|
||||
assert.deepEqual(jdCategoryNavChildren('不存在的类目'), [], '未知一级回落空子级(面板不出第二栏)')
|
||||
assert.deepEqual(jdCategoryChildren(['服饰内衣']).map(node => node.name), ['服饰配件', '内衣', '女装', '男装', '定制服装/工装'])
|
||||
assert.deepEqual(jdCategoryChildren(['不存在的类目']), [], '未知一级回落空子级(面板不出第二栏)')
|
||||
|
||||
const roots = jdCategoryNavRoots()
|
||||
assert.ok(roots.length >= 20, `一级导航 ${roots.length} 个,常用集不应被清空`)
|
||||
const roots = jdCategoryRoots().map(node => node.name)
|
||||
assert.deepEqual(roots, ['服饰内衣', '母婴', '运动户外'], '一级导航与京麦授权类目一致')
|
||||
assert.equal(new Set(roots).size, roots.length, '一级类目名不得重复')
|
||||
assert.equal(roots[0], '服饰内衣', '服饰内衣置首(客户商品全在服饰类目)')
|
||||
for (const root of roots) {
|
||||
const children = jdCategoryNavChildren(root)
|
||||
const children = jdCategoryChildren([root]).map(node => node.name)
|
||||
assert.equal(new Set(children).size, children.length, `${root} 的二级不得重复`)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -16,7 +16,7 @@ import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { createPinia, setActivePinia, type Pinia } from 'pinia'
|
||||
|
||||
import JdDatabasePage from '@/pages/jd/JdDatabasePage.vue'
|
||||
import JdProductGroupDialog from '@/pages/jd/JdProductGroupDialog.vue'
|
||||
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
|
||||
const jdApi = vi.hoisted(() => ({
|
||||
@@ -227,7 +227,8 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
expect(textInputs).toHaveLength(2, '商品编码+标题关键字两个文本筛选框(店铺/商品状态已下线)')
|
||||
await textInputs[0].setValue('JD-1001')
|
||||
await textInputs[1].setValue('保温杯')
|
||||
await wrapper.find('select').setValue('7')
|
||||
await wrapper.find('.cat-trigger').trigger('click')
|
||||
await wrapper.find('.cat-group-pick').trigger('click')
|
||||
const dateInputs = wrapper.findAll('input[type="date"]')
|
||||
await dateInputs[0].setValue('2026-11-01')
|
||||
await dateInputs[1].setValue('2026-11-09')
|
||||
@@ -257,13 +258,10 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
|
||||
expect(jdApi.fetchJdProductGroups).toHaveBeenCalledWith()
|
||||
|
||||
const groupSelect = wrapper.find('select')
|
||||
const optionTexts = groupSelect.findAll('option').map((o) => o.text())
|
||||
expect(optionTexts).toContain('全部分类')
|
||||
expect(optionTexts).toContain('甲组')
|
||||
|
||||
await wrapper.find('.cat-trigger').trigger('click')
|
||||
expect(wrapper.find('.cat-custom').text()).toContain('甲组')
|
||||
const callsBeforeSelect = jdApi.fetchJdProductList.mock.calls.length
|
||||
await groupSelect.setValue('7')
|
||||
await wrapper.find('.cat-group-pick').trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.length).toBe(callsBeforeSelect + 1, '选中分组必须立刻重查')
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7', page: 1 })
|
||||
@@ -358,22 +356,11 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].category).toBe('')
|
||||
})
|
||||
|
||||
it('分类状态下拉:全部/已分类/未分类三档,选中即查回第一页并下发对应参数', async () => {
|
||||
it('不再显示独立分类与分类状态筛选', async () => {
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
|
||||
const selects = wrapper.findAll('.jd-filter-row select')
|
||||
const scopeSelect = selects[1]
|
||||
const optionTexts = scopeSelect.findAll('option').map((o) => o.text())
|
||||
expect(optionTexts).toEqual(['全部', '已分类', '未分类'])
|
||||
|
||||
// 选「已分类」= 只看 group_id 非空的行(分类好的行想单独看时用这一档)
|
||||
await scopeSelect.setValue('grouped')
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupScope: 'grouped', page: 1 })
|
||||
|
||||
// 选「未分类」= 只看 group_id 为空的行(分类好的不显示)
|
||||
await scopeSelect.setValue('ungrouped')
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupScope: 'ungrouped', page: 1 })
|
||||
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(false)
|
||||
})
|
||||
|
||||
it('重置把筛选面回空并回第一页重取', async () => {
|
||||
@@ -565,6 +552,8 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
})
|
||||
|
||||
it('移除分类(2026-11-16 页工具栏):计数只算勾选中已分类的行(未分类行不参与=不白吃人工锁)→ 确认点名数量与人工锁后果 → (ids, null) 调批量归类,成功后刷新并清勾选', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValueOnce([{ id: 7, name: '甲组', sortOrder: 0, productCount: 3 }])
|
||||
.mockResolvedValueOnce([{ id: 7, name: '甲组', sortOrder: 0, productCount: 1 }])
|
||||
const wrapper = await mountWith({
|
||||
items: [item(1), item(2, { groupId: null, groupName: '' }), item(3)],
|
||||
total: 3, page: 1, pageSize: 20,
|
||||
@@ -604,6 +593,9 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
// 成功后重取列表并清勾选:按钮回到置灰。
|
||||
expect(jdApi.fetchJdProductList.mock.calls.length).toBeGreaterThan(1)
|
||||
expect(removeBtn().attributes('disabled')).toBeDefined()
|
||||
await wrapper.find('.cat-trigger').trigger('click')
|
||||
expect(jdApi.fetchJdProductGroups).toHaveBeenCalledTimes(2)
|
||||
expect(wrapper.find('.cat-custom').text()).toContain('甲组(1)')
|
||||
})
|
||||
|
||||
it('移除分类:确认弹窗点取消就不发请求(防误操作的第一道闸)', async () => {
|
||||
@@ -628,90 +620,62 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
expect(document.body.textContent).toContain('分类不存在,请刷新分类后重试')
|
||||
})
|
||||
|
||||
it('店铺分类弹窗(原「管理分组」):打开即拉分类列表与右栏商品行集,变更后刷新分类下拉与列表', async () => {
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
const callsBefore = jdApi.fetchJdProductList.mock.calls.length
|
||||
|
||||
await wrapper.findAll('button').find((b) => b.text() === '店铺分类')!.trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.find('.group-modal').exists()).toBe(true)
|
||||
expect(wrapper.find('.group-modal').text()).toContain('店铺分类', '弹窗标题改「店铺分类」')
|
||||
// 打开弹窗 = 拉一次分类列表(第 2 次:首屏已拉过一次;分类全平台一份、不带公司维度)
|
||||
expect(jdApi.fetchJdProductGroups).toHaveBeenCalledTimes(2)
|
||||
expect(jdApi.fetchJdProductGroups).toHaveBeenLastCalledWith()
|
||||
// 右栏取数复用 fetchJdProductList:不带公司维度(公共库),默认「全部」范围不带 ungrouped=true。
|
||||
const dialogCall = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
||||
expect(dialogCall).not.toHaveProperty('companyId')
|
||||
expect(dialogCall.ungrouped).toBe(false)
|
||||
|
||||
// 模拟分类管理里删了一个分类:emit changed → 页面刷新分类下拉与列表(回第一页)
|
||||
wrapper.findComponent(JdProductGroupDialog).vm.$emit('changed')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.length).toBeGreaterThan(callsBefore)
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ page: 1 })
|
||||
})
|
||||
|
||||
it('店铺分类弹窗:左侧点亮分类→勾选商品→「归入所选分类」按(ids, 目标分类 id)调批量归类', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([
|
||||
{ id: 7, name: '甲组', sortOrder: 0, productCount: 3 },
|
||||
{ id: 8, name: '乙组', sortOrder: 1, productCount: 0 },
|
||||
])
|
||||
jdApi.fetchJdProductList.mockImplementation(() =>
|
||||
Promise.resolve({ items: [item(1), item(2)], total: 2, page: 1, pageSize: 20 }))
|
||||
const wrapper = mount(JdProductGroupDialog, { props: { visible: false }, global: { plugins: [pinia] } })
|
||||
await wrapper.setProps({ visible: true })
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
|
||||
// 左侧点亮「甲组」=归类目标;只点亮还没勾选时按钮仍置灰(归入=目标+勾选两者齐备)。
|
||||
const assignBtn = () => wrapper.findAll('button').find((b) => b.text().includes('归入'))
|
||||
expect(assignBtn()!.attributes('disabled')).toBeDefined()
|
||||
await wrapper.findAll('.group-row')[0].trigger('click')
|
||||
await flushPromises()
|
||||
expect(assignBtn()!.attributes('disabled')).toBeDefined()
|
||||
expect(assignBtn()!.text()).toContain('甲组', '按钮点名归类目标')
|
||||
|
||||
// 勾选两行 → 按钮点亮 → 归入「甲组」。
|
||||
const boxes = wrapper.findAll('tbody input[type="checkbox"]')
|
||||
await boxes[0].setValue(true)
|
||||
await boxes[1].setValue(true)
|
||||
expect(assignBtn()!.attributes('disabled')).toBeUndefined()
|
||||
jdApi.batchAssignJdProductGroup.mockResolvedValue(2)
|
||||
await assignBtn()!.trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
|
||||
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledTimes(1)
|
||||
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1, 2], 7)
|
||||
// 成功后刷新左栏分类数(商品数)与右栏行集,勾选清空。
|
||||
expect(jdApi.fetchJdProductGroups).toHaveBeenCalled()
|
||||
expect(wrapper.findAll('tbody input[type="checkbox"]').every((b) => !(b.element as HTMLInputElement).checked).valueOf()).toBe(true)
|
||||
})
|
||||
|
||||
it('店铺分类弹窗:「未分类」页签走 ungrouped=true 取行集;「移出分类」按(ids, null)调批量归类', async () => {
|
||||
it('归类先提示人工锁,取消不发送请求', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 3 }])
|
||||
jdApi.fetchJdProductList.mockImplementation(() =>
|
||||
Promise.resolve({ items: [item(1, { groupId: null, groupName: '' })], total: 1, page: 1, pageSize: 20 }))
|
||||
const wrapper = mount(JdProductGroupDialog, { props: { visible: false }, global: { plugins: [pinia] } })
|
||||
await wrapper.setProps({ visible: true })
|
||||
await flushPromises()
|
||||
confirmMock.mockResolvedValue(false)
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
await wrapper.find('tbody input[type="checkbox"]').setValue(true)
|
||||
await wrapper.find('[aria-label="选择归入的分类"]').setValue('7')
|
||||
await wrapper.findAll('button').find(b => b.text().includes('归入分类'))!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(confirmMock).toHaveBeenCalledTimes(1)
|
||||
expect(confirmMock.mock.calls[0][0].message).toContain('人工编辑锁')
|
||||
expect(confirmMock.mock.calls[0][0].message).toContain('不再被采集自动覆盖')
|
||||
expect(jdApi.batchAssignJdProductGroup).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
const listCallsBefore = jdApi.fetchJdProductList.mock.calls.length
|
||||
await wrapper.findAll('.scope-tabs button').find((b) => b.text() === '未分类')!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.length).toBe(listCallsBefore + 1, '切「未分类」必须立刻重取')
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ ungrouped: true })
|
||||
|
||||
await wrapper.findAll('tbody input[type="checkbox"]')[0].setValue(true)
|
||||
it('分类增删、筛选切换和勾选归类', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 3 }])
|
||||
jdApi.createJdProductGroup.mockRejectedValueOnce(new Error('分类已存在')).mockResolvedValueOnce({})
|
||||
jdApi.deleteJdProductGroup.mockResolvedValue(undefined)
|
||||
jdApi.batchAssignJdProductGroup.mockResolvedValue(1)
|
||||
await wrapper.findAll('button').find((b) => b.text() === '移出分类')!.trigger('click')
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
await wrapper.find('.cat-trigger').trigger('click')
|
||||
await wrapper.find('[aria-label="新建分类名称"]').setValue('新分类')
|
||||
await wrapper.find('.cat-create').trigger('submit')
|
||||
await flushPromises()
|
||||
expect(document.body.textContent).toContain('分类已存在')
|
||||
expect((wrapper.find('[aria-label="新建分类名称"]').element as HTMLInputElement).value).toBe('新分类')
|
||||
await wrapper.find('.cat-create').trigger('submit')
|
||||
await flushPromises()
|
||||
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1], null)
|
||||
expect(jdApi.createJdProductGroup).toHaveBeenCalledWith({ name: '新分类', sortOrder: 0 })
|
||||
confirmMock.mockResolvedValueOnce(false)
|
||||
await wrapper.find('[aria-label="删除分类 甲组"]').trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.deleteJdProductGroup).not.toHaveBeenCalled()
|
||||
await wrapper.find('.cat-group-pick').trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7', category: '' })
|
||||
await wrapper.find('.cat-trigger').trigger('click')
|
||||
await wrapper.findAll('.cat-col')[0].find('.cat-search').setValue('艺考')
|
||||
await wrapper.find('.cat-col-search .cat-row').trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '', category: '艺考形体服' })
|
||||
await wrapper.find('.cat-trigger').trigger('click')
|
||||
await wrapper.find('.cat-group-pick').trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7', category: '' })
|
||||
await wrapper.find('tbody input[type="checkbox"]').setValue(true)
|
||||
await wrapper.find('[aria-label="选择归入的分类"]').setValue('7')
|
||||
await wrapper.findAll('button').find(b => b.text().includes('归入分类'))!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1], 7)
|
||||
await wrapper.find('.cat-trigger').trigger('click')
|
||||
await wrapper.find('[aria-label="删除分类 甲组"]').trigger('click')
|
||||
await flushPromises()
|
||||
expect(confirmMock.mock.calls.at(-1)![0].message).toContain('商品将保留')
|
||||
expect(jdApi.deleteJdProductGroup).toHaveBeenCalledWith(7)
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].groupId).toBe('')
|
||||
})
|
||||
|
||||
it('空态与加载失败条(失败给重试,不把整页打死)', async () => {
|
||||
|
||||
+10
-6
@@ -71,6 +71,11 @@ import java.util.List;
|
||||
* {@code sale_status} 查询参数同窗撤掉(商品状态筛选框已从前端下线)。店铺筛选参数
|
||||
* {@code shop_name} 同日客户口径「店铺不需要」同窗撤掉(前端筛选框与列下线;DB 列
|
||||
* {@code biz_jd_product.shop_name} 与详情/回传链不动)。</p>
|
||||
*
|
||||
* <p><b>分类并入类目(2026-11-16 用户口径「分类不要了,全部整合到类目里」)</b>:
|
||||
* 分页查询的 {@code ungrouped}/{@code grouped}(分类状态档)整批撤掉;独立「分类」筛选框
|
||||
* 前端下线,{@code group_id} 保留、改由类目面板「自定义分类」选中驱动(存量分组数据由
|
||||
* V201 清空,分组表保留作自定义分类存储)。</p>
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@@ -100,19 +105,18 @@ public class AdminJdProductController {
|
||||
@Parameter(description = "商品编码(包含匹配)") @RequestParam(name = "product_code", required = false) String productCode,
|
||||
@Parameter(description = "标题关键词(包含匹配)") @RequestParam(name = "title_keyword", required = false) String titleKeyword,
|
||||
@Parameter(description = "类目(京麦末级类目名,eq)") @RequestParam(name = "category", required = false) String category,
|
||||
@Parameter(description = "分组 id") @RequestParam(name = "group_id", required = false) Long groupId,
|
||||
@Parameter(description = "只看未分类(group_id IS NULL,店铺分类弹窗「未分类」范围)")
|
||||
@RequestParam(name = "ungrouped", required = false) Boolean ungrouped,
|
||||
@Parameter(description = "只看已分类(group_id IS NOT NULL,页面筛选行「分类状态」档)")
|
||||
@RequestParam(name = "grouped", required = false) Boolean grouped,
|
||||
@Parameter(description = "自定义分类 id(类目面板「自定义分类」选中驱动)") @RequestParam(name = "group_id", required = false) Long groupId,
|
||||
@Parameter(description = "同步开始时间(包含,ISO datetime)")
|
||||
@RequestParam(name = "synced_from", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime syncedFrom,
|
||||
@Parameter(description = "同步结束时间(包含,ISO datetime)")
|
||||
@RequestParam(name = "synced_to", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime syncedTo,
|
||||
HttpServletRequest request) {
|
||||
requireJdAccess(request);
|
||||
if (request.getParameter("grouped") != null || request.getParameter("ungrouped") != null) {
|
||||
throw new BusinessException("页面版本已更新,请刷新页面后重新查询");
|
||||
}
|
||||
return ApiResponse.success(jdProductQueryService.page(page, pageSize,
|
||||
productCode, titleKeyword, category, groupId, ungrouped, grouped, syncedFrom, syncedTo));
|
||||
productCode, titleKeyword, category, groupId, syncedFrom, syncedTo));
|
||||
}
|
||||
|
||||
@GetMapping("/categories")
|
||||
|
||||
@@ -42,19 +42,18 @@ public interface JdProductMapper extends BaseMapper<JdProductEntity> {
|
||||
|
||||
/**
|
||||
* 后管只读页总数(Phase 5,v1.4):与 {@link #selectProductPage} 同一过滤面
|
||||
* (商品编码/标题关键词/类目/分组/未分类/已分类/同步起止,全部 SQL 侧下推,
|
||||
* 铁律 20)。公司维过滤已随 2026-11-16「删除掉公司 tab,参考品牌数据库」撤掉
|
||||
* (商品编码/标题关键词/类目/自定义分类/同步起止,全部 SQL 侧下推,铁律 20)。
|
||||
* 公司维过滤已随 2026-11-16「删除掉公司 tab,参考品牌数据库」撤掉
|
||||
* (数据全平台公共);{@code groupId} 为空或 ≤0=不过滤该面;
|
||||
* {@code ungrouped=true}=只看未分类行(group_id IS NULL,店铺分类弹窗「未分类」范围);
|
||||
* {@code grouped=true}=只看已分类行(group_id IS NOT NULL,页面筛选行「分类状态」档)。
|
||||
* {@code ungrouped}/{@code grouped} 两档(未分类/已分类)已随同日口径
|
||||
* 「分类不要了,全部整合到类目里」撤掉(独立「分类」筛选框前端下线,
|
||||
* {@code groupId} 改由类目面板「自定义分类」选中驱动)。
|
||||
* 店铺名过滤参数已随 2026-11-15 客户口径「店铺不需要」同窗撤掉(DB 列与详情/回传链不动)。
|
||||
*/
|
||||
long countProducts(@Param("productCode") String productCode,
|
||||
@Param("titleKeyword") String titleKeyword,
|
||||
@Param("category") String category,
|
||||
@Param("groupId") Long groupId,
|
||||
@Param("ungrouped") Boolean ungrouped,
|
||||
@Param("grouped") Boolean grouped,
|
||||
@Param("syncedFrom") LocalDateTime syncedFrom,
|
||||
@Param("syncedTo") LocalDateTime syncedTo);
|
||||
|
||||
@@ -94,8 +93,6 @@ public interface JdProductMapper extends BaseMapper<JdProductEntity> {
|
||||
@Param("titleKeyword") String titleKeyword,
|
||||
@Param("category") String category,
|
||||
@Param("groupId") Long groupId,
|
||||
@Param("ungrouped") Boolean ungrouped,
|
||||
@Param("grouped") Boolean grouped,
|
||||
@Param("syncedFrom") LocalDateTime syncedFrom,
|
||||
@Param("syncedTo") LocalDateTime syncedTo,
|
||||
@Param("offset") long offset,
|
||||
|
||||
+14
-19
@@ -75,15 +75,15 @@ public class JdProductQueryService {
|
||||
/**
|
||||
* 分页查询商品行({@code synced_at} 倒序)。
|
||||
*
|
||||
* <p>过滤面:商品编码 contains、标题关键词 contains、类目 eq、分组 eq、
|
||||
* 未分类(group_id IS NULL,店铺分类弹窗「未分类」范围)、
|
||||
* 已分类(group_id IS NOT NULL,页面筛选行「分类状态」档,2026-11-15 客户口径
|
||||
* 「查询已分类的跟未分类,分类好的可以不显示」)、同步起止(datetime 闭区间)。
|
||||
* <p>过滤面:商品编码 contains、标题关键词 contains、类目 eq、分组 eq(2026-11-16 起
|
||||
* 由类目面板「自定义分类」选中驱动)、同步起止(datetime 闭区间)。
|
||||
* 未分类/已分类两档(ungrouped/grouped)与独立「分类」筛选框随同日口径
|
||||
* 「分类不要了,全部整合到类目里」整批撤掉。
|
||||
* 公司维过滤已随 2026-11-16 摘公司 tab 整批撤掉(全平台公共)。</p>
|
||||
*/
|
||||
public JdProductPageVo page(Long page, Long pageSize,
|
||||
String productCode, String titleKeyword, String category, Long groupId, Boolean ungrouped,
|
||||
Boolean grouped, LocalDateTime syncedFrom, LocalDateTime syncedTo) {
|
||||
String productCode, String titleKeyword, String category, Long groupId,
|
||||
LocalDateTime syncedFrom, LocalDateTime syncedTo) {
|
||||
if (syncedFrom != null && syncedTo != null && syncedFrom.isAfter(syncedTo)) {
|
||||
throw new BusinessException("开始时间不能晚于结束时间");
|
||||
}
|
||||
@@ -91,14 +91,14 @@ public class JdProductQueryService {
|
||||
long safeSize = pageSize == null ? PageDefaults.JD_PRODUCTS_PAGE_SIZE_INT
|
||||
: Math.min(Math.max(pageSize, 1), MAX_PAGE_SIZE);
|
||||
Filter filter = filter(productCode, titleKeyword, category,
|
||||
groupId, ungrouped, grouped, syncedFrom, syncedTo);
|
||||
groupId, syncedFrom, syncedTo);
|
||||
long total = jdProductMapper.countProducts(filter.productCode(),
|
||||
filter.titleKeyword(), filter.category(), filter.groupId(), filter.ungrouped(),
|
||||
filter.grouped(), filter.syncedFrom(), filter.syncedTo());
|
||||
filter.titleKeyword(), filter.category(), filter.groupId(),
|
||||
filter.syncedFrom(), filter.syncedTo());
|
||||
List<JdProductEntity> rows = total <= 0 ? List.of()
|
||||
: jdProductMapper.selectProductPage(filter.productCode(),
|
||||
filter.titleKeyword(), filter.category(), filter.groupId(), filter.ungrouped(),
|
||||
filter.grouped(), filter.syncedFrom(), filter.syncedTo(),
|
||||
filter.titleKeyword(), filter.category(), filter.groupId(),
|
||||
filter.syncedFrom(), filter.syncedTo(),
|
||||
(safePage - 1) * safeSize, (int) safeSize);
|
||||
List<JdProductListItemVo> items = rows.stream().map(this::toListItem).toList();
|
||||
fillGroupNames(items);
|
||||
@@ -175,21 +175,16 @@ public class JdProductQueryService {
|
||||
|
||||
/** 服务侧过滤面归一:groupId ≤0 按没选处理,文本 trim 后空串归 null(无公司维,2026-11-16 摘)。 */
|
||||
private record Filter(String productCode, String titleKeyword,
|
||||
String category, Long groupId, Boolean ungrouped, Boolean grouped,
|
||||
String category, Long groupId,
|
||||
LocalDateTime syncedFrom, LocalDateTime syncedTo) {
|
||||
}
|
||||
|
||||
private static Filter filter(String productCode, String titleKeyword,
|
||||
String category, Long groupId, Boolean ungrouped, Boolean grouped,
|
||||
String category, Long groupId,
|
||||
LocalDateTime syncedFrom, LocalDateTime syncedTo) {
|
||||
Long safeGroupId = groupId != null && groupId > 0 ? groupId : null;
|
||||
// 未分类与其它过滤面同口径:没显式要(true)=null=不进 IS NULL 分支。
|
||||
Boolean safeUngrouped = Boolean.TRUE.equals(ungrouped) ? Boolean.TRUE : null;
|
||||
// 已分类同口径:true=只看 group_id IS NOT NULL 的行;与未分类同选时 SQL 侧两谓词相与=空集
|
||||
// (前端下拉是单选,正常到不了这个组合)。
|
||||
Boolean safeGrouped = Boolean.TRUE.equals(grouped) ? Boolean.TRUE : null;
|
||||
return new Filter(trimToNull(productCode), trimToNull(titleKeyword),
|
||||
trimToNull(category), safeGroupId, safeUngrouped, safeGrouped, syncedFrom, syncedTo);
|
||||
trimToNull(category), safeGroupId, syncedFrom, syncedTo);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 列表/详情搬运
|
||||
|
||||
+5
-39
@@ -44,11 +44,8 @@ import java.util.Set;
|
||||
* statObject 对撞落 {@code biz_jd_product_image},唯一出口
|
||||
* {@link JdProductImageIngestService#registerTaskImages})→
|
||||
* scope 台账合并写(断点游标 + 批次号 + 累计行数)→
|
||||
* {@code isEnd=true} 时任务落 SUCCESS 并执行<b>覆盖清理</b>:同一店铺里本次没采到、
|
||||
* 所属任务已不在在飞的旧行整行删掉(用户拍板 2026-11-15:重爬同一店铺直接覆盖旧数据)。
|
||||
* 清理只在收尾时做且本次 {@code itemsReceived=0} 不清(B94-01 教训:载荷读不准的空回传
|
||||
* 不得抹掉存量),在飞任务(PENDING/RUNNING)的行不动,删除本体走
|
||||
* {@link JdProductRowDeleteService#deleteRows}(SKU/图片行级联)。</p>
|
||||
* {@code isEnd=true} 时任务落 SUCCESS;由于现有回传不能证明分页完整,暂不执行覆盖清理,
|
||||
* 保留历史商品并记录警告。
|
||||
*
|
||||
* <p>回传 payload 键集契约({@code JdIngestPayloadContractTest} 绊线钉住):顶层
|
||||
* {@code batchId / cursor / items / isEnd}(+ {@code error} 失败上报),行内
|
||||
@@ -168,7 +165,9 @@ public class JdResultIngestService {
|
||||
int itemsReceived = mergeScopeState(scope, request, request.getItems() == null ? 0 : request.getItems().size());
|
||||
if (Boolean.TRUE.equals(request.getIsEnd())) {
|
||||
finalizeSuccess(task, itemsReceived);
|
||||
purgeSupersededRows(task, companyId, itemsReceived);
|
||||
// 客户端缺少可验证的完整分页回执,不能据此删除未回传的旧商品。
|
||||
log.warn("[{}] 缺少全店分页完整性证明,跳过覆盖清理 taskId={} itemsReceived={}",
|
||||
LOG_TAG, task.getId(), itemsReceived);
|
||||
}
|
||||
JdIngestChunkVo vo = new JdIngestChunkVo();
|
||||
vo.setAccept(true);
|
||||
@@ -235,39 +234,6 @@ public class JdResultIngestService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 覆盖清理(用户拍板 2026-11-15:重爬同一店铺直接覆盖旧数据,采集完成时清)。
|
||||
*
|
||||
* <p>只清「本次没采到」的旧行:同公司、同店铺(shop_id 取本任务落过的行)、
|
||||
* task_id 不是本任务、且所属任务已不在在飞的行(在飞任务如 PENDING/RUNNING 的行不动,
|
||||
* 同店铺并发两单时先收尾的单不得抹掉仍在跑的单的行,后收尾的单会在自己的收尾时清)。
|
||||
* 删除本体走 {@link JdProductRowDeleteService#deleteRows}(SKU/图片行级联,同一事务)。</p>
|
||||
*
|
||||
* <p>两条护栏:① 本次 {@code itemsReceived=0} 不清(B94-01 教训——载荷读不准的空回传
|
||||
* 一旦清库=存量整库抹掉);② 清理失败不推翻采集结果(新数据已完整落库且任务已落
|
||||
* SUCCESS),但必须留痕不静默:error 日志+scope 台账记 lastError。</p>
|
||||
*/
|
||||
private void purgeSupersededRows(FileTaskEntity task, Long companyId, int itemsReceived) {
|
||||
if (itemsReceived <= 0) {
|
||||
log.warn("[{}] 收尾回传 0 行,跳过覆盖清理(B94-01:不清旧) taskId={}", LOG_TAG, task.getId());
|
||||
return;
|
||||
}
|
||||
try {
|
||||
List<Long> staleIds = jdProductMapper.selectSupersededProductIds(companyId, task.getId());
|
||||
if (staleIds.isEmpty()) {
|
||||
log.info("[{}] 覆盖清理无候选行(本次已覆盖全部旧行) taskId={}", LOG_TAG, task.getId());
|
||||
return;
|
||||
}
|
||||
int deleted = jdProductRowDeleteService.deleteRows(staleIds);
|
||||
log.info("[{}] 覆盖清理完成:本次没采到的旧行已删 taskId={} candidates={} deleted={}",
|
||||
LOG_TAG, task.getId(), staleIds.size(), deleted);
|
||||
} catch (Exception ex) {
|
||||
log.error("[{}] 覆盖清理失败(本次采集数据已完整落库,仅旧数据未清,可重爬一次补清) taskId={}",
|
||||
LOG_TAG, task.getId(), ex);
|
||||
recordLastError(task.getId(), "覆盖清理失败(本次采集数据已完整落库,仅旧数据未清,可重爬一次补清)");
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- V199 保护闸:人工编辑锁与删除忽略 ----------
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
-- 清空旧的京东自定义分类,商品保留。备份分类及商品原归属以支持人工恢复。
|
||||
-- 必须停止所有实例的分类及商品归属写入,等待在途事务结束,直至迁移与核对完成。
|
||||
-- 备份表已存在时立即失败,不覆盖或复用未知备份;失败后须先人工检查源表和备份表。
|
||||
CREATE TABLE biz_jd_product_group_v201_backup LIKE biz_jd_product_group;
|
||||
INSERT INTO biz_jd_product_group_v201_backup (id, company_id, name, sort_order, created_at, updated_at)
|
||||
SELECT id, company_id, name, sort_order, created_at, updated_at FROM biz_jd_product_group;
|
||||
|
||||
CREATE TABLE biz_jd_product_group_assignment_v201_backup (
|
||||
product_id BIGINT NOT NULL PRIMARY KEY,
|
||||
group_id BIGINT NOT NULL
|
||||
) ENGINE=InnoDB;
|
||||
INSERT INTO biz_jd_product_group_assignment_v201_backup (product_id, group_id)
|
||||
SELECT id, group_id FROM biz_jd_product WHERE group_id IS NOT NULL;
|
||||
|
||||
UPDATE biz_jd_product SET group_id = NULL WHERE group_id IS NOT NULL;
|
||||
DELETE FROM biz_jd_product_group;
|
||||
|
||||
-- 人工回滚前停止所有分类及商品归属写入,核对主键、分类名、缺失商品、已重新归类
|
||||
-- 商品与孤儿归属;有冲突须先人工处理。以下只恢复到 V200 后的状态,不能还原 V200
|
||||
-- 已合并的历史同名分类。MySQL DDL 会隐式提交,失败后应先检查源表、备份表及
|
||||
-- flyway_schema_history;Flyway repair 不会回滚数据。
|
||||
-- INSERT INTO biz_jd_product_group (id, company_id, name, sort_order, created_at, updated_at)
|
||||
-- SELECT id, company_id, name, sort_order, created_at, updated_at FROM biz_jd_product_group_v201_backup;
|
||||
-- UPDATE biz_jd_product p JOIN biz_jd_product_group_assignment_v201_backup b ON b.product_id = p.id
|
||||
-- SET p.group_id = b.group_id WHERE p.group_id IS NULL;
|
||||
@@ -101,9 +101,9 @@
|
||||
</select>
|
||||
|
||||
<!-- 后管只读页(Phase 5,v1.4)过滤面:商品编码/标题关键词(contains LIKE)、类目 eq、
|
||||
分组 eq、未分类(group_id IS NULL,店铺分类弹窗「未分类」范围)、已分类
|
||||
(group_id IS NOT NULL,页面筛选行「分类状态」档,2026-11-15 客户口径
|
||||
「查询已分类的跟未分类,分类好的可以不显示」)、同步起止(datetime 闭区间)。
|
||||
分组 eq(2026-11-16 起由类目面板「自定义分类」选中驱动,独立「分类」筛选框与
|
||||
「分类状态」档随同日口径「分类不要了,全部整合到类目里」撤掉:ungrouped/grouped
|
||||
两参数与谓词同窗删除)、同步起止(datetime 闭区间)。
|
||||
公司维过滤随 2026-11-16「删除掉公司 tab,参考品牌数据库」撤掉(数据全平台公共;
|
||||
行 company_id 列仍是同步来源标记,不构成可见性边界)。
|
||||
sale_status 筛选随 2026-11-15 客户口径撤掉;店铺名过滤同日客户口径「店铺不需要」
|
||||
@@ -114,8 +114,6 @@
|
||||
<if test="titleKeyword != null and titleKeyword != ''">AND p.title LIKE CONCAT('%', #{titleKeyword}, '%')</if>
|
||||
<if test="category != null and category != ''">AND p.category_path = #{category}</if>
|
||||
<if test="groupId != null and groupId > 0">AND p.group_id = #{groupId}</if>
|
||||
<if test="ungrouped != null and ungrouped">AND p.group_id IS NULL</if>
|
||||
<if test="grouped != null and grouped">AND p.group_id IS NOT NULL</if>
|
||||
<if test="syncedFrom != null">AND p.synced_at >= #{syncedFrom}</if>
|
||||
<if test="syncedTo != null">AND p.synced_at <= #{syncedTo}</if>
|
||||
</sql>
|
||||
|
||||
+54
-45
@@ -132,9 +132,11 @@ class AdminJdProductControllerTest {
|
||||
void 分页参数snake且带默认值() throws IOException {
|
||||
String source = stripComments(Files.readString(CONTROLLER));
|
||||
for (String param : List.of("page_size", "product_code", "title_keyword",
|
||||
"group_id", "ungrouped", "grouped", "synced_from", "synced_to")) {
|
||||
"group_id", "synced_from", "synced_to")) {
|
||||
assertTrue(source.contains(param), "查询参数必须 snake_case:" + param);
|
||||
}
|
||||
assertFalse(source.contains("@RequestParam(name = \"ungrouped\""));
|
||||
assertFalse(source.contains("@RequestParam(name = \"grouped\""));
|
||||
// company_id 参数已随 2026-11-16「删除掉公司 tab」整批摘除(读侧零公司维度支另有反向钉)。
|
||||
assertFalse(source.contains("company_id"), "company_id 请求参数必须已删除,不得回潜");
|
||||
// 商品状态筛选框已随 2026-11-15 客户口径从前端下线 ⇒ 服务端同名参数一起撤(反向钉住防回潜)。
|
||||
@@ -155,9 +157,14 @@ class AdminJdProductControllerTest {
|
||||
assertTrue(mapperSource.contains("@Mapper"), "mapper 接口必须带 @Mapper");
|
||||
Path xml = findJdProductMapperXml();
|
||||
assertNotNull(xml, "mapper XML 必须落在 src/main/resources/mapper/**(铁律 1)");
|
||||
String xmlText = stripComments(Files.readString(xml));
|
||||
String xmlText = stripComments(Files.readString(xml)).replaceAll("(?s)<!--.*?-->", "");
|
||||
assertTrue(xmlText.contains("countProducts"), "XML 必须有 countProducts(只读页总数)");
|
||||
assertTrue(xmlText.contains("selectProductPage"), "XML 必须有 selectProductPage(只读页分页)");
|
||||
assertTrue(xmlText.contains("AND p.group_id = #{groupId}"), "自定义分类必须下推 SQL");
|
||||
assertFalse(xmlText.contains("ungrouped"));
|
||||
assertFalse(xmlText.contains("grouped"));
|
||||
assertEquals(2, xmlText.split("<include refid=\"productConds\"", -1).length - 1,
|
||||
"计数和分页必须复用同一过滤条件");
|
||||
assertFalse(xmlText.contains("LIMIT #{page}"),
|
||||
"分页只收服务钳制后的 offset/limit,绝不 LIMIT #{page} 直拼(铁律 15)");
|
||||
assertTrue(xmlText.contains("ORDER BY p.synced_at DESC, p.id DESC"),
|
||||
@@ -201,17 +208,42 @@ class AdminJdProductControllerTest {
|
||||
pageVo.setTotal(0L);
|
||||
pageVo.setPage(1L);
|
||||
pageVo.setPageSize((long) PageDefaults.JD_PRODUCTS_PAGE_SIZE_INT);
|
||||
when(queryService.page(1L, 20L, null, null, null, null, null, null, null, null)).thenReturn(pageVo);
|
||||
when(queryService.page(1L, 20L, null, null, null, null, null, null)).thenReturn(pageVo);
|
||||
|
||||
// 2026-11-16 起请求面没有 company_id:任何授权身份看到的都是同一份全量。
|
||||
ApiResponse<JdProductPageVo> response = controller.page(1L, 20L, null, null, null, null, null,
|
||||
null, null, null, request);
|
||||
null, request);
|
||||
|
||||
verify(queryService).page(1L, 20L, null, null, null, null, null, null, null, null);
|
||||
verify(queryService).page(1L, 20L, null, null, null, null, null, null);
|
||||
assertEquals(Boolean.TRUE, response.isSuccess(), "拒绝走 403 业务码,放行必须是 success 信封(B80-03)");
|
||||
assertEquals(pageVo, response.getData());
|
||||
}
|
||||
|
||||
@Test
|
||||
void 旧分类筛选参数明确拒绝并提示刷新() {
|
||||
JdProductQueryService queryService = mock(JdProductQueryService.class);
|
||||
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
|
||||
AdminJdProductController controller = new AdminJdProductController(
|
||||
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class),
|
||||
authSupport, mock(PermissionMenuService.class));
|
||||
AdminUserEntity operator = new AdminUserEntity();
|
||||
operator.setId(7L);
|
||||
HttpServletRequest request = mock(HttpServletRequest.class);
|
||||
when(authSupport.requireUser(request)).thenReturn(operator);
|
||||
when(authSupport.currentRole(operator)).thenReturn("super_admin");
|
||||
|
||||
for (String name : List.of("grouped", "ungrouped")) {
|
||||
for (String value : List.of("true", "false", "")) {
|
||||
when(request.getParameter(name)).thenReturn(value);
|
||||
BusinessException ex = assertThrows(BusinessException.class,
|
||||
() -> controller.page(1L, 20L, null, null, null, 7L, null, null, request));
|
||||
assertTrue(ex.getMessage().contains("刷新页面"));
|
||||
when(request.getParameter(name)).thenReturn(null);
|
||||
}
|
||||
}
|
||||
verify(queryService, never()).page(any(), any(), any(), any(), any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void 类目下拉端点走同一鉴权正门并回全平台选项集() {
|
||||
JdProductQueryService queryService = mock(JdProductQueryService.class);
|
||||
@@ -321,23 +353,23 @@ class AdminJdProductControllerTest {
|
||||
JdProductQueryService service = new JdProductQueryService(mapper, mock(JdProductImageMapper.class),
|
||||
mock(com.nanri.aiimage.modules.jd.mapper.JdProductSkuMapper.class),
|
||||
mock(com.nanri.aiimage.modules.jd.mapper.JdProductGroupMapper.class));
|
||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(1L);
|
||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any())).thenReturn(1L);
|
||||
|
||||
// page=0 / size=null ⇒ 归一为第 1 页、默认 20 条;offset = 0。
|
||||
service.page(0L, null, null, null, null, null, null, null, null, null);
|
||||
service.page(0L, null, null, null, null, null, null, null);
|
||||
ArgumentCaptor<Long> offset = ArgumentCaptor.forClass(Long.class);
|
||||
ArgumentCaptor<Integer> limit = ArgumentCaptor.forClass(Integer.class);
|
||||
verify(mapper).selectProductPage(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(),
|
||||
isNull(), isNull(), offset.capture(), limit.capture());
|
||||
offset.capture(), limit.capture());
|
||||
assertEquals(0L, offset.getValue());
|
||||
assertEquals(PageDefaults.JD_PRODUCTS_PAGE_SIZE_INT, limit.getValue());
|
||||
|
||||
// page=Long.MAX_VALUE / size=500 ⇒ 钳到 10_000 页、100 条;乘积 999_900 不得变负(铁律 15)。
|
||||
service.page(Long.MAX_VALUE, 500L, null, null, null, null, null, null, null, null);
|
||||
service.page(Long.MAX_VALUE, 500L, null, null, null, null, null, null);
|
||||
ArgumentCaptor<Long> offsetMax = ArgumentCaptor.forClass(Long.class);
|
||||
ArgumentCaptor<Integer> limitMax = ArgumentCaptor.forClass(Integer.class);
|
||||
verify(mapper, times(2)).selectProductPage(any(), any(), any(), any(), any(), any(),
|
||||
any(), any(), offsetMax.capture(), limitMax.capture());
|
||||
offsetMax.capture(), limitMax.capture());
|
||||
assertEquals(999_900L, offsetMax.getValue(), "(page-1)*page_size 最大 999_900,钳制后不得溢出变负");
|
||||
assertEquals(100, limitMax.getValue());
|
||||
}
|
||||
@@ -351,9 +383,9 @@ class AdminJdProductControllerTest {
|
||||
LocalDateTime from = LocalDateTime.of(2026, 11, 14, 12, 0);
|
||||
LocalDateTime to = LocalDateTime.of(2026, 11, 14, 8, 0);
|
||||
BusinessException ex = assertThrows(BusinessException.class,
|
||||
() -> service.page(1L, 20L, null, null, null, null, null, null, from, to));
|
||||
() -> service.page(1L, 20L, null, null, null, null, from, to));
|
||||
assertTrue(ex.getMessage().contains("开始时间不能晚于结束时间"), "倒挂时间按业务异常拒绝");
|
||||
verify(mapper, never()).countProducts(any(), any(), any(), any(), any(), any(), any(), any());
|
||||
verify(mapper, never()).countProducts(any(), any(), any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -362,37 +394,14 @@ class AdminJdProductControllerTest {
|
||||
JdProductQueryService service = new JdProductQueryService(mapper, mock(JdProductImageMapper.class),
|
||||
mock(com.nanri.aiimage.modules.jd.mapper.JdProductSkuMapper.class),
|
||||
mock(com.nanri.aiimage.modules.jd.mapper.JdProductGroupMapper.class));
|
||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(0L);
|
||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any())).thenReturn(1L);
|
||||
service.page(1L, 20L, " SKU-1 ", " 连衣裙 ", " 艺考形体服 ", 7L, null, null);
|
||||
verify(mapper).countProducts("SKU-1", "连衣裙", "艺考形体服", 7L, null, null);
|
||||
verify(mapper).selectProductPage("SKU-1", "连衣裙", "艺考形体服", 7L, null, null, 0L, 20);
|
||||
|
||||
// groupId ≤0 按没选分组处理;文本两侧空白剥掉。
|
||||
// 类目(京麦末级类目名)走同一过滤面:传值原样直传、空白归 null。
|
||||
service.page(1L, 20L, " SKU-1 ", " 连衣裙 ", " 艺考形体服 ", 0L, null, null, null, null);
|
||||
verify(mapper).countProducts(eq("SKU-1"), eq("连衣裙"),
|
||||
eq("艺考形体服"), isNull(), isNull(), isNull(), isNull(), isNull());
|
||||
// 全量口径(2026-11-16 起读侧无公司维)⇒ 过滤面全 null。
|
||||
service.page(1L, 20L, null, null, null, null, null, null, null, null);
|
||||
verify(mapper).countProducts(isNull(), isNull(), isNull(), isNull(), isNull(),
|
||||
isNull(), isNull(), isNull());
|
||||
|
||||
// 未分类范围(店铺分类弹窗「未分类」页签):ungrouped=true 原样下推到 SQL 侧。
|
||||
service.page(1L, 20L, null, null, null, null, Boolean.TRUE, null, null, null);
|
||||
verify(mapper).countProducts(isNull(), isNull(), isNull(), isNull(), eq(Boolean.TRUE),
|
||||
isNull(), isNull(), isNull());
|
||||
// ungrouped=false / 缺省按不过滤处理(Filter 归一成 null,不进 IS NULL 分支);
|
||||
// 与②「全量」那发同形状,累计 2 次。
|
||||
service.page(1L, 20L, null, null, null, null, Boolean.FALSE, null, null, null);
|
||||
verify(mapper, times(2)).countProducts(isNull(), isNull(), isNull(), isNull(), isNull(),
|
||||
isNull(), isNull(), isNull());
|
||||
|
||||
// 已分类档(页面筛选行「分类状态」=已分类,2026-11-15 客户口径「分类好的可以不显示」反选):
|
||||
// grouped=true 原样下推到 SQL 侧(group_id IS NOT NULL),ungrouped 不动。
|
||||
service.page(1L, 20L, null, null, null, null, null, Boolean.TRUE, null, null);
|
||||
verify(mapper).countProducts(isNull(), isNull(), isNull(), isNull(), isNull(),
|
||||
eq(Boolean.TRUE), isNull(), isNull());
|
||||
// grouped=false / 缺省同口径归一成 null(不进 IS NOT NULL 分支);与②「全量」累计 3 次。
|
||||
service.page(1L, 20L, null, null, null, null, null, Boolean.FALSE, null, null);
|
||||
verify(mapper, times(3)).countProducts(isNull(), isNull(), isNull(), isNull(), isNull(),
|
||||
isNull(), isNull(), isNull());
|
||||
service.page(1L, 20L, " ", null, null, 0L, null, null);
|
||||
verify(mapper).countProducts(null, null, null, null, null, null);
|
||||
verify(mapper).selectProductPage(null, null, null, null, null, null, 0L, 20);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -591,8 +600,8 @@ class AdminJdProductControllerTest {
|
||||
grouped.setGroupId(3L);
|
||||
JdProductEntity missing = productEntity(2L);
|
||||
missing.setGroupId(99L);
|
||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(2L);
|
||||
when(mapper.selectProductPage(any(), any(), any(), any(), any(), any(), any(), any(),
|
||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any())).thenReturn(2L);
|
||||
when(mapper.selectProductPage(any(), any(), any(), any(), any(), any(),
|
||||
anyLong(), anyInt())).thenReturn(List.of(grouped, missing));
|
||||
com.nanri.aiimage.modules.jd.model.entity.JdProductGroupEntity group =
|
||||
new com.nanri.aiimage.modules.jd.model.entity.JdProductGroupEntity();
|
||||
@@ -600,7 +609,7 @@ class AdminJdProductControllerTest {
|
||||
group.setName("秋冬款");
|
||||
when(groupMapper.selectBatchIds(any())).thenReturn(List.of(group));
|
||||
|
||||
JdProductPageVo vo = service.page(1L, 20L, null, null, null, null, null, null, null, null);
|
||||
JdProductPageVo vo = service.page(1L, 20L, null, null, null, null, null, null);
|
||||
|
||||
assertEquals("秋冬款", vo.getItems().get(0).getGroupName(), "行集 group_id 一次取齐分组名(无逐行查询)");
|
||||
assertNull(vo.getItems().get(1).getGroupName(), "分组已删=不猜名字(铁律 30),前端展示 -");
|
||||
|
||||
+34
-31
@@ -377,26 +377,49 @@ class JdProductSyncServiceTest {
|
||||
|
||||
// ---------- 覆盖清理(2026-11-15 用户拍板:重爬同一店铺,采集完成时清掉旧数据) ----------
|
||||
|
||||
private JdCollectTaskCreateRequest fullShopRequest() {
|
||||
JdCollectTaskCreateRequest request = createRequest();
|
||||
request.setListTabs(List.of("ONSALE", "OFFSALE"));
|
||||
request.setMaxProducts(0);
|
||||
return request;
|
||||
}
|
||||
|
||||
@Test
|
||||
void 成功收尾后清掉本次没采到的旧行() {
|
||||
void 非完整店铺采集收尾不得查询或删除其他商品() {
|
||||
stubHappyPath();
|
||||
JdCollectTaskCreateRequest singleTab = createRequest();
|
||||
JdCollectTaskCreateRequest category = fullShopRequest();
|
||||
category.setCategoryPaths(List.of("女装"));
|
||||
JdCollectTaskCreateRequest limited = fullShopRequest();
|
||||
limited.setMaxProducts(10);
|
||||
JdCollectTaskCreateRequest missingTabs = fullShopRequest();
|
||||
missingTabs.setListTabs(null);
|
||||
JdCollectTaskCreateRequest invalidLimit = fullShopRequest();
|
||||
invalidLimit.setMaxProducts(-1);
|
||||
|
||||
for (JdCollectTaskCreateRequest config : List.of(singleTab, category, limited, missingTabs, invalidLimit)) {
|
||||
when(collectTaskService.readCreateRequest(any(FileTaskEntity.class))).thenReturn(config);
|
||||
JdIngestChunkRequest request = chunk(item("10036442942137", "艺考形体服女"));
|
||||
request.setIsEnd(true);
|
||||
assertThat(service.submitChunk(TASK_ID, request, true).isAccept()).isTrue();
|
||||
}
|
||||
verify(jdProductMapper, never()).selectSupersededProductIds(any(), any());
|
||||
verify(jdProductRowDeleteService, never()).deleteRows(anyList());
|
||||
}
|
||||
|
||||
@Test
|
||||
void 全店请求完成但缺少分页完整性证明时不清旧行() {
|
||||
stubHappyPath();
|
||||
when(collectTaskService.readCreateRequest(any(FileTaskEntity.class))).thenReturn(fullShopRequest());
|
||||
when(fileTaskMapper.update(isNull(), any(LambdaUpdateWrapper.class))).thenReturn(1);
|
||||
// 同店铺旧行:上次采集落的、本次没采到的商品行
|
||||
when(jdProductMapper.selectSupersededProductIds(COMPANY_ID, TASK_ID)).thenReturn(List.of(901L, 902L));
|
||||
when(jdProductRowDeleteService.deleteRows(anyList())).thenReturn(2);
|
||||
JdIngestChunkRequest request = chunk(item("10036442942137", "艺考形体服女"));
|
||||
request.setIsEnd(true);
|
||||
|
||||
JdIngestChunkVo vo = service.submitChunk(TASK_ID, request, true);
|
||||
|
||||
assertThat(vo.isAccept()).isTrue();
|
||||
// 删除走行级联唯一出口(SKU/图片行随删),候选 id 原样透传
|
||||
verify(jdProductRowDeleteService).deleteRows(List.of(901L, 902L));
|
||||
// 删除只发生在收尾之后:先落库,后清理
|
||||
org.mockito.InOrder order = inOrder(jdProductMapper, jdProductRowDeleteService);
|
||||
order.verify(jdProductMapper).upsertBatch(anyList());
|
||||
order.verify(jdProductMapper).selectSupersededProductIds(COMPANY_ID, TASK_ID);
|
||||
order.verify(jdProductRowDeleteService).deleteRows(anyList());
|
||||
verify(jdProductMapper, never()).selectSupersededProductIds(any(), any());
|
||||
verify(jdProductRowDeleteService, never()).deleteRows(anyList());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -428,26 +451,6 @@ class JdProductSyncServiceTest {
|
||||
verify(jdProductRowDeleteService, never()).deleteRows(anyList());
|
||||
}
|
||||
|
||||
@Test
|
||||
void 覆盖清理失败不推翻回执且台账留痕() {
|
||||
stubHappyPath();
|
||||
when(fileTaskMapper.update(isNull(), any(LambdaUpdateWrapper.class))).thenReturn(1);
|
||||
when(jdProductMapper.selectSupersededProductIds(COMPANY_ID, TASK_ID))
|
||||
.thenThrow(new RuntimeException("db down"));
|
||||
JdIngestChunkRequest request = chunk(item("10036442942137", "艺考形体服女"));
|
||||
request.setIsEnd(true);
|
||||
|
||||
JdIngestChunkVo vo = service.submitChunk(TASK_ID, request, true);
|
||||
|
||||
// 新数据已完整落库且任务已 SUCCESS:清理失败不改回执、不炸整批,但必须留痕不静默
|
||||
assertThat(vo.isAccept()).isTrue();
|
||||
verify(jdProductRowDeleteService, never()).deleteRows(anyList());
|
||||
ArgumentCaptor<TaskScopeStateEntity> scopeCaptor = ArgumentCaptor.forClass(TaskScopeStateEntity.class);
|
||||
verify(taskScopeStateMapper, times(2)).updateById(scopeCaptor.capture());
|
||||
assertThat(scopeCaptor.getAllValues().stream().map(TaskScopeStateEntity::getStateJson))
|
||||
.anySatisfy(json -> assertThat(json).contains("覆盖清理失败"));
|
||||
}
|
||||
|
||||
// ---------- V199 保护闸:人工编辑锁与删除忽略 ----------
|
||||
|
||||
@Test
|
||||
|
||||
@@ -442,7 +442,7 @@ onUnmounted(() => {
|
||||
</div>
|
||||
|
||||
<div class="category-block">
|
||||
<span class="category-label">店铺分类(管理员维护,只读)</span>
|
||||
<span class="category-label">自定义分类</span>
|
||||
<p v-if="groupList.length" class="group-chips">
|
||||
<span v-for="group in groupList" :key="group.id" class="group-chip"
|
||||
:title="`${group.name}:${group.productCount} 个商品`">
|
||||
@@ -450,7 +450,7 @@ onUnmounted(() => {
|
||||
</span>
|
||||
</p>
|
||||
<p v-else class="category-hint">
|
||||
后台还没建店铺分类;管理员在「京东数据库 → 店铺分类」里建的会显示在这里。
|
||||
后台还没建自定义分类;管理员可在「京东数据库」的类目面板中新建自定义分类,建好后会显示在这里。
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -69,8 +69,8 @@ test('endpoints 注册店铺分类 groups 只读端点,页面加载并只读
|
||||
)
|
||||
assert.ok(page.includes('fetchJdCollectGroups'),
|
||||
'JdCollectTab.vue 必须调 fetchJdCollectGroups(普通账号在这里看到管理员建的分类)')
|
||||
assert.ok(page.includes('店铺分类(管理员维护,只读)'),
|
||||
'JdCollectTab.vue 必须有「店铺分类」只读展示块(口径点名「管理员维护,只读」)')
|
||||
assert.ok(page.includes('自定义分类</span>'),
|
||||
'JdCollectTab.vue 必须以「自定义分类」展示分类块')
|
||||
})
|
||||
|
||||
test('建单请求体与推送载荷都带 categoryPaths', () => {
|
||||
|
||||
@@ -332,9 +332,9 @@ describe('获取店铺数据:一键采集 + 任务面板', () => {
|
||||
const w = await mountPage()
|
||||
|
||||
expect(api.fetchJdCollectGroups).toHaveBeenCalledTimes(1)
|
||||
const block = w.findAll('.category-block').find((el) => el.text().includes('店铺分类'))
|
||||
expect(block, '必须有「店铺分类」展示块').toBeTruthy()
|
||||
expect(block!.text()).toContain('店铺分类(管理员维护,只读)')
|
||||
const block = w.findAll('.category-block').find((el) => el.text().includes('自定义分类'))
|
||||
expect(block, '必须有「自定义分类」展示块').toBeTruthy()
|
||||
expect(block!.text()).toContain('自定义分类')
|
||||
const chips = block!.findAll('.group-chip')
|
||||
expect(chips.length).toBe(2)
|
||||
expect(chips[0].text()).toContain('ASSS(20)')
|
||||
@@ -345,10 +345,11 @@ describe('获取店铺数据:一键采集 + 任务面板', () => {
|
||||
it('后台还没建分类:只读块落空态提示,采集主路照常', async () => {
|
||||
const w = await mountPage()
|
||||
|
||||
const block = w.findAll('.category-block').find((el) => el.text().includes('店铺分类'))
|
||||
expect(block, '空态也要有「店铺分类」块(不能整块消失让用户以为没这功能)').toBeTruthy()
|
||||
expect(block!.text()).toContain('后台还没建店铺分类')
|
||||
expect(block!.text()).toContain('管理员在「京东数据库 → 店铺分类」里建的会显示在这里')
|
||||
const block = w.findAll('.category-block').find((el) => el.text().includes('自定义分类'))
|
||||
expect(block, '空态也要有「自定义分类」块(不能整块消失让用户以为没这功能)').toBeTruthy()
|
||||
expect(block!.text()).toContain('后台还没建自定义分类')
|
||||
expect(block!.text()).toContain('管理员可在「京东数据库」的类目面板中新建自定义分类')
|
||||
expect(block!.text()).not.toContain('京东数据库 → 店铺分类')
|
||||
expect(block!.find('.group-chip').exists()).toBe(false)
|
||||
// 拉取失败只 warning、不影响建单主路(catch 口径见 catch-silence-ratchet 319)
|
||||
expect(w.find('.collect-btn').exists()).toBe(true)
|
||||
|
||||
@@ -18,7 +18,7 @@ import { resolve, dirname } from 'node:path'
|
||||
*/
|
||||
|
||||
const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..')
|
||||
const read = (rel: string) => readFileSync(resolve(repoRoot, rel), 'utf-8')
|
||||
const read = (rel: string) => readFileSync(resolve(repoRoot, rel), 'utf-8').replace(/\r\n/g, '\n')
|
||||
|
||||
interface TabSpec {
|
||||
name: string
|
||||
|
||||
@@ -25,7 +25,7 @@ const PAGE = join(
|
||||
dirname(fileURLToPath(import.meta.url)),
|
||||
'../src/pages/brand/components/BrandPriceTrackTab.vue',
|
||||
)
|
||||
const source = readFileSync(PAGE, 'utf8')
|
||||
const source = readFileSync(PAGE, 'utf8').replace(/\r\n/g, '\n')
|
||||
|
||||
test('状态目录:三项、顺序稳定、取值与客户端目录同名', () => {
|
||||
assert.deepEqual(
|
||||
|
||||
Reference in New Issue
Block a user