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
@@ -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>