| | |
| | | v-model="state.tableData.listQuery.searchParams.time" |
| | | type="datetimerange" |
| | | format="YYYY-MM-DD HH:mm:ss" |
| | | value-format="YYYY-MM-DD HH:mm:ss" |
| | | range-separator="~" |
| | | start-placeholder="开始时间" |
| | | end-placeholder="结束时间" |
| | |
| | | style="max-width: 180px" |
| | | size="default" |
| | | > |
| | | <el-option v-for="item in state.tableData.gasList" :key="item.label" :label="item.value" :value="item.label"></el-option> |
| | | <el-option v-for="item in state.tableData.gasList" :key="item.id" :label="item.name" :value="item.id"></el-option> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-button size="default" type="primary" class="ml10" @click="search()"> |
| | |
| | | </el-form> |
| | | </div> |
| | | <div id="gasChart" style="height: 500px;width: auto"></div> |
| | | <el-table :data="state.tableData.data" style="width: 100%"> |
| | | <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="windSpeed" label="风速"/> |
| | | <el-table-column align="center" prop="windDirection" label="风向"/> |
| | | <el-table-column align="center" prop="gasName" label="气体名称"/> |
| | | <el-table-column align="center" prop="gasPPM" label="气体浓度"/> |
| | | <el-table-column align="center" prop="name" label="气体名称"/> |
| | | <el-table-column align="center" prop="gasValue" label="气体浓度"/> |
| | | </el-table> |
| | | <br /> |
| | | <el-pagination |
| | |
| | | </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 {TableGasState} from "/@/types/monitorData"; |
| | | import { gasManageApi } from "/@/api/basicDataManage/gasManage"; |
| | | import moment from "moment"; |
| | | import {gasDataApi} from "/@/api/monitorData/gasData"; |
| | | |
| | | const infoRef = ref(); |
| | | const state = reactive<TableGasState>({ |
| | | tableData: { |
| | | data: [], |
| | |
| | | pageIndex: 1, |
| | | pageSize: 10, |
| | | searchParams:{ |
| | | startTime: '', |
| | | endTime: '', |
| | | time: [], |
| | | gas: '' |
| | | } |
| | | }, |
| | | gasList: [ |
| | | { |
| | | label: '1', |
| | | value: '甲醛' |
| | | }, |
| | | { |
| | | label: '2', |
| | | value: '甲烷' |
| | | } |
| | | ] |
| | | gasList: [] |
| | | } |
| | | }); |
| | | |
| | | const chooseTime = (val: any) => { |
| | | console.log("val",val) |
| | | let sTime = Date.parse(new Date(val[0].replace(/-/g, "/"))); |
| | | let eTime = Date.parse(new Date(val[1].replace(/-/g, "/"))); |
| | | let sTime = Date.parse(new Date(val[0])); |
| | | let eTime = Date.parse(new Date(val[1])); |
| | | const datadiff = eTime - sTime + 86400000; |
| | | const time = 7 * 24 * 60 * 60 * 1000; |
| | | if (sTime > eTime) { |
| | |
| | | type: 'error', |
| | | message: '查询时间范围7天内', |
| | | }) |
| | | state.tableData.listQuery.searchParams.time = []; |
| | | getNowTime(); |
| | | return false; |
| | | } else { |
| | | console.log('七天内数据') |
| | | } |
| | | } |
| | | } |
| | | |
| | | const loading = ref(false); |
| | | const dataZoomEnd = ref(); |
| | | const xData = ref([]); |
| | | const yData = ref([]); |
| | | const markLines = ref(0); |
| | | const myChart = shallowRef(null) |
| | | onMounted( |
| | | () => { |
| | | getNowTime(); |
| | | initCharts(); |
| | | getAllGas(); |
| | | } |
| | | ); |
| | | const getNowTime = () => { |
| | |
| | | let sTime = `${isDate.getFullYear()}-${isDate.getMonth() + 1}-${isDate.getDate()}` |
| | | let eTime = `${isDate.getFullYear()}-${isDate.getMonth() + 1}-${isDate.getDate()}` |
| | | sTime = `${sTime} 00:00:00` |
| | | eTime = `${eTime} 23:59:59` |
| | | state.tableData.listQuery.searchParams.time = [sTime ,eTime]; |
| | | console.log("time",state.tableData.listQuery.searchParams.time) |
| | | eTime = `${eTime} ` + moment().format('HH:mm:ss') |
| | | state.tableData.listQuery.searchParams.time = [sTime,eTime]; |
| | | } |
| | | const initInfoData = () => { |
| | | console.log("数据列表") |
| | | const initInfoData = async () => { |
| | | //折线图 |
| | | const chartParam = { |
| | | startTime: moment(state.tableData.listQuery.searchParams.time[0]).format('YYYY-MM-DD HH:mm:ss'), |
| | | endTime: moment(state.tableData.listQuery.searchParams.time[1]).format('YYYY-MM-DD HH:mm:ss'), |
| | | gasName: state.tableData.listQuery.searchParams.gas |
| | | } |
| | | let resChart = await gasDataApi().getGasLineChart(chartParam); |
| | | if(resChart.data.code == 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.gasValue; |
| | | }) |
| | | dataZoomEnd.value = xData.value.length > 25 ? 30 : 100; |
| | | }else { |
| | | xData.value = []; |
| | | yData.value = []; |
| | | markLines.value = 0; |
| | | dataZoomEnd.value = 100; |
| | | } |
| | | initCharts(); |
| | | }else { |
| | | ElMessage({ |
| | | type: 'warning', |
| | | message: resChart.data.msg |
| | | }); |
| | | } |
| | | |
| | | loading.value = true; |
| | | //表格 |
| | | const pageParam = { |
| | | pageIndex: state.tableData.listQuery.pageIndex, |
| | | pageSize: state.tableData.listQuery.pageSize, |
| | | searchParams: { |
| | | startTime: moment(state.tableData.listQuery.searchParams.time[0]).format('YYYY-MM-DD HH:mm:ss'), |
| | | endTime: moment(state.tableData.listQuery.searchParams.time[1]).format('YYYY-MM-DD HH:mm:ss'), |
| | | gasName: state.tableData.listQuery.searchParams.gas |
| | | } |
| | | } |
| | | let res = await gasDataApi().getGasLinePage(pageParam); |
| | | if(res.data.code == 100) { |
| | | state.tableData.data = res.data.data; |
| | | 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', |
| | | message: res.data.msg |
| | | }); |
| | | } |
| | | }; |
| | | |
| | | const getAllGas = async () => { |
| | | let res = await gasManageApi().getGas({}); |
| | | if(res.data.code == 100) { |
| | | state.tableData.gasList = res.data.data; |
| | | console.log("气体",state.tableData.gasList) |
| | | //默认选择第一个气体 |
| | | state.tableData.listQuery.searchParams.gas = state.tableData.gasList[0].id; |
| | | markLines.value = state.tableData.gasList[0].threshold; |
| | | initInfoData(); |
| | | }else { |
| | | ElMessage({ |
| | | type: 'warning', |
| | | message: res.data.msg |
| | | }); |
| | | } |
| | | }; |
| | | |
| | | const onHandleSizeChange = (val: number) => { |
| | | state.tableData.listQuery.pageSize = val; |
| | | initInfoData(); |
| | |
| | | state.tableData.listQuery.pageIndex = val; |
| | | initInfoData(); |
| | | }; |
| | | const openDialog = (type: string, value: any) => { |
| | | infoRef.value.openDialog(type, value); |
| | | }; |
| | | const del = (val: any) => { |
| | | ElMessageBox.confirm( |
| | | '确定删除此条数据?', |
| | | '提示', |
| | | { |
| | | confirmButtonText: '确定', |
| | | cancelButtonText: '取消', |
| | | type: 'warning', |
| | | } |
| | | ) |
| | | .then(() => { |
| | | ElMessage({ |
| | | type: 'success', |
| | | message: '删除成功', |
| | | }) |
| | | }) |
| | | }; |
| | | |
| | | const search = () => { |
| | | console.log("vla",state.tableData.listQuery.searchParams) |
| | | state.tableData.listQuery.pageIndex = 1; |
| | | const gasObj = state.tableData.gasList.filter(item => { |
| | | return item.id == state.tableData.listQuery.searchParams.gas |
| | | }); |
| | | markLines.value = gasObj[0].threshold; |
| | | |
| | | initInfoData(); |
| | | } |
| | | const reset = () => { |
| | | state.tableData.listQuery.searchParams.time = []; |
| | | |
| | | state.tableData.listQuery.searchParams.gas = ''; |
| | | getNowTime(); |
| | | state.tableData.listQuery.searchParams.gas = state.tableData.gasList[0].id; |
| | | markLines.value = state.tableData.gasList[0].threshold; |
| | | state.tableData.listQuery.pageIndex = 1; |
| | | initInfoData(); |
| | | } |
| | | |
| | | 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: { |
| | |
| | | xAxis: { |
| | | show: true, |
| | | type: 'category', |
| | | data: ['10:18:26', '10:18:28', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] |
| | | data: xData.value |
| | | }, |
| | | yAxis: { |
| | | show: true, |
| | | type: 'value' |
| | | type: 'value', |
| | | max: Math.max(markLines.value,...yData.value), |
| | | min: Math.min(markLines.value,...yData.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: [ |
| | | { |
| | | data: [150, 230, 224, 218, 135, 147, 260], |
| | | data: yData.value, |
| | | type: 'line', |
| | | markLine: {//图表标线 |
| | | symbol: "none", |
| | |
| | | position: 'end', // 表现内容展示的位置 |
| | | color: 'red' // 展示内容颜色 |
| | | }, |
| | | yAxis: '200', |
| | | yAxis: markLines.value == 0 ? '':markLines.value , |
| | | lineStyle: { |
| | | color: "red", |
| | | width: 1, // 0 的时候可以隐藏线 |
| | | width: markLines.value == 0 ? 0: 1, // 0 的时候可以隐藏线 |
| | | type: "solid" // 实线,不写默认虚线 |
| | | } |
| | | },],//type: 'average', 平均值, min最小值, max 最大值, median中位数 |
| | | |
| | | }, |
| | | } |
| | | ], |
| | | dataZoom: [ |
| | | { |
| | | type: 'slider', |
| | | show: dataZoomEnd.value == 100 ? false : true, |
| | | realtime: true, |
| | | start: 0, |
| | | end: dataZoomEnd.value |
| | | }, |
| | | { |
| | | type: 'inside', |
| | | realtime: true, |
| | | start: 0, |
| | | end: dataZoomEnd.value |
| | | }, |
| | | ] |
| | | }; |
| | | // 使用刚指定的配置项和数据显示图表。 |
| | | myChart.setOption(option); |
| | | myChart.value.setOption(option,true); |
| | | //自适应宽度 |
| | | window.addEventListener('resize',function () { |
| | | myChart.value.resize(); |
| | | }) |
| | | } |
| | | </script> |
| | | <style scoped lang="scss"> |
| | |
| | | box-shadow: 4px 4px 4px rgba(0, 0, 0, 0.2); |
| | | padding: 3px |
| | | } |
| | | </style> |
| | | </style> |