feat(jd): 列表列对齐+主图投影+SKU 矩阵+删除链收口(B101/B102 服务端与后管)

This commit is contained in:
2026-11-15 00:01:24 +08:00
parent 8d8c88a5f3
commit 402447af70
36 changed files with 2184 additions and 81 deletions
@@ -1,6 +1,7 @@
<script setup lang="ts">
/** 京东数据库页(v1.4 Phase 5):公司隔离的京东商品库,筛选行(店铺/商品编码/标题关键字/商品状态/
* 分组/同步起止 date 对)+查询/导出/重置/管理分组 + 自绘明细表(点行开详情抽屉)+ OldPagination。
* 分组/同步起止 date 对)+查询/导出/重置/管理分组 + 自绘明细表(勾选列+点行开详情抽屉)
* + 删除(单行/批量,先删桶对象、全成功才删库行,确认弹窗点名数量)+ OldPagination。
* 骨架像素复刻「外观专利数据库」页(panel-box + LoadFailureBar + 自绘 table + 旧式分页);
* 公司 tab 切换=清筛选重取(watch 体照外观专利页逐字形状);日期对护栏:起侧 max=止侧、
* 止侧 min=起侧、两侧 @change 用 orderedPair 把倒挂交换回来(clampJdSyncedRange 照 clampDatePair)。
@@ -8,6 +9,7 @@
* (date-filter-default-today 护栏 EXEMPT 口径,外观专利页同款)。 */
import { computed, onMounted, reactive, ref, watch } from 'vue'
import {
deleteJdProducts,
exportJdProductList,
fetchJdProductGroups,
fetchJdProductList,
@@ -21,6 +23,7 @@ import JdProductGroupDialog from './JdProductGroupDialog.vue'
import OldPagination from '@/components/OldPagination.vue'
import { useCompanyTabStore } from '@/stores/company-tab'
import { showAdminFeedback } from '@/components/admin-feedback-ui'
import { openAdminConfirm } from '@/components/admin-confirm'
import { loadFailureMessage } from '@/components/load-failure-model'
import LoadFailureBar from '@/components/LoadFailureBar.vue'
import { formatDateTime, orderedPair } from '@/utils/datetime'
@@ -87,6 +90,8 @@ async function load(): Promise<void> {
rows.value = result.items
total.value = result.total
if (result.page >= 1) page.value = result.page
// 重取后上一批勾选可能已不在本页(翻页/筛选变化):清空,防"看不见的勾选被一起删"。
selectedIds.value = new Set()
} catch (error) {
loadFailure.value = loadFailureMessage(error, '京东商品列表加载失败')
showAdminFeedback(loadFailure.value, 'error')
@@ -161,6 +166,59 @@ function closeDetail(): void {
detailItem.value = null
}
// ---------------- 删除(先删桶、全成功才删库行,语义在后端 JdProductDeleteService) ----------------
/** 本页勾选集(按行 id)。切页/切公司/重取后勾选清空——上一页勾的行不自动带到下一页。 */
const selectedIds = ref<Set<number>>(new Set())
const deleting = ref(false)
const selectedCount = computed(() => selectedIds.value.size)
function toggleSelect(row: JdProductItem, checked: boolean): void {
const next = new Set(selectedIds.value)
if (checked) next.add(row.id)
else next.delete(row.id)
selectedIds.value = next
}
const allSelected = computed(() => rows.value.length > 0 && rows.value.every((row) => selectedIds.value.has(row.id)))
function toggleSelectAll(checked: boolean): void {
selectedIds.value = checked ? new Set(rows.value.map((row) => row.id)) : new Set()
}
/** 单行删除入口(行内按钮):确认弹窗点名商品编码与「桶内图片一并删除」。 */
async function removeOne(row: JdProductItem): Promise<void> {
await removeMany([row], `确定删除商品「${row.productCode || row.title}」吗?`)
}
/** 批量删除入口(勾选后点工具栏按钮):确认弹窗点名行数。 */
async function removeSelected(): Promise<void> {
const picked = rows.value.filter((row) => selectedIds.value.has(row.id))
await removeMany(picked, `确定删除勾选的 ${picked.length} 个商品吗?`)
}
/** 删除主流程:二次确认 → 先删桶、全成功才删库行(后端保证)→ 刷新列表并清勾选。 */
async function removeMany(picked: JdProductItem[], message: string): Promise<void> {
if (!picked.length || deleting.value) return
const ok = await openAdminConfirm({ title: '删除京东商品', message: `${message}删除后该商品的 SKU、图片登记与 jd-products 桶内图片文件一并删除(被其他商品共用的图片会保留);此操作不可恢复。`, confirmText: '确认删除', danger: true })
if (!ok) return
deleting.value = true
try {
const receipt = await deleteJdProducts(picked.map((row) => row.id), companyTab.requestCompanyId)
showAdminFeedback(`已删除 ${receipt.deleted} 个商品,清理 ${receipt.objectsDeleted} 个图片文件` +
(receipt.objectsKept ? `(${receipt.objectsKept} 个共用图片保留)` : ''), 'success')
selectedIds.value = new Set()
if (picked.length >= rows.value.length && page.value > 1) page.value -= 1
await load()
} catch (error) {
const text = error instanceof Error && error.message ? error.message : '删除失败,请稍后重试'
showAdminFeedback(text, 'error')
} finally {
deleting.value = false
}
}
// 切公司 = 重新取数:店铺/编码/关键字/状态/分组是上一家选中的值,在新一家的行集里筛不出东西,
// 必须一起清,分组选项也按新公司重取(选项集是公司隔离的)。
watch(() => companyTab.activeId, () => { filter.shopName = ''; filter.productCode = ''; filter.titleKeyword = ''; filter.saleStatus = ''; filter.groupId = ''; filter.syncedFrom = ''; filter.syncedTo = ''; page.value = 1; void loadGroupOptions(); void load() })
@@ -224,48 +282,71 @@ onMounted(() => {
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
<div class="jd-toolbar">
<span class="jd-summary">共 {{ total }} 条京东商品</span>
<button
v-if="selectedCount"
class="btn btn-danger jd-delete-btn"
type="button"
:disabled="deleting"
@click="removeSelected"
>
{{ deleting ? '删除中...' : `删除勾选(${selectedCount})` }}
</button>
</div>
<div class="table-scroll jd-table-scroll">
<table>
<thead>
<tr>
<th style="width: 42px"><input type="checkbox" :checked="allSelected" @change="toggleSelectAll(($event.target as HTMLInputElement).checked)" /></th>
<th style="width: 76px">主图</th>
<th>商品信息</th>
<th style="width: 118px">商品编码</th>
<th style="width: 118px">货号</th>
<th style="width: 110px">类目</th>
<th style="width: 86px">品牌</th>
<th style="width: 76px">信息分</th>
<th style="width: 70px">SKU</th>
<th style="width: 120px">店铺</th>
<th style="width: 110px">商品编码</th>
<th>标题</th>
<th style="width: 90px">品牌</th>
<th style="width: 110px">价格区间</th>
<th style="width: 64px">库存</th>
<th style="width: 80px">状态</th>
<th style="width: 76px">总库存</th>
<th style="width: 112px">价格区间</th>
<th style="width: 170px">上架时间</th>
<th style="width: 86px">商品状态</th>
<th style="width: 170px">创建时间</th>
<th style="width: 170px">修改时间</th>
<th style="width: 100px">分组</th>
<th style="width: 170px">京东更新时间</th>
<th style="width: 170px">同步时间</th>
</tr>
</thead>
<tbody>
<template v-if="rows.length">
<tr v-for="row in rows" :key="row.id" class="jd-row" @click="openDetail(row)">
<td @click.stop><input type="checkbox" :checked="selectedIds.has(row.id)" @change="toggleSelect(row, ($event.target as HTMLInputElement).checked)" /></td>
<td>
<img v-if="row.mainImageUrl" class="jd-thumb" :src="row.mainImageUrl" alt="" loading="lazy" />
<span v-else class="empty-mini">无图</span>
</td>
<td :title="row.shopName || ''">{{ row.shopName || '-' }}</td>
<td class="mono-cell">{{ row.productCode || '-' }}</td>
<td class="title-cell" :title="row.title">{{ row.title || '-' }}</td>
<td class="mono-cell">{{ row.productCode || '-' }}</td>
<td class="mono-cell">{{ row.itemNum || '-' }}</td>
<td :title="row.categoryPath || ''">{{ row.categoryPath || '-' }}</td>
<td>{{ row.brand || '-' }}</td>
<td>{{ jdPriceRange(row) || '-' }}</td>
<td>{{ row.healthScore ?? '-' }}</td>
<td>{{ row.skuCount ?? '-' }}</td>
<td :title="row.shopName || ''">{{ row.shopName || '-' }}</td>
<td>{{ row.stockTotal ?? '-' }}</td>
<td>{{ jdPriceRange(row) || '-' }}</td>
<td>{{ row.jdOnlineAt ? formatDateTime(row.jdOnlineAt) : '-' }}</td>
<td>{{ row.saleStatus || '-' }}</td>
<td :title="row.groupName || ''">{{ row.groupName || '未分组' }}</td>
<td>{{ row.jdCreatedAt ? formatDateTime(row.jdCreatedAt) : '-' }}</td>
<td>{{ formatDateTime(row.jdUpdatedAt || '') }}</td>
<td :title="row.groupName || ''">{{ row.groupName || '未分组' }}</td>
<td>{{ formatDateTime(row.syncedAt || '') }}</td>
</tr>
</template>
<tr v-else-if="loading">
<td colspan="11" class="empty-tip">加载中...</td>
<td colspan="18" class="empty-tip">加载中...</td>
</tr>
<tr v-else>
<td colspan="11" class="empty-tip">暂无京东商品数据</td>
<td colspan="18" class="empty-tip">暂无京东商品数据</td>
</tr>
</tbody>
</table>
@@ -416,8 +497,22 @@ h3 {
.jd-toolbar {
display: flex;
align-items: center;
gap: 14px;
margin-bottom: 10px;
}
/* 删除按钮挂到工具栏右侧(scoped:分组弹窗那份 .btn-danger 借不过来)。 */
.jd-delete-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;
@@ -437,7 +532,7 @@ h3 {
table-layout: fixed;
}
.jd-table-scroll > table {
min-width: 1260px;
min-width: 1860px;
}
.table-scroll th,
.table-scroll td {