From 565b3dd781688f4222db4a324376029ad7e53ed7 Mon Sep 17 00:00:00 2001
From: 马宇豪 <978517621@qq.com>
Date: 星期四, 08 五月 2025 13:35:24 +0800
Subject: [PATCH] 新项目
---
src/views/monitorData/gasData/index.vue | 325 +++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 297 insertions(+), 28 deletions(-)
diff --git a/src/views/monitorData/gasData/index.vue b/src/views/monitorData/gasData/index.vue
index dd84cc0..026599f 100644
--- a/src/views/monitorData/gasData/index.vue
+++ b/src/views/monitorData/gasData/index.vue
@@ -24,6 +24,27 @@
<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-form-item label="方位:">
+ <el-select
+ v-model="state.tableData.listQuery.searchParams.position"
+ class="w100"
+ style="max-width: 180px"
+ size="default"
+ >
+ <el-option v-for="item in state.tableData.positionList" :key="item.label" :label="item.value" :value="item.label"></el-option>
+ </el-select>
+ </el-form-item>
+ <el-form-item label="单位:">
+ <el-switch
+ v-model="state.tableData.isPpm"
+ class="ml-2"
+ inline-prompt
+ style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
+ active-text="ppm"
+ inactive-text="ppb"
+ @change="initInfoData"
+ />
+ </el-form-item>
<el-button size="default" type="primary" class="ml10" @click="search()">
<el-icon>
<ele-Search />
@@ -36,16 +57,29 @@
</el-icon>
重置
</el-button>
+ <vue3-json-excel
+ class="ml10"
+ :json-data="state.tableData.excelData"
+ :fields="fields"
+ name="气体数据.xls"
+ >
+ <el-button type="primary" :icon="Download" size="default">导出</el-button>
+ </vue3-json-excel>
</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="gasChart" style="height: 500px;width: auto"></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="windSpeed" label="风速"/>
- <el-table-column align="center" prop="windDirection" label="风向"/>
+ <el-table-column align="center" prop="windDirection" label="风向">
+ <template #default="scope">
+ {{ getDirection(scope.row.windDirection)+'('+ scope.row.windDirection +'度)' }}
+ </template>
+ </el-table-column>
<el-table-column align="center" prop="name" label="气体名称"/>
<el-table-column align="center" prop="gasValue" label="气体浓度"/>
+ <el-table-column align="center" prop="position" label="方位"/>
</el-table>
<br />
<el-pagination
@@ -67,13 +101,14 @@
</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";
+import {Download} from "@element-plus/icons-vue";
const state = reactive<TableGasState>({
tableData: {
@@ -87,12 +122,53 @@
startTime: '',
endTime: '',
time: [],
- gas: ''
+ gas: '',
+ position: null
}
},
- gasList: []
+ gasList: [],
+ isPpm: true,
+ positionList: [
+ {
+ value: '方位1',
+ label: 1
+ },
+ {
+ value: '方位2',
+ label: 2
+ },
+ ],
+ excelData: []
}
});
+const fields = ref({
+ 'time':'dataReceivingTime',
+ '设备ID':'equipmentId',
+ '位置':'position',
+ '经度':'lng',
+ '纬度':'lat',
+ '角度': 'angle',
+ '温度': 'temp',
+ '湿度': 'humidity',
+ '风速':'windSpeed',
+ '风向':'windDirection',
+ '气压':'pressure',
+ '甲烷CH4':'gasName01',
+ 'gasValue01':'gasValue01',
+ '乙烷C2H6':'gasName02',
+ 'gasValue02':'gasValue02',
+ '丙烷C3H8':'gasName03',
+ 'gasValue03':'gasValue03',
+ '丁烷C4H10':'gasName04',
+ 'gasValue04':'gasValue04',
+ '硫化氢H2S':'gasName05',
+ 'gasValue05':'gasValue05',
+ '乙烯C2H4':'gasName06',
+ 'gasValue06':'gasValue06',
+ '异丁烷C4H10':'gasName07',
+ 'gasValue07':'gasValue07',
+});
+const gasChart = ref("eChartgasN" + Date .now() + Math .random())
const chooseTime = (val: any) => {
let sTime = Date.parse(new Date(val[0]));
@@ -112,10 +188,16 @@
}
}
}
+const loading = ref(false);
const dataZoomEnd = ref();
const xData = ref([]);
const yData = ref([]);
+const tData = ref([]);
+const hData = ref([]);
+const wData = ref([]);
+const pData = ref([]);
const markLines = ref(0);
+const myChart = shallowRef(null)
onMounted(
() => {
getNowTime();
@@ -130,23 +212,55 @@
eTime = `${eTime} ` + moment().format('HH:mm:ss')
state.tableData.listQuery.searchParams.time = [sTime,eTime];
}
+
+const getDirection=(num:number)=>{
+ const directionName = ['北', '北东北', '东北', '东东北', '东', '东东南', '东南','南东南','南','南西南','西南','西西南','西','西西北','西北','北西北']
+ if(num<=348.75 ){
+ return directionName[Math.floor((num + 11.25) / 22.5)]
+ }else{
+ return '北'
+ }
+}
+
const initInfoData = async () => {
+ await exportGasData();
//折线图
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
+ gasName: state.tableData.listQuery.searchParams.gas,
+ position: state.tableData.listQuery.searchParams.position
}
let resChart = await gasDataApi().getGasLineChart(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.gasValue;
- })
- dataZoomEnd.value = xData.value.length > 25 ? 30 : 100;
- markLines.value = 110;
+ if (resChart.data.data) {
+ xData.value = resChart.data.data.map((item: any) => {
+ return item.time;
+ })
+ if(state.tableData.isPpm){
+ yData.value = resChart.data.data.map((item: any) => {
+ return item.gasValue;
+ })
+ }else{
+ yData.value = resChart.data.data.map((item: any) => {
+ return item.gasValue * 1000;
+ })
+ }
+ tData.value = resChart.data.data.map(i=>i.temp?i.temp:0)
+ hData.value = resChart.data.data.map(i=>i.humidity?i.humidity:0)
+ wData.value = resChart.data.data.map(i=>i.windSpeed?i.windSpeed:0)
+ pData.value = resChart.data.data.map(i=>i.pressure?i.pressure:0)
+ dataZoomEnd.value = xData.value.length > 25 ? 30 : 100;
+ }else {
+ xData.value = [];
+ yData.value = [];
+ tData.value = [];
+ hData.value = [];
+ wData.value = [];
+ pData.value = [];
+ markLines.value = 0;
+ dataZoomEnd.value = 100;
+ }
initCharts();
}else {
ElMessage({
@@ -155,6 +269,7 @@
});
}
+ loading.value = true;
//表格
const pageParam = {
pageIndex: state.tableData.listQuery.pageIndex,
@@ -162,15 +277,17 @@
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
+ gasName: state.tableData.listQuery.searchParams.gas,
+ position: state.tableData.listQuery.searchParams.position
}
}
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.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',
@@ -183,8 +300,11 @@
let res = await gasManageApi().getGas({});
if(res.data.code == 100) {
state.tableData.gasList = res.data.data;
+ //默认选择第一个气体
state.tableData.listQuery.searchParams.gas = state.tableData.gasList[0].id;
- initInfoData();
+ markLines.value = state.tableData.gasList[0].threshold;
+ await initInfoData();
+
}else {
ElMessage({
type: 'warning',
@@ -192,6 +312,34 @@
});
}
};
+const exportGasData = async () => {
+ const pageParam = {
+ 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'),
+ ch4: state.tableData.listQuery.searchParams.gas == 1 ? 1 : 0,
+ c2h6: state.tableData.listQuery.searchParams.gas == 2 ? 1:0,
+ c3H8: state.tableData.listQuery.searchParams.gas == 3 ? 1:0,
+ c4h101: state.tableData.listQuery.searchParams.gas == 4 ? 1:0,
+ h2s: state.tableData.listQuery.searchParams.gas == 5 ? 1:0,
+ c2h4: state.tableData.listQuery.searchParams.gas == 6 ? 1:0,
+ c4h102: state.tableData.listQuery.searchParams.gas == 7 ? 1:0,
+
+// 发对应的编号,查询数据;null,不查询
+ position1: state.tableData.listQuery.searchParams.position == 1 ? '1':null,
+ position2: state.tableData.listQuery.searchParams.position == 2 ? '2':null,
+ position3: state.tableData.listQuery.searchParams.position == 3 ? '3':null,
+ }
+ let res = await gasDataApi().exportGas(pageParam);
+ if(res.data.code == 200) {
+ state.tableData.excelData = res.data.data
+ console.log('excelData',state.tableData.excelData)
+ }else {
+ ElMessage({
+ type: 'warning',
+ message: res.data.msg
+ });
+ }
+}
const onHandleSizeChange = (val: number) => {
state.tableData.listQuery.pageSize = val;
@@ -203,18 +351,27 @@
initInfoData();
};
const search = () => {
+ 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();
- console.log("vla",state.tableData.listQuery.searchParams)
}
const reset = () => {
getNowTime();
state.tableData.listQuery.searchParams.gas = state.tableData.gasList[0].id;
+ markLines.value = state.tableData.gasList[0].threshold;
state.tableData.listQuery.pageIndex = 1;
+ state.tableData.listQuery.searchParams.position = null;
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.value));
// 指定图表的配置项和数据
const option = {
tooltip: {
@@ -228,14 +385,98 @@
type: 'category',
data: xData.value
},
- yAxis: {
+ legend: {
+ data: ['浓度', '温度','湿度','风速','气压']
+ },
+ yAxis: [
+ {
+ name: '浓度',
show: true,
type: 'value',
max: Math.max(markLines.value,...yData.value),
min: Math.min(markLines.value,...yData.value)
+ },
+ {
+ name: '温度',
+ type: 'value',
+ position: 'right',
+ axisLine:{
+ show: true
+ },
+ splitLine: {
+ show: false
+ },
+ axisLabel:{
+ color: '#91CC75',
+ fontSize: 9
+ }
+ },
+ {
+ name: '湿度',
+ type: 'value',
+ offset : 25,
+ position: 'right',
+ axisLine:{
+ show: true
+ },
+ splitLine: {
+ show: false
+ },
+ axisLabel:{
+ color: '#FAC858',
+ fontSize: 9
+ }
+ },
+ {
+ name: '风速',
+ type: 'value',
+ offset : 50,
+ position: 'right',
+ axisLine:{
+ show: true
+ },
+ splitLine: {
+ show: false
+ },
+ axisLabel:{
+ color: '#EE6666',
+ fontSize: 9
+ }
+ },
+ {
+ name: '气压',
+ type: 'value',
+ offset : 75,
+ position: 'right',
+ axisLine:{
+ show: true
+ },
+ splitLine: {
+ show: false
+ },
+ axisLabel:{
+ color: '#73C0DE',
+ fontSize: 9
+ }
+ }
+ ],
+ 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: [
{
+ name : '浓度',
data: yData.value,
type: 'line',
markLine: {//图表标线
@@ -245,15 +486,43 @@
position: 'end', // 表现内容展示的位置
color: 'red' // 展示内容颜色
},
- yAxis: markLines.value,
+ 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中位数
},
- }
+ },
+ {
+ name: '温度',
+ yAxisIndex: 1,
+ data: tData.value,
+ type: 'line',
+ showSymbol: false,
+ },
+ {
+ name: '湿度',
+ yAxisIndex: 2,
+ data: hData.value,
+ type: 'line',
+ showSymbol: false,
+ },
+ {
+ name: '风速',
+ yAxisIndex: 3,
+ data: wData.value,
+ type: 'line',
+ showSymbol: false,
+ },
+ {
+ name: '气压',
+ yAxisIndex: 4,
+ data: pData.value,
+ type: 'line',
+ showSymbol: false,
+ }
],
dataZoom: [
{
@@ -272,10 +541,10 @@
]
};
// 使用刚指定的配置项和数据显示图表。
- myChart.setOption(option,true);
+ myChart.value.setOption(option,true);
//自适应宽度
- window.addEventListener('resize', function () {
- myChart.resize();
+ window.addEventListener('resize',function () {
+ myChart.value.resize();
})
}
</script>
@@ -298,4 +567,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