燕山石化溯源三维电子沙盘-【前端】-Web
WX
2023-08-11 b01346e041ffa205d69fddffa8c6f78cbeb307af
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
<template>
  <div class="FX_box">
    <div class="FX_title">分析报告导出</div>
    <div class="form_box">
      <div class="inp_box">
        <!-- <span>监测点选择</span> -->
        <!-- <el-select v-model="data.SJvalue" class="m-2" size="large">
          <el-option
            v-for="item in optionsSJ"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
 
        </el-select> -->
        <el-date-picker
          size="large"
          v-model="selectform.value1"
          type="datetimerange"
          @change="changeTime"
          value-format="YYYY-MM-DD HH"
          format="YYYY-MM-DD HH"
        />
        <!-- <el-date-picker
          size="large"
          v-model="selectform.value1"
          type="date"
          @change="changeTime"
          value-format="YYYY-MM-DD"
        />
         -->
      </div>
 
      <div class="button_box">
        <el-button @click="selectList" class="button">确认</el-button>
      </div>
    </div>
  </div>
</template>
 
<script>
import { reactive, onMounted, watch, ref } from "vue";
import { useStore } from "vuex";
import {
  qxshControllerByTime,
  bjyjControllerGetAll,
  queryWeatherList,
  qxshController_query,
  weatherController_query,
  ysshSuYuanX00Controller_500_query,
  forecastAnalyse,
  getRunAlarm,
  getRunWarning,
  getAlarmAndWarnByTime,
} from "@/api/api.js";
import docxtemplater from "docxtemplater";
import PizZip from "pizzip";
import JSZipUtils from "jszip-utils";
import { saveAs } from "file-saver";
 
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  setup(props) {
    const store = useStore();
    let data = reactive({
      SJvalue: "",
      optionisshow: false,
      // 表单对象
      form: {
        time: "",
        temperature: "",
        windSpeed: "",
        windDirection: "",
        weather: "",
        arrLength: "",
      },
      // 表格信息
      tableData: [],
      time_show: "",
    });
    const selectform = reactive({
      value1: [],
      value: "",
    });
    const shortcuts = reactive([
      {
        text: "最近一周",
        value: () => {
          const end = new Date();
          const start = new Date();
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
          return [start, end];
        },
      },
      {
        text: "最近一个月",
        value: () => {
          const end = new Date();
          const start = new Date();
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
          return [start, end];
        },
      },
      {
        text: "最近三个月",
        value: () => {
          const end = new Date();
          const start = new Date();
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
          return [start, end];
        },
      },
    ]);
    let optionsSJ = ref([]);
    //网格名称选择框
    const getWGname = () => {
      let arr = [];
      //   optionsSJ = [];
      store.state.jkList.forEach((e) => {
        arr.push({ value: e.name, label: e.name });
      });
      optionsSJ = arr;
      //   console.log(optionsSJ);
    };
    // 时间格式
    function getTime() {
      const year = new Date().getFullYear();
      const month =
        new Date().getMonth() + 1 < 10
          ? "0" + (new Date().getMonth() + 1)
          : new Date().getMonth() + 1;
      const date =
        new Date().getDate() < 10
          ? "0" + new Date().getDate()
          : new Date().getDate();
      const hh =
        new Date().getHours() < 10
          ? "0" + new Date().getHours()
          : new Date().getHours();
      const h = new Date().getHours();
      const mm =
        new Date().getMinutes() < 10
          ? "0" + new Date().getMinutes()
          : new Date().getMinutes();
      const ss =
        new Date().getSeconds() < 10
          ? "0" + new Date().getSeconds()
          : new Date().getSeconds();
      const week = new Date().getDay();
      if (week === 1) {
        data.nowWeek = "星期一";
      } else if (week === 2) {
        data.nowWeek = "星期二";
      } else if (week === 3) {
        data.nowWeek = "星期三";
      } else if (week === 4) {
        data.nowWeek = "星期四";
      } else if (week === 5) {
        data.nowWeek = "星期五";
      } else if (week === 6) {
        data.nowWeek = "星期六";
      } else if (week === 0) {
        data.nowWeek = "星期日";
      } else if (week === 27) {
        data.nowWeek = "星期日";
      }
 
      data.form.time = `${year}-${month}-${date} ${hh}:${mm}:${ss}`;
      data.time_show = `${year}-${month}-${date}-${hh}:${mm}:${ss}`;
      //   data.h = hh;
 
      // sgworld.Analysis.setTime(hh);
    }
    // getWGname();
    // watch(
    //   () => store.state.jkList,
    //   (nVal, oVal) => {
    //     getWGname();
    //   },
 
    //   { deep: true }
    // );
    // 点击导出word
    function exportWord() {
      // 读取并获得模板文件的二进制内容
      JSZipUtils.getBinaryContent("input.docx", function (error, content) {
        // input.docx是模板。我们在导出的时候,会根据此模板来导出对应的数据
        // 抛出异常
        if (error) {
          throw error;
        }
 
        // 创建一个JSZip实例,内容为模板的内容
        let zip = new PizZip(content);
        // 创建并加载docxtemplater实例对象
        let doc = new docxtemplater().loadZip(zip);
        // 设置模板变量的值
        doc.setData({
          ...data.form,
          table: data.tableData,
        });
 
        try {
          // 用模板变量的值替换所有模板变量
          doc.render();
        } catch (error) {
          // 抛出异常
          let e = {
            message: error.message,
            name: error.name,
            stack: error.stack,
            properties: error.properties,
          };
          console.log(JSON.stringify({ error: e }));
          throw error;
        }
 
        // 生成一个代表docxtemplater对象的zip文件(不是一个真实的文件,而是在内存中的表示)
        let out = doc.getZip().generate({
          type: "blob",
          mimeType:
            "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
        });
        // 将目标文件对象保存为目标类型的文件,并命名
        saveAs(out, "厂区VOCs状态简报.docx");
      });
    }
    //格式化天气
    const formatWeather = (row) => {
      if (row == undefined) {
        return;
      }
      data.form.temperature = parseInt(row.temperature);
      data.form.windSpeed = Number(row.windSpeed).toFixed(2);
      // data.form.temperature = parseInt(row.temperature);
      // data.form.windSpeed = Number(row.windSpeed).toFixed(2);
 
      switch (row.windDirection) {
        case "Southwest":
          data.form.windDirection = "西南风";
          break;
        case "Southeast":
          data.form.windDirection = "东南风";
          break;
        case "Northeast":
          data.form.windDirection = "东北风";
          break;
        case "Northwest":
          data.form.windDirection = "西北风";
          break;
        case "North":
          data.form.windDirection = "北风";
          break;
        case "East":
          data.form.windDirection = "东风";
          break;
        case "West":
          data.form.windDirection = "西风";
          break;
        case "South":
          data.form.windDirection = "南风";
          break;
      }
 
      switch (row.weatherCondition) {
        case "Sunny":
          data.form.weather = "晴天";
          break;
 
        case "Moderate Rain":
          data.form.weather = "中雨";
          break;
        case "Heavy Rain":
          data.form.weather = "大雨";
          break;
        case "Light Rain":
          data.form.weather = "小雨";
          break;
        case "Light Snow":
          data.form.weather = "小雪";
          break;
        case "Moderate Snow":
          data.form.weather = "中雪";
          break;
        case "Heavy Snow":
          data.form.weather = "大雪";
          break;
        case "T-Storm":
          data.form.weather = "暴风雨";
          break;
        case "T-Storm Snow":
          data.form.weather = "暴风雪";
          break;
      }
 
      // window.sgworld.Analysis.createWeather(weatherData, true);
    };
    const selectList = async () => {
      data.form.time =
        selectform.value1[0] + ":00:00" + "-" + selectform.value1[1] + ":00:00";
      let begin = selectform.value1[0].replace(" ", "-");
      let end = selectform.value1[1].replace(" ", "-");
      console.log(begin, end);
      //获取实时预警数据
      // const dt = await getRunWarning();
      // //获取实时报警数据
      // const dt1 = await getRunAlarm();
      const dt = await getAlarmAndWarnByTime({
        begin: selectform.value1[0] + ":00:00",
        end: selectform.value1[1] + ":00:00",
      });
      //获取天气
      const weather = await queryWeatherList(begin, end);
      formatWeather(weather.result[0]);
      var flag = 0;
      if (dt.result && dt.result.length > 0) {
        dt.result.forEach((item) => {
          flag++;
          let lastVal = item.lastVal == null ? "无" : item.lastVal;
          let isSame = item.isSame == 1 ? " 一致。" : " 不一致。";
          let maxAddr = item.maxAddr == null ? "" : `(${item.maxAddr})`;
          let suObj = {
            addr1: ``,
            addr2: ``,
            addr3: ``,
          };
          if (item.su) {
            if (item.su.addr1) {
              suObj.addr1 = `可疑污染源:1、地点名:${item.su.addr1} 概率:${
                item.su.odds1 * 100
              }%。`;
            }
            if (item.su.addr2) {
              suObj.addr2 = `2、地点名:${item.su.addr2} 概率:${
                item.su.odds2 * 100
              }%。`;
            }
            if (item.su.addr3) {
              suObj.addr3 = `3、地点名:${item.su.addr3} 概率:${
                item.su.odds3 * 100
              }%。`;
            }
          }
 
          const content =
            "异常站点 " +
            item.name +
            " 的浓度值为 " +
            item.val +
            " 。去年同时期的浓度值为 " +
            lastVal +
            " 。站点风速为 " +
            data.form.windSpeed +
            " ,风向为 " +
            data.form.windDirection +
            " 。周围500米范围内的最大浓度值为 " +
            item.maxVal +
            ",对应格子为 " +
            item.maxId +
            maxAddr +
            " 。该最大浓度值距离异常站点 " +
            item.dis +
            " 米,风向为" +
            item.maxDir +
            " 。与风速方向" +
            isSame +
            suObj.addr1 +
            suObj.addr2 +
            suObj.addr3;
          data.tableData.push({
            no: flag,
            name: item.name,
            value: item.val,
            content: content,
            pos: item.lon + "," + item.lat,
            speed: data.form.windSpeed,
            direction: data.form.windDirection,
          });
        });
      }
 
      if (data.tableData.length == 0) {
        data.form.arrLength = "无";
      } else {
        data.form.arrLength = "有";
      }
      exportWord();
    };
 
    async function querydata(res) {
      const dtx1 = await qxshController_query(res.name);
    }
    function qxshControllerQuery(res) {}
    function changeTime(value) {}
    onMounted(() => {});
    return {
      data,
      selectList,
      optionsSJ,
      getWGname,
      selectform,
      shortcuts,
      changeTime,
    };
  },
};
</script>
<style lang="less" scoped>
//@import url(); 引入公共css类
.FX_box {
  width: calc(742px * 1);
  height: calc(200px * 1);
  // position: absolute;
  // right: 70px;
  // top: 490px;
  background: url("../assets/img/d.png") no-repeat center;
  background-size: 100% 100%;
  padding: 40px;
  box-sizing: border-box;
  .FX_title {
    font-size: 30px;
    font-weight: bold;
    color: #ffffff;
    padding-bottom: 10px;
  }
}
.form_box {
  display: flex;
  justify-content: space-around;
  align-items: center;
  .inp_box {
    /deep/ .el-input__wrapper {
      width: 460px;
      background: rgba(0, 0, 0, 0.2);
      border: 2px solid #2e58cc;
      border-radius: 10px;
      color: #ffffff;
      padding: 0;
      padding-left: 3px;
    }
    /deep/ .el-input__inner,
    /deep/ .el-textarea__inner {
      //   background-color: rgba(134, 132, 132, 0.5);
      color: #ffffff;
      font-size: 24px;
    }
    /deep/.el-range-input {
      color: white;
    }
    /deep/ .el-range-separator {
      color: white;
    }
    .el-select {
      width: 180px;
    }
    .el-select /deep/ .el-input__wrapper {
      background: rgba(0, 0, 0, 0.2);
      border: 2px solid #2e58cc;
      border-radius: 10px;
      color: #ffffff;
      padding: 0;
      padding-left: 6px;
    }
    .el-select /deep/ .el-input__inner {
      color: #ffffff;
      font-size: 24px;
    }
  }
}
.button {
  background: rgba(0, 0, 0, 0.2);
  border: 4px solid #2e58cc !important;
  border-radius: 20px !important;
  color: #ffffff;
  height: 64px !important;
  font-size: 28px !important;
  padding: 16px 30px !important;
}
</style>