feat(jd): 京东数据库行级编辑与删除+人工编辑锁/删除忽略保护(V199,2026-11-15 用户口径「每条数据可以编辑/删除」)——主链:PUT /api/admin/jd-products/{id} 主字段全量提交即置 manual_locked=1(采集回传 upsert/purge 对锁定行跳过,XML 侧 AND manual_locked=0 铁律 20);attrGroups 只重建 attr_json 的 tabs 段保留其它顶层键(铁律 30),原文形状不识别拒绝;skus 按 (productId,skuId) 改价改库存缺失拒绝;deleteImageIds 先删桶(共用对象保留)计数按表实数刷;删除链成功后写 biz_jd_product_ignore 防重爬复活(幂等吞 DuplicateKey);采集回传 filterProtectedRows 跳过锁定/忽略行不登记子表。后管:列表 11 列操作列(编辑/删除,@click.stop 防冒泡)+ JdProductEditDrawer(主字段/属性键值行删/SKU 价格库存/图片标删,保存提示人工维护后果),updateJdProduct 带 company_id;company-tab-wiring SEND_POINTS 26→32(补详情/删除/分组/类目/删分组/编辑六口一函数一钉对平)。判据:JdProductUpdateServiceTest 8 例+SyncServiceTest 保护闸/绊线+DeleteServiceTest 忽略登记+mount 操作列防冒泡/编辑抽屉;后端整量 5,607 例、后管 vue-tsc+1903+113 全绿。同窗交织笔(另一路会话类目下拉已收尾,文件级无法拆分一并入库):selectProductCategories/GET /categories/JdProductCategoryVo 类目筛选下拉+MigratedSqlEquivalenceTest/SqlLayeringConventionTest 适配。图片上传/替换链路记 BACKLOG B109-01;RawExceptionMessageSinkGuard/CatchSilenceRatchet 随笔抬格逐处记名
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
<script setup lang="ts">
|
||||
/** 京东数据库页(v1.4 Phase 5):公司隔离的京东商品库,筛选行(店铺/商品编码/标题关键字/商品状态/
|
||||
* 分组/同步起止 date 对)+查询/导出/重置/管理分组 + 自绘明细表(勾选列+点行开详情抽屉)
|
||||
/** 京东数据库页(v1.4 Phase 5):公司隔离的京东商品库,筛选行(店铺/商品编码/标题关键字/
|
||||
* 分组/同步起止 date 对)+查询/重置/管理分组 + 自绘明细表(勾选列+点行开详情抽屉)
|
||||
* + 删除(单行/批量,先删桶对象、全成功才删库行,确认弹窗点名数量)+ OldPagination。
|
||||
* 列表按京麦商品列表样式(2026-11-15 用户口径):店铺/分组前置为第 1/2 列;商品信息列=京麦同款
|
||||
* 合并布局(主图+图下信息分+标题两行+商品编码/货号+SKU 数标签,编码带一键复制);类目/上架
|
||||
* 时间/京东创建/修改时间仍收详情抽屉基本信息(B104「详情显示全部属性」口径不变)。
|
||||
* 商品状态筛选框/列与导出按钮随 2026-11-15 客户口径「这两个不要/导出也不用」从前端下线
|
||||
* (后端 sale_status 参数与 /export 端点保留;状态仍收详情抽屉)。
|
||||
* 骨架像素复刻「外观专利数据库」页(panel-box + LoadFailureBar + 自绘 table + 旧式分页);
|
||||
* 公司 tab 切换=清筛选重取(watch 体照外观专利页逐字形状);日期对护栏:起侧 max=止侧、
|
||||
* 止侧 min=起侧、两侧 @change 用 orderedPair 把倒挂交换回来(clampJdSyncedRange 照 clampDatePair)。
|
||||
@@ -13,15 +15,17 @@
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import {
|
||||
deleteJdProducts,
|
||||
exportJdProductList,
|
||||
fetchJdProductCategories,
|
||||
fetchJdProductGroups,
|
||||
fetchJdProductList,
|
||||
type JdProductCategoryOption,
|
||||
type JdProductGroup,
|
||||
} from './jd-product-api.ts'
|
||||
import type { JdProductItem } from './jd-product-model.ts'
|
||||
import { jdPriceRange } from './jd-product-model.ts'
|
||||
import { createJdProductFilterState, JD_SALE_STATUS_HINT } from './jd-product-filter.ts'
|
||||
import { createJdProductFilterState } from './jd-product-filter.ts'
|
||||
import JdProductDetailDrawer from './JdProductDetailDrawer.vue'
|
||||
import JdProductEditDrawer from './JdProductEditDrawer.vue'
|
||||
import JdProductGroupDialog from './JdProductGroupDialog.vue'
|
||||
import OldPagination from '@/components/OldPagination.vue'
|
||||
import { useCompanyTabStore } from '@/stores/company-tab'
|
||||
@@ -39,15 +43,34 @@ const rows = ref<JdProductItem[]>([])
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
const pageSize = ref(20)
|
||||
/** 导出在途锁:避免连点导出把同一份过滤面重复请求两遍。 */
|
||||
const exporting = ref(false)
|
||||
const filter = reactive(createJdProductFilterState())
|
||||
/** 分组下拉选项:公司 tab 切换时重取;选项失败不拦列表,只回空下拉(可见「全部分组」)。 */
|
||||
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 用户口径「每一条数据后面 需要编辑或者删除;编辑的话
|
||||
* 这里面都是可以编辑的」):删除走下面的 removeOne(同一条删除链),编辑走独立抽屉。 */
|
||||
const editItem = ref<JdProductItem | null>(null)
|
||||
const editVisible = ref(false)
|
||||
|
||||
function openEdit(item: JdProductItem): void {
|
||||
editItem.value = item
|
||||
editVisible.value = true
|
||||
}
|
||||
|
||||
function closeEdit(): void {
|
||||
editVisible.value = false
|
||||
editItem.value = null
|
||||
}
|
||||
|
||||
/** 编辑保存成功:刷新列表(该行已置人工编辑锁,标题/价格等即时可见且不再被采集覆盖)。 */
|
||||
async function onEditSaved(): Promise<void> {
|
||||
await load()
|
||||
}
|
||||
|
||||
/** min/max 挡不住手输,落值后把倒挂的起止交换回来。 */
|
||||
function clampJdSyncedRange(): void {
|
||||
@@ -67,6 +90,15 @@ async function loadGroupOptions(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
/** 类目选项同分组口径:失败静默回空下拉(可见「全部类目」),不拦首屏行集。 */
|
||||
async function loadCategoryOptions(): Promise<void> {
|
||||
try {
|
||||
categoryOptions.value = await fetchJdProductCategories(companyTab.requestCompanyId)
|
||||
} catch {
|
||||
categoryOptions.value = []
|
||||
}
|
||||
}
|
||||
|
||||
/** 分组管理弹窗里做过变更:分组下拉与列表都刷新(删除分组后行集的 groupName 会变)。 */
|
||||
async function onGroupChanged(): Promise<void> {
|
||||
await loadGroupOptions()
|
||||
@@ -84,7 +116,7 @@ async function load(): Promise<void> {
|
||||
shopName: filter.shopName,
|
||||
productCode: filter.productCode,
|
||||
titleKeyword: filter.titleKeyword,
|
||||
saleStatus: filter.saleStatus,
|
||||
category: filter.category,
|
||||
groupId: filter.groupId,
|
||||
syncedFrom: filter.syncedFrom,
|
||||
syncedTo: filter.syncedTo,
|
||||
@@ -103,38 +135,6 @@ async function load(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
/** 导出与页签同一过滤面(含公司 tab 与分组),服务端全量出 xlsx;成功后浏览器落盘,失败弹可读文案。 */
|
||||
async function exportAll(): Promise<void> {
|
||||
if (exporting.value) return
|
||||
exporting.value = true
|
||||
try {
|
||||
const result = await exportJdProductList({
|
||||
shopName: filter.shopName,
|
||||
productCode: filter.productCode,
|
||||
titleKeyword: filter.titleKeyword,
|
||||
saleStatus: filter.saleStatus,
|
||||
groupId: filter.groupId,
|
||||
syncedFrom: filter.syncedFrom,
|
||||
syncedTo: filter.syncedTo,
|
||||
companyId: companyTab.requestCompanyId,
|
||||
})
|
||||
const url = URL.createObjectURL(result.blob)
|
||||
const anchor = document.createElement('a')
|
||||
anchor.href = url
|
||||
anchor.download = result.filename
|
||||
document.body.appendChild(anchor)
|
||||
anchor.click()
|
||||
anchor.remove()
|
||||
URL.revokeObjectURL(url)
|
||||
showAdminFeedback(`已导出 ${result.filename}`, 'success')
|
||||
} catch (error) {
|
||||
const message = error instanceof Error && error.message ? error.message : '导出失败,请稍后重试'
|
||||
showAdminFeedback(message, 'error')
|
||||
} finally {
|
||||
exporting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function apply(): void {
|
||||
page.value = 1
|
||||
void load()
|
||||
@@ -233,12 +233,13 @@ async function removeMany(picked: JdProductItem[], message: string): Promise<voi
|
||||
}
|
||||
}
|
||||
|
||||
// 切公司 = 重新取数:店铺/编码/关键字/状态/分组是上一家选中的值,在新一家的行集里筛不出东西,
|
||||
// 必须一起清,分组选项也按新公司重取(选项集是公司隔离的)。
|
||||
watch(() => companyTab.activeId, () => { filter.shopName = ''; filter.productCode = ''; filter.titleKeyword = ''; filter.saleStatus = ''; filter.groupId = ''; filter.syncedFrom = ''; filter.syncedTo = ''; page.value = 1; void loadGroupOptions(); void load() })
|
||||
// 切公司 = 重新取数:店铺/编码/关键字/类目/分组是上一家选中的值,在新一家的行集里筛不出东西,
|
||||
// 必须一起清,分组/类目选项也按新公司重取(选项集是公司隔离的)。
|
||||
watch(() => companyTab.activeId, () => { filter.shopName = ''; filter.productCode = ''; filter.titleKeyword = ''; filter.category = ''; filter.groupId = ''; filter.syncedFrom = ''; filter.syncedTo = ''; page.value = 1; void loadGroupOptions(); void loadCategoryOptions(); void load() })
|
||||
|
||||
onMounted(() => {
|
||||
void loadGroupOptions()
|
||||
void loadCategoryOptions()
|
||||
void load()
|
||||
})
|
||||
</script>
|
||||
@@ -264,10 +265,6 @@ onMounted(() => {
|
||||
<label>标题关键字</label>
|
||||
<input v-model="filter.titleKeyword" type="text" placeholder="输入标题关键字" @keyup.enter="apply" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>商品状态</label>
|
||||
<input v-model="filter.saleStatus" type="text" :placeholder="JD_SALE_STATUS_HINT" @keyup.enter="apply" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>分组</label>
|
||||
<!-- 分组选中即查:选完立刻按该分组过滤刷新(回第一页),不必再点查询。 -->
|
||||
@@ -276,6 +273,16 @@ onMounted(() => {
|
||||
<option v-for="group in groupOptions" :key="group.id" :value="String(group.id)">{{ group.name }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>类目</label>
|
||||
<!-- 类目(京麦末级类目)选中即查:同分组口径,选完立刻按该类目过滤刷新(回第一页)。 -->
|
||||
<select v-model="filter.category" @change="apply">
|
||||
<option value="">全部类目</option>
|
||||
<option v-for="cat in categoryOptions" :key="cat.name" :value="cat.name">
|
||||
{{ cat.name }}({{ cat.productCount }})
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>同步开始日期</label>
|
||||
<input v-model="filter.syncedFrom" type="date" :max="filter.syncedTo" @change="clampJdSyncedRange" />
|
||||
@@ -286,9 +293,6 @@ onMounted(() => {
|
||||
</div>
|
||||
<div class="jd-filter-actions">
|
||||
<button class="btn" type="button" @click="apply">查询</button>
|
||||
<button class="btn btn-export" type="button" :disabled="exporting" @click="exportAll">
|
||||
{{ exporting ? '导出中...' : '导出' }}
|
||||
</button>
|
||||
<button class="btn btn-secondary" type="button" @click="reset">重置</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -314,11 +318,13 @@ onMounted(() => {
|
||||
<th style="width: 130px">店铺</th>
|
||||
<th style="width: 96px">分组</th>
|
||||
<th>商品信息</th>
|
||||
<th style="width: 90px">品牌</th>
|
||||
<th style="width: 110px">价格区间</th>
|
||||
<th style="width: 76px">总库存</th>
|
||||
<th style="width: 86px">商品状态</th>
|
||||
<th style="width: 120px">价格</th>
|
||||
<th style="width: 170px">上架时间 / 商品状态</th>
|
||||
<th style="width: 150px">创建时间</th>
|
||||
<th style="width: 150px">修改时间</th>
|
||||
<th style="width: 170px">同步时间</th>
|
||||
<th style="width: 120px">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -341,22 +347,37 @@ onMounted(() => {
|
||||
<button v-if="row.productCode" class="jd-copy-btn" type="button" title="复制商品编码" @click.stop="copyText(row.productCode)">⧉</button>
|
||||
</div>
|
||||
<div class="jd-info-meta">货号:<span class="jd-info-code">{{ row.itemNum || '-' }}</span></div>
|
||||
<!-- 品牌·类目行:京麦列表同款(末级类目名紧随品牌),字段与顺序 2026-11-15 对齐京麦。 -->
|
||||
<div v-if="row.brand || row.categoryPath" class="jd-info-meta jd-brand-cat">
|
||||
<span class="jd-brand-name">{{ row.brand || '' }}</span> {{ row.categoryPath || '' }}
|
||||
</div>
|
||||
<div v-if="row.skuCount" class="jd-info-tags"><span class="jd-tag">{{ row.skuCount }}个SKU</span></div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>{{ row.brand || '-' }}</td>
|
||||
<td>{{ jdPriceRange(row) || '-' }}</td>
|
||||
<td>{{ row.stockTotal ?? '-' }}</td>
|
||||
<td>{{ row.saleStatus || '-' }}</td>
|
||||
<td>{{ jdPriceRange(row) || '-' }}</td>
|
||||
<td class="jd-online-cell">
|
||||
<div>{{ formatDateTime(row.jdOnlineAt || '') || '-' }}</div>
|
||||
<div v-if="row.saleStatus" class="jd-sale-status" :class="{ off: row.saleStatus !== '上架中' }">
|
||||
<span class="jd-sale-dot"></span>{{ row.saleStatus }}
|
||||
</div>
|
||||
</td>
|
||||
<td>{{ formatDateTime(row.jdCreatedAt || '') || '-' }}</td>
|
||||
<td>{{ formatDateTime(row.jdUpdatedAt || '') || '-' }}</td>
|
||||
<td>{{ formatDateTime(row.syncedAt || '') }}</td>
|
||||
<!-- 操作列(2026-11-15 用户口径):编辑/删除;@click.stop 防冒泡开详情抽屉。 -->
|
||||
<td class="jd-ops-cell" @click.stop>
|
||||
<button class="btn btn-sm" type="button" @click="openEdit(row)">编辑</button>
|
||||
<button class="btn btn-sm btn-danger" type="button" :disabled="deleting" @click="removeOne(row)">删除</button>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
<tr v-else-if="loading">
|
||||
<td colspan="9" class="empty-tip">加载中...</td>
|
||||
<td colspan="11" class="empty-tip">加载中...</td>
|
||||
</tr>
|
||||
<tr v-else>
|
||||
<td colspan="9" class="empty-tip">暂无京东商品数据</td>
|
||||
<td colspan="11" class="empty-tip">暂无京东商品数据</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -371,6 +392,13 @@ onMounted(() => {
|
||||
:company-id="companyTab.requestCompanyId"
|
||||
@close="closeDetail"
|
||||
/>
|
||||
<JdProductEditDrawer
|
||||
:item="editItem"
|
||||
:visible="editVisible"
|
||||
:company-id="companyTab.requestCompanyId"
|
||||
@close="closeEdit"
|
||||
@saved="onEditSaved"
|
||||
/>
|
||||
<JdProductGroupDialog
|
||||
:visible="groupDialogVisible"
|
||||
:company-id="companyTab.requestCompanyId"
|
||||
@@ -415,14 +443,18 @@ h3 {
|
||||
margin: 0;
|
||||
}
|
||||
.jd-filter-row {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(7, minmax(140px, 1fr)) auto;
|
||||
/* 可换行流式布局:固定 6 列 minmax(140px) 的网格在窄面板下最小宽超出容器,
|
||||
把查询/重置挤出面板右缘(与「管理分组」重叠)。flex-wrap 让放不下的项自然折行。 */
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
align-items: end;
|
||||
align-items: flex-end;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.jd-filter-row .form-group {
|
||||
min-width: 0;
|
||||
flex: 1 1 160px;
|
||||
min-width: 150px;
|
||||
max-width: 260px;
|
||||
}
|
||||
.jd-filter-actions {
|
||||
display: flex;
|
||||
@@ -542,7 +574,21 @@ h3 {
|
||||
table-layout: fixed;
|
||||
}
|
||||
.jd-table-scroll > table {
|
||||
min-width: 1180px;
|
||||
min-width: 1500px;
|
||||
}
|
||||
/* 操作列(编辑/删除):双小按钮,放开换行不让按钮被裁。 */
|
||||
.jd-ops-cell {
|
||||
white-space: normal;
|
||||
text-overflow: clip;
|
||||
}
|
||||
.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 {
|
||||
@@ -556,6 +602,14 @@ h3 {
|
||||
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;
|
||||
@@ -666,6 +720,31 @@ h3 {
|
||||
gap: 6px;
|
||||
margin-top: 2px;
|
||||
}
|
||||
/* 品牌·类目行(京麦列表同款深色文字):信息 meta 是灰色,这行按京麦用主文字色。 */
|
||||
.jd-brand-cat {
|
||||
color: #3d5368;
|
||||
font-weight: 550;
|
||||
}
|
||||
.jd-online-cell {
|
||||
line-height: 1.45;
|
||||
}
|
||||
/* 商品状态(京麦同款圆点):上架中绿点,其余灰点。 */
|
||||
.jd-sale-status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
color: #24384d;
|
||||
}
|
||||
.jd-sale-dot {
|
||||
width: 7px;
|
||||
height: 7px;
|
||||
border-radius: 50%;
|
||||
background: #2fb26b;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.jd-sale-status.off .jd-sale-dot {
|
||||
background: #9fb0c0;
|
||||
}
|
||||
.jd-tag {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -0,0 +1,695 @@
|
||||
<script setup lang="ts">
|
||||
/** 京东商品编辑抽屉(2026-11-15 用户口径「每一条数据后面 需要编辑或者删除;编辑的话
|
||||
* 这里面都是可以编辑的」):详情抽屉的可编辑版——基本信息/属性与设置/SKU 矩阵(价格、
|
||||
* 库存)/图片(标删)四块。形状照 JdProductDetailDrawer(自绘 drawer + 分块 + attr-group
|
||||
* 表格 + image-grid,零 element-plus)。
|
||||
* 保存语义在后端 JdProductUpdateService(PUT /api/admin/jd-products/{id}):主字段全量提交
|
||||
* +可选块(attrGroups 重建 attr_json 的 tabs 段、skus 按 skuId 改价格库存、deleteImageIds
|
||||
* 删图——先删桶、共用对象保留)。保存即置人工编辑锁 manual_locked=1:后续采集不再覆盖该行,
|
||||
* 底部常驻提示点名这件事。
|
||||
* 图片只支持删除(上传/替换链路未做,BACKLOG);京东时间/信息分/商品编码只读。
|
||||
* 数据自取 fetchJdProductDetail 回填,保存成功用返回的刷新详情直接回填并 emit('saved')。 */
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import {
|
||||
fetchJdProductDetail,
|
||||
fetchJdProductGroups,
|
||||
updateJdProduct,
|
||||
type JdProductGroup,
|
||||
} from './jd-product-api.ts'
|
||||
import type {
|
||||
JdProductAttrEntry,
|
||||
JdProductAttrGroup,
|
||||
JdProductImage,
|
||||
JdProductItem,
|
||||
JdProductSku,
|
||||
} from './jd-product-model.ts'
|
||||
import { jdSkuDimensions } from './jd-product-model.ts'
|
||||
import { requestErrorMessage } from '../../api/envelope.ts'
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
|
||||
const props = defineProps<{
|
||||
item: JdProductItem | null
|
||||
visible: boolean
|
||||
companyId: number | null
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{ (event: 'close'): void; (event: 'saved'): void }>()
|
||||
|
||||
const loading = ref(false)
|
||||
const loadFailure = ref('')
|
||||
const saving = ref(false)
|
||||
/** 保存失败红条(后端校验/业务文案原样展示,如价格倒挂、SKU 行不存在)。 */
|
||||
const saveError = ref('')
|
||||
|
||||
// ---------------- 草稿(基本信息 + 属性 + SKU + 删图标记) ----------------
|
||||
|
||||
interface DraftAttrGroup {
|
||||
groupName: string
|
||||
attrs: JdProductAttrEntry[]
|
||||
}
|
||||
|
||||
const form = ref({
|
||||
title: '',
|
||||
brand: '',
|
||||
categoryPath: '',
|
||||
itemNum: '',
|
||||
priceMin: '',
|
||||
priceMax: '',
|
||||
stockTotal: '' as string,
|
||||
saleStatus: '',
|
||||
groupId: '' as string,
|
||||
})
|
||||
const draftAttrGroups = ref<DraftAttrGroup[]>([])
|
||||
const draftSkus = ref<JdProductSku[]>([])
|
||||
const images = ref<JdProductImage[]>([])
|
||||
/** 标删的图片行 id(前端只标记,保存时一次提交 deleteImageIds)。 */
|
||||
const deleteImageIds = ref<Set<number>>(new Set())
|
||||
/** attr_json 解析失败(attrJsonRaw 兜底行):属性块禁用,防保存把原文形状弄丢。 */
|
||||
const attrJsonRaw = ref('')
|
||||
const groupOptions = ref<JdProductGroup[]>([])
|
||||
|
||||
const skuDimensions = computed(() => jdSkuDimensions(draftSkus.value))
|
||||
const deletedCount = computed(() => deleteImageIds.value.size)
|
||||
const remainingImageCount = computed(() => images.value.length - deletedCount.value)
|
||||
|
||||
function skuAttrValue(sku: JdProductSku, dimension: string): string {
|
||||
return sku.saleAttrs.find((attr) => attr.name === dimension)?.value || '-'
|
||||
}
|
||||
|
||||
function toggleDeleteImage(image: JdProductImage): void {
|
||||
const next = new Set(deleteImageIds.value)
|
||||
if (next.has(image.id)) next.delete(image.id)
|
||||
else next.add(image.id)
|
||||
deleteImageIds.value = next
|
||||
}
|
||||
|
||||
function removeAttrRow(group: DraftAttrGroup, index: number): void {
|
||||
group.attrs.splice(index, 1)
|
||||
}
|
||||
|
||||
// ---------------- 取数与保存 ----------------
|
||||
|
||||
async function loadDetail(): Promise<void> {
|
||||
const item = props.item
|
||||
if (!item) return
|
||||
loading.value = true
|
||||
loadFailure.value = ''
|
||||
saveError.value = ''
|
||||
try {
|
||||
const [detail, groups] = await Promise.all([
|
||||
fetchJdProductDetail(item.id, props.companyId),
|
||||
fetchJdProductGroups(props.companyId).catch(() => [] as JdProductGroup[]),
|
||||
])
|
||||
groupOptions.value = groups
|
||||
const row = detail.item
|
||||
form.value = {
|
||||
title: row.title,
|
||||
brand: row.brand,
|
||||
categoryPath: row.categoryPath,
|
||||
itemNum: row.itemNum,
|
||||
priceMin: row.priceMin,
|
||||
priceMax: row.priceMax,
|
||||
stockTotal: row.stockTotal === null ? '' : String(row.stockTotal),
|
||||
saleStatus: row.saleStatus,
|
||||
groupId: row.groupId === null ? '' : String(row.groupId),
|
||||
}
|
||||
// 深拷贝草稿:直接改副本,保存前才拼负载。
|
||||
draftAttrGroups.value = detail.attrGroups.map((group: JdProductAttrGroup) => ({
|
||||
groupName: group.groupName,
|
||||
attrs: group.attrs.map((attr) => ({ ...attr })),
|
||||
}))
|
||||
draftSkus.value = detail.skus.map((sku) => ({ ...sku }))
|
||||
images.value = detail.images
|
||||
deleteImageIds.value = new Set()
|
||||
attrJsonRaw.value = detail.attrJsonRaw
|
||||
} catch (error) {
|
||||
loadFailure.value = requestErrorMessage(error) || '商品详情加载失败'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function close(): void {
|
||||
emit('close')
|
||||
}
|
||||
|
||||
/** 保存:主字段全量 + 有改动的可选块。前端先拦「标题为空」(后端 @NotBlank 同判),失败红条。 */
|
||||
async function save(): Promise<void> {
|
||||
if (!props.item || saving.value) return
|
||||
saveError.value = ''
|
||||
if (!form.value.title.trim()) {
|
||||
saveError.value = '标题不能为空'
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
const detail = await updateJdProduct(props.item.id, {
|
||||
title: form.value.title.trim(),
|
||||
brand: form.value.brand.trim() || null,
|
||||
categoryPath: form.value.categoryPath.trim() || null,
|
||||
itemNum: form.value.itemNum.trim() || null,
|
||||
priceMin: form.value.priceMin.trim() || null,
|
||||
priceMax: form.value.priceMax.trim() || null,
|
||||
stockTotal: form.value.stockTotal.trim() === '' ? null : Number(form.value.stockTotal),
|
||||
saleStatus: form.value.saleStatus.trim() || null,
|
||||
groupId: form.value.groupId === '' ? null : Number(form.value.groupId),
|
||||
// 属性块:原文兜底行(解析失败)不提交,防保存把解析不出的原文形状弄丢。
|
||||
attrGroups: attrJsonRaw.value
|
||||
? null
|
||||
: draftAttrGroups.value.map((group) => ({
|
||||
groupName: group.groupName,
|
||||
attrs: group.attrs.map((attr) => ({
|
||||
key: attr.key,
|
||||
label: attr.label,
|
||||
value: attr.value,
|
||||
})),
|
||||
})),
|
||||
skus: draftSkus.value.length
|
||||
? draftSkus.value.map((sku) => ({
|
||||
skuId: sku.skuId,
|
||||
price: sku.price || null,
|
||||
stock: sku.stock,
|
||||
}))
|
||||
: null,
|
||||
deleteImageIds: deleteImageIds.value.size ? [...deleteImageIds.value] : null,
|
||||
}, props.companyId)
|
||||
// 保存成功:用返回的刷新详情直接回填(图片行集已扣掉删掉的行、计数已刷新)。
|
||||
form.value.title = detail.item.title
|
||||
form.value.brand = detail.item.brand
|
||||
form.value.categoryPath = detail.item.categoryPath
|
||||
form.value.itemNum = detail.item.itemNum
|
||||
form.value.priceMin = detail.item.priceMin
|
||||
form.value.priceMax = detail.item.priceMax
|
||||
form.value.stockTotal = detail.item.stockTotal === null ? '' : String(detail.item.stockTotal)
|
||||
form.value.saleStatus = detail.item.saleStatus
|
||||
form.value.groupId = detail.item.groupId === null ? '' : String(detail.item.groupId)
|
||||
draftAttrGroups.value = detail.attrGroups.map((group) => ({
|
||||
groupName: group.groupName,
|
||||
attrs: group.attrs.map((attr) => ({ ...attr })),
|
||||
}))
|
||||
draftSkus.value = detail.skus.map((sku) => ({ ...sku }))
|
||||
images.value = detail.images
|
||||
deleteImageIds.value = new Set()
|
||||
showAdminFeedback('已保存,该商品已转为人工维护(采集不再覆盖)', 'success')
|
||||
emit('saved')
|
||||
} catch (error) {
|
||||
saveError.value = requestErrorMessage(error) || '保存失败,请稍后重试'
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => [props.visible, props.item?.id] as const,
|
||||
([visible]) => {
|
||||
if (visible && props.item) void loadDetail()
|
||||
},
|
||||
)
|
||||
|
||||
function dash(value: string | number | null | undefined): string {
|
||||
const text = value === null || value === undefined ? '' : String(value).trim()
|
||||
return text || '-'
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible" class="drawer-mask" @click.self="close">
|
||||
<aside class="drawer">
|
||||
<header class="drawer-head">
|
||||
<h3>编辑商品{{ item?.productCode ? ` · ${item.productCode}` : '' }}</h3>
|
||||
<button class="drawer-close" type="button" aria-label="关闭" @click="close">×</button>
|
||||
</header>
|
||||
|
||||
<div class="drawer-body">
|
||||
<div v-if="loadFailure" class="drawer-failure">
|
||||
<span>{{ loadFailure }}</span>
|
||||
<button class="btn btn-secondary" type="button" @click="loadDetail">重试</button>
|
||||
</div>
|
||||
<p v-else-if="loading" class="drawer-tip">加载中...</p>
|
||||
|
||||
<template v-else>
|
||||
<section class="detail-block">
|
||||
<h4>基本信息</h4>
|
||||
<div class="edit-grid">
|
||||
<div class="edit-item edit-item-wide">
|
||||
<label>标题</label>
|
||||
<input v-model="form.title" type="text" />
|
||||
</div>
|
||||
<div class="edit-item">
|
||||
<label>品牌</label>
|
||||
<input v-model="form.brand" type="text" />
|
||||
</div>
|
||||
<div class="edit-item">
|
||||
<label>类目</label>
|
||||
<input v-model="form.categoryPath" type="text" />
|
||||
</div>
|
||||
<div class="edit-item">
|
||||
<label>货号</label>
|
||||
<input v-model="form.itemNum" type="text" />
|
||||
</div>
|
||||
<div class="edit-item">
|
||||
<label>状态</label>
|
||||
<input v-model="form.saleStatus" type="text" />
|
||||
</div>
|
||||
<div class="edit-item">
|
||||
<label>价格下限</label>
|
||||
<input v-model="form.priceMin" type="text" inputmode="decimal" />
|
||||
</div>
|
||||
<div class="edit-item">
|
||||
<label>价格上限</label>
|
||||
<input v-model="form.priceMax" type="text" inputmode="decimal" />
|
||||
</div>
|
||||
<div class="edit-item">
|
||||
<label>总库存</label>
|
||||
<input v-model="form.stockTotal" type="text" inputmode="numeric" />
|
||||
</div>
|
||||
<div class="edit-item">
|
||||
<label>分组</label>
|
||||
<select v-model="form.groupId">
|
||||
<option value="">未分组</option>
|
||||
<option v-for="group in groupOptions" :key="group.id" :value="String(group.id)">
|
||||
{{ group.name }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="edit-item">
|
||||
<label>商品编码(只读)</label>
|
||||
<input type="text" :value="dash(item?.productCode)" readonly class="readonly" />
|
||||
</div>
|
||||
<div class="edit-item">
|
||||
<label>信息分(只读)</label>
|
||||
<input type="text" :value="dash(item?.healthScore)" readonly class="readonly" />
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section v-if="draftAttrGroups.length" class="detail-block">
|
||||
<h4>属性与设置(键值可改,行可删)</h4>
|
||||
<div v-for="group in draftAttrGroups" :key="group.groupName" class="attr-group">
|
||||
<h5>{{ group.groupName }}</h5>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr v-for="(attr, index) in group.attrs" :key="`${attr.key}-${index}`">
|
||||
<th>{{ attr.label || attr.key || '-' }}</th>
|
||||
<td><input v-model="attr.value" type="text" class="attr-input" /></td>
|
||||
<td class="attr-remove-cell">
|
||||
<button class="attr-remove" type="button" title="删除该属性行" @click="removeAttrRow(group, index)">删</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
<p v-else-if="attrJsonRaw" class="drawer-tip">属性原文解析失败(原始 JSON 兜底),属性区不可编辑以防丢失原文;可照常改基本信息。</p>
|
||||
<p v-else class="drawer-tip">暂无属性</p>
|
||||
|
||||
<section class="detail-block">
|
||||
<h4>SKU 矩阵(京东价 / 库存可改)</h4>
|
||||
<template v-if="draftSkus.length">
|
||||
<div class="sku-table-wrap">
|
||||
<table class="sku-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th v-for="dimension in skuDimensions" :key="dimension">{{ dimension }}</th>
|
||||
<th>京东价</th>
|
||||
<th>库存</th>
|
||||
<th>SKU ID</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="sku in draftSkus" :key="sku.skuId">
|
||||
<td v-for="dimension in skuDimensions" :key="dimension">{{ skuAttrValue(sku, dimension) }}</td>
|
||||
<td><input v-model="sku.price" type="text" inputmode="decimal" class="sku-input" /></td>
|
||||
<td>
|
||||
<input
|
||||
:value="sku.stock === null ? '' : String(sku.stock)"
|
||||
type="text"
|
||||
inputmode="numeric"
|
||||
class="sku-input"
|
||||
@input="sku.stock = ($event.target as HTMLInputElement).value === '' ? null : Number(($event.target as HTMLInputElement).value)"
|
||||
/>
|
||||
</td>
|
||||
<td class="sku-id">{{ sku.skuId }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</template>
|
||||
<p v-else class="drawer-tip">暂无 SKU 矩阵(V198 之前采集的旧行需重新采集)</p>
|
||||
</section>
|
||||
|
||||
<section class="detail-block">
|
||||
<h4>图片(点「删图」标记,保存时一并删除;上传/替换暂未开放)</h4>
|
||||
<div v-if="images.length" class="image-grid">
|
||||
<div
|
||||
v-for="image in images"
|
||||
:key="`${image.id}-${image.url}`"
|
||||
class="image-cell"
|
||||
:class="{ marked: deleteImageIds.has(image.id) }"
|
||||
>
|
||||
<img :src="image.url" alt="" loading="lazy" />
|
||||
<button class="image-del" type="button" @click="toggleDeleteImage(image)">
|
||||
{{ deleteImageIds.has(image.id) ? '撤销' : '删图' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<p v-else class="drawer-tip">暂无图片</p>
|
||||
<p v-if="deletedCount" class="delete-count">已标记删除 {{ deletedCount }} 张,保存后剩余 {{ remainingImageCount }} 张</p>
|
||||
</section>
|
||||
|
||||
<div v-if="saveError" class="drawer-failure">{{ saveError }}</div>
|
||||
<p class="save-hint">保存后该商品转为人工维护,后续采集不再覆盖它的数据(含本单重爬);删除的图片文件一并从存储桶清理(共用的保留)。</p>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<footer class="drawer-foot">
|
||||
<button class="btn btn-secondary" type="button" :disabled="saving" @click="close">取消</button>
|
||||
<button class="btn" type="button" :disabled="saving || loading" @click="save">
|
||||
{{ saving ? '保存中...' : '保存' }}
|
||||
</button>
|
||||
</footer>
|
||||
</aside>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.drawer-mask {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 2600;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
background: rgba(45, 66, 86, 0.36);
|
||||
backdrop-filter: blur(4px);
|
||||
}
|
||||
.drawer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: min(920px, 100%);
|
||||
height: 100%;
|
||||
background: #ffffff;
|
||||
box-shadow: -18px 0 40px rgba(39, 67, 94, 0.18);
|
||||
}
|
||||
.drawer-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 16px 20px;
|
||||
border-bottom: 1px solid #dbe5ee;
|
||||
}
|
||||
.drawer-head h3 {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
font-weight: 650;
|
||||
color: #24384d;
|
||||
}
|
||||
.drawer-close {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 9px;
|
||||
background: none;
|
||||
color: #5b6f83;
|
||||
font-size: 20px;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
}
|
||||
.drawer-close:hover {
|
||||
border-color: #cbd9e6;
|
||||
background: #eef4fa;
|
||||
color: #24384d;
|
||||
}
|
||||
.drawer-body {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
padding: 16px 20px 28px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
}
|
||||
.drawer-foot {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 12px;
|
||||
padding: 14px 20px;
|
||||
border-top: 1px solid #dbe5ee;
|
||||
background: #f8fbfd;
|
||||
}
|
||||
.drawer-tip {
|
||||
margin: 0;
|
||||
color: #8293a5;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.drawer-failure {
|
||||
padding: 12px 14px;
|
||||
border: 1px solid #f0c9c2;
|
||||
border-radius: 10px;
|
||||
background: #fdf1ef;
|
||||
color: #a04432;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.detail-block h4 {
|
||||
margin: 0 0 10px;
|
||||
font-size: 13.5px;
|
||||
font-weight: 650;
|
||||
color: #4e6479;
|
||||
}
|
||||
.edit-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 10px 16px;
|
||||
}
|
||||
.edit-item {
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 5px;
|
||||
}
|
||||
.edit-item-wide {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
.edit-item label {
|
||||
color: #5b6f83;
|
||||
font-size: 12px;
|
||||
}
|
||||
.edit-item input,
|
||||
.edit-item select {
|
||||
min-width: 0;
|
||||
min-height: 36px;
|
||||
padding: 6px 10px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
color: #24384d;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
outline: none;
|
||||
}
|
||||
.edit-item input:focus,
|
||||
.edit-item select:focus {
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
}
|
||||
.edit-item input.readonly {
|
||||
background: #f2f7fb;
|
||||
color: #5b6f83;
|
||||
}
|
||||
.attr-group {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.attr-group h5 {
|
||||
margin: 0 0 6px;
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
}
|
||||
.attr-group table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
border: 1px solid #dbe5ee;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.attr-group th,
|
||||
.attr-group td {
|
||||
padding: 6px 10px;
|
||||
border-bottom: 1px solid #e7eef5;
|
||||
font-size: 13px;
|
||||
text-align: left;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.attr-group th {
|
||||
width: 180px;
|
||||
background: #f2f7fb;
|
||||
color: #4e6479;
|
||||
font-weight: 600;
|
||||
}
|
||||
.attr-group tr:last-child th,
|
||||
.attr-group tr:last-child td {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.attr-input {
|
||||
width: 100%;
|
||||
min-height: 32px;
|
||||
padding: 5px 8px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 7px;
|
||||
background: #ffffff;
|
||||
color: #24384d;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
outline: none;
|
||||
}
|
||||
.attr-input:focus {
|
||||
border-color: #5f85ad;
|
||||
}
|
||||
.attr-remove-cell {
|
||||
width: 44px;
|
||||
text-align: center;
|
||||
}
|
||||
.attr-remove {
|
||||
border: 1px solid #e4b3a8;
|
||||
border-radius: 6px;
|
||||
background: #ffffff;
|
||||
color: #a04432;
|
||||
font-size: 12px;
|
||||
padding: 3px 8px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.attr-remove:hover {
|
||||
background: #fdf1ef;
|
||||
}
|
||||
.sku-table-wrap {
|
||||
overflow-x: auto;
|
||||
border: 1px solid #dbe5ee;
|
||||
border-radius: 8px;
|
||||
}
|
||||
.sku-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 12.5px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.sku-table th,
|
||||
.sku-table td {
|
||||
padding: 6px 10px;
|
||||
border-bottom: 1px solid #e7eef5;
|
||||
text-align: left;
|
||||
color: #24384d;
|
||||
}
|
||||
.sku-table th {
|
||||
background: #f2f7fb;
|
||||
color: #4e6479;
|
||||
font-weight: 600;
|
||||
}
|
||||
.sku-table tbody tr:last-child td {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.sku-input {
|
||||
width: 110px;
|
||||
min-height: 32px;
|
||||
padding: 5px 8px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 7px;
|
||||
background: #ffffff;
|
||||
color: #24384d;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
outline: none;
|
||||
}
|
||||
.sku-input:focus {
|
||||
border-color: #5f85ad;
|
||||
}
|
||||
.sku-id {
|
||||
font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
|
||||
font-size: 12px;
|
||||
color: #4e6479;
|
||||
}
|
||||
.image-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
|
||||
gap: 10px;
|
||||
}
|
||||
.image-cell {
|
||||
position: relative;
|
||||
}
|
||||
.image-cell img {
|
||||
display: block;
|
||||
width: 100%;
|
||||
aspect-ratio: 1;
|
||||
object-fit: cover;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 8px;
|
||||
background: #f2f7fb;
|
||||
}
|
||||
.image-cell.marked img {
|
||||
opacity: 0.35;
|
||||
outline: 2px solid #d08a7b;
|
||||
}
|
||||
.image-del {
|
||||
position: absolute;
|
||||
right: 6px;
|
||||
bottom: 6px;
|
||||
border: 1px solid #e4b3a8;
|
||||
border-radius: 6px;
|
||||
background: rgba(255, 255, 255, 0.92);
|
||||
color: #a04432;
|
||||
font-size: 12px;
|
||||
padding: 3px 8px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.image-del:hover {
|
||||
background: #fdf1ef;
|
||||
}
|
||||
.image-cell.marked .image-del {
|
||||
border-color: #95b1cb;
|
||||
color: #5b6f83;
|
||||
}
|
||||
.delete-count {
|
||||
margin: 10px 0 0;
|
||||
color: #a04432;
|
||||
font-size: 12.5px;
|
||||
}
|
||||
.save-hint {
|
||||
margin: 0;
|
||||
padding: 10px 14px;
|
||||
border: 1px solid #cfe3f5;
|
||||
border-radius: 10px;
|
||||
background: #eef5fc;
|
||||
color: #3b6d99;
|
||||
font-size: 12.5px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 38px;
|
||||
padding: 7px 16px;
|
||||
border-radius: 9px;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.btn:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.6;
|
||||
}
|
||||
.btn-secondary {
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
border: 1px solid #c7d7e5;
|
||||
}
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
color: #2f5d8b;
|
||||
border-color: #95b1cb;
|
||||
background: #edf5fb;
|
||||
}
|
||||
.btn:not(.btn-secondary) {
|
||||
border: 1px solid #4f78a5;
|
||||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||||
color: #ffffff;
|
||||
}
|
||||
.btn:not(.btn-secondary):hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #7094ba, #5d83ac);
|
||||
}
|
||||
</style>
|
||||
@@ -1,14 +1,12 @@
|
||||
/** 京东数据库查询适配(v1.4 Phase 5):GET /api/admin/jd-products + 删除(DELETE /{id} +
|
||||
* POST /batch-delete)+ 分组端点 /api/admin/jd-product-groups。
|
||||
* 只读列表+导出+删除+分组管理:公司 tab 的值由本发送口从原始入参自己下传
|
||||
* (白名单构造不认识 company_id),取值口形状由 company-tab-wiring 护栏钉住。 */
|
||||
* 只读列表+删除+分组管理:公司 tab 的值由本发送口从原始入参自己下传
|
||||
* (白名单构造不认识 company_id),取值口形状由 company-tab-wiring 护栏钉住。
|
||||
* 导出发送口已随 2026-11-15 客户口径「导出也不用」从前端下线(后端 /export 端点保留)。 */
|
||||
import { http } from '@/api/http'
|
||||
import { errorTextOf, unwrap } from '../../api/envelope.ts'
|
||||
import {
|
||||
toJdProductExportParams,
|
||||
toJdProductListParams,
|
||||
type JdProductExportParams,
|
||||
type JdProductExportQuery,
|
||||
type JdProductListParams,
|
||||
} from './jd-product-filter.ts'
|
||||
import {
|
||||
@@ -28,7 +26,7 @@ export async function fetchJdProductList(
|
||||
shopName: params.shopName ?? '',
|
||||
productCode: params.productCode ?? '',
|
||||
titleKeyword: params.titleKeyword ?? '',
|
||||
saleStatus: params.saleStatus ?? '',
|
||||
category: params.category ?? '',
|
||||
groupId: params.groupId ?? '',
|
||||
syncedFrom: params.syncedFrom ?? '',
|
||||
syncedTo: params.syncedTo ?? '',
|
||||
@@ -52,63 +50,6 @@ export async function fetchJdProductDetail(
|
||||
return parseJdProductDetail(data)
|
||||
}
|
||||
|
||||
export interface JdProductExportResult {
|
||||
blob: Blob
|
||||
filename: string
|
||||
}
|
||||
|
||||
/** 从 Content-Disposition 取 filename*(UTF-8 轨,后端 DownloadHeaderUtil 双轨口径),取不到回退常量名。 */
|
||||
function exportFilenameOf(disposition: unknown): string {
|
||||
const raw = typeof disposition === 'string' ? disposition : ''
|
||||
const star = /filename\*=(?:UTF-8'')?([^;]+)/i.exec(raw)
|
||||
if (star?.[1]) {
|
||||
try {
|
||||
return decodeURIComponent(star[1].trim().replace(/^"|"$/g, '')) || '京东数据库.xlsx'
|
||||
} catch {
|
||||
// 编码坏的 filename* 当作没有,走 ASCII 轨或常量名
|
||||
}
|
||||
}
|
||||
const plain = /filename="([^"]+)"/i.exec(raw)
|
||||
return plain?.[1] || '京东数据库.xlsx'
|
||||
}
|
||||
|
||||
/** 导出当前过滤面全量明细:与列表共用同一过滤面取值口(含公司 tab),blob 下载交给页面触发保存。 */
|
||||
export async function exportJdProductList(
|
||||
params: JdProductExportParams,
|
||||
): Promise<JdProductExportResult> {
|
||||
const query: JdProductExportQuery = toJdProductExportParams({
|
||||
shopName: params.shopName ?? '',
|
||||
productCode: params.productCode ?? '',
|
||||
titleKeyword: params.titleKeyword ?? '',
|
||||
saleStatus: params.saleStatus ?? '',
|
||||
groupId: params.groupId ?? '',
|
||||
syncedFrom: params.syncedFrom ?? '',
|
||||
syncedTo: params.syncedTo ?? '',
|
||||
})
|
||||
if (params.companyId != null) query.company_id = params.companyId
|
||||
const response = await http.get<Blob>(`${JD_PRODUCT_ENDPOINT}/export`, {
|
||||
params: query,
|
||||
responseType: 'blob',
|
||||
timeout: 120_000,
|
||||
})
|
||||
const disposition = response.headers?.['content-disposition']
|
||||
if (!disposition) {
|
||||
// 没有附件头=服务端回了业务错误信封(HTTP 200 + JSON),把 blob 文本解回错误文案抛给页面
|
||||
const blob = response.data
|
||||
let payload: unknown = null
|
||||
if (blob && typeof blob.text === 'function') {
|
||||
const text = await blob.text()
|
||||
try {
|
||||
payload = JSON.parse(text)
|
||||
} catch {
|
||||
payload = text
|
||||
}
|
||||
}
|
||||
throw new Error(errorTextOf(payload))
|
||||
}
|
||||
return { blob: response.data, filename: exportFilenameOf(disposition) }
|
||||
}
|
||||
|
||||
/** 删除回执(后端 JdProductDeleteVo):三个对象计数分开报——真删的、共用的、前缀外不敢动的。 */
|
||||
export interface JdProductDeleteResult {
|
||||
deleted: number
|
||||
@@ -133,8 +74,39 @@ export async function deleteJdProducts(
|
||||
return unwrap<JdProductDeleteResult>(data)
|
||||
}
|
||||
|
||||
/** 分组行(GET 列表返回:[{id,name,sortOrder,productCount}])。 */
|
||||
export interface JdProductGroup {
|
||||
/** 编辑提交负载(PUT /api/admin/jd-products/{id} body,后端 JdProductUpdateRequest):
|
||||
* 主字段全量提交;attrGroups/skus/deleteImageIds 可选——null=不修改该块
|
||||
* (后端对 null 块零触碰)。 */
|
||||
export interface JdProductUpdatePayload {
|
||||
title: string
|
||||
brand: string | null
|
||||
categoryPath: string | null
|
||||
itemNum: string | null
|
||||
priceMin: string | null
|
||||
priceMax: string | null
|
||||
stockTotal: number | null
|
||||
saleStatus: string | null
|
||||
groupId: number | null
|
||||
attrGroups: { groupName: string; attrs: { key: string; label: string; value: string }[] }[] | null
|
||||
skus: { skuId: string; price: string | null; stock: number | null }[] | null
|
||||
deleteImageIds: number[] | null
|
||||
}
|
||||
|
||||
/** 编辑保存(PUT + company_id 作 query,照 deleteJdProducts 形状):主字段保存即置
|
||||
* 人工编辑锁(V199 manual_locked=1,后续采集不再覆盖该行);失败文案原样抛给抽屉红条。
|
||||
* 返回刷新后的详情(与 fetchJdProductDetail 同一信封),抽屉用它回填。 */
|
||||
export async function updateJdProduct(
|
||||
id: number,
|
||||
payload: JdProductUpdatePayload,
|
||||
companyId: number | null,
|
||||
): Promise<ReturnType<typeof parseJdProductDetail>> {
|
||||
const query: Record<string, number> = {}
|
||||
if (companyId != null) query.company_id = companyId
|
||||
const { data } = await http.put<unknown>(`${JD_PRODUCT_ENDPOINT}/${id}`, payload, { params: query })
|
||||
return parseJdProductDetail(data)
|
||||
}
|
||||
|
||||
/** 分组行(GET 列表返回:[{id,name,sortOrder,productCount}])。 */export interface JdProductGroup {
|
||||
id: number
|
||||
name: string
|
||||
sortOrder: number
|
||||
@@ -184,6 +156,32 @@ export async function fetchJdProductGroups(companyId: number | null): Promise<Jd
|
||||
return out
|
||||
}
|
||||
|
||||
/** 类目下拉选项(GET /categories 返回 [{name, productCount}],name=京麦末级类目即
|
||||
* 落库的 category_path;等值过滤)。失败由页面自己兜(类目只是筛选项,不拦首屏行集)。 */
|
||||
export interface JdProductCategoryOption {
|
||||
name: string
|
||||
productCount: number
|
||||
}
|
||||
|
||||
export async function fetchJdProductCategories(
|
||||
companyId: number | null,
|
||||
): Promise<JdProductCategoryOption[]> {
|
||||
const query: Record<string, number> = {}
|
||||
if (companyId != null) query.company_id = companyId
|
||||
const { data } = await http.get<unknown>(`${JD_PRODUCT_ENDPOINT}/categories`, { params: query })
|
||||
const core = unwrap<unknown>(data)
|
||||
if (!Array.isArray(core)) return []
|
||||
const out: JdProductCategoryOption[] = []
|
||||
for (const raw of core) {
|
||||
if (!raw || typeof raw !== 'object') continue
|
||||
const record = raw as Record<string, unknown>
|
||||
const name = typeof record.name === 'string' ? record.name.trim() : ''
|
||||
if (!name) continue
|
||||
out.push({ name, productCount: numberOr(record.productCount ?? record.product_count, 0) })
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/** 新建分组;重名等业务失败把后端中文文案抛回(页面直接展示)。 */
|
||||
export async function createJdProductGroup(
|
||||
payload: JdProductGroupPayload,
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
/** 京东数据库页筛选纯函数(v1.4 Phase 5):店铺/商品编码/标题关键字/商品状态/分组/同步起止 + snake 分页参数。
|
||||
/** 京东数据库页筛选纯函数(v1.4 Phase 5):店铺/商品编码/标题关键字/类目/分组/同步起止 + snake 分页参数。
|
||||
* 产出与后端契约 §列表 query 逐字对撞:`page`/`page_size`(默认 20、上限 100)、`shop_name`、
|
||||
* `product_code`、`title_keyword`、`sale_status`、`group_id`、`synced_from`/`synced_to`
|
||||
* (ISO yyyy-MM-dd;空白不下发)。
|
||||
* `product_code`、`title_keyword`、`category`(京麦末级类目等值过滤,2026-11-15 增)、
|
||||
* `group_id`、`synced_from`/`synced_to`(ISO yyyy-MM-dd;空白不下发)。
|
||||
* 商品状态筛选与导出(2026-11-15 客户口径「这两个不要/导出也不用」)已从前端下线;
|
||||
* 后端 `sale_status` 参数与 `/export` 端点保留(无 UI 入口),重上时从 git 历史找回取值口。
|
||||
* 分页钳制(铁律 15):page < 1 归 1、上限 10_000(后端 CR-18 同值),(page-1)*page_size
|
||||
* 最大 999_900,Number.MAX_SAFE_INTEGER 也不会把乘积顶出安全整数。纯逻辑,node --test 直测。
|
||||
* 公司维不在这里:归一化构造器不认识 company_id(同外观专利 filter 惯例),由 api 发送口从
|
||||
@@ -16,9 +18,6 @@ export const JD_PRODUCT_MAX_PAGE_SIZE = 100
|
||||
/** 页码上限:与后端 MAX_PAGE(CR-18 先例,外观专利同值)对齐,两侧不漂。 */
|
||||
export const JD_PRODUCT_MAX_PAGE = 10_000
|
||||
|
||||
/** 商品状态值域(契约口径):筛选为简单文本输入,placeholder 提示值域。 */
|
||||
export const JD_SALE_STATUS_HINT = '上架中/已下架/审核中/草稿'
|
||||
|
||||
export interface JdProductFilterState {
|
||||
/** 店铺名(模糊),空串不限。 */
|
||||
shopName: string
|
||||
@@ -26,8 +25,8 @@ export interface JdProductFilterState {
|
||||
productCode: string
|
||||
/** 标题关键字,空串不限。 */
|
||||
titleKeyword: string
|
||||
/** 商品状态:上架中/已下架/审核中/草稿,空串=全部。 */
|
||||
saleStatus: string
|
||||
/** 类目(京麦末级类目名,等值过滤;选项来自 GET /categories),空串=全部类目。 */
|
||||
category: string
|
||||
/** 分组 id 文本(分组管理里那一行),空串=全部分组。 */
|
||||
groupId: string
|
||||
/** 同步开始日期(ISO yyyy-MM-dd;空串不限)。 */
|
||||
@@ -37,7 +36,7 @@ export interface JdProductFilterState {
|
||||
}
|
||||
|
||||
export function createJdProductFilterState(): JdProductFilterState {
|
||||
return { shopName: '', productCode: '', titleKeyword: '', saleStatus: '', groupId: '', syncedFrom: '', syncedTo: '' }
|
||||
return { shopName: '', productCode: '', titleKeyword: '', category: '', groupId: '', syncedFrom: '', syncedTo: '' }
|
||||
}
|
||||
|
||||
/** 是否有任一激活筛选条件。 */
|
||||
@@ -45,7 +44,7 @@ export function jdProductFilterActive(state: JdProductFilterState): boolean {
|
||||
if ((state.shopName || '').trim()) return true
|
||||
if ((state.productCode || '').trim()) return true
|
||||
if ((state.titleKeyword || '').trim()) return true
|
||||
if ((state.saleStatus || '').trim()) return true
|
||||
if ((state.category || '').trim()) return true
|
||||
if ((state.groupId || '').trim()) return true
|
||||
if (validIsoDateOrUndefined(state.syncedFrom) || validIsoDateOrUndefined(state.syncedTo)) return true
|
||||
return false
|
||||
@@ -58,7 +57,8 @@ export interface JdProductQuery {
|
||||
shop_name?: string
|
||||
product_code?: string
|
||||
title_keyword?: string
|
||||
sale_status?: string
|
||||
/** 京麦末级类目等值过滤(后端 JdProductQueryService.Filter.category)。 */
|
||||
category?: string
|
||||
group_id?: number
|
||||
synced_from?: string
|
||||
synced_to?: string
|
||||
@@ -66,19 +66,6 @@ export interface JdProductQuery {
|
||||
company_id?: number
|
||||
}
|
||||
|
||||
/** 导出查询参数:与列表同一过滤面、无分页(全量导出由服务侧上限兜住)。 */
|
||||
export interface JdProductExportQuery {
|
||||
shop_name?: string
|
||||
product_code?: string
|
||||
title_keyword?: string
|
||||
sale_status?: string
|
||||
group_id?: number
|
||||
synced_from?: string
|
||||
synced_to?: string
|
||||
/** 公司 tab 同列表口径:白名单构造不点名,由 api 发送口下传。 */
|
||||
company_id?: number
|
||||
}
|
||||
|
||||
/** api 模块的入参:筛选态 + 分页 + 公司值(camel)。 */
|
||||
export interface JdProductListParams {
|
||||
page: number
|
||||
@@ -86,37 +73,24 @@ export interface JdProductListParams {
|
||||
shopName?: string
|
||||
productCode?: string
|
||||
titleKeyword?: string
|
||||
saleStatus?: string
|
||||
category?: string
|
||||
groupId?: string
|
||||
syncedFrom?: string
|
||||
syncedTo?: string
|
||||
companyId?: number | null
|
||||
}
|
||||
|
||||
/** api 导出入口的入参:筛选态 + 公司值(camel,无分页)。 */
|
||||
export interface JdProductExportParams {
|
||||
shopName?: string
|
||||
productCode?: string
|
||||
titleKeyword?: string
|
||||
saleStatus?: string
|
||||
groupId?: string
|
||||
syncedFrom?: string
|
||||
syncedTo?: string
|
||||
companyId?: number | null
|
||||
}
|
||||
|
||||
/** 过滤态 → 过滤面参数(snake_case,仅下发非空字段);列表与导出共用这一个取值口,
|
||||
* 「导出的过滤面和页签看到的永远同源」由这条单出口保证,不出现两处各算各的。 */
|
||||
function toJdProductFilterQuery(state: JdProductFilterState): JdProductExportQuery {
|
||||
const query: JdProductExportQuery = {}
|
||||
/** 过滤态 → 过滤面参数(snake_case,仅下发非空字段)。 */
|
||||
function toJdProductFilterQuery(state: JdProductFilterState): Omit<JdProductQuery, 'page' | 'page_size'> {
|
||||
const query: Omit<JdProductQuery, 'page' | 'page_size'> = {}
|
||||
const shopName = (state.shopName || '').trim()
|
||||
if (shopName) query.shop_name = shopName
|
||||
const productCode = (state.productCode || '').trim()
|
||||
if (productCode) query.product_code = productCode
|
||||
const titleKeyword = (state.titleKeyword || '').trim()
|
||||
if (titleKeyword) query.title_keyword = titleKeyword
|
||||
const saleStatus = (state.saleStatus || '').trim()
|
||||
if (saleStatus) query.sale_status = saleStatus
|
||||
const category = (state.category || '').trim()
|
||||
if (category) query.category = category
|
||||
const groupId = Number.parseInt((state.groupId || '').trim(), 10)
|
||||
if (Number.isFinite(groupId) && groupId > 0) query.group_id = groupId
|
||||
const syncedFrom = validIsoDateOrUndefined(state.syncedFrom)
|
||||
@@ -141,8 +115,3 @@ export function toJdProductListParams(
|
||||
...toJdProductFilterQuery(state),
|
||||
}
|
||||
}
|
||||
|
||||
/** 过滤态 → 导出查询参数(无分页;归一规则与列表逐字同源)。 */
|
||||
export function toJdProductExportParams(state: JdProductFilterState): JdProductExportQuery {
|
||||
return toJdProductFilterQuery(state)
|
||||
}
|
||||
|
||||
@@ -132,8 +132,10 @@ export interface JdProductAttrGroup {
|
||||
attrs: JdProductAttrEntry[]
|
||||
}
|
||||
|
||||
/** 详情图片:images[{imageType, attrName, sortNo, url, byteSize, width, height}]。 */
|
||||
/** 详情图片:images[{id, imageType, attrName, sortNo, url, byteSize, width, height}]
|
||||
* (id=biz_jd_product_image 行号,编辑抽屉按它提交删图;旧后端不带 id 时按缺 0 弃行口径不拦展示)。 */
|
||||
export interface JdProductImage {
|
||||
id: number
|
||||
imageType: string
|
||||
attrName: string
|
||||
sortNo: number
|
||||
@@ -207,6 +209,7 @@ function toImages(raw: unknown): JdProductImage[] {
|
||||
const url = text(image.url)
|
||||
if (!url) continue
|
||||
out.push({
|
||||
id: numberOrNull(image.id) ?? 0,
|
||||
imageType: text(image.imageType ?? image.image_type),
|
||||
attrName: text(image.attrName ?? image.attr_name),
|
||||
sortNo: numberOrNull(image.sortNo ?? image.sort_no) ?? 0,
|
||||
|
||||
@@ -133,10 +133,19 @@ const SEND_POINTS: ReadonlyArray<SendPoint> = [
|
||||
{ menuKey: 'admin_appearance_patent_clean_items', file: 'src/pages/patent/appearance-patent-clean-api.ts', fn: 'fetchAppearancePatentCleanList', line: 'if (params.companyId != null) query.company_id = params.companyId', window: 500, title: 'GET /appearance-patent-clean-items 无侵权只读列表' },
|
||||
{ menuKey: 'admin_appearance_patent_clean_items', file: 'src/pages/patent/appearance-patent-clean-api.ts', fn: 'exportAppearancePatentCleanList', line: 'if (params.companyId != null) query.company_id = params.companyId', window: 500, title: 'GET /appearance-patent-clean-items/export 导出(2026-11-11 客户需求「数据得导出来」,与列表共用同一过滤面)' },
|
||||
// ↓ 批次 8(2026-11-14 v1.4 京东数据库):京麦店铺商品采集落库的只读镜像,归属物化在行
|
||||
// company_id 列(V193,同外观专利 V189 形状)⇒ 后端正门 readCompanyIdOrOwn。列表与导出
|
||||
// 共用同一过滤面,塞键行与外观专利逐字同行,但分属不同文件 ⇒ (文件, 整行) 各成一组。
|
||||
// company_id 列(V193,同外观专利 V189 形状)⇒ 后端正门 readCompanyIdOrOwn。
|
||||
// 导出发送口已随 2026-11-15 客户口径「导出也不用」从前端下线(后端 /export 端点保留,
|
||||
// 前端发送口撤,重上时从 git 历史找回发送行再登记——同批次 7 主管两口的先例)。
|
||||
{ menuKey: 'admin_jd_database', file: 'src/pages/jd/jd-product-api.ts', fn: 'fetchJdProductList', line: 'if (params.companyId != null) query.company_id = params.companyId', window: 500, title: 'GET /jd-products 京东数据库只读列表' },
|
||||
{ menuKey: 'admin_jd_database', file: 'src/pages/jd/jd-product-api.ts', fn: 'exportJdProductList', line: 'if (params.companyId != null) query.company_id = params.companyId', window: 500, title: 'GET /jd-products/export 京东数据库导出(与列表共用同一过滤面)' },
|
||||
// ↓ 同文件其余 6 个发送口(payload 形签名,塞键行与列表口不同形):详情/删除/分组列表/
|
||||
// 类目列表/删分组都在 2026-11-14 v1.4 就带 company_id 下传,编辑口(2026-11-15 行级编辑,
|
||||
// PUT 保存、V199 人工编辑锁)同形状——6 处塞键行逐字同行走一组,一函数一钉对平。
|
||||
{ menuKey: 'admin_jd_database', file: 'src/pages/jd/jd-product-api.ts', fn: 'fetchJdProductDetail', line: 'if (companyId != null) query.company_id = companyId', window: 500, title: 'GET /jd-products/{id} 详情抽屉取数' },
|
||||
{ menuKey: 'admin_jd_database', file: 'src/pages/jd/jd-product-api.ts', fn: 'deleteJdProducts', line: 'if (companyId != null) query.company_id = companyId', window: 500, title: 'DELETE /jd-products/{id} 与 POST batch-delete 删除' },
|
||||
{ menuKey: 'admin_jd_database', file: 'src/pages/jd/jd-product-api.ts', fn: 'fetchJdProductGroups', line: 'if (companyId != null) query.company_id = companyId', window: 500, title: 'GET /jd-product-groups 分组下拉/管理列表' },
|
||||
{ menuKey: 'admin_jd_database', file: 'src/pages/jd/jd-product-api.ts', fn: 'fetchJdProductCategories', line: 'if (companyId != null) query.company_id = companyId', window: 500, title: 'GET /jd-products/categories 类目下拉' },
|
||||
{ menuKey: 'admin_jd_database', file: 'src/pages/jd/jd-product-api.ts', fn: 'deleteJdProductGroup', line: 'if (companyId != null) query.company_id = companyId', window: 500, title: 'DELETE /jd-product-groups/{id} 删分组' },
|
||||
{ menuKey: 'admin_jd_database', file: 'src/pages/jd/jd-product-api.ts', fn: 'updateJdProduct', line: 'if (companyId != null) query.company_id = companyId', window: 500, title: 'PUT /jd-products/{id} 行级编辑保存(V199 人工编辑锁)' },
|
||||
]
|
||||
|
||||
/** 任务看板那 5 处(1b ④ 那条用例按文件筛它们,沿用旧名字不漂;表只有一份,不会漂出两个口径)。 */
|
||||
@@ -260,7 +269,7 @@ const COMPANY_ID_SOURCE_PINS: Readonly<Record<string, readonly CompanyIdPin[]>>
|
||||
admin_columns: pinsFor('admin_columns'),
|
||||
// 批次 7(v1.3 无侵权只读页):同样由 SEND_POINTS 现算——只有一个发送口(列表)。
|
||||
admin_appearance_patent_clean_items: pinsFor('admin_appearance_patent_clean_items'),
|
||||
// 批次 8(v1.4 京东数据库):列表 + 导出两口,由 SEND_POINTS 现算。
|
||||
// 批次 8(v1.4 京东数据库):列表一口(导出发送口 2026-11-15 随客户口径下线),由 SEND_POINTS 现算。
|
||||
admin_jd_database: pinsFor('admin_jd_database'),
|
||||
}
|
||||
|
||||
@@ -360,8 +369,8 @@ test('正向:声明 companyScoped 的页,其 api 文件必须真的带 company
|
||||
// ⚠ 分母是本轮实扫的表条数(批次 1 的 5 + 批次 2 的 7 + 批次 3 的 4 + 批次 4 的 1 + 批次 5 的 1 + 批次 6 的 3;
|
||||
// 批次 2 原 12 条里的品牌库 1 条 + 商品类目 4 条随 2026-10-06「这两页退回全平台共享」摘掉)。
|
||||
// 这条只防"整表被摘空/被改窄",逐处脱管由下面两条(对平闸门 + 窗口对平)负责。
|
||||
assert.ok(SEND_POINTS.length >= 27,
|
||||
`发送口表只剩 ${SEND_POINTS.length} 条(批次 1+2+3+4+5+6 实扫 21 条 + 批次 7 v1.3 无侵权列表/导出 2 条 + 主管聚合 1 条 + 按主管删除 1 条 + 批次 8 v1.4 京东数据库列表/导出 2 条 = 28 条)⇒ 有人把钉从表里摘了,取值口看守成空`)
|
||||
assert.ok(SEND_POINTS.length >= 32,
|
||||
`发送口表只剩 ${SEND_POINTS.length} 条(批次 1+2+3+4+5+6 实扫 21 条 + 批次 7 v1.3 无侵权列表/导出 2 条 + 主管聚合 1 条 + 按主管删除 1 条 + 批次 8 v1.4 京东数据库列表/详情/删除/分组/类目/删分组/编辑 7 条(导出口 2026-11-15 随客户口径下线)= 32 条)⇒ 有人把钉从表里摘了,取值口看守成空`)
|
||||
for (const p of SEND_POINTS) {
|
||||
const shape = pointShape(p)
|
||||
const compliant = pointCompliant(p)
|
||||
@@ -393,8 +402,8 @@ test('正向:声明 companyScoped 的页,其 api 文件必须真的带 company
|
||||
if (hit) hit.pinned += 1
|
||||
else grouped.set(key, { file: p.file, line: p.line, pinned: 1 })
|
||||
}
|
||||
assert.equal(grouped.size, 20,
|
||||
`发送口表按 (文件, 整行) 应聚成 20 组(28 处发送口,批次 7 的列表/导出/主管聚合/按主管删除与批次 8 的京东列表/导出逐字同行各走同一组),现在却有 ${grouped.size} 组 —— 表被改形状了,对平判据失去分母`)
|
||||
assert.equal(grouped.size, 21,
|
||||
`发送口表按 (文件, 整行) 应聚成 21 组(32 处发送口,批次 7 的列表/导出/主管聚合/按主管删除、批次 8 的京东详情/删除/分组/类目/删分组/编辑逐字同行各走同一组;京东导出口 2026-11-15 随客户口径下线),现在却有 ${grouped.size} 组 —— 表被改形状了,对平判据失去分母`)
|
||||
for (const g of grouped.values()) {
|
||||
const actual = occurrences(stripComments(read(g.file)), g.line)
|
||||
assert.equal(g.pinned, actual,
|
||||
@@ -750,14 +759,14 @@ const WATCH_BODY_PINS: ReadonlyArray<{
|
||||
{ file: 'src/pages/patent/appearance-patent-clean-api.ts', shapes: [/company_id\s*=\s*params\.companyId\b/] },
|
||||
],
|
||||
},
|
||||
// ↓ 批次 8(2026-11-14 v1.4 京东数据库):店铺/商品编码/标题是按行集筛的自由文本,分组选项集是
|
||||
// 公司隔离的(/jd-product-groups 带 company_id)⇒ 上一家的筛选值与 groupId 在新一家的行集/选项集
|
||||
// 里不存在,切 tab 必清且选项重取;页码回 1 同外观专利页。
|
||||
// ↓ 批次 8(2026-11-14 v1.4 京东数据库):店铺/商品编码/标题是按行集筛的自由文本,分组/类目
|
||||
// 选项集是公司隔离的(/jd-product-groups、/jd-products/categories 带 company_id)⇒ 上一家的
|
||||
// 筛选值与 groupId/category 在新一家的行集/选项集里不存在,切 tab 必清且选项重取;页码回 1 同外观专利页。
|
||||
{
|
||||
file: 'src/pages/jd/JdDatabasePage.vue',
|
||||
token: "filter.shopName = ''; filter.productCode = ''; filter.titleKeyword = ''; filter.saleStatus = ''; filter.groupId = ''; filter.syncedFrom = ''; filter.syncedTo = ''; page.value = 1; void loadGroupOptions(); void load()",
|
||||
token: "filter.shopName = ''; filter.productCode = ''; filter.titleKeyword = ''; filter.category = ''; filter.groupId = ''; filter.syncedFrom = ''; filter.syncedTo = ''; page.value = 1; void loadGroupOptions(); void loadCategoryOptions(); void load()",
|
||||
why: '店铺/商品编码/标题是按行集筛的自由文本,上一家的值在新一家的行里不存在 ⇒ 切 tab 后首屏被筛成「暂无商品」,'
|
||||
+ '而输入框还显示着上一家填的值;分组选项集是公司隔离的,上一家选的 groupId 在新一家的选项里不存在,'
|
||||
+ '而输入框还显示着上一家填的值;分组/类目选项集是公司隔离的,上一家选的 groupId/category 在新一家的选项里不存在,'
|
||||
+ '同罪必清且选项重取;页码回 1 是因为新一家的行数更少,末尾的 void load() 才让切 tab 真的换数据',
|
||||
premise: [
|
||||
{ file: 'src/pages/jd/jd-product-api.ts', shapes: [/company_id\s*=\s*params\.companyId\b/] },
|
||||
|
||||
@@ -60,3 +60,16 @@ test('缺 skuId 的行弃掉、空 skus 回空数组(旧数据不渲染空表
|
||||
assert.equal(parseJdProductDetail({ id: 3 }).skus.length, 0)
|
||||
assert.equal(jdSkuSummary([]), '')
|
||||
})
|
||||
|
||||
/** 类目筛选(2026-11-15):京麦末级类目等值过滤,空串不下发、非空透传 category。 */
|
||||
test('类目筛选参数序列化:空串不下发、非空下发 category(等值过滤)', async () => {
|
||||
const { createJdProductFilterState, toJdProductListParams, jdProductFilterActive } =
|
||||
await import('../src/pages/jd/jd-product-filter.ts')
|
||||
const empty = createJdProductFilterState()
|
||||
assert.equal('category' in toJdProductListParams(empty, 1, 20), false, '全部类目不下发 category')
|
||||
assert.equal(jdProductFilterActive(empty), false)
|
||||
|
||||
const filtered = { ...empty, category: ' 服饰内衣 ' }
|
||||
assert.equal(toJdProductListParams(filtered, 1, 20).category, '服饰内衣', '去空白透传(等值过滤)')
|
||||
assert.equal(jdProductFilterActive(filtered), true, '选中类目算激活筛选')
|
||||
})
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
*
|
||||
* 覆盖:
|
||||
* 1. **snake 参数形状**:toJdProductListParams 产出 `page`/`page_size`(默认 20、上限 100)、
|
||||
* `shop_name`/`product_code`/`title_keyword`/`sale_status`/`group_id`/`synced_from`/`synced_to`
|
||||
* `shop_name`/`product_code`/`title_keyword`/`group_id`/`synced_from`/`synced_to`
|
||||
* (ISO yyyy-MM-dd;空白不下发;groupId 空串→不带、有值→snake group_id);分页钳制(铁律 15)。
|
||||
* 商品状态筛选与导出参数口已随 2026-11-15 客户口径下线,不再出现在参数面。
|
||||
* 2. **详情解析**:parseJdProductDetail 解析 attrGroups/images(camel 为正 snake 容错、缺 url 弃行),
|
||||
* attrGroups 解析不出时 attrJsonRaw 原文兜底;列表行解析缺 id 弃行。
|
||||
*
|
||||
@@ -19,7 +20,6 @@ import assert from 'node:assert/strict'
|
||||
import {
|
||||
JD_PRODUCT_MAX_PAGE,
|
||||
createJdProductFilterState,
|
||||
toJdProductExportParams,
|
||||
toJdProductListParams,
|
||||
} from '../src/pages/jd/jd-product-filter.ts'
|
||||
import {
|
||||
@@ -35,7 +35,6 @@ test('京东列表参数——snake 形状:groupId 空→不带、有值→gro
|
||||
shopName: ' 旗舰自营店 ',
|
||||
productCode: ' JD-10086 ',
|
||||
titleKeyword: ' 保温杯 ',
|
||||
saleStatus: '上架中',
|
||||
groupId: ' 7 ',
|
||||
syncedFrom: '2026-11-01',
|
||||
syncedTo: '2026-11-09',
|
||||
@@ -49,7 +48,6 @@ test('京东列表参数——snake 形状:groupId 空→不带、有值→gro
|
||||
shop_name: '旗舰自营店',
|
||||
product_code: 'JD-10086',
|
||||
title_keyword: '保温杯',
|
||||
sale_status: '上架中',
|
||||
group_id: 7,
|
||||
synced_from: '2026-11-01',
|
||||
synced_to: '2026-11-09',
|
||||
@@ -60,21 +58,12 @@ test('京东列表参数——snake 形状:groupId 空→不带、有值→gro
|
||||
assert.deepEqual(blank, { page: 1, page_size: 20 })
|
||||
assert.equal('group_id' in blank, false, 'groupId 空串不带 group_id')
|
||||
const dirty = toJdProductListParams(
|
||||
{ shopName: ' ', productCode: '', titleKeyword: '', saleStatus: '', groupId: 'abc', syncedFrom: '2026/11/01', syncedTo: 'not-a-date' },
|
||||
{ shopName: ' ', productCode: '', titleKeyword: '', groupId: 'abc', syncedFrom: '2026/11/01', syncedTo: 'not-a-date' },
|
||||
1,
|
||||
20,
|
||||
)
|
||||
assert.deepEqual(dirty, { page: 1, page_size: 20 }, '脏值不下发')
|
||||
|
||||
// 导出与列表同一过滤面单出口(无分页)。
|
||||
const state = { shopName: '旗舰自营店', productCode: '', titleKeyword: '', saleStatus: '已下架', groupId: '7', syncedFrom: '2026-11-01', syncedTo: '' }
|
||||
const list = toJdProductListParams(state, 3, 20)
|
||||
const exp = toJdProductExportParams(state)
|
||||
for (const key of Object.keys(exp) as Array<keyof typeof exp>) {
|
||||
assert.equal((list as Record<string, unknown>)[key], exp[key], `导出与列表的 ${key} 必须同源`)
|
||||
}
|
||||
assert.equal('page' in exp, false, '导出参数无分页')
|
||||
assert.deepEqual(exp, { shop_name: '旗舰自营店', sale_status: '已下架', group_id: 7, synced_from: '2026-11-01' })
|
||||
assert.equal('sale_status' in full, false, '商品状态筛选已下线,参数面不再出现 sale_status')
|
||||
})
|
||||
|
||||
test('京东列表参数——page 钳制防 (page-1)*page_size 溢出(铁律 15)', () => {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
/**
|
||||
* 京东数据库页(v1.4 Phase 5)的挂载契约。
|
||||
*
|
||||
* 形态:panel-box + 筛选行(店铺/商品编码/标题关键字/商品状态/分组/同步起止 date 对)+
|
||||
* 查询/导出/重置/管理分组 + 自绘明细表(点行开详情抽屉)+ OldPagination;
|
||||
* 形态:panel-box + 筛选行(店铺/商品编码/标题关键字/分组/同步起止 date 对)+
|
||||
* 查询/重置/管理分组 + 自绘明细表(点行开详情抽屉)+ OldPagination;
|
||||
* 公司 tab 切换=清筛选重取(company-tab-wiring 同口径)。
|
||||
* 商品状态筛选/列与导出按钮已随 2026-11-15 客户口径从前端下线(后端端点保留)。
|
||||
* 不用 readFileSync(source-pin-ratchet 对台账外新文件带读点即红),全部走真实挂载断言。
|
||||
*
|
||||
* 跑法:`npx vitest run tests/mount/jd-database-page.mount.test.ts`
|
||||
@@ -22,12 +23,13 @@ const jdApi = vi.hoisted(() => ({
|
||||
JD_PRODUCT_GROUP_ENDPOINT: '/api/admin/jd-product-groups',
|
||||
fetchJdProductList: vi.fn(),
|
||||
fetchJdProductDetail: vi.fn(),
|
||||
exportJdProductList: vi.fn(),
|
||||
deleteJdProducts: vi.fn(),
|
||||
fetchJdProductGroups: vi.fn(),
|
||||
fetchJdProductCategories: vi.fn(),
|
||||
createJdProductGroup: vi.fn(),
|
||||
updateJdProductGroup: vi.fn(),
|
||||
deleteJdProductGroup: vi.fn(),
|
||||
updateJdProduct: vi.fn(),
|
||||
}))
|
||||
|
||||
const confirmMock = vi.hoisted(() => vi.fn())
|
||||
@@ -75,6 +77,7 @@ beforeEach(() => {
|
||||
useAdminSessionStore().user = { id: 1, username: 'root', role: 'super_admin' }
|
||||
useCompanyTabStore().setActiveId(1)
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([])
|
||||
jdApi.fetchJdProductCategories.mockResolvedValue([])
|
||||
confirmMock.mockResolvedValue(true)
|
||||
})
|
||||
|
||||
@@ -98,34 +101,97 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
expect(wrapper.find('.jd-summary').text()).toContain('共 42 条京东商品')
|
||||
})
|
||||
|
||||
it('行内容按京麦商品列表样式(2026-11-15 用户口径):勾选/店铺/分组/商品信息(图+标题+编码+货号+SKU/信息分)/品牌/价格/库存/状态/同步(9 列),类目等其余收进详情抽屉', async () => {
|
||||
it('行列字段与顺序对齐京麦(2026-11-15 用户口径):勾选/店铺/分组/商品信息(图+标题+编码+货号+品牌·类目+SKU/信息分)/总库存/价格/上架时间·商品状态/创建/修改/同步/操作(11 列)', async () => {
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
const cells = wrapper.findAll('tbody tr')[0].findAll('td')
|
||||
expect(cells).toHaveLength(9)
|
||||
expect(cells).toHaveLength(11)
|
||||
expect(cells[0].find('input[type="checkbox"]').exists()).toBe(true, '第 1 列是勾选框')
|
||||
expect(cells[1].text()).toBe('旗舰自营店', '第 2 列=店铺(用户口径前置为第 1 数据列)')
|
||||
expect(cells[2].text()).toBe('甲组', '第 3 列=分组')
|
||||
// 商品信息列=京麦同款合并布局:主图+信息分+标题+商品编码+货号+SKU 标签。
|
||||
expect(cells[1].text()).toBe('旗舰自营店', '第 2 列=店铺(admin 专属,置前)')
|
||||
expect(cells[2].text()).toBe('甲组', '第 3 列=分组(admin 专属)')
|
||||
// 商品信息列=京麦同款合并布局:主图+信息分+标题+商品编码+货号+品牌·类目行+SKU 标签。
|
||||
const info = cells[3]
|
||||
expect(info.find('.jd-thumb').exists()).toBe(true, '商品信息列含主图')
|
||||
expect(info.text()).toContain('304不锈钢保温杯')
|
||||
expect(info.text()).toContain('JD-1001', '商品编码并入商品信息列')
|
||||
expect(info.text()).toContain('ITEM-1', '货号并入商品信息列')
|
||||
expect(info.text()).toContain('锅宝', '品牌并入商品信息列(京麦品牌·类目行)')
|
||||
expect(info.text()).toContain('家居 > 厨具 > 保温杯', '类目随品牌·类目行上列表(京麦同款)')
|
||||
expect(info.text()).toContain('12个SKU')
|
||||
expect(info.text()).toContain('信息分 81')
|
||||
expect(cells[4].text()).toBe('锅宝')
|
||||
expect(cells[5].text()).toBe('12.90 ~ 15.90', '价格区间=min ~ max')
|
||||
expect(cells[6].text()).toBe('500', '总库存列')
|
||||
expect(cells[7].text()).toBe('上架中')
|
||||
expect(cells[8].text()).not.toBe('-', '同步时间格式化展示')
|
||||
// 类目/上架时间/京东创建/修改时间仍收进详情抽屉(信息分/SKU 数 2026-11-15 起随京麦样式回列表)。
|
||||
expect(cells[4].text()).toBe('500', '第 4 数据列=总库存(京麦第 2 列)')
|
||||
expect(cells[5].text()).toBe('12.90 ~ 15.90', '第 5 数据列=价格(京麦第 3 列)')
|
||||
expect(cells[6].text()).toContain('上架中', '第 6 数据列=上架时间/商品状态(京麦合并列)')
|
||||
expect(cells[6].find('.jd-sale-dot').exists()).toBe(true, '状态带京麦同款圆点')
|
||||
expect(cells[7].text()).not.toBe('-', '第 7 数据列=创建时间')
|
||||
expect(cells[8].text()).not.toBe('-', '第 8 数据列=修改时间')
|
||||
expect(cells[9].text()).not.toBe('-', '第 9 数据列=同步时间(admin 专属,置末)')
|
||||
expect(cells[10].text()).toContain('编辑', '第 10 数据列=操作(编辑/删除)')
|
||||
// 表头字段名与顺序与京麦一致;品牌/类目不再是独立列(收进商品信息)。
|
||||
const headerText = wrapper.find('thead').text()
|
||||
for (const gone of ['类目', '上架时间', '创建时间', '修改时间']) {
|
||||
expect(headerText).not.toContain(gone, `${gone}列已收进详情抽屉,不再上列表`)
|
||||
for (const gone of ['品牌', '类目']) {
|
||||
expect(headerText).not.toContain(gone, `${gone}不再是独立列(京麦把它们收进商品信息)`)
|
||||
}
|
||||
for (const head of ['商品信息', '总库存', '价格', '上架时间 / 商品状态', '创建时间', '修改时间', '同步时间']) {
|
||||
expect(headerText).toContain(head, `表头必须有「${head}」(京麦字段名)`)
|
||||
}
|
||||
expect(wrapper.find('.jd-thumb').exists()).toBe(true, '商品信息列渲染缩略图')
|
||||
})
|
||||
|
||||
it('操作列删除按钮防冒泡且走确认弹窗:确认后调 deleteJdProducts,取消不动(2026-11-15 行级删除)', async () => {
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
// beforeEach 默认 confirm=true;本例先翻回 false 验「取消不动」。
|
||||
confirmMock.mockResolvedValue(false)
|
||||
const opsCell = wrapper.findAll('tbody tr')[0].findAll('td')[10]
|
||||
await opsCell.findAll('button').find((b) => b.text() === '删除')!.trigger('click')
|
||||
await flushPromises()
|
||||
// 防冒泡:点删除不得顺手打开详情抽屉(抽屉的可视判据=.drawer 出现)。
|
||||
expect(wrapper.find('.drawer').exists()).toBe(false, '删除按钮 @click.stop,点它不开详情抽屉')
|
||||
expect(confirmMock).toHaveBeenCalledTimes(1, '删除必须过二次确认')
|
||||
expect(jdApi.deleteJdProducts).toHaveBeenCalledTimes(0, '确认弹窗取消时不发删除请求')
|
||||
// 确认后:deleteJdProducts 按公司 tab 下传(id, companyId)。
|
||||
confirmMock.mockResolvedValue(true)
|
||||
jdApi.deleteJdProducts.mockResolvedValueOnce({ deleted: 1, imagesDeleted: 0, objectsDeleted: 0, objectsKept: 0, objectsSkipped: 0 })
|
||||
await wrapper.findAll('tbody tr')[0].findAll('td')[10].findAll('button').find((b) => b.text() === '删除')!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.deleteJdProducts).toHaveBeenCalledWith([1], 1)
|
||||
})
|
||||
|
||||
it('操作列编辑按钮防冒泡且打开编辑抽屉(抽屉自取详情回填,2026-11-15 行级编辑)', async () => {
|
||||
// fetchJdProductDetail 的返回已由 parseJdProductDetail 归一成 {item, attrGroups, images, skus, attrJsonRaw}。
|
||||
jdApi.fetchJdProductDetail.mockResolvedValue({
|
||||
item: {
|
||||
id: 1,
|
||||
title: '304不锈钢保温杯大容量便携',
|
||||
brand: '锅宝',
|
||||
categoryPath: '家居 > 厨具 > 保温杯',
|
||||
itemNum: 'ITEM-1',
|
||||
priceMin: '12.90',
|
||||
priceMax: '15.90',
|
||||
stockTotal: 500,
|
||||
saleStatus: '上架中',
|
||||
groupId: 7,
|
||||
groupName: '甲组',
|
||||
productCode: 'JD-1001',
|
||||
shopName: '旗舰自营店',
|
||||
},
|
||||
attrGroups: [],
|
||||
images: [],
|
||||
skus: [],
|
||||
attrJsonRaw: '',
|
||||
})
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
const opsCell = wrapper.findAll('tbody tr')[0].findAll('td')[10]
|
||||
await opsCell.findAll('button').find((b) => b.text() === '编辑')!.trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
expect(wrapper.find('.drawer').exists()).toBe(true, '编辑抽屉打开')
|
||||
expect(wrapper.text()).toContain('编辑商品', '抽屉标题点商品')
|
||||
// 抽屉按 (id, companyId) 自取详情回填。
|
||||
expect(jdApi.fetchJdProductDetail).toHaveBeenCalledWith(1, 1)
|
||||
// 编辑抽屉的保存提示文案点名人工编辑锁后果(用户保存前看得见「采集不再覆盖」)。
|
||||
expect(wrapper.text()).toContain('人工维护', '保存后果提示常驻(V199 人工编辑锁)')
|
||||
})
|
||||
|
||||
it('商品信息列:主图无 URL 显示「无图」占位、healthScore 为空不出信息分行、skuCount 为空不出 SKU 标签', async () => {
|
||||
const wrapper = await mountWith({
|
||||
items: [item(1), item(2, { mainImageUrl: '', healthScore: null, skuCount: null })],
|
||||
@@ -153,16 +219,15 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
expect(wrapper.findAll('tbody tr')[0].findAll('td')[2].text()).toBe('未分组')
|
||||
})
|
||||
|
||||
it('筛选生效:店铺/编码/关键字/状态/分组/起止日期,查询回第一页重发', async () => {
|
||||
it('筛选生效:店铺/编码/关键字/分组/起止日期,查询回第一页重发', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 3 }])
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
|
||||
|
||||
const textInputs = wrapper.findAll('.form-group input[type="text"]')
|
||||
expect(textInputs).toHaveLength(4, '店铺+商品编码+标题关键字+商品状态四个文本筛选框')
|
||||
expect(textInputs).toHaveLength(3, '店铺+商品编码+标题关键字三个文本筛选框(商品状态已下线)')
|
||||
await textInputs[0].setValue('旗舰自营店')
|
||||
await textInputs[1].setValue('JD-1001')
|
||||
await textInputs[2].setValue('保温杯')
|
||||
await textInputs[3].setValue('上架中')
|
||||
await wrapper.find('select').setValue('7')
|
||||
const dateInputs = wrapper.findAll('input[type="date"]')
|
||||
await dateInputs[0].setValue('2026-11-01')
|
||||
@@ -175,13 +240,13 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
shopName: '旗舰自营店',
|
||||
productCode: 'JD-1001',
|
||||
titleKeyword: '保温杯',
|
||||
saleStatus: '上架中',
|
||||
groupId: '7',
|
||||
syncedFrom: '2026-11-01',
|
||||
syncedTo: '2026-11-09',
|
||||
page: 1,
|
||||
companyId: 1,
|
||||
})
|
||||
expect(last).not.toHaveProperty('saleStatus', '商品状态筛选已下线,入参不再带 saleStatus')
|
||||
})
|
||||
|
||||
it('分组下拉选中即查', async () => {
|
||||
@@ -204,6 +269,29 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7', page: 1 })
|
||||
})
|
||||
|
||||
it('类目下拉:选项来自 GET /categories(带商品数),选中即查回第一页', async () => {
|
||||
jdApi.fetchJdProductCategories.mockResolvedValue([
|
||||
{ name: '服饰内衣', productCount: 120 },
|
||||
{ name: '运动户外', productCount: 8 },
|
||||
])
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
|
||||
expect(jdApi.fetchJdProductCategories).toHaveBeenCalledWith(1)
|
||||
|
||||
// 第 1 个 select = 分组(既有契约不动),类目下拉紧随其后
|
||||
const selects = wrapper.findAll('.jd-filter-row select')
|
||||
expect(selects).toHaveLength(2)
|
||||
const categorySelect = selects[1]
|
||||
const optionTexts = categorySelect.findAll('option').map((o) => o.text())
|
||||
expect(optionTexts[0]).toBe('全部类目')
|
||||
expect(optionTexts).toContain('服饰内衣(120)')
|
||||
|
||||
const callsBeforeSelect = jdApi.fetchJdProductList.mock.calls.length
|
||||
await categorySelect.setValue('运动户外')
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.length).toBe(callsBeforeSelect + 1, '选中类目必须立刻重查')
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ category: '运动户外', page: 1 })
|
||||
})
|
||||
|
||||
it('重置把筛选面回空并回第一页重取', async () => {
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
|
||||
const textInputs = wrapper.findAll('.form-group input[type="text"]')
|
||||
@@ -235,48 +323,11 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
expect(last.page).toBe(1, '改每页条数后回第一页')
|
||||
})
|
||||
|
||||
it('导出=当前过滤面全量(含公司 tab 与分组),成功反馈点名落盘文件', async () => {
|
||||
const createObjectURL = vi.fn(() => 'blob:mock-url')
|
||||
const revokeObjectURL = vi.fn()
|
||||
const urlRecord = URL as unknown as Record<string, unknown>
|
||||
Object.defineProperty(URL, 'createObjectURL', { value: createObjectURL, configurable: true, writable: true })
|
||||
Object.defineProperty(URL, 'revokeObjectURL', { value: revokeObjectURL, configurable: true, writable: true })
|
||||
const clickSpy = vi.spyOn(HTMLAnchorElement.prototype, 'click').mockImplementation(() => {})
|
||||
jdApi.exportJdProductList.mockImplementation(() =>
|
||||
Promise.resolve({ blob: new Blob(['xlsx']), filename: '京东数据库-20261114090000.xlsx' }),
|
||||
)
|
||||
|
||||
try {
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
const btn = wrapper.findAll('button').find((b) => b.text() === '导出')
|
||||
expect(btn, '筛选行必须有「导出」按钮').toBeTruthy()
|
||||
await btn!.trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
|
||||
expect(jdApi.exportJdProductList).toHaveBeenCalledTimes(1)
|
||||
const call = jdApi.exportJdProductList.mock.calls[0][0]
|
||||
expect(call).toMatchObject({ shopName: '', groupId: '', companyId: 1 })
|
||||
expect(createObjectURL).toHaveBeenCalledTimes(1)
|
||||
expect(clickSpy).toHaveBeenCalled()
|
||||
expect(document.body.textContent).toContain('已导出', '成功反馈点名落盘文件')
|
||||
} finally {
|
||||
Object.defineProperty(URL, 'createObjectURL', { value: undefined, configurable: true, writable: true })
|
||||
Object.defineProperty(URL, 'revokeObjectURL', { value: undefined, configurable: true, writable: true })
|
||||
clickSpy.mockRestore()
|
||||
}
|
||||
})
|
||||
|
||||
it('导出失败把服务端业务文案弹出来,不许静默;在途标记复位', async () => {
|
||||
jdApi.exportJdProductList.mockImplementation(() => Promise.reject(new Error('京东商品共 80001 行,超过导出上限 50000 行,请缩小筛选范围后重试')))
|
||||
it('导出按钮已下线:筛选行不再出现「导出」(2026-11-15 客户口径「导出也不用」)', async () => {
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
await wrapper.findAll('button').find((b) => b.text() === '导出')!.trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
expect(document.body.textContent).toContain('超过导出上限')
|
||||
const btn = wrapper.findAll('button').find((b) => b.text() === '导出')
|
||||
expect(btn!.text()).toBe('导出', '失败后在途标记必须复位')
|
||||
expect((btn!.element as HTMLButtonElement).disabled).toBe(false)
|
||||
expect(btn, '导出按钮必须已从前端移除').toBeUndefined()
|
||||
expect(jdApi.fetchJdProductList).toHaveBeenCalledTimes(1, '下线导出不影响列表首屏')
|
||||
})
|
||||
|
||||
it('点行打开详情抽屉:按 (id, companyId) 取详情,attrGroups 分块渲染', async () => {
|
||||
@@ -460,6 +511,7 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
expect(last.shopName).toBe('', '切公司必须清掉上一家的店铺名')
|
||||
expect(last.titleKeyword).toBe('', '切公司必须清掉上一家的标题关键字')
|
||||
expect(last.groupId).toBe('', '切公司必须清掉上一家选的分组')
|
||||
expect(last).not.toHaveProperty('category', '切公司必须清掉上一家选的类目')
|
||||
expect(last.page).toBe(1)
|
||||
expect(jdApi.fetchJdProductGroups).toHaveBeenLastCalledWith(2)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user