feat: 优化商品卡

This commit is contained in:
小蟑螂
2026-05-12 12:27:53 +08:00
parent 4279af3fb4
commit 1621388d9f
5 changed files with 306 additions and 198 deletions
@@ -0,0 +1,13 @@
---
description: Ant Design Vue Spin 与可滚动 flex/grid 布局的配合方式,避免列表无法滚动
globs: ecom-dmb-frontend/apps/web-antd/**/*.vue
alwaysApply: false
---
# Spin 与侧栏/向导内滚动
- **不要用 `<Spin :spinning>` 整块包住「可滚动列表」所在的主内容区**。`Spin` 会渲染 `ant-spin-nested-loading` / `ant-spin-container`,内层常见 `overflow: hidden` 或高度链断裂,导致子元素虽有 `overflow-y: auto` 但**滚轮/触控滚不动**。
- **推荐**:加载态拆细——例如字段定义用独立 `ref`(如 `fieldDefsLoading`),只在列表上方或占位区放小号 `Spin`/文案;提交操作用按钮 `:loading` + `message.loading`,避免大 Spin 套滚动容器。
- **布局**:侧栏/向导内滚动依赖整条 flex 链上的 **`min-h-0` / `minmax(0,1fr)`**,列表容器用 **`flex-1 min-h-0 overflow-y-auto`**;需要时可加 **`overscroll-behavior-y: contain`**(如 Tailwind `overscroll-y-contain`)减少滚动链冒泡到外层页面。
参考实现:`ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/order-import/components/ImportTaskWizard.vue`(订单导入向导)。
@@ -118,35 +118,76 @@ export const COST_STRUCTURE_PIE_COLORS = [
'#14b8a6',
] as const;
export const FUNNEL_STEPS = [
{ name: 'GMV', value: 286.4 },
{ name: '实收金额', value: 271.8 },
{ name: '扣除成本', value: 220.4 },
{ name: '扣除广告', value: 170.0 },
{ name: '扣除佣金', value: 141.4 },
{ name: '扣除物流', value: 107.8 },
{ name: '毛利润', value: 68.2 },
{ name: '净利润', value: 38.9 },
] as const;
/** 商品销量 TOP5(演示):件数、GMV、环比 */
export type ProductSalesTopItem = {
rank: number;
name: string;
sales: number;
gmvWan: number;
momPct: number;
barColor: string;
};
/** 漏斗图各层颜色(与 FUNNEL_STEPS 顺序一致) */
export const FUNNEL_STAGE_COLORS = [
'#ef4444',
'#f97316',
'#f59e0b',
'#eab308',
'#84cc16',
'#22c55e',
'#14b8a6',
'#10b981',
] as const;
export const PRODUCT_SALES_TOP5: ProductSalesTopItem[] = [
{
rank: 1,
name: '316不锈钢保温杯-女款 500ml',
sales: 42_860,
gmvWan: 42.6,
momPct: 18.2,
barColor: '#f59e0b',
},
{
rank: 2,
name: '大容量运动水壶 1.2L 吸管款',
sales: 31_240,
gmvWan: 28.9,
momPct: 9.6,
barColor: '#6366f1',
},
{
rank: 3,
name: '玻璃内胆保温壶 2.5L 家用',
sales: 24_180,
gmvWan: 36.2,
momPct: -2.1,
barColor: '#10b981',
},
{
rank: 4,
name: '儿童保温杯卡通款 350ml',
sales: 19_650,
gmvWan: 15.4,
momPct: 6.8,
barColor: '#a855f7',
},
{
rank: 5,
name: '情侣对杯礼盒 限定包装',
sales: 15_920,
gmvWan: 22.7,
momPct: 14.0,
barColor: '#ec4899',
},
];
/** 近12月:柱=GMV(万),折线=净利率(%)— 与原型 HTML 一致 */
export const MONTHLY_GMV_NET_RATE = {
months: ['4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月', '1月', '2月', '3月'],
gmvWan: [168, 194, 282, 156, 172, 188, 201, 486, 218, 183, 248, 286],
netRatePct: [12.3, 13.1, 11.8, 12.8, 13.4, 14.1, 13.9, 10.2, 13.8, 14.2, 14.8, 14.3],
} as const;
/** 平台销量 TOP5(演示):万件 + 占比 */
export type PlatformSalesTopItem = {
rank: number;
label: string;
short: string;
salesWan: number;
sharePct: number;
color: string;
};
export const PLATFORM_SALES_TOP5: PlatformSalesTopItem[] = [
{ rank: 1, label: '拼多多', short: 'PDD', salesWan: 58.2, sharePct: 38.6, color: '#e02e24' },
{ rank: 2, label: '抖音电商', short: '抖店', salesWan: 36.4, sharePct: 24.1, color: '#fe2c55' },
{ rank: 3, label: '淘宝', short: 'TB', salesWan: 28.7, sharePct: 19.0, color: '#ff5000' },
{ rank: 4, label: '京东', short: 'JD', salesWan: 21.3, sharePct: 14.1, color: '#e3393c' },
{ rank: 5, label: '快手小店', short: 'KS', salesWan: 6.2, sharePct: 4.1, color: '#ff6600' },
];
export const STORES = [
{
@@ -24,13 +24,12 @@ import {
COST_STRUCTURE,
COST_STRUCTURE_PIE_COLORS,
FINANCE_KPIS,
FUNNEL_STAGE_COLORS,
FUNNEL_STEPS,
GLOBAL_SUMMARY,
GMV_TREND,
MONTHLY_GMV_NET_RATE,
PLATFORM_OPTIONS,
PLATFORM_SALES_TOP5,
PRODUCT_RANK,
PRODUCT_SALES_TOP5,
PRODUCT_TIME_SEGMENTS,
PROMO_TABLE,
PROMO_TIMELINE,
@@ -64,12 +63,6 @@ const platformSelectOptions = computed(() =>
const financeChartRef = ref<EchartsUIType>();
const { renderEcharts: renderFinanceTrend } = useEcharts(financeChartRef);
const funnelChartRef = ref<EchartsUIType>();
const { renderEcharts: renderFunnelChart } = useEcharts(funnelChartRef);
const monthlyChartRef = ref<EchartsUIType>();
const { renderEcharts: renderMonthlyChart } = useEcharts(monthlyChartRef);
const costPieChartRef = ref<EchartsUIType>();
const { renderEcharts: renderCostPieChart } = useEcharts(costPieChartRef);
@@ -93,6 +86,27 @@ const costTotal = computed(() =>
COST_STRUCTURE.reduce((a, x) => a + x.value, 0),
);
const productSalesTopMax = computed(() =>
Math.max(...PRODUCT_SALES_TOP5.map((x) => x.sales), 1),
);
const platformSalesTopMax = computed(() =>
Math.max(...PLATFORM_SALES_TOP5.map((x) => x.salesWan), 0.01),
);
const rankMedalClass = (rank: number) => {
if (rank === 1) {
return 'bg-gradient-to-br from-amber-400 to-orange-600 text-white shadow-md shadow-amber-500/30';
}
if (rank === 2) {
return 'bg-gradient-to-br from-slate-300 to-slate-500 text-slate-900 dark:from-slate-500 dark:to-slate-700 dark:text-white';
}
if (rank === 3) {
return 'bg-gradient-to-br from-amber-700 to-orange-900 text-amber-100';
}
return 'bg-slate-100 text-slate-600 dark:bg-slate-800 dark:text-slate-300';
};
const keywordColumnsSimple = [
{ title: '关键词', dataIndex: 'keyword', key: 'keyword', ellipsis: true },
{ title: '曝光量', dataIndex: 'impression', key: 'impression' },
@@ -224,138 +238,6 @@ const drawFinanceTrend = () => {
});
};
const drawFunnel = () => {
if (!funnelChartRef.value) return;
const isDark = document.documentElement.classList.contains('dark');
const border = isDark ? 'hsl(222.34deg 10.43% 12.27%)' : '#fff';
renderFunnelChart({
tooltip: {
trigger: 'item',
backgroundColor: isDark ? 'hsl(222.34deg 10.43% 12.27%)' : '#fff',
textStyle: { color: isDark ? 'hsl(0deg 0% 95%)' : '#0f172a' },
formatter: '{b}: <b>{c}</b> 万元',
},
series: [
{
type: 'funnel',
left: '6%',
width: '88%',
top: 16,
bottom: 8,
minSize: '8%',
maxSize: '100%',
sort: 'descending',
gap: 2,
label: {
show: true,
position: 'inside',
formatter: '{b}\n{c}万',
color: '#fff',
fontSize: 11,
fontWeight: 700,
},
labelLine: { show: false },
itemStyle: {
borderColor: border,
borderWidth: 2,
},
data: FUNNEL_STEPS.map((s, i) => ({
name: s.name,
value: s.value,
itemStyle: {
color: FUNNEL_STAGE_COLORS[i] ?? '#6366f1',
},
})),
},
],
});
};
const drawMonthlyGmvNetRate = () => {
if (!monthlyChartRef.value) return;
const isDark = document.documentElement.classList.contains('dark');
const axisLabel = isDark ? 'hsl(240deg 5% 64.9%)' : '#64748b';
const split = isDark ? 'hsl(240deg 3.7% 22%)' : '#f1f5f9';
renderMonthlyChart({
tooltip: {
trigger: 'axis',
backgroundColor: isDark ? 'hsl(222.34deg 10.43% 12.27%)' : '#fff',
textStyle: { color: isDark ? 'hsl(0deg 0% 95%)' : '#0f172a' },
},
legend: {
top: 0,
textStyle: { color: axisLabel },
data: ['月GMV(万)', '净利率(%)'],
},
grid: { left: '3%', right: '3%', bottom: '3%', top: 48, containLabel: true },
xAxis: {
type: 'category',
data: [...MONTHLY_GMV_NET_RATE.months],
axisLine: { lineStyle: { color: split } },
axisLabel: { color: axisLabel, fontSize: 11 },
},
yAxis: [
{
type: 'value',
name: 'GMV(万)',
nameTextStyle: { color: axisLabel },
splitLine: { lineStyle: { type: 'dashed', color: split } },
axisLabel: { color: axisLabel },
},
{
type: 'value',
name: '净利率%',
min: 8,
max: 20,
position: 'right',
nameTextStyle: { color: axisLabel },
axisLabel: {
color: axisLabel,
formatter: '{value}%',
},
splitLine: { show: false },
},
],
series: [
{
name: '月GMV(万)',
type: 'bar',
data: [...MONTHLY_GMV_NET_RATE.gmvWan],
barMaxWidth: 22,
itemStyle: {
color: {
type: 'linear',
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{ offset: 0, color: '#6366f1' },
{ offset: 1, color: 'rgba(99, 102, 241, 0.35)' },
],
},
},
markPoint: {
data: [{ type: 'max', name: '峰值' }],
itemStyle: { color: '#f59e0b' },
},
},
{
name: '净利率(%)',
type: 'line',
yAxisIndex: 1,
smooth: true,
symbolSize: 6,
data: [...MONTHLY_GMV_NET_RATE.netRatePct],
lineStyle: { width: 2.5, color: '#10b981' },
itemStyle: { color: '#10b981' },
},
],
});
};
const drawCostPie = () => {
if (!costPieChartRef.value) return;
const isDark = document.documentElement.classList.contains('dark');
@@ -425,8 +307,6 @@ const rerenderFinanceCharts = async () => {
await nextTick();
drawFinanceTrend();
drawCostPie();
drawFunnel();
drawMonthlyGmvNetRate();
};
watch(activeTab, (k) => {
@@ -645,27 +525,124 @@ const panelCardClass =
</div>
</div>
<div :class="panelCardClass">
<h3 class="mb-1 text-lg font-black text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
利润漏斗(万元)
</h3>
<p class="mb-4 text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
从 GMV 到净利润全链路拆解
</p>
<div class="h-[380px] w-full sm:h-[400px]">
<EchartsUI ref="funnelChartRef" />
<div class="grid grid-cols-1 gap-6 xl:grid-cols-2">
<div :class="panelCardClass">
<div class="mb-5 flex flex-wrap items-end justify-between gap-2">
<div>
<h3 class="text-lg font-black text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
商品销量 TOP5
</h3>
<p class="mt-1 text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
近30天 · 按销量件数 · 含 GMV 与环比(演示)
</p>
</div>
</div>
<ul class="space-y-5">
<li
v-for="row in PRODUCT_SALES_TOP5"
:key="row.rank"
class="rounded-xl border border-slate-100 bg-slate-50/80 p-3 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(240deg_3.7%_15.9%/35%)]"
>
<div class="flex gap-3">
<div
class="flex h-9 w-9 shrink-0 items-center justify-center rounded-xl text-sm font-black tabular-nums"
:class="rankMedalClass(row.rank)"
>
{{ row.rank }}
</div>
<div class="min-w-0 flex-1">
<div class="flex flex-wrap items-start justify-between gap-x-2 gap-y-1">
<p class="min-w-0 flex-1 text-sm font-bold leading-snug text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
{{ row.name }}
</p>
<span
class="shrink-0 text-right text-sm font-black tabular-nums text-slate-900 dark:text-[hsl(0deg_0%_95%)]"
>
{{ row.sales.toLocaleString() }}
<span class="text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">件</span>
</span>
</div>
<div class="mt-1.5 flex flex-wrap items-center justify-between gap-2 text-xs font-bold text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
<span>GMV {{ row.gmvWan }} 万</span>
<Tag :color="row.momPct >= 0 ? 'success' : 'error'" class="!m-0 !text-[11px]">
环比 {{ row.momPct >= 0 ? '+' : '' }}{{ row.momPct }}%
</Tag>
</div>
<div class="mt-2 h-2 overflow-hidden rounded-full bg-slate-200/80 dark:bg-slate-900/60">
<div
class="h-full rounded-full transition-[width] duration-500"
:style="{
width: `${Math.round((row.sales / productSalesTopMax) * 100)}%`,
backgroundColor: row.barColor,
boxShadow: `0 0 12px ${row.barColor}55`,
}"
/>
</div>
</div>
</div>
</li>
</ul>
</div>
</div>
<div :class="panelCardClass">
<h3 class="mb-1 text-lg font-black text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
月度 GMV &amp; 净利率环比
</h3>
<p class="mb-4 text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
柱=月 GMV(万),折线=净利率(%)· 近12月
</p>
<div class="h-[300px] w-full sm:h-[320px]">
<EchartsUI ref="monthlyChartRef" />
<div :class="panelCardClass">
<div class="mb-5 flex flex-wrap items-end justify-between gap-2">
<div>
<h3 class="text-lg font-black text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
平台销量 TOP5
</h3>
<p class="mt-1 text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
全店铺聚合 · 销量(万件)与占比(演示)
</p>
</div>
</div>
<ul class="space-y-4">
<li
v-for="p in PLATFORM_SALES_TOP5"
:key="p.rank"
class="flex items-center gap-3 rounded-xl border border-slate-100 bg-slate-50/80 px-3 py-3 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(240deg_3.7%_15.9%/35%)]"
>
<div
class="flex h-8 w-8 shrink-0 items-center justify-center rounded-lg text-xs font-black tabular-nums"
:class="rankMedalClass(p.rank)"
>
{{ p.rank }}
</div>
<div
class="flex h-10 w-10 shrink-0 items-center justify-center rounded-xl text-[11px] font-black ring-1 ring-slate-200/80 dark:ring-[hsl(240deg_3.7%_22%)]"
:style="{
backgroundColor: `${p.color}18`,
color: p.color,
}"
>
{{ p.short }}
</div>
<div class="min-w-0 flex-1">
<div class="flex flex-wrap items-baseline justify-between gap-2">
<span class="truncate text-sm font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
{{ p.label }}
</span>
<span class="shrink-0 text-sm font-black tabular-nums text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
{{ p.salesWan }}<span class="text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">万件</span>
</span>
</div>
<div class="mt-2 flex items-center gap-3">
<div class="h-2 min-w-0 flex-1 overflow-hidden rounded-full bg-slate-200/80 dark:bg-slate-900/60">
<div
class="h-full rounded-full"
:style="{
width: `${Math.round((p.salesWan / platformSalesTopMax) * 100)}%`,
backgroundColor: p.color,
boxShadow: `0 0 10px ${p.color}44`,
}"
/>
</div>
<span class="w-12 shrink-0 text-right text-xs font-black tabular-nums text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
{{ p.sharePct }}%
</span>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
@@ -15,6 +15,7 @@ import {
Input,
InputNumber,
message,
Pagination,
Popconfirm,
Tooltip,
TreeSelect,
@@ -69,6 +70,8 @@ interface Emits {
(e: 'delete', product: ProductVO.Info): void;
(e: 'updated', product: ProductVO.Info): void;
(e: 'editing-change', editing: boolean): void;
/** 规格分页等导致卡片高度变化时,通知父级刷新瀑布流 */
(e: 'layout-change'): void;
}
const handleDelete = (product: ProductVO.Info) => {
@@ -241,6 +244,48 @@ const displaySpecs = computed(() => {
return props.product.specs || [];
});
/** 规格表格每页条数 */
const SPECS_PAGE_SIZE = 5;
const specsCurrentPage = ref(1);
const specsTotalPages = computed(() =>
Math.max(1, Math.ceil(displaySpecs.value.length / SPECS_PAGE_SIZE)),
);
const pagedSpecsWithIndex = computed(() => {
const list = displaySpecs.value;
const start = (specsCurrentPage.value - 1) * SPECS_PAGE_SIZE;
return list.slice(start, start + SPECS_PAGE_SIZE).map((spec, i) => ({
spec,
globalIndex: start + i,
}));
});
watch(
() => displaySpecs.value.length,
() => {
const last = specsTotalPages.value;
if (specsCurrentPage.value > last) {
specsCurrentPage.value = last;
}
},
);
watch(
() => props.product.id,
() => {
specsCurrentPage.value = 1;
},
);
watch(
specsCurrentPage,
() => {
emit('layout-change');
},
{ flush: 'post' },
);
const formatCost = (val?: number) => `¥${(val ?? 0).toFixed(2)}`;
function addSpec() {
@@ -253,6 +298,8 @@ function addSpec() {
shippingCost: 0,
specCode: '',
});
const len = draft.value.specs.length;
specsCurrentPage.value = Math.ceil(len / SPECS_PAGE_SIZE);
(emit as (event: string, ...args: unknown[]) => void)('editing-change');
}
@@ -514,24 +561,31 @@ const saveEdit = async () => {
<span v-if="isEditing" class="op-col">操作</span>
</div>
<div
v-for="(spec, index) in displaySpecs"
v-for="{ spec, globalIndex } in pagedSpecsWithIndex"
:key="
isEditing
? (spec as EditableSpec).id ?? (spec as EditableSpec)._clientKey ?? `idx-${index}`
: spec.id
? (spec as EditableSpec).id ??
(spec as EditableSpec)._clientKey ??
`idx-${globalIndex}`
: `${spec.id ?? 'row'}-${globalIndex}`
"
class="spec-row spec-row--body group"
:class="{ 'editing-row': isEditing }"
>
<span class="cell cell-code">
<span v-if="!isEditing" class="code-tag">{{ spec.specCode || '未填写' }}</span>
<Input v-else v-model:value="draft.specs[index]!.specCode" class="field-input" placeholder="编码" />
<Input
v-else
v-model:value="draft.specs[globalIndex]!.specCode"
class="field-input"
placeholder="编码"
/>
</span>
<span class="cell cell-name">
<span v-if="!isEditing" class="field-text spec-name-text">{{ spec.name || '-' }}</span>
<TextArea
v-else
v-model:value="draft.specs[index]!.name"
v-model:value="draft.specs[globalIndex]!.name"
class="field-textarea"
placeholder="规格名称"
:auto-size="{ minRows: 1, maxRows: 3 }"
@@ -549,7 +603,7 @@ const saveEdit = async () => {
placeholder="0"
:min="0"
:precision="2"
@update:value="(v) => { draft.specs[index]!.productCost = (v as number) ?? 0; }"
@update:value="(v) => { draft.specs[globalIndex]!.productCost = (v as number) ?? 0; }"
/>
</span>
<span class="cell cell-cost">
@@ -564,7 +618,7 @@ const saveEdit = async () => {
placeholder="0"
:min="0"
:precision="2"
@update:value="(v) => { draft.specs[index]!.shippingCost = (v as number) ?? 0; }"
@update:value="(v) => { draft.specs[globalIndex]!.shippingCost = (v as number) ?? 0; }"
/>
</span>
<span class="cell cell-cost">
@@ -579,17 +633,26 @@ const saveEdit = async () => {
placeholder="0"
:min="0"
:precision="2"
@update:value="(v) => { draft.specs[index]!.otherCost = (v as number) ?? 0; }"
@update:value="(v) => { draft.specs[globalIndex]!.otherCost = (v as number) ?? 0; }"
/>
</span>
<span v-if="isEditing" class="cell op-col">
<Tooltip title="删除此规格">
<Button type="text" danger size="small" class="delete-spec-btn" @click="removeSpec(index)">
<Button type="text" danger size="small" class="delete-spec-btn" @click="removeSpec(globalIndex)">
<template #icon><TrashIcon class="h-4 w-4" /></template>
</Button>
</Tooltip>
</span>
</div>
<div v-if="displaySpecs.length > SPECS_PAGE_SIZE" class="specs-pagination-row">
<Pagination
v-model:current="specsCurrentPage"
size="small"
:total="displaySpecs.length"
:page-size="SPECS_PAGE_SIZE"
:show-size-changer="false"
/>
</div>
</div>
<div v-else-if="!isEditing" class="empty-text">暂无规格数据</div>
</div>
@@ -1130,6 +1193,19 @@ const saveEdit = async () => {
background: rgb(248 250 252 / 0.45);
}
.table-container:has(.specs-pagination-row) > .spec-row--body:last-of-type {
border-bottom: none;
}
.specs-pagination-row {
display: flex;
align-items: center;
justify-content: flex-end;
padding: 8px 16px;
background: rgb(248 250 252 / 0.45);
border-top: 1px solid #f1f5f9;
}
.spec-head {
color: #64748b;
font-weight: 700;
@@ -344,6 +344,7 @@ onUnmounted(() => {
@updated="(p) => refreshTable(p)"
@delete="handleDelete"
@editing-change="handleEditingChange"
@layout-change="handleEditingChange"
/>
</div>
</template>