yangyin
2023-07-13 27d9a0bc91e065ae2e69a3425bb3e237a45fbece
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
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
<template>
  <div class="main_contain">
    <div class="ec_header">
      <div class="ec_header_left">
        <div class="ec_header_left_view">{{ pointName }}</div>
        <div class="ec_header_left_view">
          <span class="ec_header_val">{{
            state.currentRecordParas.RecordValue
          }}</span>
        </div>
      </div>
      <div class="ec_header_right">
        <div class="ec_header_right_view">
          <div>状态:{{ state.currentRecordParas.RecordStatusName }}</div>
          <div>警报:{{ state.currentRecordParas.AlarmNumber }}</div>
        </div>
        <div class="ec_header_right_view">
          <div>{{ state.currentRecordParas.RecordTime }}</div>
          <div>{{ lastRefreshTime }}s后刷新</div>
        </div>
      </div>
    </div>
    <div class="container">
      <div id="chartMain" style="width: 100%; height: 418px"></div>
    </div>
    <!--先隐藏详情,目前接口返回值
       <div class="ykt-detail-wraper">
      <van-collapse v-model="state.activeNames">
        <van-collapse-item name="1">
          <template #title>
            <div>详情</div>
          </template>
          <van-cell :value="state.MonitorPointID">
            <template #title>
              <div class="custom-title">测点编号</div>
            </template>
          </van-cell>
          <van-cell value="瞬时压力">
            <template #title>
              <div class="custom-title">监控名称</div>
            </template>
          </van-cell>
          <van-cell value="MPa">
            <template #title>
              <div class="custom-title">单位</div>
            </template>
          </van-cell>
          <van-cell value="">
            <template #title>
              <div class="custom-title">上次报警</div>
            </template>
          </van-cell>
          <van-cell>
            <template #title>
              <div class="custom-title">是否显示报警点</div>
            </template>
            <template #value>
              <van-switch v-model="state.checked" size="24px" />
            </template>
          </van-cell>
          <van-cell value="阈值">
            <template #title>
              <div class="custom-title">警报类型</div>
            </template>
          </van-cell>
        </van-collapse-item>
      </van-collapse>
    </div> -->
    <div class="ykt-detail-wrapers">
      <div class="hykt_header" style="margin-bottom: 5px">
        <div class="hykt_span">时间</div>
        <div
          class="hykt_span"
          @click="changeMonitorStatus"
          :style="state.isMonitorChange ? 'color:red;' : ''"
        >
          状态
        </div>
        <div class="hykt_span">监控值</div>
      </div>
      <div
        class="hykt_li"
        v-for="(monitor, index) in state.c_monitorList"
        :key="index"
      >
        <div class="hykt_span">{{ monitor.RecordTime }}</div>
        <div class="hykt_span">
          {{
            monitor.RecordStatusText.length > 0 &&
            monitor.RecordStatusText[0] == "BJ"
              ? "中断"
              : "正常"
          }}
        </div>
 
        <div class="hykt_span">{{ monitor.RecordValue }}</div>
      </div>
    </div>
    <!-- 刷新 -->
    <div style="bottom: 140px" class="icon_view">
      <van-icon name="revoke" size="20px" @click="onTapRefresh()" />
    </div>
    <!-- 间隔 -->
    <div style="bottom: 200px" class="icon_view" @click="onTapInterval">
      <van-icon
        :name="state.isOnTapInterval ? 'exchange' : 'shrink'"
        size="20px"
      />
    </div>
  </div>
</template>
 
<script setup>
import { reactive, onMounted, ref, shallowRef, onBeforeUnmount } from "vue";
import moment from "moment";
import * as echarts from "echarts"; //引入echarts
import axios from "axios";
import { useRouter } from "vue-router";
const router = useRouter();
const pointName = ref("");
const myChart = shallowRef(null);
const lastRefreshTime = ref(120);
let times = ref(null);
const now = new Date();
const minDate = new Date(
  now.getFullYear(),
  now.getMonth(),
  now.getDate(),
  0,
  0,
  0
);
const maxDate = new Date(
  now.getFullYear(),
  now.getMonth(),
  now.getDate(),
  23,
  59,
  59
);
let state = reactive({
  currentRecordParas: {
    RecordValue: "",
    RecordStatusName: "",
    AlarmNumber: 0,
    RecordTime: "",
  },
  chartData: [],
  x_yData: [],
  activeNames: [""],
  checked: false, //是否显示报警点
  loading: false, //加载状态
  isMonitorChange: false, //监测界面 --- 是否启用状态筛选
  isOnTapInterval: false,
  monitorList: [],
  c_monitorList: [],
  // PointID: "1620681990539972608",
  PointID: "",
  // token:
  //   "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySUQiOjEsIkxvZ2luTmFtZSI6Inl3YWRtaW4iLCJMb2dpblB3ZCI6ImFkbWluIiwiQ29ycElEIjoxLCJJc0FkbWluIjp0cnVlLCJpYXQiOjE2ODkyMTg3NzEsIm5iZiI6MTY4OTIxODc3MSwiZXhwIjoxNjg5MzA1MTcxLCJpc3MiOiJpc3RhdGlvbiIsImF1ZCI6ImlzdGF0aW9uIn0.cUxpJbn8krlTpaHkmd_nTgzc6YQzPxBn6pCJ0mFHAS8",
  token: "",
});
onMounted(() => {
  // console.log(router.currentRoute.value.query, 162);
  state.PointID = router.currentRoute.value.query.PointID;
  state.token = router.currentRoute.value.query.Token;
  state.currentRecordParas.RecordTime = moment().format("YYYY-MM-DD");
  initialRealTimeRecord();
  getRecordDetail();
});
const countdown = () => {
  if (lastRefreshTime.value === 0) {
    onTapRefresh();
    lastRefreshTime.value = 120;
    return;
  } else {
    lastRefreshTime.value--;
  }
};
onBeforeUnmount(() => {
  console.log("mounted!", 307);
  clearInterval(times.value);
  times.value = null;
});
 
//刷新
const onTapRefresh = () => {
  axios({
    url: "http://47.101.141.88:9019/Run/MonitorRealRecord/Mobile/GetLastRecordByMonitorPointID@V1.0",
    method: "GET",
    headers: {
      Authorization: `Bearer ${state.token}`,
    },
    params: {
      CorpID: 14,
      MonitorPointID: state.PointID,
    },
  })
    .then((res) => {
      if (res.data.Code != 0) {
        return;
      }
      if (res.data.Data == null || res.data.Data == "") {
        return;
      }
      var refreshData = res.data.Data;
      var last_record = state.chartData[state.chartData.length - 1]; //获取最后一条数据
      refreshData.forEach((item) => {
        let getStatus = DataStatusTextEmun(item.DataStatus);
        state.currentRecordParas.RecordStatusName = getStatus;
        state.currentRecordParas.RecordValue = item.DataValue;
        if (
          item.DataValue != last_record.DataValue ||
          item.DataTime != last_record.DataTime
        ) {
          state.chartData.push(item);
        }
      });
 
      setTimeout(() => {
        drawBar();
      }, 200);
    })
    .catch((error) => {
      console.log(error);
    });
};
//监控图标间隔
const onTapInterval = () => {
  if (!state.isOnTapInterval) {
    myChart.value.setOption({
      yAxis: {
        boundaryGap: ["0%", "0%"],
        scale: true,
      },
    });
    state.isOnTapInterval = true;
    return;
  }
  if (state.isOnTapInterval) {
    myChart.value.setOption({
      yAxis: {
        boundaryGap: ["15%", "15%"],
        scale: false,
      },
    });
    state.isOnTapInterval = false;
    return;
  }
};
//初始化获取数据
const initialRealTimeRecord = () => {
  axios({
    url: "http://47.101.141.88:9019/Run/MonitorRealRecord/Mobile/GetByMonitorPointIDOfDay@V1.0",
    method: "GET",
    headers: {
      Authorization: `Bearer ${state.token}`,
    },
    params: {
      CorpID: 14,
      MonitorPointID: state.PointID,
      Day: state.currentRecordParas.RecordTime,
    },
  })
    .then((res) => {
      if (res.data.Code != 0) {
        return;
      }
      if (res.data.Data == null || res.data.Data == "") {
        return;
      }
      var data = res.data.Data || [];
      state.chartData = data;
      var last_record = state.chartData[state.chartData.length - 1]; //获取最后一条数据
      state.currentRecordParas.RecordStatusName = DataStatusTextEmun(
        last_record.DataStatus
      );
      state.currentRecordParas.RecordValue = last_record.DataValue;
      let m_MonitorList = data.map((item) => {
        let totalState = DataStatusTextEmun(item.DataStatus);
        return {
          RecordTime: subTime(item.DataTime, 11, 16),
          RecordStatusText: totalState,
          RecordValue: item.DataValue,
        };
      });
      let monitor_List = data.map((item) => {
        let normalState = DataStatusTextEmun(item.DataStatus);
        if (normalState == "正常") {
          return {
            RecordTime: subTime(item.DataTime, 11, 16),
            RecordStatusText: normalState,
            RecordValue: item.DataValue,
          };
        }
      });
      state.monitorList = m_MonitorList; //源数据
      state.c_monitorList = monitor_List.reverse(); //切换数据
 
      setTimeout(() => {
        drawBar();
      }, 200);
    })
    .catch((error) => {
      console.log(error);
    });
};
//  初始化echarts折线图
const drawBar = () => {
  //先获取Dom上的实例
  let chartDom = echarts.getInstanceByDom(document.getElementById("chartMain"));
  //然后判断实例是否存在,如果不存在,就创建新实例
  if (chartDom == null) {
    chartDom = echarts.init(document.getElementById("chartMain"));
    myChart.value = chartDom;
  }
  let x_yData = [];
  state.chartData.forEach((item) => {
    x_yData.push({ value: [item.DataTime, item.DataValue] });
  });
  state.x_yData = x_yData;
  let series_arr = [];
  series_arr.push({
    type: "line",
    showSymbol: false,
    emphasis: { scale: false },
    data: state.x_yData,
    itemStyle: {
      color: "#4169E1",
    },
  });
  let option = {
    tooltip: {
      trigger: "axis",
    },
    legend: {
      show: false,
      fontSize: 12,
      color: "#7e8390",
    },
    grid: {
      left: "5%",
      right: "5%",
      bottom: "10%",
      top: "12%",
      containLabel: true,
    },
    xAxis: {
      type: "time",
      boundaryGap: false,
      min: minDate,
      max: maxDate,
      axisLabel: {
        showMaxLabel: true,
        formatter: function (value) {
          // 如果时间是 23:59:59 , 格式化为 24:00
          if (
            value ===
            new Date(
              moment().endOf("day").format("YYYY-MM-DD HH:mm:ss")
            ).getTime()
          ) {
            return moment(value).format("24:00");
          } else {
            // 其他的时间返回格式化 00:00
            return moment(value).format("HH:mm");
          }
        },
      },
      axisLine: { onZero: true, show: true },
      minorTick: {
        show: false,
        splitNumber: 2,
      },
      splitLine: {
        show: true, //是否显示分隔线
        interval: "auto", //坐标轴分隔线的显示间隔
      },
    },
    yAxis: {
      boundaryGap: ["20%", "20%"],
 
      type: "value",
      axisLabel: {
        formatter: "{value}",
      },
      // 整条y轴
      axisLine: {
        show: true,
      },
    },
    dataZoom: [
      {
        type: "slider", //图表下方的伸缩条
        show: true, //是否显示
        realtime: true, //
        start: 0, //伸缩条开始位置(1-100),可以随时更改
        end: 100, //伸缩条结束位置(1-100),可以随时更改
        left: 10,
        right: 15,
        bottom: 5, //底部的距离
        fillerColor: "rgba(22,181,203,0.4)", //选中范围的填充颜色。
        borderColor: "#ddd", //边框颜色。
        backgroundColor: "rgba(167,183,204,0.4)", //组件的背景颜色
        throttle: 100, //设置触发视图刷新的频率。单位为毫秒(ms)。
        handleIcon:
          "path://M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z",
        handleSize: "80%", //  控制手柄的尺寸,可以是像素大小,也可以是相对于 dataZoom 组件宽度的百分比,默认跟 dataZoom 宽度相同。
        handleStyle: {
          color: "#16b5cb",
          shadowBlur: 3, // shadowBlur图片阴影模糊值,shadowColor阴影的颜色
          shadowColor: "#77CCD8",
          shadowOffsetX: 1,
          shadowOffsetY: 1,
          opacity: 0.6,
        },
      },
    ],
    series: series_arr,
  };
  myChart.value.clear();
  myChart.value.setOption(option, true);
  window.addEventListener("resize", selfAdaption);
  times.value = setInterval(countdown, 1000);
};
//  自适应
const selfAdaption = () => {
  if (!myChart.value) return;
  myChart.value.resize();
  setTimeout(() => {
    drawBar();
  }, 100);
};
//获取详情
const getRecordDetail = () => {
  axios({
    url: "http://47.101.141.88:9019/Monitor/MonitorPoint/GetByID@V1.0",
    method: "GET",
    headers: {
      Authorization: `Bearer ${state.token}`,
    },
    params: {
      CorpID: 14,
      ID: state.PointID,
    },
  })
    .then((res) => {
      let getDetailData = res.data.Data || [];
      if (res.data.Code != 0) {
        return;
      }
      if (getDetailData == null || getDetailData == "") {
        return;
      }
      pointName.value = getDetailData.Name;
    })
    .catch((error) => {
      console.log(error);
    });
};
//切换状态(正常/中断)
const changeMonitorStatus = () => {
  if (!state.isMonitorChange) {
    let arr = [];
    state.monitorList.forEach((item) => {
      if (item.RecordStatusText != "正常") {
        arr.push({
          RecordTime: item.RecordTime,
          RecordStatusText: item.RecordStatusText,
          RecordValue: item.RecordValue,
        });
      }
    });
    state.isMonitorChange = true;
    state.c_monitorList = arr.reverse();
    return;
  } else {
    let arr = [];
    state.monitorList.forEach((item) => {
      if (item.RecordStatusText == "正常") {
        arr.push({
          RecordTime: item.RecordTime,
          RecordStatusText: item.RecordStatusText,
          RecordValue: item.RecordValue,
        });
      }
    });
    state.isMonitorChange = false;
    state.c_monitorList = arr.reverse();
    return;
  }
};
const DataStatusTextEmun = (value) => {
  if (value.length == 0) return "正常";
  let text = "";
  if (value[0] == "GLSB") {
    text = "过滤失败";
  }
  if (value[0] == "SZGSCW") {
    text = "数据格式错误";
  }
  if (value[0] == "ZHSB") {
    text = "转换失败";
  }
  if (value[0] == "BJ") {
    text = "报警";
  }
  return text;
};
//切割数字
const subTime = (val, start, end) => {
  var getVal = val.substring(start, end);
  return getVal;
};
</script>
<style scoped lang="scss">
.main_contain {
  background-color: #efeff4;
  // overflow-y: unset;
  .ec_header {
    width: 100%;
    font-size: 10px;
    color: #fff;
    display: flex;
 
    .ec_header_left {
      width: 55%;
      height: 82px;
      background: linear-gradient(to left, #97d8e0, #16b5cb);
      border-radius: 5px;
      .ec_header_left_view {
        height: 40px;
        font-size: 20px;
        font-weight: 600;
        display: flex;
        align-items: center;
        justify-content: center;
        .ec_header_name {
          font-size: 14px;
        }
      }
    }
    .ec_header_right {
      width: 45%;
 
      font-size: 10px;
      .ec_header_right_view {
        height: 40px;
        display: flex;
        justify-content: space-around;
        align-items: center;
        background: linear-gradient(45deg, #97d8e0, #16b5cb);
        border-radius: 3px;
        margin: 1px 1px;
      }
    }
  }
  .container {
    /* position: relative; */
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    box-sizing: border-box;
    background-color: #fff;
    border-radius: 3px;
  }
  .ykt-detail-wraper {
    width: 100%;
    display: flex;
    flex-direction: column;
    margin: 10px auto;
    background: #fff;
    border-radius: 3px;
  }
  .ykt-detail-wrapers {
    padding: 8px 0px 0px 0px;
    // background: #fff;
    width: 100%;
    height: auto;
    // height: calc(100vh - 60px);
    // overflow-y: auto;
    font-size: 12px;
    justify-content: center;
  }
  .hykt_header {
    width: 100%;
    min-height: 25px;
    background-color: #16b5cb;
    color: #fff;
    font-weight: 600;
    border-radius: 50px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: space-between;
    .hykt_span {
      font-size: 12px;
      height: 100%;
      min-width: 100px;
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
 
  .hykt_li {
    width: 100%;
    min-height: 25px;
    background-color: #fff;
    color: #000;
    font-weight: 500;
    border-radius: 50px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: space-between;
    margin-bottom: 5px;
    .hykt_span {
      font-size: 12px;
      height: 100%;
      min-width: 100px;
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
  .custom-title {
    text-align: left;
  }
  .icon_view {
    font-size: 30px;
    color: #fff;
    width: 40px;
    height: 40px;
    position: fixed;
    right: 10px;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #16b5cb;
    border-radius: 5px;
    box-shadow: 0 2px 6px 0 rgba(114, 124, 245, 0.5);
  }
}
</style>