mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 04:29:20 +08:00
feat(order-stat,workbench): 订单统计日表扩展 GMV/销售单量件数并贯通刷新读写,工作台经营 KPI 扩至 22 项及前端展示配置
This commit is contained in:
+131
-139
@@ -1,115 +1,109 @@
|
||||
<script lang="ts" setup>
|
||||
import type { Component } from 'vue';
|
||||
import type { WorkbenchVO } from '#/api/ecommerce/workbench/types';
|
||||
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import { Tooltip } from 'ant-design-vue';
|
||||
|
||||
import { formatWanShort, formatYuanDetail } from '../../../utils/money';
|
||||
import OverviewColumnHint from '#/components/overview/OverviewColumnHint.vue';
|
||||
|
||||
import { formatYuanDetail, yuanToWanNum } from '../../../utils/money';
|
||||
import {
|
||||
catalogLabels,
|
||||
clampFinanceKpiColsPerRow,
|
||||
kpiMetaByLabel,
|
||||
sortLabelsByCatalog,
|
||||
} from '../kpi-catalog';
|
||||
import { getFinanceKpiHint } from '../finance-kpi-hints';
|
||||
|
||||
defineOptions({ name: 'WorkbenchFinanceKpiGrid' });
|
||||
|
||||
const props = defineProps<{
|
||||
kpis: WorkbenchVO.KpiItem[];
|
||||
/** 用户勾选的 KPI label 列表 */
|
||||
visibleLabels: string[];
|
||||
/** 与汇总表一致,用于「税额」列说明 */
|
||||
taxRate?: number;
|
||||
/** 每行卡片数(来自用户设置) */
|
||||
colsPerRow?: number;
|
||||
momCompareDateStart?: string | null;
|
||||
momCompareDateEnd?: string | null;
|
||||
yoyCompareDateStart?: string | null;
|
||||
yoyCompareDateEnd?: string | null;
|
||||
}>();
|
||||
|
||||
const COLS_PER_ROW = 4;
|
||||
|
||||
const IconGmv = createIconifyIcon('lucide:layers');
|
||||
const IconSales = createIconifyIcon('lucide:wallet');
|
||||
const IconGross = createIconifyIcon('lucide:trending-up');
|
||||
const IconNet = createIconifyIcon('lucide:badge-dollar-sign');
|
||||
const IconOrders = createIconifyIcon('lucide:shopping-bag');
|
||||
const IconAov = createIconifyIcon('lucide:receipt');
|
||||
const IconRefund = createIconifyIcon('lucide:undo-2');
|
||||
const IconRoi = createIconifyIcon('lucide:target');
|
||||
const IconDefault = createIconifyIcon('lucide:bar-chart-3');
|
||||
|
||||
type KpiMeta = {
|
||||
icon: Component;
|
||||
upIsGood: boolean;
|
||||
};
|
||||
|
||||
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_META: KpiMeta = {
|
||||
icon: IconDefault,
|
||||
upIsGood: true,
|
||||
};
|
||||
const displayOrder = computed(() => {
|
||||
const fromPrefs = sortLabelsByCatalog(props.visibleLabels);
|
||||
if (fromPrefs.length > 0) return fromPrefs;
|
||||
return catalogLabels();
|
||||
});
|
||||
|
||||
const orderedKpiRows = computed(() => {
|
||||
const byLabel = new Map(props.kpis.map((k) => [k.label, k]));
|
||||
const visibleSet = new Set(displayOrder.value);
|
||||
const ordered: WorkbenchVO.KpiItem[] = [];
|
||||
for (const label of KPI_DISPLAY_ORDER) {
|
||||
for (const label of displayOrder.value) {
|
||||
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);
|
||||
}
|
||||
if (!visibleSet.has(k.label)) continue;
|
||||
if (!ordered.some((o) => o.label === k.label)) 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) => ({
|
||||
return ordered.map((kpi) => ({
|
||||
kpi,
|
||||
meta: KPI_META[kpi.label] ?? DEFAULT_META,
|
||||
fillSpan: index === total - 1 && lastRowFillSpan > 1 ? lastRowFillSpan : 0,
|
||||
meta: kpiMetaByLabel(kpi.label),
|
||||
}));
|
||||
});
|
||||
|
||||
const showEmptyPrefsHint = computed(
|
||||
() => props.kpis.length > 0 && props.visibleLabels.length === 0,
|
||||
);
|
||||
|
||||
const gridColumnCount = computed(() =>
|
||||
clampFinanceKpiColsPerRow(props.colsPerRow),
|
||||
);
|
||||
|
||||
const gridStyle = computed(() => ({
|
||||
gridTemplateColumns: `repeat(${gridColumnCount.value}, minmax(0, 1fr))`,
|
||||
}));
|
||||
|
||||
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 } {
|
||||
/** 主数字与单位分开展示,便于单位、环比胶囊紧跟数字 */
|
||||
function primaryLine(kpi: WorkbenchVO.KpiItem): {
|
||||
display: string;
|
||||
unitText: string;
|
||||
hover: string;
|
||||
} {
|
||||
const ay = kpi.amountYuan;
|
||||
if (ay == null || !Number.isFinite(ay)) {
|
||||
return { display: String(kpi.value ?? ''), hover: '' };
|
||||
return {
|
||||
display: String(kpi.value ?? ''),
|
||||
unitText: kpi.unit?.trim() ?? '',
|
||||
hover: '',
|
||||
};
|
||||
}
|
||||
const hover = formatYuanDetail(ay);
|
||||
if (kpi.preferWanDisplay === true) {
|
||||
return { display: formatWanShort(ay), hover };
|
||||
return {
|
||||
display: yuanToWanNum(ay).toFixed(2),
|
||||
unitText: '万',
|
||||
hover,
|
||||
};
|
||||
}
|
||||
return { display: String(kpi.value ?? ''), hover };
|
||||
return {
|
||||
display: String(kpi.value ?? ''),
|
||||
unitText: kpi.unit?.trim() ?? '',
|
||||
hover,
|
||||
};
|
||||
}
|
||||
|
||||
function trendIsGood(kpi: WorkbenchVO.KpiItem, up: boolean): boolean {
|
||||
const meta = KPI_META[kpi.label] ?? DEFAULT_META;
|
||||
const meta = kpiMetaByLabel(kpi.label);
|
||||
return meta.upIsGood ? up : !up;
|
||||
}
|
||||
|
||||
@@ -127,63 +121,65 @@ function deltaTextClass(good: boolean): string {
|
||||
: 'text-rose-600 dark:text-rose-400';
|
||||
}
|
||||
|
||||
/** 末行未满时,最后一张卡跨列铺满 */
|
||||
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%)]';
|
||||
'group flex min-h-[6.75rem] min-w-0 flex-col rounded-xl border border-slate-200/90 bg-gradient-to-b from-white to-slate-50/80 p-3.5 shadow-sm transition-[border-color,box-shadow] duration-200 hover:border-slate-300 hover:shadow-md dark:border-[hsl(240deg_3.7%_22%)] dark:from-[hsl(222.34deg_10.43%_12.27%)] dark:to-[hsl(222.34deg_10.43%_10%)] dark:shadow-none dark:hover:border-[hsl(240deg_3.7%_32%)]';
|
||||
const labelClass =
|
||||
'truncate text-xs font-semibold leading-none text-slate-600 dark:text-[hsl(240deg_5%_72%)]';
|
||||
const valueUnitClass =
|
||||
'text-sm font-semibold leading-none text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]';
|
||||
const trendChipClass =
|
||||
'inline-flex cursor-default items-baseline gap-px rounded-full border border-slate-200/80 bg-white/80 px-1.5 py-0.5 text-[11px] font-medium leading-none text-slate-500 dark:border-[hsl(240deg_3.7%_26%)] dark:bg-[hsl(240deg_3.7%_14%)] 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-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%)]"
|
||||
class="rounded-xl border border-dashed border-slate-200 bg-white/60 px-4 py-8 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 数据
|
||||
</div>
|
||||
<div
|
||||
v-else-if="showEmptyPrefsHint"
|
||||
class="rounded-xl border border-dashed border-amber-200 bg-amber-50/60 px-4 py-8 text-center text-sm text-amber-700 dark:border-amber-900/40 dark:bg-amber-950/20 dark:text-amber-300"
|
||||
>
|
||||
未选择任何 KPI,请点击上方「KPI 显示设置」勾选要展示的指标。
|
||||
</div>
|
||||
<div
|
||||
v-else-if="orderedKpiRows.length === 0"
|
||||
class="rounded-xl border border-dashed border-slate-200 bg-white/60 px-4 py-8 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 数据
|
||||
</div>
|
||||
<div
|
||||
v-else
|
||||
class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4"
|
||||
class="grid gap-3"
|
||||
:style="gridStyle"
|
||||
>
|
||||
<div
|
||||
v-for="{ kpi, meta, fillSpan } in orderedKpiRows"
|
||||
v-for="{ kpi, meta } in orderedKpiRows"
|
||||
:key="kpi.label"
|
||||
:class="[cardShellClass, gridSpanClass(fillSpan)]"
|
||||
:class="cardShellClass"
|
||||
>
|
||||
<div class="mb-4 flex items-start justify-between gap-3">
|
||||
<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 class="mb-2 flex items-start justify-between gap-2">
|
||||
<div class="flex min-w-0 flex-1 items-center gap-1.5">
|
||||
<component
|
||||
:is="meta.icon"
|
||||
class="size-4 shrink-0 text-slate-400 dark:text-[hsl(240deg_5%_55%)]"
|
||||
/>
|
||||
<OverviewColumnHint
|
||||
class="min-w-0"
|
||||
:title="getFinanceKpiHint(kpi.label, taxRate ?? 0.04)"
|
||||
>
|
||||
<span :class="labelClass">{{ kpi.label }}</span>
|
||||
</OverviewColumnHint>
|
||||
</div>
|
||||
<div class="flex shrink-0 flex-col items-end gap-1.5">
|
||||
<div class="flex shrink-0 items-center gap-1">
|
||||
<Tooltip
|
||||
:title="compareRangeHint(momCompareDateStart, momCompareDateEnd)"
|
||||
>
|
||||
<span :class="trendBadgeShellClass">
|
||||
<span class="mr-1 opacity-60">环</span>
|
||||
<span :class="trendChipClass">
|
||||
<span class="text-slate-400 dark:text-[hsl(240deg_5%_55%)]">环</span>
|
||||
<span :class="deltaTextClass(trendIsGood(kpi, kpi.up === true))">
|
||||
{{ formatDelta(kpi, kpi.changePct) }}
|
||||
</span>
|
||||
@@ -193,9 +189,11 @@ const trendBadgeShellClass =
|
||||
v-if="kpi.yoyChangePct != null && kpi.yoyUp != null"
|
||||
:title="compareRangeHint(yoyCompareDateStart, yoyCompareDateEnd)"
|
||||
>
|
||||
<span :class="trendBadgeShellClass">
|
||||
<span class="mr-1 opacity-60">同</span>
|
||||
<span :class="deltaTextClass(trendIsGood(kpi, kpi.yoyUp === true))">
|
||||
<span :class="trendChipClass">
|
||||
<span class="text-slate-400 dark:text-[hsl(240deg_5%_55%)]">同</span>
|
||||
<span
|
||||
:class="deltaTextClass(trendIsGood(kpi, kpi.yoyUp === true))"
|
||||
>
|
||||
{{ formatDelta(kpi, kpi.yoyChangePct) }}
|
||||
</span>
|
||||
</span>
|
||||
@@ -203,38 +201,32 @@ const trendBadgeShellClass =
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<!-- 主数字 + 单位紧跟 -->
|
||||
<span class="inline-flex max-w-full items-baseline whitespace-nowrap">
|
||||
<Tooltip v-if="primaryLine(kpi).hover" :title="primaryLine(kpi).hover">
|
||||
<span
|
||||
class="cursor-default tabular-nums text-2xl font-bold leading-none tracking-tight text-slate-900 dark:text-[hsl(0deg_0%_95%)]"
|
||||
>
|
||||
{{ primaryLine(kpi).display }}
|
||||
<span
|
||||
v-if="kpi.unit"
|
||||
class="ml-1 text-base font-medium text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
{{ kpi.unit }}
|
||||
</span>
|
||||
</template>
|
||||
</div>
|
||||
<div
|
||||
v-if="kpi.sub"
|
||||
class="mt-1 truncate text-[11px] font-medium text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
</span>
|
||||
</Tooltip>
|
||||
<span
|
||||
v-else
|
||||
class="tabular-nums text-2xl font-bold leading-none tracking-tight text-slate-900 dark:text-[hsl(0deg_0%_95%)]"
|
||||
>
|
||||
{{ kpi.sub }}
|
||||
</div>
|
||||
</div>
|
||||
{{ primaryLine(kpi).display }}
|
||||
</span>
|
||||
<span v-if="primaryLine(kpi).unitText" :class="valueUnitClass">
|
||||
{{ primaryLine(kpi).unitText }}
|
||||
</span>
|
||||
</span>
|
||||
|
||||
<p
|
||||
v-if="kpi.sub"
|
||||
class="mt-1.5 w-full truncate text-right text-[11px] leading-snug text-slate-400 dark:text-[hsl(240deg_5%_55%)]"
|
||||
>
|
||||
{{ kpi.sub }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
+200
@@ -0,0 +1,200 @@
|
||||
<script lang="ts" setup>
|
||||
import type { FinanceKpiGroupId } from '../kpi-catalog';
|
||||
|
||||
import { computed, ref, watch } from 'vue';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import { Button, Checkbox, message, Modal, Radio } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
clampFinanceKpiColsPerRow,
|
||||
FINANCE_KPI_CATALOG,
|
||||
FINANCE_KPI_COLS_PER_ROW_OPTIONS,
|
||||
FINANCE_KPI_DEFAULT_COLS_PER_ROW,
|
||||
FINANCE_KPI_DEFAULT_VISIBLE,
|
||||
FINANCE_KPI_GROUP_ORDER,
|
||||
type FinanceKpiColsPerRow,
|
||||
} from '../kpi-catalog';
|
||||
|
||||
defineOptions({ name: 'WorkbenchFinanceKpiSettingsModal' });
|
||||
|
||||
const props = defineProps<{
|
||||
open: boolean;
|
||||
visibleLabels: string[];
|
||||
colsPerRow: number;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:open', v: boolean): void;
|
||||
(e: 'save', payload: { labels: string[]; colsPerRow: number }): void;
|
||||
}>();
|
||||
|
||||
const IconSettings = createIconifyIcon('lucide:settings-2');
|
||||
|
||||
const draft = ref<string[]>([]);
|
||||
const draftColsPerRow = ref<FinanceKpiColsPerRow>(FINANCE_KPI_DEFAULT_COLS_PER_ROW);
|
||||
|
||||
watch(
|
||||
() => props.open,
|
||||
(isOpen) => {
|
||||
if (isOpen) {
|
||||
draft.value = [...props.visibleLabels];
|
||||
draftColsPerRow.value = clampFinanceKpiColsPerRow(props.colsPerRow);
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
const grouped = computed(() => {
|
||||
const map = new Map<FinanceKpiGroupId, { title: string; labels: string[] }>();
|
||||
for (const g of FINANCE_KPI_GROUP_ORDER) {
|
||||
map.set(g, { title: '', labels: [] });
|
||||
}
|
||||
for (const item of FINANCE_KPI_CATALOG) {
|
||||
const bucket = map.get(item.group)!;
|
||||
if (!bucket.title) bucket.title = item.groupTitle;
|
||||
bucket.labels.push(item.label);
|
||||
}
|
||||
return FINANCE_KPI_GROUP_ORDER.map((id) => ({
|
||||
id,
|
||||
title: map.get(id)!.title,
|
||||
labels: map.get(id)!.labels,
|
||||
})).filter((g) => g.labels.length > 0);
|
||||
});
|
||||
|
||||
function isGroupAllChecked(labels: string[]): boolean {
|
||||
return labels.every((l) => draft.value.includes(l));
|
||||
}
|
||||
|
||||
function isGroupIndeterminate(labels: string[]): boolean {
|
||||
const n = labels.filter((l) => draft.value.includes(l)).length;
|
||||
return n > 0 && n < labels.length;
|
||||
}
|
||||
|
||||
function toggleGroup(labels: string[], checked: boolean) {
|
||||
const set = new Set(draft.value);
|
||||
for (const l of labels) {
|
||||
if (checked) set.add(l);
|
||||
else set.delete(l);
|
||||
}
|
||||
draft.value = [...set];
|
||||
}
|
||||
|
||||
function onCheckboxChange(label: string, checked: boolean) {
|
||||
const set = new Set(draft.value);
|
||||
if (checked) set.add(label);
|
||||
else set.delete(label);
|
||||
draft.value = [...set];
|
||||
}
|
||||
|
||||
function onGroupCheckboxChange(labels: string[], e: { target: { checked: boolean } }) {
|
||||
toggleGroup(labels, e.target.checked);
|
||||
}
|
||||
|
||||
function onItemCheckboxChange(label: string, e: { target: { checked: boolean } }) {
|
||||
onCheckboxChange(label, e.target.checked);
|
||||
}
|
||||
|
||||
function applyDefaultCore() {
|
||||
draft.value = [...FINANCE_KPI_DEFAULT_VISIBLE];
|
||||
draftColsPerRow.value = FINANCE_KPI_DEFAULT_COLS_PER_ROW;
|
||||
}
|
||||
|
||||
function applySelectAll() {
|
||||
draft.value = FINANCE_KPI_CATALOG.map((c) => c.label);
|
||||
}
|
||||
|
||||
function handleOk() {
|
||||
if (draft.value.length === 0) {
|
||||
message.warning('请至少选择一项 KPI');
|
||||
return;
|
||||
}
|
||||
emit('save', { labels: draft.value, colsPerRow: draftColsPerRow.value });
|
||||
emit('update:open', false);
|
||||
}
|
||||
|
||||
function handleCancel() {
|
||||
emit('update:open', false);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
:open="open"
|
||||
title="KPI 显示设置"
|
||||
width="640px"
|
||||
:destroy-on-close="false"
|
||||
@cancel="handleCancel"
|
||||
@ok="handleOk"
|
||||
>
|
||||
<template #title>
|
||||
<span class="inline-flex flex-nowrap items-center gap-2 whitespace-nowrap">
|
||||
<component :is="IconSettings" class="size-[1.125rem] shrink-0 text-slate-500" />
|
||||
<span class="shrink-0">KPI 显示设置</span>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<p class="mb-4 text-sm text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
勾选要在经营概览中展示的指标,并可调整每行卡片数量;设置保存在本浏览器。
|
||||
</p>
|
||||
|
||||
<div
|
||||
class="mb-4 rounded-xl border border-slate-100 bg-slate-50/80 px-4 py-3 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(240deg_3.7%_12%)]"
|
||||
>
|
||||
<div class="mb-2 text-sm font-semibold text-slate-700 dark:text-[hsl(0deg_0%_90%)]">
|
||||
每行显示卡片数
|
||||
</div>
|
||||
<Radio.Group v-model:value="draftColsPerRow" class="flex flex-wrap gap-2">
|
||||
<Radio
|
||||
v-for="n in FINANCE_KPI_COLS_PER_ROW_OPTIONS"
|
||||
:key="n"
|
||||
:value="n"
|
||||
>
|
||||
{{ n }} 张
|
||||
</Radio>
|
||||
</Radio.Group>
|
||||
</div>
|
||||
|
||||
<div class="mb-4 flex flex-wrap gap-2">
|
||||
<Button size="small" @click="applySelectAll">全选</Button>
|
||||
<Button size="small" @click="applyDefaultCore">恢复默认(8 项)</Button>
|
||||
</div>
|
||||
|
||||
<div class="max-h-[min(60vh,28rem)] space-y-5 overflow-y-auto pr-1">
|
||||
<section
|
||||
v-for="group in grouped"
|
||||
:key="group.id"
|
||||
class="rounded-xl border border-slate-100 bg-slate-50/80 p-4 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(240deg_3.7%_12%)]"
|
||||
>
|
||||
<div class="mb-3 flex items-center gap-2">
|
||||
<Checkbox
|
||||
:checked="isGroupAllChecked(group.labels)"
|
||||
:indeterminate="isGroupIndeterminate(group.labels)"
|
||||
@change="(e) => onGroupCheckboxChange(group.labels, e)"
|
||||
>
|
||||
<span class="font-semibold text-slate-700 dark:text-[hsl(0deg_0%_90%)]">
|
||||
{{ group.title }}
|
||||
</span>
|
||||
</Checkbox>
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-x-4 gap-y-2 sm:grid-cols-3">
|
||||
<Checkbox
|
||||
v-for="label in group.labels"
|
||||
:key="label"
|
||||
:checked="draft.includes(label)"
|
||||
@change="(e) => onItemCheckboxChange(label, e)"
|
||||
>
|
||||
<span class="text-sm">{{ label }}</span>
|
||||
</Checkbox>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<p
|
||||
v-if="draft.length === 0"
|
||||
class="mt-3 text-sm text-amber-600 dark:text-amber-400"
|
||||
>
|
||||
请至少选择一项指标,否则概览区将无 KPI 卡片。
|
||||
</p>
|
||||
</Modal>
|
||||
</template>
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
import { overviewTableHints, salesTaxColumnHint } from '#/utils/overview-table-hints';
|
||||
|
||||
/** 工作台经营 KPI 计算说明(与汇总表、后端 WorkbenchServiceImpl 口径一致) */
|
||||
const FINANCE_KPI_HINTS: Record<string, string> = {
|
||||
总GMV: overviewTableHints.gmv,
|
||||
GMV单量:
|
||||
'所选时间范围内,全部订单状态的订单笔数合计(不按是否计入销售额过滤)。环比/同比为笔数变化率。',
|
||||
GMV销量:
|
||||
'所选时间范围内,全部订单状态的销售件数合计(订单行件数汇总)。',
|
||||
GMV客单价: 'GMV ÷ GMV单量;GMV单量为 0 时为 0。',
|
||||
GMV件单价: 'GMV ÷ GMV销量;GMV销量为 0 时为 0。',
|
||||
实际销售额: overviewTableHints.salesAmount,
|
||||
销售单量:
|
||||
'统计口径下,计入销售额的有效订单笔数(与下方汇总表「单量」列一致)。环比/同比为笔数变化率。',
|
||||
实际销量: '计入销售额的订单状态件数合计。',
|
||||
客单价: '实际销售额 ÷ 销售单量;销售单量为 0 时为 0。',
|
||||
销售件单价: '实际销售额 ÷ 实际销量;实际销量为 0 时为 0。',
|
||||
净销售额: '实际销售额 − 退款额(与广告 ROI 分子、税额计税基数同口径)。',
|
||||
退款额: overviewTableHints.refundAmount,
|
||||
退款率: '退款额 ÷ 实际销售额 × 100%;实际销售额为 0 时为 0。',
|
||||
'GMV与销售差额': '总GMV − 实际销售额,反映未计入销售口径的订单实收差额。',
|
||||
订单成本: overviewTableHints.orderCost,
|
||||
商品成本: overviewTableHints.productCost,
|
||||
运费成本: overviewTableHints.shippingCost,
|
||||
其他成本: overviewTableHints.otherCost,
|
||||
毛利润: overviewTableHints.grossProfit,
|
||||
推广费: overviewTableHints.totalPromotionFee,
|
||||
刷单费: overviewTableHints.brushFee,
|
||||
净利润:
|
||||
'净利润 = 毛利润 − 推广费 − 刷单费 − 税额(与汇总表损益链路一致)。卡片副文案中的净利率 = 净利润 ÷ 实际销售额。',
|
||||
广告ROI: overviewTableHints.roi,
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取 KPI 标题旁问号 Tooltip 文案;税额随页面税率变化。
|
||||
*/
|
||||
export function getFinanceKpiHint(label: string, taxRate = 0.04): string {
|
||||
if (label === '税额') {
|
||||
return `${salesTaxColumnHint(taxRate)} 工作台按净销售额计税基数汇总。`;
|
||||
}
|
||||
return (
|
||||
FINANCE_KPI_HINTS[label] ??
|
||||
'该指标说明暂未配置,请以汇总表同名列或系统配置口径为准。'
|
||||
);
|
||||
}
|
||||
+52
-1
@@ -4,11 +4,18 @@ import type { CompanyOverviewVO } from '#/api/ecommerce/store-overview';
|
||||
|
||||
import { computed, nextTick, ref } from 'vue';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import { Button, message } from 'ant-design-vue';
|
||||
|
||||
import FinanceCostPieChart from './components/FinanceCostPieChart.vue';
|
||||
import FinanceKpiGrid from './components/FinanceKpiGrid.vue';
|
||||
import FinanceKpiSettingsModal from './components/FinanceKpiSettingsModal.vue';
|
||||
import FinanceTrendChart from './components/FinanceTrendChart.vue';
|
||||
import OverviewTables from './components/OverviewTables.vue';
|
||||
|
||||
import { sortLabelsByCatalog } from './kpi-catalog';
|
||||
import { useFinanceKpiPreferences } from './useFinanceKpiPreferences';
|
||||
|
||||
import {
|
||||
buildCategoryOverviewFromDimRows,
|
||||
buildPlatformOverviewFromDimRows,
|
||||
@@ -52,6 +59,23 @@ const productOverview = computed(
|
||||
buildCategoryOverviewFromDimRows(props.multiAnalysis.product),
|
||||
);
|
||||
|
||||
const IconSliders = createIconifyIcon('lucide:sliders-horizontal');
|
||||
|
||||
const { visibleLabels, colsPerRow, applySettings } = useFinanceKpiPreferences();
|
||||
const kpiSettingsOpen = ref(false);
|
||||
|
||||
const visibleKpiCount = computed(() => visibleLabels.value.length);
|
||||
|
||||
function onKpiSettingsSave(payload: { labels: string[]; colsPerRow: number }) {
|
||||
const normalized = sortLabelsByCatalog(payload.labels);
|
||||
if (normalized.length === 0) {
|
||||
message.warning('请至少选择一项 KPI');
|
||||
return;
|
||||
}
|
||||
applySettings(normalized, payload.colsPerRow);
|
||||
message.success('KPI 显示已更新');
|
||||
}
|
||||
|
||||
const trendChartRef = ref<InstanceType<
|
||||
typeof FinanceTrendChart
|
||||
> | null>(null);
|
||||
@@ -69,9 +93,36 @@ defineExpose({ redraw });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="mt-4 space-y-6">
|
||||
<div class="mt-4 space-y-4">
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<span class="text-sm text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
经营 KPI
|
||||
<span v-if="visibleKpiCount > 0" class="ml-1 text-slate-400">
|
||||
(已选 {{ visibleKpiCount }} 项 · 每行 {{ colsPerRow }} 张)
|
||||
</span>
|
||||
</span>
|
||||
<Button
|
||||
type="default"
|
||||
class="shrink-0 whitespace-nowrap"
|
||||
@click="kpiSettingsOpen = true"
|
||||
>
|
||||
<template #icon>
|
||||
<component :is="IconSliders" class="size-4 shrink-0" />
|
||||
</template>
|
||||
KPI 显示设置
|
||||
</Button>
|
||||
</div>
|
||||
<FinanceKpiSettingsModal
|
||||
v-model:open="kpiSettingsOpen"
|
||||
:cols-per-row="colsPerRow"
|
||||
:visible-labels="visibleLabels"
|
||||
@save="onKpiSettingsSave"
|
||||
/>
|
||||
<FinanceKpiGrid
|
||||
:kpis="finance.kpis"
|
||||
:cols-per-row="colsPerRow"
|
||||
:tax-rate="taxRate"
|
||||
:visible-labels="visibleLabels"
|
||||
:mom-compare-date-start="finance.momCompareDateStart"
|
||||
:mom-compare-date-end="finance.momCompareDateEnd"
|
||||
:yoy-compare-date-start="finance.yoyCompareDateStart"
|
||||
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
import type { Component } from 'vue';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
/** localStorage 键(本机浏览器) */
|
||||
export const FINANCE_KPI_PREFS_KEY = 'workbench-finance-kpi-visible-v1';
|
||||
|
||||
/** 每行 KPI 卡片数默认值 */
|
||||
export const FINANCE_KPI_DEFAULT_COLS_PER_ROW = 5;
|
||||
|
||||
/** 设置里可选的每行卡片数 */
|
||||
export const FINANCE_KPI_COLS_PER_ROW_OPTIONS = [3, 4, 5, 6] as const;
|
||||
|
||||
export type FinanceKpiColsPerRow = (typeof FINANCE_KPI_COLS_PER_ROW_OPTIONS)[number];
|
||||
|
||||
export function clampFinanceKpiColsPerRow(value: unknown): FinanceKpiColsPerRow {
|
||||
const n = typeof value === 'number' ? value : Number(value);
|
||||
if (FINANCE_KPI_COLS_PER_ROW_OPTIONS.includes(n as FinanceKpiColsPerRow)) {
|
||||
return n as FinanceKpiColsPerRow;
|
||||
}
|
||||
return FINANCE_KPI_DEFAULT_COLS_PER_ROW;
|
||||
}
|
||||
|
||||
export type FinanceKpiGroupId =
|
||||
| 'gmv'
|
||||
| 'sales'
|
||||
| 'net'
|
||||
| 'cost'
|
||||
| 'profit'
|
||||
| 'ops';
|
||||
|
||||
export type FinanceKpiCatalogItem = {
|
||||
label: string;
|
||||
group: FinanceKpiGroupId;
|
||||
groupTitle: string;
|
||||
/** 涨跌颜色:true=涨绿跌红,false=涨红跌绿(如退款率) */
|
||||
upIsGood: boolean;
|
||||
icon: Component;
|
||||
};
|
||||
|
||||
const IconGmv = createIconifyIcon('lucide:layers');
|
||||
const IconSales = createIconifyIcon('lucide:wallet');
|
||||
const IconGross = createIconifyIcon('lucide:trending-up');
|
||||
const IconNet = createIconifyIcon('lucide:badge-dollar-sign');
|
||||
const IconOrders = createIconifyIcon('lucide:shopping-bag');
|
||||
const IconAov = createIconifyIcon('lucide:receipt');
|
||||
const IconRefund = createIconifyIcon('lucide:undo-2');
|
||||
const IconRoi = createIconifyIcon('lucide:target');
|
||||
const IconCost = createIconifyIcon('lucide:coins');
|
||||
const IconPercent = createIconifyIcon('lucide:percent');
|
||||
const IconPackage = createIconifyIcon('lucide:package');
|
||||
const IconTruck = createIconifyIcon('lucide:truck');
|
||||
const IconMegaphone = createIconifyIcon('lucide:megaphone');
|
||||
const IconBrush = createIconifyIcon('lucide:brush');
|
||||
const IconTax = createIconifyIcon('lucide:landmark');
|
||||
const IconScale = createIconifyIcon('lucide:scale');
|
||||
const IconReceipt = createIconifyIcon('lucide:receipt');
|
||||
const IconDefault = createIconifyIcon('lucide:bar-chart-3');
|
||||
|
||||
const G = {
|
||||
gmv: 'GMV 口径',
|
||||
sales: '实际销售',
|
||||
net: '净收与退款',
|
||||
cost: '成本',
|
||||
profit: '利润与费用',
|
||||
ops: '运营效率',
|
||||
} as const;
|
||||
|
||||
/** 与后端 buildKpis 顺序一致,用于默认排序 */
|
||||
export const FINANCE_KPI_CATALOG: FinanceKpiCatalogItem[] = [
|
||||
{ label: '总GMV', group: 'gmv', groupTitle: G.gmv, upIsGood: true, icon: IconGmv },
|
||||
{ label: 'GMV单量', group: 'gmv', groupTitle: G.gmv, upIsGood: true, icon: IconOrders },
|
||||
{ label: 'GMV销量', group: 'gmv', groupTitle: G.gmv, upIsGood: true, icon: IconPackage },
|
||||
{ label: 'GMV客单价', group: 'gmv', groupTitle: G.gmv, upIsGood: true, icon: IconAov },
|
||||
{ label: 'GMV件单价', group: 'gmv', groupTitle: G.gmv, upIsGood: true, icon: IconReceipt },
|
||||
{ label: '实际销售额', group: 'sales', groupTitle: G.sales, upIsGood: true, icon: IconSales },
|
||||
{ label: '销售单量', group: 'sales', groupTitle: G.sales, upIsGood: true, icon: IconOrders },
|
||||
{ label: '实际销量', group: 'sales', groupTitle: G.sales, upIsGood: true, icon: IconPackage },
|
||||
{ label: '客单价', group: 'sales', groupTitle: G.sales, upIsGood: true, icon: IconAov },
|
||||
{ label: '销售件单价', group: 'sales', groupTitle: G.sales, upIsGood: true, icon: IconReceipt },
|
||||
{ label: '净销售额', group: 'net', groupTitle: G.net, upIsGood: true, icon: IconNet },
|
||||
{ label: '退款额', group: 'net', groupTitle: G.net, upIsGood: false, icon: IconRefund },
|
||||
{ label: '退款率', group: 'net', groupTitle: G.net, upIsGood: false, icon: IconPercent },
|
||||
{ label: 'GMV与销售差额', group: 'net', groupTitle: G.net, upIsGood: true, icon: IconScale },
|
||||
{ label: '订单成本', group: 'cost', groupTitle: G.cost, upIsGood: false, icon: IconCost },
|
||||
{ label: '商品成本', group: 'cost', groupTitle: G.cost, upIsGood: false, icon: IconPackage },
|
||||
{ label: '运费成本', group: 'cost', groupTitle: G.cost, upIsGood: false, icon: IconTruck },
|
||||
{ label: '其他成本', group: 'cost', groupTitle: G.cost, upIsGood: false, icon: IconCost },
|
||||
{ label: '毛利润', group: 'profit', groupTitle: G.profit, upIsGood: true, icon: IconGross },
|
||||
{ label: '推广费', group: 'profit', groupTitle: G.profit, upIsGood: false, icon: IconMegaphone },
|
||||
{ label: '刷单费', group: 'profit', groupTitle: G.profit, upIsGood: false, icon: IconBrush },
|
||||
{ label: '税额', group: 'profit', groupTitle: G.profit, upIsGood: false, icon: IconTax },
|
||||
{ label: '净利润', group: 'profit', groupTitle: G.profit, upIsGood: true, icon: IconNet },
|
||||
{ label: '广告ROI', group: 'ops', groupTitle: G.ops, upIsGood: true, icon: IconRoi },
|
||||
];
|
||||
|
||||
/** 首次进入默认展示(与改版前 8 卡接近,订单量→销售单量) */
|
||||
export const FINANCE_KPI_DEFAULT_VISIBLE: string[] = [
|
||||
'总GMV',
|
||||
'实际销售额',
|
||||
'毛利润',
|
||||
'净利润',
|
||||
'销售单量',
|
||||
'客单价',
|
||||
'退款率',
|
||||
'广告ROI',
|
||||
];
|
||||
|
||||
export const FINANCE_KPI_GROUP_ORDER: FinanceKpiGroupId[] = [
|
||||
'gmv',
|
||||
'sales',
|
||||
'net',
|
||||
'cost',
|
||||
'profit',
|
||||
'ops',
|
||||
];
|
||||
|
||||
export function kpiMetaByLabel(label: string): Pick<
|
||||
FinanceKpiCatalogItem,
|
||||
'icon' | 'upIsGood'
|
||||
> {
|
||||
const item = FINANCE_KPI_CATALOG.find((c) => c.label === label);
|
||||
return item ?? { icon: IconDefault, upIsGood: true };
|
||||
}
|
||||
|
||||
export function catalogLabels(): string[] {
|
||||
return FINANCE_KPI_CATALOG.map((c) => c.label);
|
||||
}
|
||||
|
||||
/** 按目录顺序排列可见 label */
|
||||
export function sortLabelsByCatalog(visible: string[]): string[] {
|
||||
const set = new Set(visible);
|
||||
return FINANCE_KPI_CATALOG.map((c) => c.label).filter((l) => set.has(l));
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
import { ref } from 'vue';
|
||||
|
||||
import {
|
||||
catalogLabels,
|
||||
clampFinanceKpiColsPerRow,
|
||||
FINANCE_KPI_DEFAULT_COLS_PER_ROW,
|
||||
FINANCE_KPI_DEFAULT_VISIBLE,
|
||||
FINANCE_KPI_PREFS_KEY,
|
||||
sortLabelsByCatalog,
|
||||
} from './kpi-catalog';
|
||||
|
||||
type PrefsPayload = {
|
||||
visibleLabels: string[];
|
||||
colsPerRow?: number;
|
||||
};
|
||||
|
||||
function parseStored(): PrefsPayload | null {
|
||||
try {
|
||||
const raw = localStorage.getItem(FINANCE_KPI_PREFS_KEY);
|
||||
if (!raw) return null;
|
||||
const parsed = JSON.parse(raw) as PrefsPayload;
|
||||
if (!Array.isArray(parsed.visibleLabels)) return null;
|
||||
return {
|
||||
visibleLabels: parsed.visibleLabels
|
||||
.filter((x) => typeof x === 'string')
|
||||
.map((l) => (l === '订单量' ? '销售单量' : l)),
|
||||
colsPerRow: parsed.colsPerRow,
|
||||
};
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeVisible(labels: string[]): string[] {
|
||||
const catalog = new Set(catalogLabels());
|
||||
const seen = new Set<string>();
|
||||
const out: string[] = [];
|
||||
for (const label of labels) {
|
||||
if (!catalog.has(label) || seen.has(label)) continue;
|
||||
seen.add(label);
|
||||
out.push(label);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
export function useFinanceKpiPreferences() {
|
||||
const stored = parseStored();
|
||||
const visibleLabels = ref<string[]>(
|
||||
normalizeVisible(stored?.visibleLabels ?? [...FINANCE_KPI_DEFAULT_VISIBLE]),
|
||||
);
|
||||
const colsPerRow = ref(
|
||||
clampFinanceKpiColsPerRow(stored?.colsPerRow ?? FINANCE_KPI_DEFAULT_COLS_PER_ROW),
|
||||
);
|
||||
|
||||
function persist() {
|
||||
const payload: PrefsPayload = {
|
||||
visibleLabels: visibleLabels.value,
|
||||
colsPerRow: colsPerRow.value,
|
||||
};
|
||||
localStorage.setItem(FINANCE_KPI_PREFS_KEY, JSON.stringify(payload));
|
||||
}
|
||||
|
||||
function setVisibleLabels(labels: string[]) {
|
||||
visibleLabels.value = sortLabelsByCatalog(normalizeVisible(labels));
|
||||
persist();
|
||||
}
|
||||
|
||||
function setColsPerRow(cols: number) {
|
||||
colsPerRow.value = clampFinanceKpiColsPerRow(cols);
|
||||
persist();
|
||||
}
|
||||
|
||||
function applySettings(labels: string[], cols: number) {
|
||||
visibleLabels.value = sortLabelsByCatalog(normalizeVisible(labels));
|
||||
colsPerRow.value = clampFinanceKpiColsPerRow(cols);
|
||||
persist();
|
||||
}
|
||||
|
||||
function resetToDefault() {
|
||||
applySettings([...FINANCE_KPI_DEFAULT_VISIBLE], FINANCE_KPI_DEFAULT_COLS_PER_ROW);
|
||||
}
|
||||
|
||||
function selectAll() {
|
||||
setVisibleLabels(catalogLabels());
|
||||
}
|
||||
|
||||
return {
|
||||
visibleLabels,
|
||||
colsPerRow,
|
||||
setVisibleLabels,
|
||||
setColsPerRow,
|
||||
applySettings,
|
||||
resetToDefault,
|
||||
selectAll,
|
||||
};
|
||||
}
|
||||
@@ -16,7 +16,7 @@ export function formatYuanDetail(yuan: number | null | undefined): string {
|
||||
/** 主展示:万,两位小数 */
|
||||
export function formatWanShort(yuan: number | null | undefined, digits = 2): string {
|
||||
if (yuan == null || !Number.isFinite(yuan)) return '—';
|
||||
return `${yuanToWanNum(yuan).toFixed(digits)} 万`;
|
||||
return `${yuanToWanNum(yuan).toFixed(digits)}万`;
|
||||
}
|
||||
|
||||
/** Tooltip 等:主数字为万,括号内为精确元(与图例「万」口径一致) */
|
||||
@@ -30,5 +30,5 @@ export function formatWanWithYuanDetail(
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 2,
|
||||
}).format(yuan);
|
||||
return `${wanStr} 万(${yuanStr} 元)`;
|
||||
return `${wanStr}万(${yuanStr} 元)`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user