From 40137f182c41259b5c7256eb7ad43d31eba11a67 Mon Sep 17 00:00:00 2001 From: zhongzm Date: Tue, 2 Sep 2025 16:43:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:Data=20Usage=20Report=E5=9B=BE=E8=A1=A8?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E7=8A=B6=E6=80=81=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/dashboard/smfCDRByIMSI/index.vue | 71 ++++++++++++++++------ 1 file changed, 53 insertions(+), 18 deletions(-) diff --git a/src/views/dashboard/smfCDRByIMSI/index.vue b/src/views/dashboard/smfCDRByIMSI/index.vue index 16624ee0..01f30646 100644 --- a/src/views/dashboard/smfCDRByIMSI/index.vue +++ b/src/views/dashboard/smfCDRByIMSI/index.vue @@ -24,7 +24,7 @@ echarts.use([ UniversalTransition, ]); -import { reactive, onMounted, toRaw, onBeforeUnmount, ref } from 'vue'; +import { reactive, onMounted, toRaw, onBeforeUnmount, ref, nextTick, watch } from 'vue'; import { PageContainer } from 'antdv-pro-layout'; import { OptionsType, WS } from '@/plugins/ws-websocket'; import useI18n from '@/hooks/useI18n'; @@ -218,16 +218,19 @@ const option = { function fnRanderChart() { const container: HTMLElement | undefined = cdrChartDom.value; if (!container) return; + + // 如果图表已经存在,先销毁 + if (cdrChart) { + cdrChart.dispose(); + cdrChart = null; + } + const locale = currentLocale.value.split('_')[0]; cdrChart = echarts.init(container, 'light', { // https://github.com/apache/echarts/tree/release/src/i18n 取值langEN.ts ==> EN locale: locale.toUpperCase(), }); cdrChart.setOption(option); - // cdrChart.showLoading('default', { - // text: 'Please enter IMSI to query user traffic', - // fontSize: 16, // 字体大小 - // }); // 创建 ResizeObserver 实例 监听图表容器大小变化,并在变化时调整图表大小 var observer = new ResizeObserver(entries => { @@ -284,21 +287,26 @@ let state = reactive({ loading: false, /**数据总量 up,down */ dataUsage: ['0 B', '0 B'], + /**是否显示图表 */ + showChart: false, }); /**查询列表, pageNum初始页数 */ function fnGetList(pageNum?: number) { if (state.loading) return; state.loading = true; - // if (!queryParams.subscriberID) { - // message.warning('Please enter IMSI to query user traffic'); - // state.loading = false; - // return; - // } + + // 根据subscriberID是否为完整的15位决定是否显示图表 + // 15位subscriberID表示查询单个用户,显示图表 + // 少于15位表示模糊查询多个用户,隐藏图表 + state.showChart = queryParams.subscriberID && queryParams.subscriberID.length === 15; + if (pageNum) { queryParams.pageNum = pageNum; } - if (cdrChart) { + + // 只有当显示图表时才操作图表 + if (state.showChart && cdrChart) { cdrChart.showLoading('default', { text: 'Loading...', fontSize: 16, // 字体大小 @@ -355,7 +363,18 @@ let dataVolumeUplinkYSeriesData: number[] = []; let dataVolumeDownlinkYSeriesData: number[] = []; /**图表数据渲染 */ function fnRanderChartDataLoad() { - if (!cdrChart) return; + // 如果不显示图表,则不进行图表相关操作 + if (!state.showChart) return; + + // 如果需要显示图表但图表未初始化,则先初始化图表 + if (!cdrChart) { + // 使用 nextTick 确保DOM已更新 + nextTick(() => { + fnRanderChart(); + fnRanderChartDataLoad(); // 递归调用以继续数据加载 + }); + return; + } dataTimeXAxisData = []; dataVolumeUplinkYSeriesData = []; dataVolumeDownlinkYSeriesData = []; @@ -420,7 +439,7 @@ function fnRanderChartDataLoad() { } /**图表数据渲染 */ function fnRanderChartDataUpdate() { - if (cdrChart == null) return; + if (!state.showChart || cdrChart == null) return; // 绘制图数据 cdrChart.setOption({ title: { @@ -542,6 +561,16 @@ function fnRealTime() { ws.connect(options); } +// 监听图表显示状态变化 +watch(() => state.showChart, (newVal) => { + if (newVal && cdrChart) { + // 当图表从隐藏变为显示时,需要调整图表大小 + nextTick(() => { + cdrChart?.resize(); + }); + } +}); + onMounted(() => { // 获取网元网元列表 useNeInfoStore() @@ -568,7 +597,7 @@ onMounted(() => { } }) .finally(() => { - fnRanderChart(); + // 移除初始化时的图表创建,改为在需要时动态创建 fnRealTime(); }); }); @@ -603,7 +632,7 @@ onBeforeUnmount(() => { - + { title="Data Usage" bordered :column="2" - style="width: 60%; margin-bottom: 24px" - + :style="{ + width: '60%', + marginBottom: state.showChart ? '24px' : '0px' + }" > {{ state.dataUsage[0] }} @@ -683,7 +714,11 @@ onBeforeUnmount(() => { -
+