mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 11:49:20 +08:00
style(工作台): 优化工作台kpi卡片样式
This commit is contained in:
+125
-149
@@ -19,6 +19,8 @@ const props = defineProps<{
|
|||||||
yoyCompareDateEnd?: string | null;
|
yoyCompareDateEnd?: string | null;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
|
const COLS_PER_ROW = 4;
|
||||||
|
|
||||||
const IconGmv = createIconifyIcon('lucide:layers');
|
const IconGmv = createIconifyIcon('lucide:layers');
|
||||||
const IconSales = createIconifyIcon('lucide:wallet');
|
const IconSales = createIconifyIcon('lucide:wallet');
|
||||||
const IconGross = createIconifyIcon('lucide:trending-up');
|
const IconGross = createIconifyIcon('lucide:trending-up');
|
||||||
@@ -29,88 +31,71 @@ const IconRefund = createIconifyIcon('lucide:undo-2');
|
|||||||
const IconRoi = createIconifyIcon('lucide:target');
|
const IconRoi = createIconifyIcon('lucide:target');
|
||||||
const IconDefault = createIconifyIcon('lucide:bar-chart-3');
|
const IconDefault = createIconifyIcon('lucide:bar-chart-3');
|
||||||
|
|
||||||
type KpiVisual = {
|
type KpiMeta = {
|
||||||
icon: Component;
|
icon: Component;
|
||||||
iconWrap: string;
|
|
||||||
valueText: string;
|
|
||||||
highlight?: boolean;
|
|
||||||
/** 指标上升是否为利好(退款率上升为劣) */
|
|
||||||
upIsGood: boolean;
|
upIsGood: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const KPI_VISUALS: Record<string, KpiVisual> = {
|
const KPI_DISPLAY_ORDER = [
|
||||||
总GMV: {
|
'总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,
|
'广告ROI',
|
||||||
iconWrap: 'bg-blue-50 text-blue-600 dark:bg-blue-950/60 dark:text-blue-300',
|
] as const;
|
||||||
valueText: 'text-blue-700 dark:text-blue-300',
|
|
||||||
highlight: true,
|
const KPI_META: Record<string, KpiMeta> = {
|
||||||
upIsGood: true,
|
总GMV: { icon: IconGmv, upIsGood: true },
|
||||||
},
|
实际销售额: { icon: IconSales, upIsGood: true },
|
||||||
毛利润: {
|
毛利润: { icon: IconGross, upIsGood: true },
|
||||||
icon: IconGross,
|
净利润: { icon: IconNet, upIsGood: true },
|
||||||
iconWrap: 'bg-emerald-50 text-emerald-600 dark:bg-emerald-950/50 dark:text-emerald-300',
|
订单量: { icon: IconOrders, upIsGood: true },
|
||||||
valueText: 'text-emerald-700 dark:text-emerald-300',
|
客单价: { icon: IconAov, upIsGood: true },
|
||||||
upIsGood: true,
|
退款率: { icon: IconRefund, upIsGood: false },
|
||||||
},
|
广告ROI: { icon: IconRoi, 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 DEFAULT_VISUAL: KpiVisual = {
|
const DEFAULT_META: KpiMeta = {
|
||||||
icon: IconDefault,
|
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,
|
upIsGood: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
const kpiRows = computed(() =>
|
const orderedKpiRows = computed(() => {
|
||||||
props.kpis.map((kpi, index) => ({
|
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,
|
kpi,
|
||||||
index,
|
meta: KPI_META[kpi.label] ?? DEFAULT_META,
|
||||||
visual: KPI_VISUALS[kpi.label] ?? DEFAULT_VISUAL,
|
fillSpan: index === total - 1 && lastRowFillSpan > 1 ? lastRowFillSpan : 0,
|
||||||
})),
|
}));
|
||||||
);
|
});
|
||||||
|
|
||||||
function compareRangeHint(start?: string | null, end?: string | null): string {
|
function compareRangeHint(start?: string | null, end?: string | null): string {
|
||||||
if (start && end) return `对比区间:${start} 至 ${end}`;
|
if (start && end) return `对比区间:${start} 至 ${end}`;
|
||||||
return '对比区间未返回';
|
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 } {
|
function primaryLine(kpi: WorkbenchVO.KpiItem): { display: string; hover: string } {
|
||||||
const ay = kpi.amountYuan;
|
const ay = kpi.amountYuan;
|
||||||
if (ay == null || !Number.isFinite(ay)) {
|
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 };
|
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 {
|
function trendIsGood(kpi: WorkbenchVO.KpiItem, up: boolean): boolean {
|
||||||
const v = visualFor(kpi);
|
const meta = KPI_META[kpi.label] ?? DEFAULT_META;
|
||||||
return v.upIsGood ? up : !up;
|
return meta.upIsGood ? up : !up;
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatDelta(kpi: WorkbenchVO.KpiItem, pct: number | undefined | null): string {
|
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}`;
|
return `${sign}${n}${suffix}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function badgeClass(good: boolean): string {
|
function deltaTextClass(good: boolean): string {
|
||||||
return good
|
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'
|
? 'text-emerald-600 dark:text-emerald-400'
|
||||||
: '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-rose-600 dark:text-rose-400';
|
||||||
}
|
}
|
||||||
|
|
||||||
function cardShellClass(highlight?: boolean): string {
|
/** 末行未满时,最后一张卡跨列铺满 */
|
||||||
const base =
|
function gridSpanClass(fillSpan: number): string {
|
||||||
'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 (fillSpan <= 1) return '';
|
||||||
if (highlight) {
|
return `lg:col-span-${fillSpan}`;
|
||||||
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%)]`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
v-if="kpis.length === 0"
|
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>
|
||||||
<div
|
<div
|
||||||
v-else
|
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
|
<div
|
||||||
v-for="{ kpi, visual } in kpiRows"
|
v-for="{ kpi, meta, fillSpan } in orderedKpiRows"
|
||||||
:key="kpi.label"
|
:key="kpi.label"
|
||||||
:class="cardShellClass(visual.highlight)"
|
:class="[cardShellClass, gridSpanClass(fillSpan)]"
|
||||||
>
|
>
|
||||||
<div class="mb-4 flex items-start justify-between gap-3">
|
<div class="mb-4 flex items-start justify-between gap-3">
|
||||||
<div class="flex min-w-0 items-center gap-2.5">
|
<div class="flex min-w-0 items-center gap-3">
|
||||||
<span
|
<span :class="iconShellClass">
|
||||||
class="flex h-9 w-9 shrink-0 items-center justify-center rounded-xl"
|
<component :is="meta.icon" class="text-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 }}
|
|
||||||
</span>
|
</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>
|
||||||
<div class="flex shrink-0 flex-wrap justify-end gap-1">
|
<div class="flex shrink-0 flex-col items-end gap-1.5">
|
||||||
<Tooltip
|
<Tooltip
|
||||||
:title="compareRangeHint(momCompareDateStart, momCompareDateEnd)"
|
:title="compareRangeHint(momCompareDateStart, momCompareDateEnd)"
|
||||||
>
|
>
|
||||||
<span
|
<span :class="trendBadgeShellClass">
|
||||||
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"
|
<span class="mr-1 opacity-60">环</span>
|
||||||
:class="badgeClass(trendIsGood(kpi, kpi.up === true))"
|
<span :class="deltaTextClass(trendIsGood(kpi, kpi.up === true))">
|
||||||
>
|
{{ formatDelta(kpi, kpi.changePct) }}
|
||||||
<span class="opacity-70">环</span>
|
</span>
|
||||||
<span>{{ formatDelta(kpi, kpi.changePct) }}</span>
|
|
||||||
</span>
|
</span>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Tooltip
|
<Tooltip
|
||||||
v-if="kpi.yoyChangePct != null && kpi.yoyUp != null"
|
v-if="kpi.yoyChangePct != null && kpi.yoyUp != null"
|
||||||
:title="compareRangeHint(yoyCompareDateStart, yoyCompareDateEnd)"
|
:title="compareRangeHint(yoyCompareDateStart, yoyCompareDateEnd)"
|
||||||
>
|
>
|
||||||
<span
|
<span :class="trendBadgeShellClass">
|
||||||
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"
|
<span class="mr-1 opacity-60">同</span>
|
||||||
:class="badgeClass(trendIsGood(kpi, kpi.yoyUp === true))"
|
<span :class="deltaTextClass(trendIsGood(kpi, kpi.yoyUp === true))">
|
||||||
>
|
{{ formatDelta(kpi, kpi.yoyChangePct) }}
|
||||||
<span class="opacity-70">同</span>
|
</span>
|
||||||
<span>{{ formatDelta(kpi, kpi.yoyChangePct) }}</span>
|
|
||||||
</span>
|
</span>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div class="flex flex-col">
|
||||||
class="text-[1.75rem] font-black leading-tight tracking-tight sm:text-[2rem]"
|
<div
|
||||||
:class="visual.valueText"
|
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">
|
<Tooltip v-if="primaryLine(kpi).hover" :title="primaryLine(kpi).hover">
|
||||||
<span
|
<span class="cursor-default">
|
||||||
class="cursor-default border-b border-dotted border-current/30 pb-0.5"
|
{{ 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 }}
|
{{ primaryLine(kpi).display }}
|
||||||
<span
|
<span
|
||||||
v-if="kpi.preferWanDisplay !== true && kpi.unit"
|
v-if="kpi.unit"
|
||||||
class="ml-1 text-base font-bold opacity-60"
|
class="ml-1 text-base font-medium text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||||
>
|
>
|
||||||
{{ kpi.unit }}
|
{{ kpi.unit }}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</template>
|
||||||
</Tooltip>
|
</div>
|
||||||
<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%)]"
|
|
||||||
>
|
|
||||||
<div
|
<div
|
||||||
class="h-full rounded-full bg-rose-500 transition-all duration-500 dark:bg-rose-400"
|
v-if="kpi.sub"
|
||||||
:style="{
|
class="mt-1 truncate text-[11px] font-medium text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||||
width: `${Math.min(Math.max(Number(kpi.value) || 0, 0), 100)}%`,
|
>
|
||||||
}"
|
{{ kpi.sub }}
|
||||||
/>
|
</div>
|
||||||
</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>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user