diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/dashboard/company-overview/index.vue b/ecom-dmb-frontend/apps/web-antd/src/views/dashboard/company-overview/index.vue index 84983f27..0fa02be2 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/dashboard/company-overview/index.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/dashboard/company-overview/index.vue @@ -360,26 +360,60 @@ const renderShopBarChart = () => { // 渲染店铺效率象限图 const renderShopScatterChart = () => { - if (!scatterChartRef.value || !overviewData.value?.shopEfficiencyQuadrants) - return; + if (!scatterChartRef.value || !overviewData.value) return; - const quadrants = overviewData.value.shopEfficiencyQuadrants; - const data = quadrants.map((q) => [ - q.roi, - q.netProfit / 10_000, // 转换为万元 - q.shopName, - ]); + const quadrants = overviewData.value.shopEfficiencyQuadrants ?? []; + const scatterSource = + quadrants.length > 0 + ? quadrants.map((q) => ({ + shopId: q.shopId, + shopName: q.shopName, + roi: Number(q.roi), + netProfit: Number(q.netProfit), + })) + : (overviewData.value.shopComparisons ?? []).map((shop) => ({ + shopId: shop.shopId, + shopName: shop.shopName, + roi: Number(shop.roi), + netProfit: Number(shop.profitAfterTax), + })); + + const data: Array<[number, number, string]> = scatterSource.map((q) => { + const roi = Number.isFinite(q.roi) ? q.roi : 0; + const netProfit = Number.isFinite(q.netProfit) ? q.netProfit : 0; + return [roi, netProfit / 10_000, q.shopName]; + }); + + const roiValues = data.map((item) => item[0]); + const profitValues = data.map((item) => item[1]); + const minRoi = roiValues.length ? Math.min(...roiValues) : 0; + const maxRoi = roiValues.length ? Math.max(...roiValues) : 1; + const minProfit = profitValues.length ? Math.min(...profitValues) : 0; + const maxProfit = profitValues.length ? Math.max(...profitValues) : 1; + const roiPadding = minRoi === maxRoi ? 1 : (maxRoi - minRoi) * 0.2; + const profitPadding = + minProfit === maxProfit ? 1 : (maxProfit - minProfit) * 0.2; renderScatterChart({ + grid: { + left: '6%', + right: '4%', + top: '8%', + bottom: '16%', + containLabel: true, + }, tooltip: { trigger: 'item', formatter: (params: any) => { - const shop = quadrants[params.dataIndex]; + const shop = scatterSource[params.dataIndex]; if (!shop) return ''; return `
${shop.shopName}

投资回报率 (ROI): ${shop.roi.toFixed(2)}
净利润: ¥${(shop.netProfit / 10_000).toFixed(2)}万`; }, }, xAxis: { + type: 'value', + min: minRoi - roiPadding, + max: Math.max(maxRoi + roiPadding, 3.5), name: '投资回报率 (ROI)', nameLocation: 'middle', nameGap: 35, @@ -389,6 +423,9 @@ const renderShopScatterChart = () => { }, }, yAxis: { + type: 'value', + min: Math.min(minProfit - profitPadding, 0), + max: Math.max(maxProfit + profitPadding, 10), name: '税后净利润 (单位: 万元)', nameLocation: 'middle', nameGap: 50, @@ -402,10 +439,17 @@ const renderShopScatterChart = () => { type: 'scatter', symbolSize: 45, data, + label: { + show: true, + position: 'top', + color: '#334155', + fontWeight: 700, + formatter: (params: any) => params.data?.[2] ?? '', + }, itemStyle: { color: (params: any) => { - const roi = params.data[0]; - const profit = params.data[1]; + const roi = params.data?.[0]; + const profit = params.data?.[1]; if (roi >= 3.5 && profit >= 10) return '#10b981'; // 高产区 if (roi < 3 || profit < 0) return '#f43f5e'; // 风险区 return '#6366f1'; // 潜力区