From 96acbc0919d219fe1a9600f6ebaf25ed2d103c69 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Wed, 15 Jan 2025 18:42:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BD=91=E5=85=83=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E6=A6=82=E8=A7=88=E9=A1=B5=E9=9D=A2=E5=AE=9A=E6=97=B6=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E5=BC=82=E5=B8=B8=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/configManage/neOverview/index.vue | 77 +++++++++++++-------- 1 file changed, 50 insertions(+), 27 deletions(-) diff --git a/src/views/configManage/neOverview/index.vue b/src/views/configManage/neOverview/index.vue index ec3c7a3e..fc372d86 100644 --- a/src/views/configManage/neOverview/index.vue +++ b/src/views/configManage/neOverview/index.vue @@ -2,7 +2,14 @@ import { PageContainer } from 'antdv-pro-layout'; import { ColumnsType } from 'ant-design-vue/es/table'; import { message } from 'ant-design-vue/es'; -import { reactive, ref, onMounted, onBeforeUnmount, markRaw } from 'vue'; +import { + reactive, + ref, + onMounted, + onBeforeUnmount, + markRaw, + useTemplateRef, +} from 'vue'; import useI18n from '@/hooks/useI18n'; import { TooltipComponent } from 'echarts/components'; import { GaugeChart } from 'echarts/charts'; @@ -32,7 +39,7 @@ echarts.use([ ]); /**图DOM节点实例对象 */ -const statusBar = ref(undefined); +const statusBar = useTemplateRef('statusBar'); /**图实例对象 */ const statusBarChart = ref(null); @@ -116,25 +123,20 @@ let tableState: TabeStateType = reactive({ let serverState: any = ref({}); /**查询网元状态列表 */ -async function fnGetList() { +async function fnGetList(reload: boolean = false) { + tableState.loading = !reload; try { const res = await listAllNeInfo({ bandStatus: true }); tableState.data = res.data; - // 选择第一个 - if (res.data.length > 0) { - const id = res.data[0].id; - fnTableSelectedRowKeys([id]); - } else { - fnTableSelectedRowKeys(tableState.selectedRowKeys); - } } catch (error) { console.log(error); tableState.data = []; } - + tableState.loading = false; if (tableState.data.length == 0) { return; } + var rightNum = 0; var errorNum = 0; for (const v of tableState.data) { @@ -144,6 +146,35 @@ async function fnGetList() { errorNum++; } } + + // 初始 + if (!reload) { + // 选择第一个 + if (tableState.data.length > 0) { + const id = tableState.data[0].id; + fnTableSelectedRowKeys([id]); + } else { + fnTableSelectedRowKeys(tableState.selectedRowKeys); + } + + if (statusBar.value) { + fnDesign(statusBar.value, rightNum, errorNum); + } + } else { + statusBarChart.value.setOption({ + series: [ + { + data: [ + { value: rightNum, name: t('views.index.normal') }, + { value: errorNum, name: t('views.index.abnormal') }, + ], + }, + ], + }); + } +} + +function fnDesign(container: HTMLElement, rightNum: number, errorNum: number) { /// 图表数据 const optionData: any = { title: { @@ -172,16 +203,8 @@ async function fnGetList() { }, ], }; - fnDesign(statusBar.value, optionData); -} - -function fnDesign(container: HTMLElement | undefined, option: any) { - if (!container) return; - - if (!statusBarChart.value) { - statusBarChart.value = markRaw(echarts.init(container, 'light')); - } - option && statusBarChart.value.setOption(option); + statusBarChart.value = markRaw(echarts.init(container, 'light')); + statusBarChart.value.setOption(optionData); // 创建 ResizeObserver 实例 var observer = new ResizeObserver(entries => { @@ -267,12 +290,10 @@ onMounted(() => { }) .finally(async () => { fnLocale(); - tableState.loading = true; - await fnGetList(); - tableState.loading = false; + await fnGetList(false); timer = setInterval(() => { if (!timer) return; - fnGetList(); + fnGetList(true); }, 10_000); // 每隔10秒执行一次 }); }); @@ -285,7 +306,7 @@ onBeforeUnmount(() => {