From 392ff42d4115e0edf003757c85827cf0b5b56acb Mon Sep 17 00:00:00 2001
From: zhouwx <1175765986@qq.com>
Date: 星期二, 16 七月 2024 13:47:16 +0800
Subject: [PATCH] 导出

---
 src/api/monitorData/gasData/index.ts        |    8 ++
 .env.development                            |    4 
 package-lock.json                           |   31 +++++++
 src/views/monitorData/gasData/index.vue     |   73 +++++++++++++++++
 yarn.lock                                   |   12 +++
 package.json                                |    1 
 src/views/monitorData/fluxData/index.vue    |   69 +++++++++++++++++
 src/types/monitorData.d.ts                  |    8 +
 src/views/monitorData/weatherData/index.vue |    2 
 src/api/monitorData/fluxData/index.ts       |    8 ++
 src/main.ts                                 |    3 
 11 files changed, 208 insertions(+), 11 deletions(-)

diff --git a/.env.development b/.env.development
index 85daf2d..23070ad 100644
--- a/.env.development
+++ b/.env.development
@@ -1,6 +1,6 @@
 # 本地环境
 ENV = 'development'
-VITE_API_URL = 'http://192.168.0.27:17080'
+VITE_API_URL = 'http://192.168.2.10:17080'
 
 #线上正式环境接口地址
-#VITE_API_URL = 'http://ftir.sinanoaq.cn/api'
\ No newline at end of file
+#VITE_API_URL = 'http://ftir.sinanoaq.cn/api'
diff --git a/package-lock.json b/package-lock.json
index 52ecf7e..594d707 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -40,6 +40,7 @@
         "vue-grid-layout": "^3.0.0-beta1",
         "vue-i18n": "^9.1.10",
         "vue-router": "^4.0.15",
+        "vue3-json-excel": "^1.0.10-alpha",
         "wangeditor": "^4.7.15",
         "xlsx": "^0.18.5"
       },
@@ -1997,6 +1998,11 @@
       "engines": {
         "node": ">=12"
       }
+    },
+    "node_modules/downloadjs": {
+      "version": "1.4.7",
+      "resolved": "https://registry.npmmirror.com/downloadjs/-/downloadjs-1.4.7.tgz",
+      "integrity": "sha512-LN1gO7+u9xjU5oEScGFKvXhYf7Y/empUIIEAGBs1LzUq/rg5duiDrkuH5A2lQGd5jfMOb9X9usDa2oVXwJ0U/Q=="
     },
     "node_modules/echarts": {
       "version": "5.3.3",
@@ -4674,6 +4680,18 @@
         "vue": "^3.2.0"
       }
     },
+    "node_modules/vue3-json-excel": {
+      "version": "1.0.10-alpha",
+      "resolved": "https://registry.npmmirror.com/vue3-json-excel/-/vue3-json-excel-1.0.10-alpha.tgz",
+      "integrity": "sha512-wTcHSWdGQ5hFjpYbw2KOoLNQKVMFqDPfMPKuRpisxAACMk/E483/RLP3GT6HGMxocSO61wGKrAzYymYhKjo1Ew==",
+      "dependencies": {
+        "downloadjs": "^1.4.7"
+      },
+      "peerDependencies": {
+        "downloadjs": "^1.4.7",
+        "vue": "^3.2.25"
+      }
+    },
     "node_modules/wangeditor": {
       "version": "4.7.15",
       "resolved": "https://registry.npmjs.org/wangeditor/-/wangeditor-4.7.15.tgz",
@@ -6348,6 +6366,11 @@
       "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.1.tgz",
       "integrity": "sha512-1K6hR6wtk2FviQ4kEiSjFiH5rpzEVi8WW0x96aztHVMhEspNpc4DVOUTEHtEva5VThQ8IaBX1Pe4gSzpVVUsKQ==",
       "dev": true
+    },
+    "downloadjs": {
+      "version": "1.4.7",
+      "resolved": "https://registry.npmmirror.com/downloadjs/-/downloadjs-1.4.7.tgz",
+      "integrity": "sha512-LN1gO7+u9xjU5oEScGFKvXhYf7Y/empUIIEAGBs1LzUq/rg5duiDrkuH5A2lQGd5jfMOb9X9usDa2oVXwJ0U/Q=="
     },
     "echarts": {
       "version": "5.3.3",
@@ -8215,6 +8238,14 @@
         "@vue/devtools-api": "^6.0.0"
       }
     },
+    "vue3-json-excel": {
+      "version": "1.0.10-alpha",
+      "resolved": "https://registry.npmmirror.com/vue3-json-excel/-/vue3-json-excel-1.0.10-alpha.tgz",
+      "integrity": "sha512-wTcHSWdGQ5hFjpYbw2KOoLNQKVMFqDPfMPKuRpisxAACMk/E483/RLP3GT6HGMxocSO61wGKrAzYymYhKjo1Ew==",
+      "requires": {
+        "downloadjs": "^1.4.7"
+      }
+    },
     "wangeditor": {
       "version": "4.7.15",
       "resolved": "https://registry.npmjs.org/wangeditor/-/wangeditor-4.7.15.tgz",
diff --git a/package.json b/package.json
index 5326c6d..d7cdde8 100644
--- a/package.json
+++ b/package.json
@@ -41,6 +41,7 @@
     "vue-grid-layout": "^3.0.0-beta1",
     "vue-i18n": "^9.1.10",
     "vue-router": "^4.0.15",
+    "vue3-json-excel": "^1.0.10-alpha",
     "wangeditor": "^4.7.15",
     "xlsx": "^0.18.5"
   },
diff --git a/src/api/monitorData/fluxData/index.ts b/src/api/monitorData/fluxData/index.ts
index 6dfee1d..7199999 100644
--- a/src/api/monitorData/fluxData/index.ts
+++ b/src/api/monitorData/fluxData/index.ts
@@ -20,6 +20,14 @@
                 data: data
             });
         },
+        //通量监测数据-导出
+        exportFlux: (data: object) => {
+            return request({
+                url: import.meta.env.VITE_API_URL + `/gasMonitorData/gasFlux/export`,
+                method: 'post',
+                data: data
+            });
+        },
 
     };
 }
diff --git a/src/api/monitorData/gasData/index.ts b/src/api/monitorData/gasData/index.ts
index 40d5468..77f22ec 100644
--- a/src/api/monitorData/gasData/index.ts
+++ b/src/api/monitorData/gasData/index.ts
@@ -20,6 +20,14 @@
                 data: data
             });
         },
+        //气体监测数据-导出
+        exportGas: (data: object) => {
+            return request({
+                url: import.meta.env.VITE_API_URL + `/gasMonitorData/gasConcentration/export`,
+                method: 'post',
+                data: data
+            });
+        },
 
     };
 }
diff --git a/src/main.ts b/src/main.ts
index 7cfa70a..a3c5f47 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -14,6 +14,7 @@
 import VueGridLayout from 'vue-grid-layout';
 import zhCn from 'element-plus/lib/locale/lang/zh-cn';
 import DataVVue3 from '@kjgl77/datav-vue3'
+import vue3JsonExcel from 'vue3-json-excel'
 // import 'lib-flexible/flexible'
 const app = createApp(App);
 for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
@@ -22,6 +23,6 @@
 directive(app);
 other.elSvg(app);
 
-app.use(pinia).use(router).use(ElementPlus, { i18n: i18n.global.t, locale: zhCn }).use(i18n).use(DataVVue3).use(VueGridLayout).mount('#app');
+app.use(pinia).use(router).use(ElementPlus, { i18n: i18n.global.t, locale: zhCn }).use(i18n).use(DataVVue3).use(VueGridLayout).use(vue3JsonExcel).mount('#app');
 
 app.config.globalProperties.mittBus = mitt();
diff --git a/src/types/monitorData.d.ts b/src/types/monitorData.d.ts
index 9ff2d0c..7d983d8 100644
--- a/src/types/monitorData.d.ts
+++ b/src/types/monitorData.d.ts
@@ -38,12 +38,13 @@
                 startTime: string;
                 endTime: string;
                 time: Array<any>;
-                gas: string;
+                gas: string | number;
                 position: number | null;
             }
         };
         gasList: Array<any>;
         positionList: Array<any>;
+        excelData: Array<any>;
     }
 }
 
@@ -66,12 +67,13 @@
             pageSize: number;
             searchParams: {
                 time: Array<any>;
-                gas: string;
-                area: string;
+                gas: string | number;
+                area: string |number;
             }
         };
         gasList: Array<any>;
         areaList: Array<any>;
+        excelData: Array<any>;
     },
 }
 
diff --git a/src/views/monitorData/fluxData/index.vue b/src/views/monitorData/fluxData/index.vue
index 664a26c..97ef4ff 100644
--- a/src/views/monitorData/fluxData/index.vue
+++ b/src/views/monitorData/fluxData/index.vue
@@ -46,6 +46,14 @@
                         </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="fluxChart" style="height: 500px;width: auto"></div>
@@ -86,6 +94,8 @@
 import { gasManageApi } from "/@/api/basicDataManage/gasManage";
 import { areaManageApi } from "/@/api/basicDataManage/areaManage";
 import { fluxDataApi } from "/@/api/monitorData/fluxData";
+import {Download} from "@element-plus/icons-vue";
+import {gasDataApi} from "/@/api/monitorData/gasData";
 
 const state = reactive<TableFluxState>({
     tableData: {
@@ -103,7 +113,29 @@
         },
         gasList: [],
         areaList: [],
+        excelData: []
     },
+});
+const fields = ref({
+  'time':'dataReceivingTime',
+  '设备ID':'equipmentId',
+  '区域': 'areaId',
+  '风速':'windSpeed',
+  '风向':'windDirection',
+  '甲烷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 loading = ref(false);
@@ -157,6 +189,7 @@
 const yData = ref([]);
 const areaChart = ref([]as any);
 const initInfoData = async () => {
+    await exportFluxData()
     //柱状图
     const chartParam = {
         startTime: moment(state.tableData.listQuery.searchParams.time[0]).format('YYYY-MM-DD HH:mm:ss'),
@@ -211,6 +244,7 @@
             yData.value = [];
             xData.value = [];
             dataZoomEnd.value = 100;
+          initCharts([],[]);
         }
 
         // initCharts();
@@ -236,7 +270,7 @@
     let res = await fluxDataApi().getFluxLinePage(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;
@@ -247,6 +281,38 @@
         });
     }
 };
+
+const exportFluxData = 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,不查询
+    areaId1: state.tableData.listQuery.searchParams.area == 1 ? '1':null,
+    areaId2: state.tableData.listQuery.searchParams.area == 2 ? '2':null,
+    areaId3: state.tableData.listQuery.searchParams.area == 3 ? '3':null,
+    areaId4: state.tableData.listQuery.searchParams.area == 4 ? '4':null,
+    areaId5: state.tableData.listQuery.searchParams.area == 5 ? '5':null,
+    areaId6: state.tableData.listQuery.searchParams.area == 6 ? '6':null,
+  }
+  let res = await fluxDataApi().exportFlux(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 labelOption = {
     rotate: 90,
@@ -355,6 +421,7 @@
     if (myChart.value != null && myChart.value != "" && myChart.value != undefined) {
         myChart.value.dispose();
     }
+    console.log(yData.value.length,'xxxx')
 
     myChart.value = echarts.init(document.getElementById(fluxChart.value));
     // 指定图表的配置项和数据
diff --git a/src/views/monitorData/gasData/index.vue b/src/views/monitorData/gasData/index.vue
index 1d2d9ee..1baa150 100644
--- a/src/views/monitorData/gasData/index.vue
+++ b/src/views/monitorData/gasData/index.vue
@@ -47,6 +47,14 @@
                         </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>
@@ -86,6 +94,7 @@
 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: {
@@ -117,8 +126,36 @@
             value: '方位3',
             label: 3
           },
-        ]
+        ],
+      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())
 
@@ -161,6 +198,7 @@
     state.tableData.listQuery.searchParams.time = [sTime,eTime];
 }
 const initInfoData = async () => {
+    await exportGasData();
     //折线图
     const chartParam = {
         startTime: moment(state.tableData.listQuery.searchParams.time[0]).format('YYYY-MM-DD HH:mm:ss'),
@@ -207,7 +245,7 @@
     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;
@@ -227,7 +265,8 @@
         //默认选择第一个气体
         state.tableData.listQuery.searchParams.gas = state.tableData.gasList[0].id;
         markLines.value = state.tableData.gasList[0].threshold;
-        initInfoData();
+        await initInfoData();
+
     }else {
         ElMessage({
             type: 'warning',
@@ -235,6 +274,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;
diff --git a/src/views/monitorData/weatherData/index.vue b/src/views/monitorData/weatherData/index.vue
index d760617..50f988b 100644
--- a/src/views/monitorData/weatherData/index.vue
+++ b/src/views/monitorData/weatherData/index.vue
@@ -198,7 +198,7 @@
     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;
diff --git a/yarn.lock b/yarn.lock
index c3ce256..fa80e58 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1247,6 +1247,11 @@
   "resolved" "https://registry.npmjs.org/dotenv/-/dotenv-16.0.1.tgz"
   "version" "16.0.1"
 
+"downloadjs@^1.4.7":
+  "integrity" "sha512-LN1gO7+u9xjU5oEScGFKvXhYf7Y/empUIIEAGBs1LzUq/rg5duiDrkuH5A2lQGd5jfMOb9X9usDa2oVXwJ0U/Q=="
+  "resolved" "https://registry.npmmirror.com/downloadjs/-/downloadjs-1.4.7.tgz"
+  "version" "1.4.7"
+
 "echarts-gl@^2.0.9":
   "integrity" "sha512-oKeMdkkkpJGWOzjgZUsF41DOh6cMsyrGGXimbjK2l6Xeq/dBQu4ShG2w2Dzrs/1bD27b2pLTGSaUzouY191gzA=="
   "resolved" "https://registry.npmjs.org/echarts-gl/-/echarts-gl-2.0.9.tgz"
@@ -2685,6 +2690,13 @@
     "@vue/server-renderer" "3.2.36"
     "@vue/shared" "3.2.36"
 
+"vue3-json-excel@^1.0.10-alpha":
+  "integrity" "sha512-wTcHSWdGQ5hFjpYbw2KOoLNQKVMFqDPfMPKuRpisxAACMk/E483/RLP3GT6HGMxocSO61wGKrAzYymYhKjo1Ew=="
+  "resolved" "https://registry.npmmirror.com/vue3-json-excel/-/vue3-json-excel-1.0.10-alpha.tgz"
+  "version" "1.0.10-alpha"
+  dependencies:
+    "downloadjs" "^1.4.7"
+
 "wangeditor@^4.7.15":
   "integrity" "sha512-aPTdREd8BxXVyJ5MI+LU83FQ7u1EPd341iXIorRNYSOvoimNoZ4nPg+yn3FGbB93/owEa6buLw8wdhYnMCJQLg=="
   "resolved" "https://registry.npmjs.org/wangeditor/-/wangeditor-4.7.15.tgz"

--
Gitblit v1.9.2