mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:59:19 +08:00
style(工作台): 优化工作台kpi卡片样式
This commit is contained in:
+125
-149
@@ -19,6 +19,8 @@ const props = defineProps<{
|
||||
yoyCompareDateEnd?: string | null;
|
||||
}>();
|
||||
|
||||
const COLS_PER_ROW = 4;
|
||||
|
||||
const IconGmv = createIconifyIcon('lucide:layers');
|
||||
const IconSales = createIconifyIcon('lucide:wallet');
|
||||
const IconGross = createIconifyIcon('lucide:trending-up');
|
||||
@@ -29,88 +31,71 @@ const IconRefund = createIconifyIcon('lucide:undo-2');
|
||||
const IconRoi = createIconifyIcon('lucide:target');
|
||||
const IconDefault = createIconifyIcon('lucide:bar-chart-3');
|
||||
|
||||
type KpiVisual = {
|
||||
type KpiMeta = {
|
||||
icon: Component;
|
||||
iconWrap: string;
|
||||
valueText: string;
|
||||
highlight?: boolean;
|
||||
/** 指标上升是否为利好(退款率上升为劣) */
|
||||
upIsGood: boolean;
|
||||
};
|
||||
|
||||
const KPI_VISUALS: Record<string, KpiVisual> = {
|
||||
总GMV: {
|
||||
icon: IconGmv,
|
||||
iconWrap: 'bg-slate-100 text-slate-600 dark:bg-slate-800 dark:text-slate-300',
|
||||
valueText: 'text-slate-900 dark:text-[hsl(0deg_0%_95%)]',
|
||||
upIsGood: true,
|
||||
},
|
||||
实际销售额: {
|
||||
icon: IconSales,
|
||||
iconWrap: 'bg-blue-50 text-blue-600 dark:bg-blue-950/60 dark:text-blue-300',
|
||||
valueText: 'text-blue-700 dark:text-blue-300',
|
||||
highlight: true,
|
||||
upIsGood: true,
|
||||
},
|
||||
毛利润: {
|
||||
icon: IconGross,
|
||||
iconWrap: 'bg-emerald-50 text-emerald-600 dark:bg-emerald-950/50 dark:text-emerald-300',
|
||||
valueText: 'text-emerald-700 dark:text-emerald-300',
|
||||
upIsGood: true,
|
||||
},
|
||||
净利润: {
|
||||
icon: IconNet,
|
||||
iconWrap: 'bg-violet-50 text-violet-600 dark:bg-violet-950/50 dark:text-violet-300',
|
||||
valueText: 'text-violet-700 dark:text-violet-300',
|
||||
highlight: true,
|
||||
upIsGood: true,
|
||||
},
|
||||
订单量: {
|
||||
icon: IconOrders,
|
||||
iconWrap: 'bg-cyan-50 text-cyan-700 dark:bg-cyan-950/50 dark:text-cyan-300',
|
||||
valueText: 'text-slate-900 dark:text-[hsl(0deg_0%_95%)]',
|
||||
upIsGood: true,
|
||||
},
|
||||
客单价: {
|
||||
icon: IconAov,
|
||||
iconWrap: 'bg-amber-50 text-amber-700 dark:bg-amber-950/50 dark:text-amber-300',
|
||||
valueText: 'text-slate-900 dark:text-[hsl(0deg_0%_95%)]',
|
||||
upIsGood: true,
|
||||
},
|
||||
退款率: {
|
||||
icon: IconRefund,
|
||||
iconWrap: 'bg-rose-50 text-rose-600 dark:bg-rose-950/50 dark:text-rose-300',
|
||||
valueText: 'text-rose-700 dark:text-rose-300',
|
||||
upIsGood: false,
|
||||
},
|
||||
广告ROI: {
|
||||
icon: IconRoi,
|
||||
iconWrap: 'bg-indigo-50 text-indigo-600 dark:bg-indigo-950/50 dark:text-indigo-300',
|
||||
valueText: 'text-indigo-700 dark:text-indigo-300',
|
||||
upIsGood: true,
|
||||
},
|
||||
const KPI_DISPLAY_ORDER = [
|
||||
'总GMV',
|
||||
'实际销售额',
|
||||
'毛利润',
|
||||
'净利润',
|
||||
'订单量',
|
||||
'客单价',
|
||||
'退款率',
|
||||
'广告ROI',
|
||||
] as const;
|
||||
|
||||
const KPI_META: Record<string, KpiMeta> = {
|
||||
总GMV: { icon: IconGmv, upIsGood: true },
|
||||
实际销售额: { icon: IconSales, upIsGood: true },
|
||||
毛利润: { icon: IconGross, upIsGood: true },
|
||||
净利润: { icon: IconNet, upIsGood: true },
|
||||
订单量: { icon: IconOrders, upIsGood: true },
|
||||
客单价: { icon: IconAov, upIsGood: true },
|
||||
退款率: { icon: IconRefund, upIsGood: false },
|
||||
广告ROI: { icon: IconRoi, upIsGood: true },
|
||||
};
|
||||
|
||||
const DEFAULT_VISUAL: KpiVisual = {
|
||||
const DEFAULT_META: KpiMeta = {
|
||||
icon: IconDefault,
|
||||
iconWrap: 'bg-slate-100 text-slate-600 dark:bg-slate-800 dark:text-slate-300',
|
||||
valueText: 'text-slate-900 dark:text-[hsl(0deg_0%_95%)]',
|
||||
upIsGood: true,
|
||||
};
|
||||
|
||||
const kpiRows = computed(() =>
|
||||
props.kpis.map((kpi, index) => ({
|
||||
const orderedKpiRows = computed(() => {
|
||||
const byLabel = new Map(props.kpis.map((k) => [k.label, k]));
|
||||
const ordered: WorkbenchVO.KpiItem[] = [];
|
||||
for (const label of KPI_DISPLAY_ORDER) {
|
||||
const k = byLabel.get(label);
|
||||
if (k) ordered.push(k);
|
||||
}
|
||||
for (const k of props.kpis) {
|
||||
if (!KPI_DISPLAY_ORDER.includes(k.label as (typeof KPI_DISPLAY_ORDER)[number])) {
|
||||
ordered.push(k);
|
||||
}
|
||||
}
|
||||
const total = ordered.length;
|
||||
const remainder = total % COLS_PER_ROW;
|
||||
const lastRowFillSpan = remainder === 0 ? 0 : COLS_PER_ROW - remainder + 1;
|
||||
|
||||
return ordered.map((kpi, index) => ({
|
||||
kpi,
|
||||
index,
|
||||
visual: KPI_VISUALS[kpi.label] ?? DEFAULT_VISUAL,
|
||||
})),
|
||||
);
|
||||
meta: KPI_META[kpi.label] ?? DEFAULT_META,
|
||||
fillSpan: index === total - 1 && lastRowFillSpan > 1 ? lastRowFillSpan : 0,
|
||||
}));
|
||||
});
|
||||
|
||||
function compareRangeHint(start?: string | null, end?: string | null): string {
|
||||
if (start && end) return `对比区间:${start} 至 ${end}`;
|
||||
return '对比区间未返回';
|
||||
}
|
||||
|
||||
function labelTooltip(kpi: WorkbenchVO.KpiItem): string | undefined {
|
||||
const sub = kpi.sub?.trim();
|
||||
return sub || undefined;
|
||||
}
|
||||
|
||||
function primaryLine(kpi: WorkbenchVO.KpiItem): { display: string; hover: string } {
|
||||
const ay = kpi.amountYuan;
|
||||
if (ay == null || !Number.isFinite(ay)) {
|
||||
@@ -123,13 +108,9 @@ function primaryLine(kpi: WorkbenchVO.KpiItem): { display: string; hover: string
|
||||
return { display: String(kpi.value ?? ''), hover };
|
||||
}
|
||||
|
||||
function visualFor(kpi: WorkbenchVO.KpiItem): KpiVisual {
|
||||
return KPI_VISUALS[kpi.label] ?? DEFAULT_VISUAL;
|
||||
}
|
||||
|
||||
function trendIsGood(kpi: WorkbenchVO.KpiItem, up: boolean): boolean {
|
||||
const v = visualFor(kpi);
|
||||
return v.upIsGood ? up : !up;
|
||||
const meta = KPI_META[kpi.label] ?? DEFAULT_META;
|
||||
return meta.upIsGood ? up : !up;
|
||||
}
|
||||
|
||||
function formatDelta(kpi: WorkbenchVO.KpiItem, pct: number | undefined | null): string {
|
||||
@@ -140,125 +121,120 @@ function formatDelta(kpi: WorkbenchVO.KpiItem, pct: number | undefined | null):
|
||||
return `${sign}${n}${suffix}`;
|
||||
}
|
||||
|
||||
function badgeClass(good: boolean): string {
|
||||
function deltaTextClass(good: boolean): string {
|
||||
return good
|
||||
? 'bg-emerald-50 text-emerald-700 ring-emerald-200/80 dark:bg-emerald-950/40 dark:text-emerald-300 dark:ring-emerald-800/50'
|
||||
: 'bg-red-50 text-red-600 ring-red-200/80 dark:bg-red-950/40 dark:text-red-400 dark:ring-red-900/50';
|
||||
? 'text-emerald-600 dark:text-emerald-400'
|
||||
: 'text-rose-600 dark:text-rose-400';
|
||||
}
|
||||
|
||||
function cardShellClass(highlight?: boolean): string {
|
||||
const base =
|
||||
'group relative overflow-hidden rounded-2xl border border-slate-200/90 p-5 shadow-[0_4px_14px_rgba(15,23,42,0.04)] transition-[box-shadow,transform] duration-200 hover:-translate-y-0.5 hover:shadow-[0_8px_24px_rgba(15,23,42,0.08)] dark:border-[hsl(240deg_3.7%_22%)] dark:shadow-none dark:hover:shadow-[0_8px_28px_rgba(0,0,0,0.35)] sm:p-6 backdrop-blur-[10px]';
|
||||
if (highlight) {
|
||||
return `${base} bg-gradient-to-br from-white via-white to-slate-50/90 dark:from-[hsl(222.34deg_10.43%_12.27%)] dark:via-[hsl(222.34deg_10.43%_12.27%)] dark:to-[hsl(240deg_3.7%_15.9%)]`;
|
||||
}
|
||||
return `${base} bg-white/92 dark:bg-[hsl(222.34deg_10.43%_12.27%)]`;
|
||||
/** 末行未满时,最后一张卡跨列铺满 */
|
||||
function gridSpanClass(fillSpan: number): string {
|
||||
if (fillSpan <= 1) return '';
|
||||
return `lg:col-span-${fillSpan}`;
|
||||
}
|
||||
|
||||
const cardShellClass =
|
||||
'group flex min-h-[8.5rem] min-w-0 flex-col justify-between rounded-2xl border border-slate-200 bg-white/90 p-5 shadow-[0_4px_12px_rgba(0,0,0,0.03)] transition-all duration-200 hover:border-slate-300 hover:shadow-md dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(222.34deg_10.43%_12.27%)] dark:shadow-none dark:hover:border-[hsl(240deg_3.7%_35%)] backdrop-blur-[10px] sm:min-h-[9rem] sm:p-6';
|
||||
const iconShellClass =
|
||||
'flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-slate-50 text-slate-500 transition-colors group-hover:bg-slate-100 dark:bg-[hsl(240deg_3.7%_15.9%)] dark:text-[hsl(240deg_5%_64.9%)] dark:group-hover:bg-[hsl(240deg_3.7%_22%)]';
|
||||
const trendBadgeShellClass =
|
||||
'inline-flex cursor-default items-center rounded-lg bg-slate-50 px-2 py-1 text-[11px] font-bold leading-none text-slate-500 dark:bg-[hsl(240deg_3.7%_15.9%)] dark:text-[hsl(240deg_5%_64.9%)]';
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-if="kpis.length === 0"
|
||||
class="rounded-2xl border border-dashed border-slate-200 bg-white/60 px-6 py-10 text-center text-sm font-bold text-slate-400 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(222.34deg_10.43%_12.27%)] dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
class="rounded-2xl border border-dashed border-slate-200 bg-white/60 px-4 py-12 text-center text-sm text-slate-400 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(222.34deg_10.43%_12.27%)] dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
暂无 KPI 数据(请调整筛选或日期范围)
|
||||
暂无 KPI 数据
|
||||
</div>
|
||||
<div
|
||||
v-else
|
||||
class="grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4"
|
||||
class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4"
|
||||
>
|
||||
<div
|
||||
v-for="{ kpi, visual } in kpiRows"
|
||||
v-for="{ kpi, meta, fillSpan } in orderedKpiRows"
|
||||
:key="kpi.label"
|
||||
:class="cardShellClass(visual.highlight)"
|
||||
:class="[cardShellClass, gridSpanClass(fillSpan)]"
|
||||
>
|
||||
<div class="mb-4 flex items-start justify-between gap-3">
|
||||
<div class="flex min-w-0 items-center gap-2.5">
|
||||
<span
|
||||
class="flex h-9 w-9 shrink-0 items-center justify-center rounded-xl"
|
||||
:class="visual.iconWrap"
|
||||
>
|
||||
<component :is="visual.icon" class="text-lg" />
|
||||
</span>
|
||||
<span
|
||||
class="truncate text-xs font-black uppercase tracking-wide text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
{{ kpi.label }}
|
||||
<div class="flex min-w-0 items-center gap-3">
|
||||
<span :class="iconShellClass">
|
||||
<component :is="meta.icon" class="text-xl" />
|
||||
</span>
|
||||
<div class="flex flex-col min-w-0">
|
||||
<Tooltip v-if="labelTooltip(kpi)" :title="labelTooltip(kpi)">
|
||||
<span
|
||||
class="cursor-default truncate text-xs font-bold uppercase tracking-wider text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
{{ kpi.label }}
|
||||
</span>
|
||||
</Tooltip>
|
||||
<span
|
||||
v-else
|
||||
class="truncate text-xs font-bold uppercase tracking-wider text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
{{ kpi.label }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex shrink-0 flex-wrap justify-end gap-1">
|
||||
<div class="flex shrink-0 flex-col items-end gap-1.5">
|
||||
<Tooltip
|
||||
:title="compareRangeHint(momCompareDateStart, momCompareDateEnd)"
|
||||
>
|
||||
<span
|
||||
class="inline-flex cursor-default items-center gap-0.5 rounded-md px-1.5 py-0.5 text-[10px] font-black ring-1 ring-inset"
|
||||
:class="badgeClass(trendIsGood(kpi, kpi.up === true))"
|
||||
>
|
||||
<span class="opacity-70">环</span>
|
||||
<span>{{ formatDelta(kpi, kpi.changePct) }}</span>
|
||||
<span :class="trendBadgeShellClass">
|
||||
<span class="mr-1 opacity-60">环</span>
|
||||
<span :class="deltaTextClass(trendIsGood(kpi, kpi.up === true))">
|
||||
{{ formatDelta(kpi, kpi.changePct) }}
|
||||
</span>
|
||||
</span>
|
||||
</Tooltip>
|
||||
<Tooltip
|
||||
v-if="kpi.yoyChangePct != null && kpi.yoyUp != null"
|
||||
:title="compareRangeHint(yoyCompareDateStart, yoyCompareDateEnd)"
|
||||
>
|
||||
<span
|
||||
class="inline-flex cursor-default items-center gap-0.5 rounded-md px-1.5 py-0.5 text-[10px] font-black ring-1 ring-inset"
|
||||
:class="badgeClass(trendIsGood(kpi, kpi.yoyUp === true))"
|
||||
>
|
||||
<span class="opacity-70">同</span>
|
||||
<span>{{ formatDelta(kpi, kpi.yoyChangePct) }}</span>
|
||||
<span :class="trendBadgeShellClass">
|
||||
<span class="mr-1 opacity-60">同</span>
|
||||
<span :class="deltaTextClass(trendIsGood(kpi, kpi.yoyUp === true))">
|
||||
{{ formatDelta(kpi, kpi.yoyChangePct) }}
|
||||
</span>
|
||||
</span>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="text-[1.75rem] font-black leading-tight tracking-tight sm:text-[2rem]"
|
||||
:class="visual.valueText"
|
||||
>
|
||||
<Tooltip v-if="primaryLine(kpi).hover" :title="primaryLine(kpi).hover">
|
||||
<span
|
||||
class="cursor-default border-b border-dotted border-current/30 pb-0.5"
|
||||
>
|
||||
<div class="flex flex-col">
|
||||
<div
|
||||
class="min-w-0 truncate text-2xl font-bold leading-tight tracking-tight text-slate-900 dark:text-[hsl(0deg_0%_95%)] sm:text-3xl"
|
||||
>
|
||||
<Tooltip v-if="primaryLine(kpi).hover" :title="primaryLine(kpi).hover">
|
||||
<span class="cursor-default">
|
||||
{{ primaryLine(kpi).display }}
|
||||
<span
|
||||
v-if="kpi.preferWanDisplay !== true && kpi.unit"
|
||||
class="ml-1 text-base font-medium text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
{{ kpi.unit }}
|
||||
</span>
|
||||
</span>
|
||||
</Tooltip>
|
||||
<template v-else>
|
||||
{{ primaryLine(kpi).display }}
|
||||
<span
|
||||
v-if="kpi.preferWanDisplay !== true && kpi.unit"
|
||||
class="ml-1 text-base font-bold opacity-60"
|
||||
v-if="kpi.unit"
|
||||
class="ml-1 text-base font-medium text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
{{ kpi.unit }}
|
||||
</span>
|
||||
</span>
|
||||
</Tooltip>
|
||||
<template v-else>
|
||||
{{ primaryLine(kpi).display }}
|
||||
<span
|
||||
v-if="kpi.unit"
|
||||
class="ml-1 text-base font-bold opacity-60"
|
||||
>
|
||||
{{ kpi.unit }}
|
||||
</span>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="kpi.label === '退款率' && kpi.changePct != null"
|
||||
class="mt-3 h-1.5 w-full overflow-hidden rounded-full bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)]"
|
||||
>
|
||||
</template>
|
||||
</div>
|
||||
<div
|
||||
class="h-full rounded-full bg-rose-500 transition-all duration-500 dark:bg-rose-400"
|
||||
:style="{
|
||||
width: `${Math.min(Math.max(Number(kpi.value) || 0, 0), 100)}%`,
|
||||
}"
|
||||
/>
|
||||
v-if="kpi.sub"
|
||||
class="mt-1 truncate text-[11px] font-medium text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
{{ kpi.sub }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p
|
||||
v-if="kpi.sub"
|
||||
class="mt-3 border-t border-slate-100 pt-3 text-[11px] font-bold leading-relaxed text-slate-400 dark:border-[hsl(240deg_3.7%_22%)] dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
{{ kpi.sub }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user