feat: 发布工作台悬停 SKU 数展示规格明细表

This commit is contained in:
2026-09-14 17:37:31 +08:00
parent 618e052807
commit 333f8a3031
@@ -13,6 +13,7 @@ import {
Empty,
InputNumber,
Modal,
Popover,
Space,
Table,
Tag,
@@ -97,12 +98,110 @@ const columns = [
{ type: 'selection', width: 48 },
{ title: '标题', dataIndex: 'title', key: 'title', ellipsis: true },
{ title: '店铺', dataIndex: 'shopName', key: 'shopName', width: 140 },
{ title: 'SKU数', dataIndex: 'skuCount', key: 'skuCount', width: 80 },
{ title: 'SKU数', dataIndex: 'skuCount', key: 'skuCount', width: 88 },
{ title: '状态', key: 'status', width: 100 },
{ title: '更新时间', dataIndex: 'updateTime', key: 'updateTime', width: 170 },
{ title: '操作', key: 'actions', width: 200 },
];
/** 列表悬停:从草稿 payloadJson.editorState.skuRows 解析 */
type DraftSkuPreview = {
key: string;
skuName: string;
specText: string;
outSkuSn: string;
/** 原价(元) */
priceYuan?: number;
/** 拼团价(元) */
multiPriceYuan?: number;
quantity?: number;
internalLabel: string;
};
const skuPreviewColumns = [
{ title: '规格', dataIndex: 'specText', key: 'specText', width: 140, ellipsis: true },
{ title: '商家编码', dataIndex: 'outSkuSn', key: 'outSkuSn', width: 120, ellipsis: true },
{ title: '原价', key: 'priceYuan', width: 80 },
{ title: '拼团价', key: 'multiPriceYuan', width: 80 },
{ title: '库存', dataIndex: 'quantity', key: 'quantity', width: 64 },
{ title: '内部SKU', dataIndex: 'internalLabel', key: 'internalLabel', width: 160, ellipsis: true },
];
function toOptionalNumber(raw: unknown): number | undefined {
if (typeof raw === 'number') {
return Number.isFinite(raw) ? raw : undefined;
}
if (raw == null || raw === '') return undefined;
const n = Number(raw);
return Number.isFinite(n) ? n : undefined;
}
function parseDraftSkuPreviews(draft: {
id?: number;
payloadJson?: string;
}): DraftSkuPreview[] {
if (!draft.payloadJson) return [];
try {
const root = JSON.parse(draft.payloadJson) as {
editorState?: { skuRows?: Record<string, unknown>[] };
};
const rows = root.editorState?.skuRows;
if (!Array.isArray(rows) || rows.length === 0) return [];
const draftId = draft.id ?? 0;
return rows.map((r, i) => {
const saleValues = r.saleValues;
let specText = '';
if (saleValues && typeof saleValues === 'object' && !Array.isArray(saleValues)) {
specText = Object.values(saleValues as Record<string, unknown>)
.map((v) => String(v ?? '').trim())
.filter(Boolean)
.join(' / ');
}
const skuName = String(r.skuName || '').trim();
const productName = String(r.productName || '').trim();
const internalSkuName = String(r.internalSkuName || '').trim();
let internalLabel = '—';
if (productName && internalSkuName) {
internalLabel = `${productName} / ${internalSkuName}`;
} else if (internalSkuName || productName) {
internalLabel = internalSkuName || productName;
}
return {
key: `${draftId}-${i}`,
skuName,
specText: specText || skuName || '—',
outSkuSn: String(r.outSkuSn || '').trim() || '—',
priceYuan: toOptionalNumber(r.priceYuan),
multiPriceYuan: toOptionalNumber(r.multiPriceYuan),
quantity: toOptionalNumber(r.quantity),
internalLabel,
};
});
} catch {
return [];
}
}
/** 同一草稿对象只解析一次 */
const skuPreviewCache = new WeakMap<object, DraftSkuPreview[]>();
/** Table bodyCell 的 record 类型偏宽,只依赖 id / payloadJson */
function getDraftSkuPreviews(draft: {
id?: number;
payloadJson?: string;
}): DraftSkuPreview[] {
const hit = skuPreviewCache.get(draft);
if (hit) return hit;
const list = parseDraftSkuPreviews(draft);
skuPreviewCache.set(draft, list);
return list;
}
function formatSkuPrice(price?: number) {
if (price == null || Number.isNaN(price)) return '—';
return `¥${price.toFixed(2)}`;
}
async function loadShops() {
try {
const data = await getPddShopPageApi({
@@ -396,7 +495,42 @@ onUnmounted(() => stopJobPoll());
:locale="{ emptyText: '暂无待发草稿' }"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'status'">
<template v-if="column.key === 'skuCount'">
<Popover
v-if="getDraftSkuPreviews(record).length > 0"
trigger="hover"
placement="bottomLeft"
:overlay-style="{ maxWidth: '800px' }"
>
<template #content>
<div class="mb-1 text-xs text-muted-foreground">
共 {{ getDraftSkuPreviews(record).length }} 个 SKU
</div>
<Table
size="small"
:pagination="false"
:scroll="{ y: 280 }"
:columns="skuPreviewColumns"
:data-source="getDraftSkuPreviews(record)"
row-key="key"
>
<template #bodyCell="{ column: col, record: sku }">
<template v-if="col.key === 'priceYuan'">
{{ formatSkuPrice(sku.priceYuan) }}
</template>
<template v-else-if="col.key === 'multiPriceYuan'">
{{ formatSkuPrice(sku.multiPriceYuan) }}
</template>
</template>
</Table>
</template>
<span class="cursor-default text-primary underline decoration-dotted">
{{ record.skuCount ?? 0 }}
</span>
</Popover>
<span v-else>{{ record.skuCount ?? 0 }}</span>
</template>
<template v-else-if="column.key === 'status'">
<Tag :color="statusLabel[record.status]?.color || 'default'">
{{ statusLabel[record.status]?.text || record.status }}
</Tag>