From 932c3ab49ea4e911fb2c2531c29d6609ac5afefd Mon Sep 17 00:00:00 2001
From: dengzedong <dengzedong@email>
Date: 星期四, 02 一月 2025 10:51:37 +0800
Subject: [PATCH] itemchart bug修复。 页面优化

---
 src/views/model/pre/item/MmPredictItemChart.vue |   69 ++++++++++++++++++++--------------
 1 files changed, 40 insertions(+), 29 deletions(-)

diff --git a/src/views/model/pre/item/MmPredictItemChart.vue b/src/views/model/pre/item/MmPredictItemChart.vue
index 3fd55b5..4d24c06 100644
--- a/src/views/model/pre/item/MmPredictItemChart.vue
+++ b/src/views/model/pre/item/MmPredictItemChart.vue
@@ -3,6 +3,7 @@
     title="预测数据"
     :close-on-click-modal="false"
     width="50%"
+    @close="dialogClose"
     v-model="visible"
   >
     <el-form
@@ -12,7 +13,6 @@
     >
       <el-form-item label="开始时间">
         <el-date-picker
-          size="mini"
           v-model="dataForm.startTime"
           format="YYYY-MM-DD HH:mm:00"
           value-format="YYYY-MM-DD HH:mm:00"
@@ -22,7 +22,6 @@
       </el-form-item>
       <el-form-item label="结束时间">
         <el-date-picker
-          size="mini"
           v-model="dataForm.endTime"
           format="YYYY-MM-DD HH:mm:00"
           value-format="YYYY-MM-DD HH:mm:00"
@@ -58,8 +57,8 @@
 
 const message = useMessage() // 消息弹窗
 const visible = ref(false);
-const chartDomPre = ref(null);
-let myChart = null;
+const chartDomPre = ref();
+let myChart = undefined;
 const chartParams = reactive({
   itemId: undefined,
   startTime: undefined,
@@ -79,7 +78,16 @@
   dataForm.value.id = row.id;
   dataForm.value.itemName = row.itemname;
   if (row.id) {
+    nextTick(() => {
+      myChart = echarts.init(chartDomPre.value);
+    });
     getDataList();
+  }
+}
+
+const dialogClose = () => {
+  if (myChart) {
+    myChart.dispose(); // 组件卸载时销毁实例
   }
 }
 
@@ -94,15 +102,15 @@
       chartParams.endTime = dataForm.value.endTime;
       const data = await McsApi.getPreDataItemChart(chartParams)
       let legendData = []
-      if (data.legend && data.legend.length > 0) {
-        data.legend.forEach(item => {
-          legendData.push(item + ":" + '真实值')
-          legendData.push(item + ":" + '预测值')
-        })
-      }
+      // if (data.legend && data.legend.length > 0) {
+      //   data.legend.forEach(item => {
+      //     legendData.push(item + ":" + '真实值')
+      //     legendData.push(item + ":" + '预测值')
+      //   })
+      // }
 
       let seriesData = []
-      if (data.lastTime) {
+      if (data.predictTime) {
         seriesData.push({
           name: '',
           data: [null],
@@ -116,11 +124,11 @@
               width: 2
             },
             data: [{
-              xAxis: data.lastTime
+              xAxis: data.predictTime
             }],
             label: {
               normal: {
-                formatter: data.lastTime
+                formatter: data.predictTime
               }
             },
             symbol: ['circle', 'none'],
@@ -131,18 +139,22 @@
       if (data.viewMap) {
         Object.keys(data.viewMap).forEach(key => {
           let viewData = data.viewMap[key]
-          seriesData.push({
-            name: key + ":" + '真实值',
-            type: "line",
-            data: viewData.realData,
-            showSymbol: false,
-            smooth: false,
-            lineStyle: {
-              normal: {
-                width: 1,
+          if(viewData.realData) {
+            legendData.push(key + ":" + '真实值')
+            seriesData.push({
+              name: key + ":" + '真实值',
+              type: "line",
+              data: viewData.realData,
+              showSymbol: false,
+              smooth: false,
+              lineStyle: {
+                normal: {
+                  width: 1,
+                },
               },
-            },
-          })
+            })
+          }
+          legendData.push(key + ":" + '预测值')
           seriesData.push({
             name: key + ":" + '预测值',
             type: "line",
@@ -158,7 +170,6 @@
         })
       }
 
-      myChart = echarts.init(chartDomPre.value);
       const option = {
         title: {
           text: dataForm.value.itemName,
@@ -217,15 +228,15 @@
 const exportLoading = ref(false)
 const handleExport = async () => {
   chartParams.itemId = dataForm.value.id;
-  chartParams.startTime = dataForm.value.startTime;
-  chartParams.endTime = dataForm.value.endTime;
+  chartParams.startTime = dataForm.value.startTime?dataForm.value.startTime:"";
+  chartParams.endTime = dataForm.value.endTime?dataForm.value.endTime:"";
   try {
     // 导出的二次确认
     await message.exportConfirm()
     // 发起导出
     exportLoading.value = true
-    /*const data = await DaPoint.exportDaPointValue(chartParams)
-    download.excel(data, dataForm.value.pointName + '.xls')*/
+    const data = await McsApi.exportPredictValue(chartParams)
+    download.excel(data, dataForm.value.itemName + '.xls')
   } catch {
   } finally {
     exportLoading.value = false

--
Gitblit v1.9.3