From bdd99a4f6edb84d8eebe6afc38c2c2f86fb4a52c Mon Sep 17 00:00:00 2001 From: zhouwx <1175765986@qq.com> Date: 星期一, 16 六月 2025 14:13:57 +0800 Subject: [PATCH] 修改查询条件 --- src/views/monitorData/weatherData/index.vue | 69 +++++++++++++++++++++++++--------- 1 files changed, 50 insertions(+), 19 deletions(-) diff --git a/src/views/monitorData/weatherData/index.vue b/src/views/monitorData/weatherData/index.vue index 4a90727..ca25d9f 100644 --- a/src/views/monitorData/weatherData/index.vue +++ b/src/views/monitorData/weatherData/index.vue @@ -11,8 +11,9 @@ range-separator="~" start-placeholder="开始时间" end-placeholder="结束时间" - @change = "chooseTime" + /> +<!-- @change = "chooseTime"--> </el-form-item> <el-form-item label="气象类型:"> <el-select @@ -38,8 +39,8 @@ </el-button> </el-form> </div> - <div id="gasChart" style="height: 500px;width: auto"></div> - <el-table :data="state.tableData.data" style="width: 100%;margin-top: 20px"> + <div :id="weatherChart" style="height: 500px;width: auto" v-loading="picLoading"></div> + <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 +65,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 +109,14 @@ ] } }); +const loading = ref(false); +const picLoading = ref(false); const weatherName = ref('温度'); const dataZoomEnd = ref(); const xData = ref([]); const yData = ref([]); +const myChart = shallowRef(null) +const weatherChart = ref("eChartweatherN" + Date .now() + Math .random()) const chooseTime = (val: any) => { console.log("val",val) @@ -140,7 +145,6 @@ getNowTime(); initInfoData(); initCharts(); - } ); const getNowTime = () => { @@ -152,6 +156,7 @@ state.tableData.listQuery.searchParams.time = [sTime ,eTime]; } const initInfoData = async () => { + picLoading.value = true; //折线图 const chartParam = { startTime: moment(state.tableData.listQuery.searchParams.time[0]).format('YYYY-MM-DD HH:mm:ss'), @@ -160,13 +165,21 @@ } 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; + picLoading.value = false + }else { + xData.value = []; + yData.value = []; + dataZoomEnd.value = 100; + } + initCharts(); }else { ElMessage({ @@ -175,6 +188,7 @@ }); } + loading.value = true //表格 const pageParam = { pageIndex: state.tableData.listQuery.pageIndex, @@ -188,9 +202,10 @@ let res = await weatherDataApi().getWeatherLinePage(pageParam); if(res.data.code == 100) { state.tableData.data = res.data.data; - state.tableData.total = res.data.total; + state.tableData.total = res.data.total == null ? 0 :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 +230,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 +242,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(weatherChart.value)); // 指定图表的配置项和数据 const option = { tooltip: { @@ -245,6 +262,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 +300,10 @@ ] }; // 使用刚指定的配置项和数据显示图表。 - myChart.setOption(option,true); + myChart.value.setOption(option,true); //自适应宽度 window.addEventListener('resize', function () { - myChart.resize(); + myChart.value.resize(); }) } </script> @@ -295,4 +326,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