From 446d5c8eda333a4e6ee3fb6e838e9d859fc847f5 Mon Sep 17 00:00:00 2001
From: zhouwx <1175765986@qq.com>
Date: 星期四, 08 五月 2025 14:35:51 +0800
Subject: [PATCH] 新增风速等级

---
 src/views/monitorData/gasData/index.vue |  461 +++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 392 insertions(+), 69 deletions(-)

diff --git a/src/views/monitorData/gasData/index.vue b/src/views/monitorData/gasData/index.vue
index 992af73..026599f 100644
--- a/src/views/monitorData/gasData/index.vue
+++ b/src/views/monitorData/gasData/index.vue
@@ -8,7 +8,6 @@
                             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="结束时间"
@@ -22,9 +21,30 @@
                             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-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 />
@@ -37,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%">
+            <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="gasName" label="气体名称"/>
-                <el-table-column align="center" prop="gasPPM" 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
@@ -68,12 +101,15 @@
 </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 infoRef = ref();
 const state = reactive<TableGasState>({
     tableData: {
         data: [],
@@ -83,27 +119,60 @@
             pageIndex: 1,
             pageSize: 10,
             searchParams:{
+                startTime: '',
+                endTime: '',
                 time: [],
-                gas: ''
+                gas: '',
+                position: null
             }
         },
-        gasList: [
-            {
-                label: '1',
-                value: '甲醛'
-            },
-            {
-                label: '2',
-                value: '甲烷'
-            }
-        ]
+        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) => {
-    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) {
@@ -114,18 +183,25 @@
                 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 tData = ref([]);
+const hData = ref([]);
+const wData = ref([]);
+const pData = ref([]);
+const markLines = ref(0);
+const myChart = shallowRef(null)
 onMounted(
     () => {
         getNowTime();
-        initCharts();
+        getAllGas();
     }
 );
 const getNowTime = () => {
@@ -133,13 +209,138 @@
     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 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,
+        position: state.tableData.listQuery.searchParams.position
+    }
+    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;
+            })
+            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({
+            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,
+            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 == 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',
+            message: res.data.msg
+        });
+    }
 };
+
+const getAllGas = async () => {
+    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;
+        markLines.value = state.tableData.gasList[0].threshold;
+        await initInfoData();
+
+    }else {
+        ElMessage({
+            type: 'warning',
+            message: res.data.msg
+        });
+    }
+};
+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;
     initInfoData();
@@ -149,38 +350,28 @@
     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;
+    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: {
@@ -192,15 +383,101 @@
         xAxis: {
             show: true,
             type: 'category',
-            data: ['10:18:26', '10:18:28', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
+            data: xData.value
         },
-        yAxis: {
+        legend: {
+          data: ['浓度', '温度','湿度','风速','气压']
+        },
+        yAxis: [
+          {
+            name: '浓度',
             show: true,
-            type: 'value'
+            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: [
             {
-                data: [150, 230, 224, 218, 135, 147, 260],
+                name : '浓度',
+                data: yData.value,
                 type: 'line',
                 markLine: {//图表标线
                     symbol: "none",
@@ -209,20 +486,66 @@
                             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中位数
-
                 },
-            }
+            },
+          {
+            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: [
+            {
+                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">
@@ -244,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