From 67ddfbd2db13529c8923838d4dc7ed4cf105b0fe Mon Sep 17 00:00:00 2001 From: 马宇豪 <978517621@qq.com> Date: 星期五, 20 十月 2023 15:41:51 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- src/views/monitorData/weatherData/index.vue | 57 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 42 insertions(+), 15 deletions(-) diff --git a/src/views/monitorData/weatherData/index.vue b/src/views/monitorData/weatherData/index.vue index 4a90727..85cb432 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', @@ -215,9 +226,8 @@ }; const search = () => { - console.log("vla",state.tableData.listQuery.searchParams) - changeWeather(state.tableData.listQuery.searchParams.weatherType); initInfoData(); + changeWeather(state.tableData.listQuery.searchParams.weatherType); } const reset = () => { getNowTime(); @@ -228,7 +238,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 +258,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 +296,10 @@ ] }; // 使用刚指定的配置项和数据显示图表。 - myChart.setOption(option,true); + myChart.value.setOption(option,true); //自适应宽度 window.addEventListener('resize', function () { - myChart.resize(); + myChart.value.resize(); }) } </script> @@ -295,4 +322,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