From 8d73ae17f0e0b91f392d5fda109cc4fd6bc742a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=9F=91=E8=9E=82?= Date: Fri, 5 Jun 2026 00:17:15 +0800 Subject: [PATCH] =?UTF-8?q?fix(workbench):=20=E5=B7=A5=E5=85=B7=E6=A0=8F?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E7=BC=A9=E7=95=A5+=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E5=B1=95=E5=BC=80=20Popover=EF=BC=8C=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=AA=84=E5=B1=8F=E5=B8=83=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/views/dashboard/workbench/index.vue | 443 +++++++++++------- .../components/FinanceCostPieChart.vue | 171 ++++--- 2 files changed, 382 insertions(+), 232 deletions(-) diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/dashboard/workbench/index.vue b/ecom-dmb-frontend/apps/web-antd/src/views/dashboard/workbench/index.vue index 9d5a2f94..9c59673e 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/dashboard/workbench/index.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/dashboard/workbench/index.vue @@ -5,7 +5,7 @@ import { useRouter } from 'vue-router'; import { Page } from '@vben/common-ui'; import { createIconifyIcon } from '@vben/icons'; -import { DatePicker, InputNumber, message, Select, Spin, Tabs } from 'ant-design-vue'; +import { DatePicker, InputNumber, message, Popover, Select, Spin, Tabs } from 'ant-design-vue'; import dayjs from 'dayjs'; import { getPlatformPageApi } from '#/api/ecommerce/platform/apis'; @@ -31,6 +31,16 @@ import WorkbenchSalesRankTab from './tabs/sales-rank/index.vue'; defineOptions({ name: 'PddWorkbench' }); +const openPopover = ref(null); + +function handlePopoverOpen(name: string, open: boolean) { + if (open) { + openPopover.value = name; + } else if (openPopover.value === name) { + openPopover.value = null; + } +} + const EMPTY_MULTI: WorkbenchVO.MultiPanel = { platform: [], shop: [], @@ -79,6 +89,9 @@ const router = useRouter(); const ImportOrderIcon = createIconifyIcon('lucide:upload'); const PromotionFeeIcon = createIconifyIcon('lucide:dollar-sign'); +const ToolbarToggleIcon = createIconifyIcon('lucide:sliders-horizontal'); +const ReceiptIcon = createIconifyIcon('lucide:receipt'); +const CalendarIcon = createIconifyIcon('lucide:calendar'); function goToImportOrder() { void router.push('/import/order'); @@ -112,7 +125,7 @@ const toolbarActionClass = 'inline-flex min-w-0 shrink-0 cursor-pointer items-center justify-center gap-1.5 rounded-xl border-0 bg-transparent px-3 py-2 text-sm font-bold text-slate-800 transition-colors hover:bg-slate-100 dark:text-slate-200 dark:hover:bg-[hsl(240deg_3.7%_22%)]'; const timeRangeBtnClass = - 'inline-flex min-w-0 cursor-pointer items-center justify-center rounded-xl border-0 px-3 py-2 text-sm font-bold transition-colors sm:px-5'; + 'inline-flex min-w-0 shrink-0 cursor-pointer items-center justify-center rounded-xl border-0 px-3 py-2 text-sm font-bold whitespace-nowrap transition-colors sm:px-5'; function timeRangeBtnState(active: boolean) { return active @@ -621,187 +634,246 @@ onUnmounted(() => {
-
-
- - + 导入 +
-
-
-
- - 税率 - - -
-
-
+ + + -
-
- - 平台 + +
- - 店铺 - - + + 税率{{ formatTaxRate(taxRate) }}
-
-
-
- - - - + + {{ selectedPlatformLabelCache || selectedShopLabelCache ? `${selectedPlatformLabelCache || '全部'}/${selectedShopLabelCache || '全部'}` : '平台/店铺' }} +
-
-
+
@@ -1015,6 +1087,7 @@ onUnmounted(() => { :deep(.workbench-header-extra .tax-rate-input .ant-input-number-input) { height: 32px; line-height: 32px; + text-align: center; padding-top: 0; padding-bottom: 0; color: rgb(15 23 42); @@ -1065,4 +1138,40 @@ html.dark .workbench-header-extra .workbench-header-range-picker .ant-picker-sep html.dark .workbench-header-extra .workbench-header-range-picker .ant-picker-suffix { color: hsl(240deg 5% 75%); } + +.workbench-toolbar-popover .ant-popover-inner { + padding: 4px !important; + border-radius: 12px !important; +} + +html.dark .workbench-toolbar-popover .ant-popover-inner { + background-color: hsl(222.34deg 10.43% 14%) !important; +} + +html.dark .workbench-toolbar-popover .ant-popover-arrow { + --antd-arrow-background-color: hsl(222.34deg 10.43% 14%) !important; +} + +.workbench-toolbar-popover .tax-rate-input.ant-input-number { + background: transparent !important; + border: none !important; + box-shadow: none !important; +} + +.workbench-toolbar-popover .tax-rate-input .ant-input-number-input { + height: 32px !important; + line-height: 32px !important; + text-align: center !important; + padding-top: 0 !important; + padding-bottom: 0 !important; + background: transparent !important; +} + +.workbench-toolbar-popover .tax-rate-input:hover .ant-input-number-input { + background-color: rgb(241 245 249) !important; +} + +html.dark .workbench-toolbar-popover .tax-rate-input .ant-input-number-input { + color: hsl(0deg 0% 95%) !important; +} diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/dashboard/workbench/tabs/finance/components/FinanceCostPieChart.vue b/ecom-dmb-frontend/apps/web-antd/src/views/dashboard/workbench/tabs/finance/components/FinanceCostPieChart.vue index 2b4952ad..0301d5bc 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/dashboard/workbench/tabs/finance/components/FinanceCostPieChart.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/dashboard/workbench/tabs/finance/components/FinanceCostPieChart.vue @@ -2,7 +2,7 @@ import type { EchartsUIType } from '@vben/plugins/echarts'; import type { WorkbenchVO } from '#/api/ecommerce/workbench/types'; -import { nextTick, onMounted, ref, watch } from 'vue'; +import { computed, nextTick, onMounted, onUnmounted, ref, watch } from 'vue'; import { EchartsUI, useEcharts } from '@vben/plugins/echarts'; @@ -33,91 +33,131 @@ const chartOverviewShell = const pieChartRef = ref(); const { renderEcharts: renderPieChart } = useEcharts(pieChartRef); +let renderTimer: ReturnType | null = null; +let isUnmounted = false; + +/** 与趋势图一致:有切片且存在非零销售额才绘制,避免空态卸载图表 DOM */ +const hasData = computed( + () => + props.platformSalesShare.length > 0 && + props.platformSalesShare.some((row) => Number(row.value ?? 0) !== 0), +); + function colorForIndex(index: number): string { return PLATFORM_PIE_COLORS[index % PLATFORM_PIE_COLORS.length] ?? '#6366f1'; } function drawPie() { - if (!pieChartRef.value) return; - const isDark = document.documentElement.classList.contains('dark'); - const labelColor = isDark ? 'hsl(0deg 0% 95%)' : '#334155'; - const legendColor = isDark ? 'hsl(240deg 5% 64.9%)' : '#64748b'; - const border = isDark ? 'hsl(222.34deg 10.43% 12.27%)' : '#fff'; + if (!pieChartRef.value || !hasData.value) return; + try { + const isDark = document.documentElement.classList.contains('dark'); + const labelColor = isDark ? 'hsl(0deg 0% 95%)' : '#334155'; + const legendColor = isDark ? 'hsl(240deg 5% 64.9%)' : '#64748b'; + const border = isDark ? 'hsl(222.34deg 10.43% 12.27%)' : '#fff'; - renderPieChart({ - tooltip: { - trigger: 'item', - backgroundColor: isDark ? 'hsl(222.34deg 10.43% 12.27%)' : '#fff', - textStyle: { color: isDark ? 'hsl(0deg 0% 95%)' : '#0f172a' }, - formatter: (params: any) => { - const name = String(params.name ?? ''); - const val = Number(params.value ?? 0); - const row = props.platformSalesShare.find((r) => r.name === name); - const pctText = - row?.pct != null ? `${row.pct}%(占实际销售额)` : ''; - return `${name}
约 ${formatWanShort(val)}
${formatYuanDetail(val)}
${pctText}`; + renderPieChart({ + tooltip: { + trigger: 'item', + backgroundColor: isDark ? 'hsl(222.34deg 10.43% 12.27%)' : '#fff', + textStyle: { color: isDark ? 'hsl(0deg 0% 95%)' : '#0f172a' }, + formatter: (params: any) => { + const name = String(params.name ?? ''); + const val = Number(params.value ?? 0); + const row = props.platformSalesShare.find((r) => r.name === name); + const pctText = + row?.pct != null ? `${row.pct}%(占实际销售额)` : ''; + return `${name}
约 ${formatWanShort(val)}
${formatYuanDetail(val)}
${pctText}`; + }, }, - }, - legend: { - orient: 'vertical', - right: '0', - top: 'center', - itemWidth: 10, - itemHeight: 10, - textStyle: { color: legendColor, fontSize: 11, fontWeight: 700 }, - }, - series: [ - { - type: 'pie', - radius: ['40%', '68%'], - center: ['36%', '50%'], - avoidLabelOverlap: true, - itemStyle: { - borderRadius: 6, - borderColor: border, - borderWidth: 2, - }, - label: { - show: true, - formatter: '{b}\n{d}%', - color: labelColor, - fontSize: 11, - fontWeight: 700, - }, - labelLine: { - length: 12, - length2: 8, - lineStyle: { color: isDark ? 'hsl(240deg 3.7% 35%)' : '#cbd5e1' }, - }, - data: props.platformSalesShare.map((row, index) => ({ - name: row.name, - value: row.value ?? 0, + legend: { + orient: 'vertical', + right: '0', + top: 'center', + itemWidth: 10, + itemHeight: 10, + textStyle: { color: legendColor, fontSize: 11, fontWeight: 700 }, + }, + series: [ + { + type: 'pie', + radius: ['40%', '68%'], + center: ['36%', '50%'], + avoidLabelOverlap: true, itemStyle: { - color: colorForIndex(index), + borderRadius: 6, + borderColor: border, + borderWidth: 2, }, - })), - }, - ], - }); + label: { + show: true, + formatter: '{b}\n{d}%', + color: labelColor, + fontSize: 11, + fontWeight: 700, + }, + labelLine: { + length: 12, + length2: 8, + lineStyle: { color: isDark ? 'hsl(240deg 3.7% 35%)' : '#cbd5e1' }, + }, + data: props.platformSalesShare.map((row, index) => ({ + name: row.name, + value: row.value ?? 0, + itemStyle: { + color: colorForIndex(index), + }, + })), + }, + ], + }); + } catch (error) { + console.error('[WorkbenchFinancePlatformSalesPieChart] render failed:', error); + } +} + +/** 延迟一帧再绘制,确保 v-show 切换后 ref 与容器尺寸已就绪 */ +async function scheduleRender() { + if (renderTimer) { + clearTimeout(renderTimer); + renderTimer = null; + } + await nextTick(); + if (isUnmounted || !hasData.value) return; + renderTimer = setTimeout(() => { + if (isUnmounted) return; + drawPie(); + }, 50); } async function redraw() { - await nextTick(); - drawPie(); + await scheduleRender(); } onMounted(() => { - void redraw(); + isUnmounted = false; + void scheduleRender(); +}); + +onUnmounted(() => { + isUnmounted = true; + if (renderTimer) { + clearTimeout(renderTimer); + renderTimer = null; + } }); watch( () => props.platformSalesShare, () => { - void redraw(); + void scheduleRender(); }, - { deep: true }, + { deep: true, immediate: true }, ); +watch(hasData, (ok) => { + if (ok) void scheduleRender(); +}); + defineExpose({ redraw }); @@ -137,12 +177,13 @@ defineExpose({ redraw });
暂无销售额数据
-
+ +