From b41ac68e06f77d09a03dc61e5419296d48cce48f Mon Sep 17 00:00:00 2001 From: nehc <934298133@qq.com> Date: Mon, 21 Jul 2025 21:36:40 +0800 Subject: [PATCH] =?UTF-8?q?refactor(@vben/web-antd):=20ERP=20=E9=A6=96?= =?UTF-8?q?=E9=A1=B5=E9=80=82=E9=85=8D=E5=B7=B2=E6=9C=89=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除不必要的 API 调用和数据处理逻辑 - 使用 AnalysisOverview 组件替换自定义统计卡片 - 优化 TimeSummaryChart组件,支持不同类型的数据展示 - 简化页面结构,提高组件的可复用性和可维护性 --- .../views/erp/home/components/SummaryCard.vue | 78 +++++++++++++---- .../erp/home/components/TimeSummaryChart.vue | 61 ++++++++++++- apps/web-antd/src/views/erp/home/index.vue | 86 +++---------------- 3 files changed, 128 insertions(+), 97 deletions(-) diff --git a/apps/web-antd/src/views/erp/home/components/SummaryCard.vue b/apps/web-antd/src/views/erp/home/components/SummaryCard.vue index 467155d14..ff98e556a 100644 --- a/apps/web-antd/src/views/erp/home/components/SummaryCard.vue +++ b/apps/web-antd/src/views/erp/home/components/SummaryCard.vue @@ -1,29 +1,69 @@ - - - {{ title }} - - - - - + diff --git a/apps/web-antd/src/views/erp/home/components/TimeSummaryChart.vue b/apps/web-antd/src/views/erp/home/components/TimeSummaryChart.vue index 831e33f80..40d9f1398 100644 --- a/apps/web-antd/src/views/erp/home/components/TimeSummaryChart.vue +++ b/apps/web-antd/src/views/erp/home/components/TimeSummaryChart.vue @@ -3,23 +3,51 @@ import type { EChartsOption } from 'echarts'; import type { EchartsUIType } from '@vben/plugins/echarts'; -import { ref, watch } from 'vue'; +import type { ErpPurchaseStatisticsApi } from '#/api/erp/statistics/purchase'; +import type { ErpSaleStatisticsApi } from '#/api/erp/statistics/sale'; + +import { onMounted, ref, watch } from 'vue'; import { EchartsUI, useEcharts } from '@vben/plugins/echarts'; import { Card } from 'ant-design-vue'; +import { + getPurchaseSummary, + getPurchaseTimeSummary, +} from '#/api/erp/statistics/purchase'; +import { getSaleSummary, getSaleTimeSummary } from '#/api/erp/statistics/sale'; import { CardTitle } from '#/components/card'; interface Props { title: string; - value?: Array<{ price: number; time: string }>; + type?: 'purchase' | 'sale'; } const props = withDefaults(defineProps(), { - value: () => [], + type: 'sale', }); +/** 销售统计数据 */ +const saleSummary = ref(); // 销售概况统计 +const saleTimeSummaryList = ref(); // 销售时段统计 +const getSaleStatistics = async () => { + saleSummary.value = await getSaleSummary(); + saleTimeSummaryList.value = await getSaleTimeSummary(); +}; + +/** 采购统计数据 */ +const purchaseSummary = ref(); // 采购概况统计 +const purchaseTimeSummaryList = + ref(); // 采购时段统计 +const getPurchaseStatistics = async () => { + purchaseSummary.value = await getPurchaseSummary(); + purchaseTimeSummaryList.value = await getPurchaseTimeSummary(); +}; + +/** 获取当前类型的时段数据 */ +const currentTimeSummaryList = ref>(); + const chartRef = ref(); const { renderEcharts } = useEcharts(chartRef); @@ -80,8 +108,20 @@ const lineChartOptions: EChartsOption = { }, }; +/** 初始化数据 */ +const initData = async () => { + if (props.type === 'sale') { + await getSaleStatistics(); + currentTimeSummaryList.value = saleTimeSummaryList.value; + } else { + await getPurchaseStatistics(); + currentTimeSummaryList.value = purchaseTimeSummaryList.value; + } +}; + +/** 监听数据变化并更新图表 */ watch( - () => props.value, + () => currentTimeSummaryList.value, (val) => { if (!val || val.length === 0) { return; @@ -109,6 +149,19 @@ watch( }, { immediate: true }, ); + +/** 组件挂载时初始化数据 */ +onMounted(() => { + initData(); +}); + +/** 暴露数据给父组件使用 */ +defineExpose({ + saleSummary, + purchaseSummary, + saleTimeSummaryList, + purchaseTimeSummaryList, +}); diff --git a/apps/web-antd/src/views/erp/home/index.vue b/apps/web-antd/src/views/erp/home/index.vue index 3f3507be2..76f6af79a 100644 --- a/apps/web-antd/src/views/erp/home/index.vue +++ b/apps/web-antd/src/views/erp/home/index.vue @@ -1,50 +1,21 @@ @@ -59,56 +30,23 @@ onMounted(async () => { - - - - - - - - - - - - - - - - - - - - - - - - - - + - +