From 328febf368f1494b4b5b647f3eab5f4ad38eb072 Mon Sep 17 00:00:00 2001
From: zhouwenxuan <1175765986@qq.com>
Date: 星期四, 12 十月 2023 16:54:27 +0800
Subject: [PATCH] 日报接口、图表优化

---
 src/views/monitorData/weatherData/index.vue |   54 +++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 41 insertions(+), 13 deletions(-)

diff --git a/src/views/monitorData/weatherData/index.vue b/src/views/monitorData/weatherData/index.vue
index 4a90727..9e92ed5 100644
--- a/src/views/monitorData/weatherData/index.vue
+++ b/src/views/monitorData/weatherData/index.vue
@@ -39,7 +39,7 @@
                 </el-form>
             </div>
             <div id="gasChart" style="height: 500px;width: auto"></div>
-            <el-table :data="state.tableData.data" style="width: 100%;margin-top: 20px">
+            <el-table :data="state.tableData.data" style="width: 100%;margin-top: 20px" v-loading="loading">
                 <el-table-column type="index" label="序号" width="80" />
                 <el-table-column align="center" prop="time" label="采集时间"/>
                 <el-table-column align="center" prop="value" :label='weatherName' />
@@ -64,7 +64,7 @@
 </template>
 
 <script setup lang="ts">
-import {reactive, ref,onMounted} from "vue";
+import {reactive, ref, onMounted, shallowRef} from "vue";
 import * as echarts from "echarts";
 import { ElMessage, ElMessageBox } from 'element-plus'
 import {TableWeatherState} from "/@/types/monitorData";
@@ -108,10 +108,12 @@
         ]
     }
 });
+const loading = ref(false);
 const weatherName = ref('温度');
 const dataZoomEnd = ref();
 const xData = ref([]);
 const yData = ref([]);
+const myChart = shallowRef(null)
 
 const chooseTime = (val: any) => {
     console.log("val",val)
@@ -160,13 +162,20 @@
     }
     let resChart = await weatherDataApi().getWeatherLineChart(chartParam);
     if(resChart.data.code == 100) {
-        xData.value = resChart.data.data.map((item: any) => {
-            return item.time;
-        })
-        yData.value = resChart.data.data.map((item: any) => {
-            return item.value;
-        })
-        dataZoomEnd.value = xData.value.length > 25 ? 5 : 100;
+        if(resChart.data.data) {
+            xData.value = resChart.data.data.map((item: any) => {
+                return item.time;
+            })
+            yData.value = resChart.data.data.map((item: any) => {
+                return item.value;
+            })
+            dataZoomEnd.value = xData.value.length > 25 ? 5 : 100;
+        }else {
+            xData.value = [];
+            yData.value = [];
+            dataZoomEnd.value = 100;
+        }
+
         initCharts();
     }else {
         ElMessage({
@@ -175,6 +184,7 @@
         });
     }
 
+    loading.value = true;
     //表格
     const pageParam = {
         pageIndex: state.tableData.listQuery.pageIndex,
@@ -191,6 +201,7 @@
         state.tableData.total = res.data.total;
         state.tableData.listQuery.pageIndex = res.data.pageIndex;
         state.tableData.listQuery.pageSize = res.data.pageSize;
+        loading.value = false;
     }else {
         ElMessage({
             type: 'warning',
@@ -228,7 +239,10 @@
 }
 
 const initCharts = () => {
-    const myChart = echarts.init(document.getElementById('gasChart'));
+    if (myChart.value != null && myChart.value != "" && myChart.value != undefined) {
+        myChart.value.dispose();
+    }
+    myChart.value = echarts.init(document.getElementById('gasChart'));
     // 指定图表的配置项和数据
     const option = {
         tooltip: {
@@ -245,6 +259,20 @@
         yAxis: {
             show: true,
             type: 'value'
+        },
+        graphic: {
+            type: 'text',     // 类型:文本
+            left: 'center',
+            top: 'middle',
+            silent: true,     // 不响应事件
+            invisible: yData.value.length > 0,   // 有数据就隐藏
+            style: {
+                fill: '#9d9d9d',
+                fontWeight: 'bold',
+                text: '暂无数据',
+                fontFamily: 'Microsoft YaHei',
+                fontSize: '25px'
+            }
         },
         series: [
             {
@@ -269,10 +297,10 @@
         ]
     };
     // 使用刚指定的配置项和数据显示图表。
-    myChart.setOption(option,true);
+    myChart.value.setOption(option,true);
     //自适应宽度
     window.addEventListener('resize', function () {
-        myChart.resize();
+        myChart.value.resize();
     })
 }
 </script>
@@ -295,4 +323,4 @@
     box-shadow: 4px 4px 4px rgba(0, 0, 0, 0.2);
     padding: 3px
 }
-</style>
\ No newline at end of file
+</style>

--
Gitblit v1.9.2