feat(store-overview): 全店大盘新增销售额与单量趋势平滑曲线

- CompanyOverviewVO 新增 TrendData / TrendDataItem 结构及 salesAmountTrend / orderCountTrend 字段
- CompanyOverviewServiceImpl 新增按日汇总销售额和单量的趋势计算逻辑
- ShopCharts.vue 重构:左侧替换为趋势平滑曲线(双Y轴),右侧保留店铺销售贡献排行柱状图,移除店铺经营健康度散点图
- 前端类型定义同步更新
This commit is contained in:
小蟑螂
2026-04-30 02:11:28 +08:00
parent 5941662211
commit 640a254a12
5 changed files with 235 additions and 154 deletions
@@ -23,6 +23,10 @@ export namespace CompanyOverviewVO {
shopSalesRatios?: ShopSalesRatio[];
/** 店铺效率象限(ROI vs 净利) */
shopEfficiencyQuadrants?: ShopEfficiencyQuadrant[];
/** 销售额趋势分析 */
salesAmountTrend?: TrendData;
/** 单量趋势分析 */
orderCountTrend?: TrendData;
/** 多店铺数据横向汇总 */
shopComparisons?: ShopOverview;
/** 多品类数据横向汇总 */
@@ -43,6 +47,22 @@ export namespace CompanyOverviewVO {
salesAmountAchievementRate?: number;
}
/** 趋势数据 */
export interface TrendData {
/** 时间范围的总值 */
total?: number;
/** 每日数据列表 */
dailyDataList?: TrendDataItem[];
}
/** 趋势数据项 */
export interface TrendDataItem {
/** 日期 */
date: string;
/** 对应的值 */
value: number;
}
/** 店铺销售占比 */
export interface ShopSalesRatio {
/** 店铺ID */
@@ -5,21 +5,23 @@ import type { CompanyOverviewVO } from '#/api/ecommerce/store-overview';
import { nextTick, onMounted, ref, watch } from 'vue';
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
import dayjs from 'dayjs';
defineOptions({ name: 'ShopCharts' });
interface Props {
shopSalesRatios?: CompanyOverviewVO.ShopSalesRatio[];
shopComparisons?: CompanyOverviewVO.ShopOverview;
shopEfficiencyQuadrants?: CompanyOverviewVO.ShopEfficiencyQuadrant[];
salesAmountTrend?: CompanyOverviewVO.TrendData;
orderCountTrend?: CompanyOverviewVO.TrendData;
}
const props = defineProps<Props>();
const barChartRef = ref<EchartsUIType>();
const scatterChartRef = ref<EchartsUIType>();
const trendChartRef = ref<EchartsUIType>();
const { renderEcharts: renderBarChart } = useEcharts(barChartRef);
const { renderEcharts: renderScatterChart } = useEcharts(scatterChartRef);
const { renderEcharts: renderTrendChart } = useEcharts(trendChartRef);
const formatAmount = (amount: number) => {
return `¥${amount.toLocaleString('zh-CN')}`;
@@ -38,6 +40,8 @@ const renderShopBarChart = () => {
const shopNames = ratios.map((r) => r.shopName).reverse();
const salesAmounts = ratios.map((r) => r.salesAmount).reverse();
const isDark = document.documentElement.classList.contains('dark');
renderBarChart({
grid: {
left: '3%',
@@ -48,6 +52,8 @@ const renderShopBarChart = () => {
},
tooltip: {
trigger: 'axis',
backgroundColor: isDark ? 'hsl(222.34deg 10.43% 12.27%)' : '#fff',
textStyle: { color: isDark ? 'hsl(0deg 0% 95%)' : '#000' },
formatter: (params: any) => {
const param = Array.isArray(params) ? params[0] : params;
const index = param.dataIndex;
@@ -68,7 +74,7 @@ const renderShopBarChart = () => {
axisTick: { show: false },
axisLabel: {
fontWeight: 'bold',
color: 'hsl(240deg 5% 64.9%)',
color: isDark ? 'hsl(240deg 5% 64.9%)' : '#64748b',
fontSize: 13,
},
},
@@ -97,50 +103,29 @@ const renderShopBarChart = () => {
formatter: (params: any) =>
`¥${params.value.toLocaleString('zh-CN')}`,
fontWeight: 900,
color:
document.documentElement.classList.contains('dark')
? 'hsl(0deg 0% 95%)'
: '#334155',
color: isDark ? 'hsl(0deg 0% 95%)' : '#334155',
},
},
],
});
};
// 渲染店铺经营健康度分层图(效率 × 结果 × 规模)
const renderShopScatterChart = () => {
if (!scatterChartRef.value || !props.shopComparisons) return;
// 渲染销售额与单量趋势平滑曲线
const renderTrendLineChart = () => {
if (!trendChartRef.value) return;
const source = props.shopComparisons?.shops || [];
const salesTrend = props.salesAmountTrend;
const orderTrend = props.orderCountTrend;
const data: Array<[number, number, string, number, number, number, number]> =
source.map((shop) => [
// x: 销售额达成率(%)
safeNumber(shop.salesAmountAchievementRate),
// y: 税后盈亏(万元)
safeNumber(shop.profitAfterTax) / 10_000,
// label: 店铺名
shop.shopName,
// size: 销售额(元)
safeNumber(shop.salesAmount),
// color metric: 费比(0~1)
safeNumber(shop.feeRatio),
// tooltip metric: ROI
safeNumber(shop.roi),
// tooltip metric: 订单达成率
safeNumber(shop.orderCountAchievementRate),
]);
if (data.length === 0) {
renderScatterChart({
if (!salesTrend?.dailyDataList?.length && !orderTrend?.dailyDataList?.length) {
const isDark = document.documentElement.classList.contains('dark');
renderTrendChart({
title: {
text: '暂无店铺经营数据',
text: '暂无趋势数据',
left: 'center',
top: 'middle',
textStyle: {
color: document.documentElement.classList.contains('dark')
? 'hsl(240deg 5% 64.9%)'
: '#64748b',
color: isDark ? 'hsl(240deg 5% 64.9%)' : '#64748b',
fontSize: 14,
fontWeight: 'bold',
},
@@ -152,101 +137,95 @@ const renderShopScatterChart = () => {
return;
}
const achieveValues = data.map((item) => item[0]);
const profitValues = data.map((item) => item[1]);
const salesValues = data.map((item) => item[3]);
const minAchieve = Math.min(...achieveValues);
const maxAchieve = Math.max(...achieveValues);
const minProfit = Math.min(...profitValues);
const maxProfit = Math.max(...profitValues);
const minSales = Math.min(...salesValues);
const maxSales = Math.max(...salesValues);
const achievePadding =
minAchieve === maxAchieve ? 10 : (maxAchieve - minAchieve) * 0.2;
const profitPadding =
minProfit === maxProfit ? 1 : (maxProfit - minProfit) * 0.2;
const dates = (salesTrend?.dailyDataList || orderTrend?.dailyDataList || []).map(
(item) => dayjs(item.date).format('MM-DD'),
);
const salesData = (salesTrend?.dailyDataList || []).map((item) => item.value);
const orderData = (orderTrend?.dailyDataList || []).map((item) => item.value);
const calcBubbleSize = (salesAmount: number) => {
if (maxSales === minSales) return 36;
const ratio = (salesAmount - minSales) / (maxSales - minSales);
return 28 + ratio * 26;
};
const isDark = document.documentElement.classList.contains('dark');
const getFeeRatioColor = (feeRatio: number) => {
if (feeRatio <= 0.08) return '#10b981'; // 低费比-健康
if (feeRatio <= 0.15) return '#6366f1'; // 中费比-可控
return '#f43f5e'; // 高费比-风险
};
renderScatterChart({
renderTrendChart({
grid: {
left: '6%',
right: '4%',
top: '8%',
bottom: '16%',
left: '3%',
right: '3%',
bottom: '3%',
top: '5%',
containLabel: true,
},
tooltip: {
trigger: 'item',
formatter: (params: any) => {
const item = params.data;
if (!item) return '';
const feeRatioPercent = (item[4] * 100).toFixed(2);
return `<div style="padding:4px; font-weight:bold">${item[2]}</div><hr/>销售额达成率: ${item[0].toFixed(2)}%<br/>税后盈亏: ¥${item[1].toFixed(2)}万<br/>销售额: ¥${item[3].toLocaleString('zh-CN')}<br/>费比: ${feeRatioPercent}%<br/>ROI: ${item[5].toFixed(2)}<br/>订单达成率: ${item[6].toFixed(2)}%`;
},
trigger: 'axis',
backgroundColor: isDark ? 'hsl(222.34deg 10.43% 12.27%)' : '#fff',
textStyle: { color: isDark ? 'hsl(0deg 0% 95%)' : '#000' },
},
xAxis: {
type: 'value',
min: Math.min(minAchieve - achievePadding, 0),
max: Math.max(maxAchieve + achievePadding, 120),
name: '销售额达成率 (%)',
nameLocation: 'middle',
nameGap: 35,
axisLabel: {
fontWeight: 'bold',
formatter: '{value}%',
},
splitLine: {
lineStyle: { type: 'dashed' },
type: 'category',
boundaryGap: false,
data: dates,
axisLine: {
lineStyle: { color: isDark ? 'hsl(240deg 3.7% 22%)' : '#e2e8f0' },
},
axisLabel: { color: isDark ? 'hsl(240deg 5% 64.9%)' : undefined },
},
yAxis: {
type: 'value',
min: minProfit - profitPadding,
max: maxProfit + profitPadding,
name: '税后盈亏 (单位: 万元)',
nameLocation: 'middle',
nameGap: 50,
axisLabel: { fontWeight: 'bold' },
splitLine: {
lineStyle: { type: 'dashed' },
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: [
{
type: 'scatter',
symbolSize: (val: any) => calcBubbleSize(Number(val[3] ?? 0)),
data,
label: {
show: true,
position: 'top',
color:
document.documentElement.classList.contains('dark')
? 'hsl(0deg 0% 95%)'
: '#334155',
fontWeight: 700,
formatter: (params: any) => params.data?.[2] ?? '',
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)' },
],
},
},
itemStyle: {
color: (params: any) => getFeeRatioColor(Number(params.data?.[4] ?? 0)),
shadowBlur: 15,
shadowColor: 'rgba(0,0,0,0.1)',
},
markLine: {
silent: true,
lineStyle: { type: 'dashed', color: '#94a3b8' },
data: [{ xAxis: 100 }, { yAxis: 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,
},
],
});
@@ -255,11 +234,11 @@ const renderShopScatterChart = () => {
const rerenderCharts = async () => {
await nextTick();
renderShopBarChart();
renderShopScatterChart();
renderTrendLineChart();
};
watch(
() => [props.shopSalesRatios, props.shopComparisons],
() => [props.shopSalesRatios, props.salesAmountTrend, props.orderCountTrend],
() => {
rerenderCharts();
},
@@ -270,13 +249,23 @@ onMounted(() => {
rerenderCharts();
});
// 暴露方法给父组件调用
defineExpose({ renderShopBarChart, renderShopScatterChart });
defineExpose({ renderShopBarChart, renderShopScatterChart: renderTrendLineChart });
</script>
<template>
<div class="grid grid-cols-1 gap-6 xl:grid-cols-2">
<!-- 销售占比排行 -->
<!-- 销售额与单量趋势分析 -->
<div
class="rounded-2xl border border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] bg-white/90 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-8 shadow-[0_4px_12px_rgba(0,0,0,0.03)] dark:shadow-none backdrop-blur-[10px] xl:col-span-1"
>
<h3 class="mb-6 text-lg font-black text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
销售额与单量趋势分析
</h3>
<div class="h-[380px] w-full">
<EchartsUI ref="trendChartRef" />
</div>
</div>
<!-- 各店铺销售贡献排行 -->
<div
class="rounded-2xl border border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] bg-white/90 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-8 shadow-[0_4px_12px_rgba(0,0,0,0.03)] dark:shadow-none backdrop-blur-[10px]"
>
@@ -287,36 +276,5 @@ defineExpose({ renderShopBarChart, renderShopScatterChart });
<EchartsUI ref="barChartRef" />
</div>
</div>
<!-- 效率象限图 -->
<div
class="rounded-2xl border border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] bg-white/90 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-8 shadow-[0_4px_12px_rgba(0,0,0,0.03)] dark:shadow-none backdrop-blur-[10px]"
>
<h3 class="mb-6 text-lg font-black text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
店铺经营健康度分层 (达成率 vs 税后盈亏)
</h3>
<div class="h-[380px] w-full">
<EchartsUI ref="scatterChartRef" />
</div>
<div class="mt-4 flex justify-center gap-6">
<div
class="flex items-center gap-2 text-xs font-bold text-slate-600 dark:text-[hsl(240deg_5%_64.9%)]"
>
<span class="h-3 w-3 rounded-full bg-emerald-500"></span>
低费比(健康)
</div>
<div
class="flex items-center gap-2 text-xs font-bold text-slate-600 dark:text-[hsl(240deg_5%_64.9%)]"
>
<span class="h-3 w-3 rounded-full bg-blue-500"></span>
中费比(可控)
</div>
<div
class="flex items-center gap-2 text-xs font-bold text-slate-600 dark:text-[hsl(240deg_5%_64.9%)]"
>
<span class="h-3 w-3 rounded-full bg-rose-500"></span>
高费比(风险)
</div>
</div>
</div>
</div>
</template>
@@ -596,7 +596,8 @@ const navigateToShopOverview = (shopId: number) => {
ref="shopChartsRef"
:shop-sales-ratios="overviewData?.shopSalesRatios"
:shop-comparisons="overviewData?.shopComparisons"
:shop-efficiency-quadrants="overviewData?.shopEfficiencyQuadrants"
:sales-amount-trend="overviewData?.salesAmountTrend"
:order-count-trend="overviewData?.orderCountTrend"
/>
<!-- 第三层:平台/店铺/品类明细切换 -->