mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 03:09:19 +08:00
feat: 按经营概览风格重做商品概览并补齐 KPI 与趋势
This commit is contained in:
@@ -1,155 +1,127 @@
|
||||
export namespace ProductOverviewVO {
|
||||
/** 趋势数据项 */
|
||||
/** 与工作台经营 KPI 同形 */
|
||||
export interface KpiItem {
|
||||
label: string;
|
||||
value: number;
|
||||
unit: string;
|
||||
changePct?: number;
|
||||
up?: boolean;
|
||||
yoyChangePct?: number | null;
|
||||
yoyUp?: boolean | null;
|
||||
sub?: string;
|
||||
amountYuan?: number | null;
|
||||
preferWanDisplay?: boolean | null;
|
||||
}
|
||||
|
||||
export interface TrendPoint {
|
||||
date: string;
|
||||
dealYuan?: number;
|
||||
dealOrderCount?: number;
|
||||
salesYuan?: number;
|
||||
salesOrderCount?: number;
|
||||
profitYuan?: number;
|
||||
netProfitYuan?: number;
|
||||
refundYuan?: number;
|
||||
}
|
||||
|
||||
export interface PieSlice {
|
||||
name: string;
|
||||
value?: number;
|
||||
pct?: number;
|
||||
}
|
||||
|
||||
/** @deprecated 旧趋势结构,优先用 dealTrend */
|
||||
export interface TrendDataItem {
|
||||
/** 日期 */
|
||||
date: string;
|
||||
/** 对应的值 */
|
||||
value: number;
|
||||
}
|
||||
|
||||
/** 趋势数据 */
|
||||
/** @deprecated */
|
||||
export interface TrendData {
|
||||
/** 时间范围的总值 */
|
||||
total: number;
|
||||
/** 每日数据列表 */
|
||||
dailyDataList: TrendDataItem[];
|
||||
}
|
||||
|
||||
/** SKU 销量排名项 */
|
||||
export interface SkuSalesRankItem {
|
||||
/** SKU ID */
|
||||
skuId?: number;
|
||||
/** SKU 名称 */
|
||||
skuName?: string;
|
||||
/** SKU 编码 */
|
||||
skuCode?: string;
|
||||
/** 订单量 */
|
||||
orderCount?: number;
|
||||
/** 销售额 */
|
||||
salesAmount?: number;
|
||||
}
|
||||
|
||||
/** SKU 销售明细项 */
|
||||
export interface SkuSummaryItem {
|
||||
/** SKU ID */
|
||||
skuId: number;
|
||||
/** SKU 名称 */
|
||||
skuName: string;
|
||||
/** SKU 编码 */
|
||||
skuCode: string;
|
||||
/** 销售额 */
|
||||
salesAmount: number;
|
||||
/** 订单量 */
|
||||
orderCount: number;
|
||||
/** 总件数 */
|
||||
quantity: number;
|
||||
/** 客单价 */
|
||||
averageOrderValue: number;
|
||||
/** 商品成本 */
|
||||
productCost: number;
|
||||
/** 运费 */
|
||||
shippingCost: number;
|
||||
/** 其他成本 */
|
||||
otherCost: number;
|
||||
/** 订单成本(商品成本+运费+其他成本,不含推广费、刷单费) */
|
||||
orderCost?: number;
|
||||
/** 退款金额 */
|
||||
refundAmount: number;
|
||||
/** 推广费 */
|
||||
promotionFee: number;
|
||||
/** 费比 */
|
||||
feeRatio: number;
|
||||
/** 税前盈亏 */
|
||||
profitBeforeTax: number;
|
||||
/** 销售额×税率的税额 */
|
||||
salesTaxAmount: number;
|
||||
/** ROI */
|
||||
roi: number;
|
||||
/** 税后盈亏 */
|
||||
profitAfterTax: number;
|
||||
}
|
||||
|
||||
/** SKU 销售汇总合计行 */
|
||||
export interface SkuSummaryTotal {
|
||||
/** 销售额 */
|
||||
salesAmount: number;
|
||||
/** 订单量 */
|
||||
orderCount: number;
|
||||
/** 总件数 */
|
||||
quantity: number;
|
||||
/** 客单价(前端汇总或后端可选返回) */
|
||||
averageOrderValue?: number;
|
||||
/** 商品成本 */
|
||||
productCost: number;
|
||||
/** 运费 */
|
||||
shippingCost: number;
|
||||
/** 其他成本 */
|
||||
otherCost: number;
|
||||
/** 订单成本(商品成本+运费+其他成本,不含推广费、刷单费) */
|
||||
orderCost?: number;
|
||||
/** 退款金额 */
|
||||
refundAmount: number;
|
||||
/** 推广费 */
|
||||
promotionFee: number;
|
||||
/** 费比 */
|
||||
feeRatio: number;
|
||||
/** 税前盈亏 */
|
||||
profitBeforeTax: number;
|
||||
/** 税额 */
|
||||
salesTaxAmount: number;
|
||||
/** ROI */
|
||||
roi: number;
|
||||
/** 税后盈亏 */
|
||||
profitAfterTax: number;
|
||||
}
|
||||
|
||||
/** SKU 销售汇总 */
|
||||
export interface SkuSummary {
|
||||
/** 各 SKU 明细列表 */
|
||||
list: SkuSummaryItem[];
|
||||
/** 合计行 */
|
||||
total: SkuSummaryTotal;
|
||||
}
|
||||
|
||||
/** 商品概览响应 */
|
||||
export interface Overview {
|
||||
/** 商品 ID */
|
||||
productId: number;
|
||||
/** 商品名称 */
|
||||
productName: string;
|
||||
|
||||
// ========== KPI 汇总指标 ==========
|
||||
/** 总销售额 */
|
||||
totalSalesAmount: number;
|
||||
/** 较上月同期增长百分比 */
|
||||
monthOverMonthGrowth: number;
|
||||
/** 总订单量 */
|
||||
totalOrderCount: number;
|
||||
/** 平均费比 */
|
||||
averageFeeRatio: number;
|
||||
/** 总净利润(税后) */
|
||||
totalNetProfitAfterTax: number;
|
||||
/** 扣除总税额 */
|
||||
totalTaxAmount: number;
|
||||
/** 销量目标达成率 */
|
||||
orderCountAchievementRate: number;
|
||||
/** 销售额目标达成率 */
|
||||
salesAmountAchievementRate: number;
|
||||
/** 汇总 ROI */
|
||||
totalROI: number;
|
||||
/** 经营 KPI(与工作台同口径) */
|
||||
kpis?: KpiItem[];
|
||||
dealTrend?: TrendPoint[];
|
||||
skuSalesShare?: PieSlice[];
|
||||
momCompareDateStart?: string | null;
|
||||
momCompareDateEnd?: string | null;
|
||||
yoyCompareDateStart?: string | null;
|
||||
yoyCompareDateEnd?: string | null;
|
||||
|
||||
// ========== 各 SKU 销量 Top10 ==========
|
||||
/** 各 SKU 销量 Top10(后端字段名仍为 specSalesTop10) */
|
||||
specSalesTop10: SkuSalesRankItem[];
|
||||
totalSalesAmount?: number;
|
||||
monthOverMonthGrowth?: number;
|
||||
totalOrderCount?: number;
|
||||
averageFeeRatio?: number;
|
||||
totalNetProfitAfterTax?: number;
|
||||
totalTaxAmount?: number;
|
||||
orderCountAchievementRate?: number;
|
||||
salesAmountAchievementRate?: number;
|
||||
totalROI?: number;
|
||||
|
||||
// ========== 趋势数据 ==========
|
||||
/** 销售额趋势分析 */
|
||||
salesAmountTrend: TrendData;
|
||||
/** 单量趋势分析 */
|
||||
orderCountTrend: TrendData;
|
||||
|
||||
// ========== SKU 销售汇总 ==========
|
||||
/** SKU 销售汇总(后端字段名仍为 specSummaries) */
|
||||
specSummaries: SkuSummary;
|
||||
specSalesTop10?: SkuSalesRankItem[];
|
||||
/** @deprecated */
|
||||
salesAmountTrend?: TrendData;
|
||||
/** @deprecated */
|
||||
orderCountTrend?: TrendData;
|
||||
specSummaries?: SkuSummary;
|
||||
}
|
||||
}
|
||||
|
||||
+20
-6
@@ -11,9 +11,23 @@ import { FINANCE_PANEL_SHELL } from '../constants/finance-ui';
|
||||
|
||||
defineOptions({ name: 'WorkbenchFinancePlatformSalesPieChart' });
|
||||
|
||||
const props = defineProps<{
|
||||
platformSalesShare: WorkbenchVO.PieSlice[];
|
||||
}>();
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
platformSalesShare: WorkbenchVO.PieSlice[];
|
||||
/** 面板标题,商品概览可改为「各 SKU 净销售额分布」 */
|
||||
title?: string;
|
||||
subtitle?: string;
|
||||
/** 覆盖面板外壳(商品概览等可传入自身主题 class) */
|
||||
panelClass?: string;
|
||||
}>(),
|
||||
{
|
||||
title: '各平台净销售额分布',
|
||||
subtitle: '占当前筛选条件下净销售额合计的比例',
|
||||
panelClass: undefined,
|
||||
},
|
||||
);
|
||||
|
||||
const shellClass = computed(() => props.panelClass || FINANCE_PANEL_SHELL);
|
||||
|
||||
const PLATFORM_PIE_COLORS = [
|
||||
'#3b82f6',
|
||||
@@ -164,17 +178,17 @@ defineExpose({ redraw });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div :class="FINANCE_PANEL_SHELL">
|
||||
<div :class="shellClass">
|
||||
<div
|
||||
class="border-b border-slate-100 px-5 pb-3.5 pt-5 md:px-6 md:pt-5 dark:border-b-[hsl(240deg_3.7%_22%)]"
|
||||
>
|
||||
<h3
|
||||
class="text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]"
|
||||
>
|
||||
各平台净销售额分布
|
||||
{{ title }}
|
||||
</h3>
|
||||
<p class="mt-1 text-xs font-normal text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
占当前筛选条件下净销售额合计的比例
|
||||
{{ subtitle }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="px-5 py-4 md:px-6 md:py-5">
|
||||
|
||||
+13
-4
@@ -11,9 +11,18 @@ import { FINANCE_PANEL_SHELL } from '../constants/finance-ui';
|
||||
|
||||
defineOptions({ name: 'WorkbenchFinanceTrendChart' });
|
||||
|
||||
const props = defineProps<{
|
||||
trend: WorkbenchVO.TrendPoint[];
|
||||
}>();
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
trend: WorkbenchVO.TrendPoint[];
|
||||
/** 覆盖面板外壳(商品概览等可传入自身主题 class) */
|
||||
panelClass?: string;
|
||||
}>(),
|
||||
{
|
||||
panelClass: undefined,
|
||||
},
|
||||
);
|
||||
|
||||
const shellClass = computed(() => props.panelClass || FINANCE_PANEL_SHELL);
|
||||
|
||||
const financeChartRef = ref<EchartsUIType>();
|
||||
const { renderEcharts: renderFinanceTrend } = useEcharts(financeChartRef);
|
||||
@@ -425,7 +434,7 @@ defineExpose({ redraw });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div :class="FINANCE_PANEL_SHELL">
|
||||
<div :class="shellClass">
|
||||
<div
|
||||
class="border-b border-slate-100 px-5 pb-3.5 pt-5 md:px-6 md:pt-5 dark:border-b-[hsl(240deg_3.7%_22%)]"
|
||||
>
|
||||
|
||||
+179
@@ -0,0 +1,179 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ProductOverviewVO } from '#/api/ec/product/overview';
|
||||
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import {
|
||||
PRODUCT_HERO_SHELL,
|
||||
PRODUCT_SPOT_CARD,
|
||||
} from '../constants/product-ui';
|
||||
|
||||
defineOptions({ name: 'ProductOverviewHero' });
|
||||
|
||||
const props = defineProps<{
|
||||
data: ProductOverviewVO.Overview;
|
||||
dateLabel?: string;
|
||||
shopLabel?: string;
|
||||
}>();
|
||||
|
||||
const IconPackage = createIconifyIcon('lucide:package');
|
||||
const IconWallet = createIconifyIcon('lucide:wallet');
|
||||
const IconBag = createIconifyIcon('lucide:shopping-bag');
|
||||
const IconNet = createIconifyIcon('lucide:badge-dollar-sign');
|
||||
const IconRoi = createIconifyIcon('lucide:target');
|
||||
|
||||
function pickKpi(label: string) {
|
||||
return props.data.kpis?.find((k) => k.label === label);
|
||||
}
|
||||
|
||||
function formatYuan(v: number | undefined | null) {
|
||||
if (v == null || !Number.isFinite(Number(v))) return '—';
|
||||
return `¥${Number(v).toLocaleString('zh-CN', {
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 2,
|
||||
})}`;
|
||||
}
|
||||
|
||||
function formatNum(v: number | undefined | null, digits = 0) {
|
||||
if (v == null || !Number.isFinite(Number(v))) return '—';
|
||||
return Number(v).toLocaleString('zh-CN', {
|
||||
minimumFractionDigits: digits,
|
||||
maximumFractionDigits: digits,
|
||||
});
|
||||
}
|
||||
|
||||
const spots = computed(() => {
|
||||
const sales = pickKpi('净销售额');
|
||||
const orders = pickKpi('净销售单量');
|
||||
const profit = pickKpi('净利润');
|
||||
const roi = pickKpi('广告ROI');
|
||||
return [
|
||||
{
|
||||
key: 'sales',
|
||||
label: '净销售额',
|
||||
value:
|
||||
sales?.amountYuan != null
|
||||
? formatYuan(sales.amountYuan)
|
||||
: formatYuan(props.data.totalSalesAmount),
|
||||
delta: sales?.changePct,
|
||||
icon: IconWallet,
|
||||
},
|
||||
{
|
||||
key: 'orders',
|
||||
label: '净销售单量',
|
||||
value:
|
||||
orders != null
|
||||
? `${formatNum(orders.value)} 单`
|
||||
: `${formatNum(props.data.totalOrderCount)} 单`,
|
||||
delta: orders?.changePct,
|
||||
icon: IconBag,
|
||||
},
|
||||
{
|
||||
key: 'profit',
|
||||
label: '净利润',
|
||||
value:
|
||||
profit?.amountYuan != null
|
||||
? formatYuan(profit.amountYuan)
|
||||
: formatYuan(props.data.totalNetProfitAfterTax),
|
||||
delta: profit?.changePct,
|
||||
icon: IconNet,
|
||||
},
|
||||
{
|
||||
key: 'roi',
|
||||
label: '广告 ROI',
|
||||
value:
|
||||
roi != null
|
||||
? formatNum(Number(roi.value), 2)
|
||||
: formatNum(props.data.totalROI, 2),
|
||||
delta: roi?.changePct,
|
||||
icon: IconRoi,
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
function deltaClass(pct: number | undefined | null) {
|
||||
if (pct == null || !Number.isFinite(Number(pct))) return 'text-slate-400';
|
||||
return Number(pct) >= 0
|
||||
? 'text-emerald-600 dark:text-emerald-400'
|
||||
: 'text-rose-500 dark:text-rose-400';
|
||||
}
|
||||
|
||||
function formatDelta(pct: number | undefined | null) {
|
||||
if (pct == null || !Number.isFinite(Number(pct))) return '';
|
||||
const n = Number(pct);
|
||||
return `环比 ${n > 0 ? '+' : ''}${n}%`;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section :class="PRODUCT_HERO_SHELL">
|
||||
<div
|
||||
class="pointer-events-none absolute -right-8 -top-10 size-40 rounded-full bg-teal-200/30 blur-2xl dark:bg-teal-500/10"
|
||||
/>
|
||||
<div
|
||||
class="pointer-events-none absolute -bottom-12 left-1/3 size-48 rounded-full bg-cyan-200/25 blur-3xl dark:bg-cyan-500/10"
|
||||
/>
|
||||
|
||||
<div class="relative flex flex-wrap items-start justify-between gap-4">
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="flex items-center gap-2">
|
||||
<span
|
||||
class="grid size-9 shrink-0 place-items-center rounded-[12px] bg-teal-600 text-white shadow-sm shadow-teal-600/25 dark:bg-teal-500"
|
||||
>
|
||||
<component :is="IconPackage" class="size-4" />
|
||||
</span>
|
||||
<span
|
||||
class="rounded-full bg-teal-600/10 px-2 py-0.5 text-[11px] font-semibold text-teal-700 dark:bg-teal-400/10 dark:text-teal-300"
|
||||
>
|
||||
单品诊断
|
||||
</span>
|
||||
</div>
|
||||
<h2
|
||||
class="mt-3 max-w-3xl text-xl font-bold tracking-tight text-slate-900 dark:text-[hsl(0deg_0%_96%)] sm:text-2xl"
|
||||
:title="data.productName"
|
||||
>
|
||||
{{ data.productName || '未命名商品' }}
|
||||
</h2>
|
||||
<p class="mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
<span v-if="dateLabel">统计区间 {{ dateLabel }}</span>
|
||||
<span v-if="shopLabel" class="truncate">店铺:{{ shopLabel }}</span>
|
||||
<span v-else>全渠道店铺汇总</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="relative mt-5 grid grid-cols-2 gap-2.5 lg:grid-cols-4"
|
||||
>
|
||||
<div
|
||||
v-for="spot in spots"
|
||||
:key="spot.key"
|
||||
:class="PRODUCT_SPOT_CARD"
|
||||
>
|
||||
<div class="flex items-center justify-between gap-2">
|
||||
<span class="truncate text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
{{ spot.label }}
|
||||
</span>
|
||||
<component
|
||||
:is="spot.icon"
|
||||
class="size-3.5 shrink-0 text-teal-600/80 dark:text-teal-400/80"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
class="mt-1.5 truncate text-lg font-bold tabular-nums tracking-tight text-slate-900 dark:text-[hsl(0deg_0%_95%)]"
|
||||
>
|
||||
{{ spot.value }}
|
||||
</div>
|
||||
<div
|
||||
v-if="spot.delta != null"
|
||||
class="mt-1 text-[11px] font-medium tabular-nums"
|
||||
:class="deltaClass(spot.delta)"
|
||||
>
|
||||
{{ formatDelta(spot.delta) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ProductOverviewVO } from '#/api/ec/product/overview';
|
||||
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { PRODUCT_PANEL_SHELL, PRODUCT_SECTION_LABEL } from '../constants/product-ui';
|
||||
|
||||
defineOptions({ name: 'ProductSkuRankStrip' });
|
||||
|
||||
const props = defineProps<{
|
||||
items?: ProductOverviewVO.SkuSalesRankItem[] | null;
|
||||
}>();
|
||||
|
||||
const rows = computed(() => (props.items ?? []).slice(0, 8));
|
||||
|
||||
const maxOrders = computed(() =>
|
||||
Math.max(1, ...rows.value.map((r) => Number(r.orderCount ?? 0))),
|
||||
);
|
||||
|
||||
function formatAmount(amount: number | undefined) {
|
||||
if (amount == null) return '—';
|
||||
return `¥${amount.toLocaleString('zh-CN', {
|
||||
minimumFractionDigits: 0,
|
||||
maximumFractionDigits: 0,
|
||||
})}`;
|
||||
}
|
||||
|
||||
function barWidth(orderCount: number | undefined) {
|
||||
const n = Number(orderCount ?? 0);
|
||||
return `${Math.max(8, Math.round((n / maxOrders.value) * 100))}%`;
|
||||
}
|
||||
|
||||
function rankTone(idx: number) {
|
||||
if (idx === 0) return 'bg-teal-600 text-white';
|
||||
if (idx === 1) return 'bg-teal-500/90 text-white';
|
||||
if (idx === 2) return 'bg-cyan-600 text-white';
|
||||
return 'bg-slate-100 text-slate-600 dark:bg-[hsl(200deg_10%_18%)] dark:text-slate-300';
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section v-if="rows.length" :class="PRODUCT_PANEL_SHELL">
|
||||
<div
|
||||
class="flex flex-wrap items-end justify-between gap-2 border-b border-teal-100/80 px-5 pb-3.5 pt-5 md:px-6 dark:border-teal-900/35"
|
||||
>
|
||||
<div>
|
||||
<span :class="PRODUCT_SECTION_LABEL">SKU 结构</span>
|
||||
<h3
|
||||
class="mt-2 text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]"
|
||||
>
|
||||
热销规格速览
|
||||
</h3>
|
||||
<p class="mt-1 text-xs text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
按净销售单量排序,突出本商品规格贡献
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="space-y-2.5 px-5 py-4 md:px-6 md:py-5">
|
||||
<div
|
||||
v-for="(row, idx) in rows"
|
||||
:key="row.skuId ?? `sku-${idx}`"
|
||||
class="grid grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-3"
|
||||
>
|
||||
<span
|
||||
class="flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-[11px] font-bold tabular-nums"
|
||||
:class="rankTone(idx)"
|
||||
>
|
||||
{{ idx + 1 }}
|
||||
</span>
|
||||
<div class="min-w-0">
|
||||
<div class="flex items-baseline justify-between gap-2">
|
||||
<span
|
||||
class="truncate text-sm font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]"
|
||||
:title="row.skuName"
|
||||
>
|
||||
{{ row.skuName || '—' }}
|
||||
</span>
|
||||
<span class="shrink-0 text-xs tabular-nums text-slate-500">
|
||||
{{ row.orderCount?.toLocaleString('zh-CN') ?? 0 }} 单 ·
|
||||
{{ formatAmount(row.salesAmount) }}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="mt-1.5 h-1.5 overflow-hidden rounded-full bg-teal-50 dark:bg-teal-950/50"
|
||||
>
|
||||
<div
|
||||
class="h-full rounded-full bg-gradient-to-r from-teal-500 to-cyan-400 transition-all duration-500"
|
||||
:style="{ width: barWidth(row.orderCount) }"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
-227
@@ -1,227 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
import type { EchartsUIType } from '@vben/plugins/echarts';
|
||||
|
||||
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { FINANCE_PANEL_SHELL } from '#/views/bi/workbench/tabs/finance/constants/finance-ui';
|
||||
|
||||
import { nextTick, onMounted, onUnmounted, ref, watch } from 'vue';
|
||||
|
||||
interface Props {
|
||||
data: {
|
||||
salesAmountTrend?: {
|
||||
dailyDataList: { date: string; value: number }[];
|
||||
};
|
||||
orderCountTrend?: {
|
||||
dailyDataList: { date: string; value: number }[];
|
||||
};
|
||||
} | null;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
|
||||
const trendChartRef = ref<EchartsUIType>();
|
||||
const { renderEcharts: renderTrendChart } = useEcharts(trendChartRef);
|
||||
let isUnmounted = false;
|
||||
let renderTimer: null | ReturnType<typeof setTimeout> = null;
|
||||
let darkObserver: MutationObserver | null = null;
|
||||
|
||||
const renderChart = () => {
|
||||
if (!trendChartRef.value || !props.data) return;
|
||||
|
||||
const salesTrend = props.data.salesAmountTrend;
|
||||
const orderTrend = props.data.orderCountTrend;
|
||||
|
||||
if (!salesTrend || !orderTrend) return;
|
||||
const salesList = Array.isArray(salesTrend.dailyDataList)
|
||||
? salesTrend.dailyDataList
|
||||
: [];
|
||||
const orderList = Array.isArray(orderTrend.dailyDataList)
|
||||
? orderTrend.dailyDataList
|
||||
: [];
|
||||
|
||||
if (salesList.length === 0 && orderList.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const dates = salesList.map((item) =>
|
||||
dayjs(item.date).format('MM-DD'),
|
||||
);
|
||||
const salesData = salesList.map((item) => item.value);
|
||||
const orderData = orderList.map((item) => item.value);
|
||||
|
||||
const isDark = document.documentElement.classList.contains('dark');
|
||||
try {
|
||||
renderTrendChart({
|
||||
grid: {
|
||||
left: '3%',
|
||||
right: '3%',
|
||||
bottom: '3%',
|
||||
top: '5%',
|
||||
containLabel: true,
|
||||
},
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
backgroundColor: isDark ? 'hsl(222.34deg 10.43% 12.27%)' : '#fff',
|
||||
textStyle: {
|
||||
color: isDark ? 'hsl(0deg 0% 95%)' : '#000',
|
||||
},
|
||||
},
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
boundaryGap: false,
|
||||
data: dates,
|
||||
axisLine: {
|
||||
lineStyle: {
|
||||
color: isDark ? 'hsl(240deg 3.7% 22%)' : '#e2e8f0',
|
||||
},
|
||||
},
|
||||
},
|
||||
yAxis: [
|
||||
{
|
||||
type: 'value',
|
||||
name: '销售额',
|
||||
nameTextStyle: {
|
||||
color: isDark ? 'hsl(240deg 5% 64.9%)' : undefined,
|
||||
},
|
||||
axisLabel: {
|
||||
color: isDark ? 'hsl(240deg 5% 64.9%)' : undefined,
|
||||
},
|
||||
splitLine: {
|
||||
lineStyle: {
|
||||
type: 'dashed',
|
||||
color: isDark ? 'hsl(240deg 3.7% 22%)' : undefined,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'value',
|
||||
name: '单量',
|
||||
position: 'right',
|
||||
nameTextStyle: {
|
||||
color: isDark ? 'hsl(240deg 5% 64.9%)' : undefined,
|
||||
},
|
||||
axisLabel: {
|
||||
color: isDark ? 'hsl(240deg 5% 64.9%)' : undefined,
|
||||
},
|
||||
splitLine: { show: false },
|
||||
},
|
||||
],
|
||||
series: [
|
||||
{
|
||||
name: '销售额',
|
||||
type: 'line',
|
||||
smooth: true,
|
||||
symbol: 'none',
|
||||
lineStyle: { width: 3, color: '#3b82f6' },
|
||||
areaStyle: {
|
||||
color: {
|
||||
type: 'linear',
|
||||
x: 0,
|
||||
y: 0,
|
||||
x2: 0,
|
||||
y2: 1,
|
||||
colorStops: [
|
||||
{ offset: 0, color: 'rgba(59, 130, 246, 0.4)' },
|
||||
{ offset: 1, color: 'rgba(59, 130, 246, 0)' },
|
||||
],
|
||||
},
|
||||
},
|
||||
data: salesData,
|
||||
},
|
||||
{
|
||||
name: '日单量',
|
||||
type: 'line',
|
||||
yAxisIndex: 1,
|
||||
smooth: true,
|
||||
symbol: 'none',
|
||||
lineStyle: { width: 3, color: '#10b981' },
|
||||
areaStyle: {
|
||||
color: {
|
||||
type: 'linear',
|
||||
x: 0,
|
||||
y: 0,
|
||||
x2: 0,
|
||||
y2: 1,
|
||||
colorStops: [
|
||||
{ offset: 0, color: 'rgba(16, 185, 129, 0.2)' },
|
||||
{ offset: 1, color: 'rgba(16, 185, 129, 0)' },
|
||||
],
|
||||
},
|
||||
},
|
||||
data: orderData,
|
||||
},
|
||||
],
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('渲染趋势图失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const scheduleRender = async () => {
|
||||
if (renderTimer) {
|
||||
clearTimeout(renderTimer);
|
||||
renderTimer = null;
|
||||
}
|
||||
await nextTick();
|
||||
if (isUnmounted) return;
|
||||
renderTimer = setTimeout(() => {
|
||||
if (isUnmounted) return;
|
||||
renderChart();
|
||||
}, 16);
|
||||
};
|
||||
|
||||
watch(
|
||||
() => props.data,
|
||||
() => {
|
||||
if (props.data) {
|
||||
scheduleRender();
|
||||
}
|
||||
},
|
||||
{ deep: true, immediate: true },
|
||||
);
|
||||
|
||||
onMounted(() => {
|
||||
isUnmounted = false;
|
||||
darkObserver = new MutationObserver(() => {
|
||||
if (props.data) scheduleRender();
|
||||
});
|
||||
darkObserver.observe(document.documentElement, {
|
||||
attributes: true,
|
||||
attributeFilter: ['class'],
|
||||
});
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
isUnmounted = true;
|
||||
if (renderTimer) {
|
||||
clearTimeout(renderTimer);
|
||||
renderTimer = null;
|
||||
}
|
||||
darkObserver?.disconnect();
|
||||
darkObserver = null;
|
||||
});
|
||||
|
||||
defineExpose({ renderChart });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div :class="[FINANCE_PANEL_SHELL, 'xl:col-span-2']">
|
||||
<div
|
||||
class="border-b border-slate-100 px-5 pb-3.5 pt-5 md:px-6 md:pt-5 dark:border-b-[hsl(240deg_3.7%_22%)]"
|
||||
>
|
||||
<h3 class="text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
||||
销售额与单量趋势
|
||||
</h3>
|
||||
<p class="mt-1 text-xs font-normal text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
双轴展示销售额与订单量,与上方 KPI 同一时间范围
|
||||
</p>
|
||||
</div>
|
||||
<div class="px-5 py-4 md:px-6 md:py-5">
|
||||
<div class="h-[320px] w-full">
|
||||
<EchartsUI ref="trendChartRef" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
-97
@@ -1,97 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
import { FINANCE_PANEL_SHELL } from '#/views/bi/workbench/tabs/finance/constants/finance-ui';
|
||||
|
||||
interface SkuSalesRankItem {
|
||||
skuId?: number;
|
||||
skuName?: string;
|
||||
skuCode?: string;
|
||||
orderCount?: number;
|
||||
salesAmount?: number;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
data: SkuSalesRankItem[] | null;
|
||||
}
|
||||
|
||||
defineProps<Props>();
|
||||
|
||||
const formatAmount = (amount: number | undefined) => {
|
||||
if (amount === undefined || amount === null) return '-';
|
||||
return `¥${amount.toLocaleString('zh-CN', {
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 2,
|
||||
})}`;
|
||||
};
|
||||
|
||||
function rankBadgeClass(idx: number) {
|
||||
if (idx === 0) return 'bg-amber-50 text-amber-700 dark:bg-amber-950/50 dark:text-amber-300';
|
||||
if (idx === 1) return 'bg-slate-100 text-slate-600 dark:bg-[hsl(240deg_3.7%_22%)] dark:text-slate-300';
|
||||
if (idx === 2) return 'bg-orange-50 text-orange-700 dark:bg-orange-950/40 dark:text-orange-300';
|
||||
return 'bg-slate-50 text-slate-500 dark:bg-[hsl(240deg_3.7%_15.9%)] dark:text-[hsl(240deg_5%_64.9%)]';
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div :class="FINANCE_PANEL_SHELL">
|
||||
<div
|
||||
class="border-b border-slate-100 px-5 pb-3.5 pt-5 md:px-6 md:pt-5 dark:border-b-[hsl(240deg_3.7%_22%)]"
|
||||
>
|
||||
<h3 class="text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
||||
各 SKU 销量 Top10
|
||||
</h3>
|
||||
<p class="mt-1 text-xs font-normal text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
按单量排序,与当前筛选时间范围一致
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="px-5 py-4 md:px-6 md:py-5">
|
||||
<div class="max-h-[320px] space-y-2 overflow-y-auto pr-1">
|
||||
<template v-if="data?.length">
|
||||
<div
|
||||
v-for="(row, idx) in data"
|
||||
:key="row.skuId ?? `rank-${idx}`"
|
||||
class="flex items-center gap-3 rounded-[10px] border border-slate-200/90 bg-white px-3 py-2.5 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(222.34deg_10.43%_12.27%)]"
|
||||
>
|
||||
<span
|
||||
class="flex h-7 w-7 shrink-0 items-center justify-center rounded-lg text-xs font-bold tabular-nums"
|
||||
:class="rankBadgeClass(idx)"
|
||||
>
|
||||
{{ idx + 1 }}
|
||||
</span>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div
|
||||
class="truncate text-sm font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]"
|
||||
:title="row.skuName"
|
||||
>
|
||||
{{ row.skuName || '-' }}
|
||||
</div>
|
||||
<div
|
||||
v-if="row.skuCode"
|
||||
class="truncate text-[11px] text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
{{ row.skuCode }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="shrink-0 text-right">
|
||||
<div class="text-sm font-bold tabular-nums text-blue-600 dark:text-blue-400">
|
||||
{{ row.orderCount != null ? row.orderCount.toLocaleString('zh-CN') : '-' }}
|
||||
<span class="text-[10px] font-medium text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
单
|
||||
</span>
|
||||
</div>
|
||||
<div class="text-[11px] font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
{{ formatAmount(row.salesAmount) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<div
|
||||
v-else
|
||||
class="flex h-[280px] items-center justify-center text-sm text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
暂无 SKU 数据
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
+5
-5
@@ -12,7 +12,7 @@ import {
|
||||
import { formatIntCell, formatNumberCell } from '#/utils/overview-table-cells';
|
||||
import { formatFeeRatioPercent } from '#/utils/overview-fee-ratio';
|
||||
|
||||
import { FINANCE_PANEL_SHELL } from '#/views/bi/workbench/tabs/finance/constants/finance-ui';
|
||||
import { PRODUCT_PANEL_SHELL } from '../constants/product-ui';
|
||||
|
||||
interface SkuData {
|
||||
skuId: number;
|
||||
@@ -116,16 +116,16 @@ const footerRow = computed(() => props.footerTotal ?? computedFooter.value);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div :class="FINANCE_PANEL_SHELL">
|
||||
<div :class="PRODUCT_PANEL_SHELL">
|
||||
<div
|
||||
class="flex flex-col items-start justify-between gap-4 border-b border-slate-100 p-5 md:flex-row md:items-center md:px-6 dark:border-b-[hsl(240deg_3.7%_22%)]"
|
||||
class="flex flex-col items-start justify-between gap-4 border-b border-teal-100/80 p-5 md:flex-row md:items-center md:px-6 dark:border-teal-900/35"
|
||||
>
|
||||
<div>
|
||||
<h3 class="text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
||||
商品 SKU 销售汇总
|
||||
规格经营明细
|
||||
</h3>
|
||||
<p class="mt-1 text-xs font-normal text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
各 SKU 经营明细:规模、成本及最终损益(列序与工作台店铺汇总表对齐)
|
||||
本商品各 SKU 的规模、成本与损益(商品概览核心明细)
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
-199
@@ -1,199 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import {
|
||||
FINANCE_KPI_CARD_SHELL,
|
||||
FINANCE_TONE_ICON,
|
||||
} from '#/views/bi/workbench/tabs/finance/constants/finance-ui';
|
||||
|
||||
const IconSales = createIconifyIcon('lucide:wallet');
|
||||
const IconOrders = createIconifyIcon('lucide:shopping-bag');
|
||||
const IconRoi = createIconifyIcon('lucide:target');
|
||||
const IconNet = createIconifyIcon('lucide:badge-dollar-sign');
|
||||
const IconTax = createIconifyIcon('lucide:landmark');
|
||||
|
||||
interface Props {
|
||||
data: {
|
||||
productName?: string;
|
||||
totalSalesAmount?: number;
|
||||
totalOrderCount?: number;
|
||||
monthOverMonthGrowth?: number;
|
||||
salesAmountAchievementRate?: number;
|
||||
orderCountAchievementRate?: number;
|
||||
averageFeeRatio?: number;
|
||||
totalROI?: number;
|
||||
totalNetProfitAfterTax?: number;
|
||||
totalTaxAmount?: number;
|
||||
} | null;
|
||||
loading?: boolean;
|
||||
}
|
||||
|
||||
defineProps<Props>();
|
||||
|
||||
const cards = [
|
||||
{
|
||||
key: 'sales',
|
||||
label: '净销售额',
|
||||
tone: 'blue' as const,
|
||||
icon: IconSales,
|
||||
},
|
||||
{
|
||||
key: 'orders',
|
||||
label: '净销售单量',
|
||||
tone: 'blue' as const,
|
||||
icon: IconOrders,
|
||||
},
|
||||
{
|
||||
key: 'roi',
|
||||
label: '广告 ROI',
|
||||
tone: 'purple' as const,
|
||||
icon: IconRoi,
|
||||
},
|
||||
{
|
||||
key: 'profit',
|
||||
label: '净利润',
|
||||
tone: 'green' as const,
|
||||
icon: IconNet,
|
||||
},
|
||||
];
|
||||
|
||||
function toneClass(tone: string) {
|
||||
return FINANCE_TONE_ICON[tone] ?? FINANCE_TONE_ICON.blue;
|
||||
}
|
||||
|
||||
const formatAmount = (amount: number | undefined) => {
|
||||
if (amount === undefined) return '-';
|
||||
return `¥${amount.toLocaleString('zh-CN', {
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 2,
|
||||
})}`;
|
||||
};
|
||||
|
||||
const toNumber = (value: unknown): number | undefined => {
|
||||
if (value === undefined || value === null || value === '') return undefined;
|
||||
const parsed = Number(value);
|
||||
return Number.isFinite(parsed) ? parsed : undefined;
|
||||
};
|
||||
|
||||
const formatPercentPlain = (value: number | undefined | null) => {
|
||||
if (value == null) return '-';
|
||||
return `${value.toFixed(1)}%`;
|
||||
};
|
||||
|
||||
const formatGrowth = (value: number | undefined) => {
|
||||
if (value === undefined) return '';
|
||||
return `${value > 0 ? '+' : ''}${value.toFixed(1)}%`;
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="grid grid-cols-1 gap-3.5 sm:grid-cols-2 xl:grid-cols-4">
|
||||
<div
|
||||
v-for="meta in cards"
|
||||
:key="meta.key"
|
||||
:class="FINANCE_KPI_CARD_SHELL"
|
||||
>
|
||||
<div class="flex items-start justify-between gap-2">
|
||||
<span
|
||||
class="min-w-0 truncate text-[16px] font-semibold leading-snug text-slate-800 dark:text-[hsl(0deg_0%_90%)]"
|
||||
>
|
||||
{{ meta.label }}
|
||||
</span>
|
||||
<div
|
||||
class="grid size-9 shrink-0 place-items-center rounded-[10px]"
|
||||
:class="toneClass(meta.tone)"
|
||||
>
|
||||
<component :is="meta.icon" class="size-4" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 销售额 -->
|
||||
<template v-if="meta.key === 'sales'">
|
||||
<div class="mt-3 tabular-nums text-[26px] font-bold leading-none tracking-tight text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
||||
{{ data?.totalSalesAmount ? formatAmount(data.totalSalesAmount) : '-' }}
|
||||
</div>
|
||||
<div
|
||||
class="mt-2.5 flex min-h-[1.25rem] flex-wrap items-center justify-between gap-x-2 gap-y-1 text-xs text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
<span v-if="data?.salesAmountAchievementRate !== undefined">
|
||||
目标达成
|
||||
<span class="ml-1 font-semibold text-blue-600 dark:text-blue-400">
|
||||
{{ formatPercentPlain(data.salesAmountAchievementRate) }}
|
||||
</span>
|
||||
</span>
|
||||
<span
|
||||
v-if="data?.monthOverMonthGrowth !== undefined"
|
||||
:class="
|
||||
data.monthOverMonthGrowth >= 0
|
||||
? 'font-semibold text-emerald-500 dark:text-emerald-400'
|
||||
: 'font-semibold text-rose-500 dark:text-rose-400'
|
||||
"
|
||||
>
|
||||
环比 {{ formatGrowth(data.monthOverMonthGrowth) }}
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 单量 -->
|
||||
<template v-else-if="meta.key === 'orders'">
|
||||
<div class="mt-3 inline-flex items-baseline gap-1 tabular-nums">
|
||||
<span class="text-[26px] font-bold leading-none tracking-tight text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
||||
{{ data?.totalOrderCount?.toLocaleString('zh-CN') || '-' }}
|
||||
</span>
|
||||
<span class="text-sm font-semibold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
单
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
v-if="data?.orderCountAchievementRate !== undefined"
|
||||
class="mt-2.5 space-y-2"
|
||||
>
|
||||
<div class="flex justify-between text-xs text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
<span>目标达成率</span>
|
||||
<span class="font-semibold text-blue-600 dark:text-blue-400">
|
||||
{{ formatPercentPlain(data.orderCountAchievementRate) }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="h-1.5 w-full overflow-hidden rounded-full bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)]">
|
||||
<div
|
||||
class="h-full rounded-full bg-blue-500 transition-all duration-700"
|
||||
:style="{
|
||||
width: `${Math.min(data.orderCountAchievementRate || 0, 100)}%`,
|
||||
}"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- ROI -->
|
||||
<template v-else-if="meta.key === 'roi'">
|
||||
<div class="mt-3 tabular-nums text-[26px] font-bold leading-none tracking-tight text-indigo-600 dark:text-indigo-400">
|
||||
{{ toNumber(data?.totalROI)?.toFixed(2) ?? '-' }}
|
||||
</div>
|
||||
<div
|
||||
v-if="data?.averageFeeRatio !== undefined"
|
||||
class="mt-2.5 text-xs text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
平均费比
|
||||
<span class="ml-1 font-semibold text-slate-700 dark:text-[hsl(0deg_0%_90%)]">
|
||||
{{ formatPercentPlain(data.averageFeeRatio) }}
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 净利润 -->
|
||||
<template v-else-if="meta.key === 'profit'">
|
||||
<div class="mt-3 tabular-nums text-[26px] font-bold leading-none tracking-tight text-emerald-600 dark:text-emerald-400">
|
||||
{{ data?.totalNetProfitAfterTax ? formatAmount(data.totalNetProfitAfterTax) : '-' }}
|
||||
</div>
|
||||
<div
|
||||
v-if="data?.totalTaxAmount !== undefined"
|
||||
class="mt-2.5 flex items-center gap-1.5 text-xs text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
<IconTax class="size-3.5 shrink-0 opacity-70" />
|
||||
<span>已扣税额 {{ formatAmount(data.totalTaxAmount) }}</span>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,16 @@
|
||||
/** 商品概览:青绿强调,与经营概览蓝灰区分 */
|
||||
|
||||
export const PRODUCT_PAGE_BG =
|
||||
'bg-[#f4f9f8] dark:bg-[hsl(200deg_18%_8%)]';
|
||||
|
||||
export const PRODUCT_PANEL_SHELL =
|
||||
'overflow-hidden rounded-[16px] border border-teal-200/70 bg-white shadow-[0_1px_2px_rgba(15,118,110,0.04),0_10px_28px_rgba(15,118,110,0.05)] dark:border-teal-900/40 dark:bg-[hsl(200deg_14%_11%)] dark:shadow-none';
|
||||
|
||||
export const PRODUCT_HERO_SHELL =
|
||||
'relative overflow-hidden rounded-[18px] border border-teal-200/80 bg-gradient-to-br from-teal-50 via-white to-cyan-50/80 p-5 shadow-[0_1px_2px_rgba(15,118,110,0.05),0_12px_32px_rgba(15,118,110,0.07)] md:p-6 dark:border-teal-900/45 dark:from-teal-950/40 dark:via-[hsl(200deg_14%_11%)] dark:to-cyan-950/30 dark:shadow-none';
|
||||
|
||||
export const PRODUCT_SPOT_CARD =
|
||||
'min-w-0 rounded-[14px] border border-teal-100/90 bg-white/80 px-3.5 py-3 backdrop-blur-sm dark:border-teal-900/35 dark:bg-[hsl(200deg_14%_12%/80%)]';
|
||||
|
||||
export const PRODUCT_SECTION_LABEL =
|
||||
'inline-flex items-center gap-1.5 rounded-full border border-teal-200/80 bg-teal-50/80 px-2.5 py-0.5 text-[11px] font-semibold tracking-wide text-teal-700 dark:border-teal-800/50 dark:bg-teal-950/40 dark:text-teal-300';
|
||||
@@ -1,18 +1,21 @@
|
||||
<script lang="ts" setup>
|
||||
import type { Dayjs } from 'dayjs';
|
||||
import type { ProductOverviewVO } from '#/api/ec/product/overview';
|
||||
import type { WorkbenchVO } from '#/api/bi/workbench/types';
|
||||
import type { FinanceKpiCardId } from '#/views/bi/workbench/tabs/finance/constants/kpi-catalog';
|
||||
|
||||
import { computed, onActivated, onMounted, onUnmounted, ref, watch } from 'vue';
|
||||
import { computed, nextTick, onActivated, onMounted, onUnmounted, ref, watch } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Spin, message } from 'ant-design-vue';
|
||||
import { Button, Spin, message } from 'ant-design-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import TimeRangeBar from './components/TimeRangeBar.vue';
|
||||
import StatCards from './components/StatCards.vue';
|
||||
import SalesTrendChart from './components/SalesTrendChart.vue';
|
||||
import SkuSalesTop10Panel from './components/SkuSalesTop10Panel.vue';
|
||||
import ProductHeroBanner from './components/ProductHeroBanner.vue';
|
||||
import ProductSkuRankStrip from './components/ProductSkuRankStrip.vue';
|
||||
import SkuSummaryTable from './components/SkuSummaryTable.vue';
|
||||
import { getProductPageApi } from '#/api/ec/product/apis';
|
||||
import type { ProductVO } from '#/api/ec/product/types';
|
||||
@@ -26,19 +29,30 @@ import {
|
||||
syncOverviewDateRangeToUrl,
|
||||
} from '#/utils/overview-date-range';
|
||||
|
||||
import FinanceCostPieChart from '#/views/bi/workbench/tabs/finance/components/FinanceCostPieChart.vue';
|
||||
import FinanceKpiGrid from '#/views/bi/workbench/tabs/finance/components/FinanceKpiGrid.vue';
|
||||
import FinanceKpiSettingsModal from '#/views/bi/workbench/tabs/finance/components/FinanceKpiSettingsModal.vue';
|
||||
import FinanceTrendChart from '#/views/bi/workbench/tabs/finance/components/FinanceTrendChart.vue';
|
||||
import { useFinanceKpiPreferences } from '#/views/bi/workbench/tabs/finance/composables/useFinanceKpiPreferences';
|
||||
|
||||
import {
|
||||
PRODUCT_PAGE_BG,
|
||||
PRODUCT_PANEL_SHELL,
|
||||
PRODUCT_SECTION_LABEL,
|
||||
} from './constants/product-ui';
|
||||
|
||||
defineOptions({ name: 'ProductOverview' });
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const IconSliders = createIconifyIcon('lucide:sliders-horizontal');
|
||||
|
||||
const PRODUCT_PAGE_SIZE = 20;
|
||||
const SHOP_PAGE_SIZE = 20;
|
||||
|
||||
/** 当前是否为商品概览路由(keep-alive 下勿用其它页的 params.id 请求商品接口) */
|
||||
const isProductOverviewRoute = () =>
|
||||
/\/ec\/product\/overview\/[^/]+\/?$/.test(route.path);
|
||||
|
||||
// 商品ID(从路由参数获取)
|
||||
const productId = computed(() => {
|
||||
if (!isProductOverviewRoute()) return 0;
|
||||
const id = route.params.id;
|
||||
@@ -46,7 +60,6 @@ const productId = computed(() => {
|
||||
return Number.isFinite(parsed) && parsed > 0 ? parsed : 0;
|
||||
});
|
||||
|
||||
/** 路由 query.shopId:工作台筛选店铺跳转时带入 */
|
||||
const contextShopId = computed(() => {
|
||||
if (!isProductOverviewRoute()) return undefined;
|
||||
return parseOverviewShopIdFromQuery(
|
||||
@@ -85,9 +98,8 @@ const shopSelectOptions = computed(() => {
|
||||
return opts;
|
||||
});
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const overviewData = ref<any>(null);
|
||||
const overviewData = ref<ProductOverviewVO.Overview | null>(null);
|
||||
|
||||
const productSelectOptions = computed(() => {
|
||||
const opts = products.value.map((p) => ({
|
||||
@@ -102,43 +114,73 @@ const productSelectOptions = computed(() => {
|
||||
return opts;
|
||||
});
|
||||
|
||||
const normalizeOverview = (raw: any) => {
|
||||
if (!raw || typeof raw !== 'object') return null;
|
||||
return {
|
||||
// 保留所有 KPI 字段
|
||||
...raw,
|
||||
// 防御性处理嵌套结构
|
||||
salesAmountTrend: {
|
||||
...(raw.salesAmountTrend || {}),
|
||||
dailyDataList: Array.isArray(raw.salesAmountTrend?.dailyDataList)
|
||||
? raw.salesAmountTrend.dailyDataList
|
||||
: [],
|
||||
},
|
||||
orderCountTrend: {
|
||||
...(raw.orderCountTrend || {}),
|
||||
dailyDataList: Array.isArray(raw.orderCountTrend?.dailyDataList)
|
||||
? raw.orderCountTrend.dailyDataList
|
||||
: [],
|
||||
},
|
||||
specSummaries: {
|
||||
...(raw.specSummaries || {}),
|
||||
list: Array.isArray(raw.specSummaries?.list) ? raw.specSummaries.list : [],
|
||||
},
|
||||
};
|
||||
};
|
||||
const financeKpis = computed<WorkbenchVO.KpiItem[]>(
|
||||
() => (overviewData.value?.kpis as WorkbenchVO.KpiItem[] | undefined) ?? [],
|
||||
);
|
||||
const dealTrend = computed<WorkbenchVO.TrendPoint[]>(
|
||||
() => (overviewData.value?.dealTrend as WorkbenchVO.TrendPoint[] | undefined) ?? [],
|
||||
);
|
||||
const skuSalesShare = computed<WorkbenchVO.PieSlice[]>(
|
||||
() =>
|
||||
(overviewData.value?.skuSalesShare as WorkbenchVO.PieSlice[] | undefined) ??
|
||||
[],
|
||||
);
|
||||
|
||||
// 日期范围(默认:本月至今日)
|
||||
const dateRange = ref<[Dayjs, Dayjs]>([
|
||||
dayjs().startOf('month'),
|
||||
dayjs(),
|
||||
]);
|
||||
const periodDateLabel = computed(() => {
|
||||
const [start, end] = dateRange.value;
|
||||
return `${start.format('YYYY-MM-DD')} ~ ${end.format('YYYY-MM-DD')}`;
|
||||
});
|
||||
|
||||
// 当前选中的时间范围类型
|
||||
const heroShopLabel = computed(() => {
|
||||
const id = contextShopId.value;
|
||||
if (id == null || id <= 0) return undefined;
|
||||
return (
|
||||
shopSelectOptions.value.find((o) => o.value === String(id))?.label ||
|
||||
selectedShopLabelCache.value ||
|
||||
`店铺 #${id}`
|
||||
);
|
||||
});
|
||||
|
||||
const {
|
||||
visibleCardIds,
|
||||
primaryByCardId,
|
||||
colsPerRow,
|
||||
applySettings,
|
||||
setCardPrimary,
|
||||
} = useFinanceKpiPreferences();
|
||||
const kpiSettingsOpen = ref(false);
|
||||
const visibleKpiCount = computed(() => visibleCardIds.value.length);
|
||||
|
||||
const trendChartRef = ref<InstanceType<typeof FinanceTrendChart> | null>(null);
|
||||
const costPieRef = ref<InstanceType<typeof FinanceCostPieChart> | null>(null);
|
||||
|
||||
async function redrawCharts() {
|
||||
await nextTick();
|
||||
await trendChartRef.value?.redraw();
|
||||
await costPieRef.value?.redraw();
|
||||
}
|
||||
|
||||
function onKpiSettingsSave(payload: {
|
||||
visibleCardIds: string[];
|
||||
primaryByCardId: Record<string, string>;
|
||||
colsPerRow: number;
|
||||
}) {
|
||||
if (payload.visibleCardIds.length === 0) {
|
||||
message.warning('请至少选择一张 KPI 卡片');
|
||||
return;
|
||||
}
|
||||
applySettings(payload);
|
||||
message.success('KPI 显示已更新');
|
||||
}
|
||||
|
||||
function onSetPrimary(payload: { cardId: FinanceKpiCardId; metricLabel: string }) {
|
||||
setCardPrimary(payload.cardId, payload.metricLabel);
|
||||
}
|
||||
|
||||
const dateRange = ref<[Dayjs, Dayjs]>([dayjs().startOf('month'), dayjs()]);
|
||||
const activeTimeRange = ref<
|
||||
'7days' | '30days' | 'thisMonth' | 'custom' | 'today' | 'yesterday'
|
||||
>('thisMonth');
|
||||
|
||||
// 自定义日期范围
|
||||
const customDateRange = ref<[Dayjs, Dayjs] | undefined>([
|
||||
dateRange.value[0],
|
||||
dateRange.value[1],
|
||||
@@ -147,13 +189,12 @@ const customDateRange = ref<[Dayjs, Dayjs] | undefined>([
|
||||
const lastRequestKey = ref('');
|
||||
const isRequesting = ref(false);
|
||||
|
||||
// 税率(持久化,与全店/店铺概览共用 key)
|
||||
const TAX_RATE_KEY = 'overview-tax-rate';
|
||||
const taxRate = ref<number>(0.04);
|
||||
taxRate.value = Number(localStorage.getItem(TAX_RATE_KEY)) || 0.04;
|
||||
|
||||
watch(taxRate, () => {
|
||||
loadOverviewData();
|
||||
void loadOverviewData();
|
||||
});
|
||||
|
||||
const setTimeRangeTypeByDates = (startDate: Dayjs, endDate: Dayjs) => {
|
||||
@@ -174,31 +215,26 @@ const setTimeRangeTypeByDates = (startDate: Dayjs, endDate: Dayjs) => {
|
||||
customDateRange.value = [startDate, endDate];
|
||||
return;
|
||||
}
|
||||
|
||||
if (daysDiff === 0 && startDate.isSame(today, 'day')) {
|
||||
activeTimeRange.value = 'today';
|
||||
customDateRange.value = [startDate, endDate];
|
||||
return;
|
||||
}
|
||||
|
||||
if (daysDiff === 0 && startDate.isSame(dayjs().subtract(1, 'day'), 'day')) {
|
||||
activeTimeRange.value = 'yesterday';
|
||||
customDateRange.value = [startDate, endDate];
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEndDateToday && isStartDate7DaysAgo) {
|
||||
activeTimeRange.value = '7days';
|
||||
customDateRange.value = [startDate, endDate];
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEndDateToday && isStartDate30DaysAgo) {
|
||||
activeTimeRange.value = '30days';
|
||||
customDateRange.value = [startDate, endDate];
|
||||
return;
|
||||
}
|
||||
|
||||
activeTimeRange.value = 'custom';
|
||||
customDateRange.value = [startDate, endDate];
|
||||
};
|
||||
@@ -337,7 +373,6 @@ function handleProductChange(nextProductId: number) {
|
||||
});
|
||||
}
|
||||
|
||||
// 时间范围状态(传递给子组件)
|
||||
const timeRangeState = computed(() => ({
|
||||
taxRate: taxRate.value,
|
||||
activeTimeRange: activeTimeRange.value,
|
||||
@@ -345,7 +380,6 @@ const timeRangeState = computed(() => ({
|
||||
dateRange: dateRange.value,
|
||||
}));
|
||||
|
||||
// 监听子组件的时间范围变化(与店铺概览一致:写 URL + 按条件刷新)
|
||||
const handleTimeRangeChange = async (val: typeof timeRangeState.value) => {
|
||||
taxRate.value = val.taxRate;
|
||||
activeTimeRange.value = val.activeTimeRange;
|
||||
@@ -371,7 +405,8 @@ async function loadOverviewData() {
|
||||
? { shopId: contextShopId.value }
|
||||
: {}),
|
||||
});
|
||||
overviewData.value = normalizeOverview(res);
|
||||
overviewData.value = res ?? null;
|
||||
await redrawCharts();
|
||||
} catch (err: any) {
|
||||
message.error(err?.message || '加载失败');
|
||||
} finally {
|
||||
@@ -385,7 +420,7 @@ const refreshOverviewByCurrentParams = async (force = false) => {
|
||||
applyDateRangeFromRouteQuery();
|
||||
if (!productId.value) return;
|
||||
|
||||
const requestKey = `${productId.value}_${dateRange.value[0].format('YYYY-MM-DD')}_${dateRange.value[1].format('YYYY-MM-DD')}_${contextShopId.value ?? ''}`;
|
||||
const requestKey = `${productId.value}_${dateRange.value[0].format('YYYY-MM-DD')}_${dateRange.value[1].format('YYYY-MM-DD')}_${contextShopId.value ?? ''}_${taxRate.value}`;
|
||||
if (!force && lastRequestKey.value === requestKey) {
|
||||
return;
|
||||
}
|
||||
@@ -394,7 +429,6 @@ const refreshOverviewByCurrentParams = async (force = false) => {
|
||||
await loadOverviewData();
|
||||
};
|
||||
|
||||
// 监听路由(与店铺概览一致;日期 query 以 window.location 为准,见 applyOverviewDateRangeFromUrl)
|
||||
watch(
|
||||
() => [
|
||||
route.path,
|
||||
@@ -436,16 +470,21 @@ onUnmounted(() => {
|
||||
<template>
|
||||
<Page
|
||||
auto-content-height
|
||||
class="bg-[#f8fafc] dark:bg-[hsl(222.34deg_10.43%_12.27%)]"
|
||||
:class="PRODUCT_PAGE_BG"
|
||||
content-padding-class="px-4 pb-4"
|
||||
header-class="product-overview-page-header"
|
||||
>
|
||||
<template #title>
|
||||
<div
|
||||
class="text-xl font-black tracking-tight text-slate-900 dark:text-[hsl(0deg_0%_98%)] sm:text-2xl md:text-3xl"
|
||||
class="text-xl font-black tracking-tight text-teal-950 dark:text-teal-50 sm:text-2xl md:text-3xl"
|
||||
>
|
||||
商品概览
|
||||
</div>
|
||||
<p
|
||||
class="mt-0.5 text-xs font-normal text-teal-700/70 dark:text-teal-300/70"
|
||||
>
|
||||
单品诊断 · 规格结构优先
|
||||
</p>
|
||||
</template>
|
||||
|
||||
<template #extra>
|
||||
@@ -474,31 +513,93 @@ onUnmounted(() => {
|
||||
</template>
|
||||
|
||||
<Spin :spinning="loading">
|
||||
<div v-if="overviewData" class="product-overview-body mx-auto w-full min-w-0 space-y-4 pt-4">
|
||||
<div>
|
||||
<h2 class="text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
||||
经营概览
|
||||
</h2>
|
||||
<p class="mt-0.5 text-xs text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
商品核心 KPI · 与当前筛选时间范围一致
|
||||
</p>
|
||||
<div
|
||||
v-if="overviewData"
|
||||
class="product-overview-body mx-auto w-full min-w-0 space-y-4 pt-4"
|
||||
>
|
||||
<ProductHeroBanner
|
||||
:data="overviewData"
|
||||
:date-label="periodDateLabel"
|
||||
:shop-label="heroShopLabel"
|
||||
/>
|
||||
|
||||
<!-- 商品特色:先看趋势与规格占比,再下钻指标 -->
|
||||
<div class="grid grid-cols-1 gap-3.5 xl:grid-cols-5">
|
||||
<FinanceTrendChart
|
||||
ref="trendChartRef"
|
||||
:trend="dealTrend"
|
||||
:panel-class="PRODUCT_PANEL_SHELL"
|
||||
class="xl:col-span-3"
|
||||
/>
|
||||
<FinanceCostPieChart
|
||||
ref="costPieRef"
|
||||
class="xl:col-span-2"
|
||||
:platform-sales-share="skuSalesShare"
|
||||
:panel-class="PRODUCT_PANEL_SHELL"
|
||||
title="规格销售额占比"
|
||||
subtitle="本商品各 SKU 占净销售额的比例"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<StatCards :data="overviewData" :loading="loading" />
|
||||
<ProductSkuRankStrip :items="overviewData.specSalesTop10" />
|
||||
|
||||
<div class="grid grid-cols-1 gap-3.5 xl:grid-cols-3">
|
||||
<SalesTrendChart :data="overviewData" />
|
||||
<SkuSalesTop10Panel :data="overviewData?.specSalesTop10 ?? []" />
|
||||
<div class="flex flex-wrap items-center justify-between gap-3 pt-1">
|
||||
<div>
|
||||
<span :class="PRODUCT_SECTION_LABEL">指标明细</span>
|
||||
<h2
|
||||
class="mt-2 text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]"
|
||||
>
|
||||
单品经营指标
|
||||
</h2>
|
||||
<p class="mt-0.5 text-xs text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
口径与工作台一致,卡片布局可自定义
|
||||
<span v-if="visibleKpiCount > 0">
|
||||
· 已选 {{ visibleKpiCount }} 张 · 最多 {{ colsPerRow }} 列
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
type="default"
|
||||
class="shrink-0 whitespace-nowrap !rounded-[10px] !border-teal-200 !bg-white !text-teal-800 shadow-[0_1px_2px_rgba(15,118,110,0.05)] hover:!border-teal-400 hover:!text-teal-700 dark:!border-teal-800/50 dark:!bg-[hsl(200deg_14%_12%)] dark:!text-teal-200 dark:hover:!border-teal-500/50 dark:hover:!text-teal-100"
|
||||
@click="kpiSettingsOpen = true"
|
||||
>
|
||||
<template #icon>
|
||||
<component :is="IconSliders" class="size-4 shrink-0" />
|
||||
</template>
|
||||
KPI 显示设置
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<!-- 第三层:SKU 销售汇总 -->
|
||||
<FinanceKpiSettingsModal
|
||||
v-model:open="kpiSettingsOpen"
|
||||
:cols-per-row="colsPerRow"
|
||||
:visible-card-ids="visibleCardIds"
|
||||
:primary-by-card-id="primaryByCardId"
|
||||
@save="onKpiSettingsSave"
|
||||
/>
|
||||
<FinanceKpiGrid
|
||||
:kpis="financeKpis"
|
||||
:cols-per-row="colsPerRow"
|
||||
:tax-rate="taxRate"
|
||||
:visible-card-ids="visibleCardIds"
|
||||
:primary-by-card-id="primaryByCardId"
|
||||
:mom-compare-date-start="overviewData.momCompareDateStart"
|
||||
:mom-compare-date-end="overviewData.momCompareDateEnd"
|
||||
:yoy-compare-date-start="overviewData.yoyCompareDateStart"
|
||||
:yoy-compare-date-end="overviewData.yoyCompareDateEnd"
|
||||
@set-primary="onSetPrimary"
|
||||
/>
|
||||
|
||||
<SkuSummaryTable
|
||||
:data="overviewData?.specSummaries?.list ?? []"
|
||||
:footer-total="overviewData?.specSummaries?.total"
|
||||
:tax-rate="taxRate"
|
||||
/>
|
||||
</div>
|
||||
<div v-else-if="!loading" class="flex items-center justify-center p-8 text-slate-400">
|
||||
<div
|
||||
v-else-if="!loading"
|
||||
class="flex items-center justify-center p-8 text-slate-400"
|
||||
>
|
||||
暂无数据
|
||||
</div>
|
||||
</Spin>
|
||||
|
||||
Reference in New Issue
Block a user