zmc
2023-08-15 d58be9584f409e7d198fd34982155331d6710f1f
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
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
<!-- 实时监测 -->
 
<script>
import axiosInstanceInstance from '../utils/request.js';
// 异步组件
const DashBoard = defineAsyncComponent(() =>
  import('../sfc/DashboardChart.vue')
);
export default {
  components: {
    DashBoard
  },
  data() {
    return {
      button:{
        setButton:false
      },
      totalData: [],
      // 保存设置
      save: false,
      // 默认打开的折叠面板
      activeNames: '1',
      // 实时更新间隔 60秒
      timeInterval: 60000,
      // 外部设备
      outside: {
        // 搜索
        searchText: '',
        isall: false,
        isLoading: false,
        // 设备信息表的数据
        shopnames: [],
        // 当前展示的多选框组值
        displayedShopnames: [],
        // 当前页
        currentPage: 1,
        // 每页显示的数量
        pageSize: 5,
        // 是否已加载完所有数据
        allDataLoaded: false,
        // 是否全选
        checkAll: false,
        isIndeterminate: false,
        // 已选择店铺
        checkedShops: [],
        //返回选择的所有店铺的数据
        realTimeData: []
      },
 
      // 内部设备
      inner: {
        searchText: '',
        isall: false,
        isLoading: false,
        // 内部接口返回的所有数据
        getData: [],
        // 选中的店铺对应全部字段信息
        inFumeValue: [],
        // 所有店铺名字
        shopnames: [],
        // 当前展示的多选框组值
        displayedShopnames: [],
        // 当前页
        currentPage: 1,
        // 每页显示的数量
        pageSize: 2,
        // 是否已加载完所有数据
        allDataLoaded: false,
        // 是否全选
        checkAll: false,
        isIndeterminate: false,
        // 已选择店铺
        checkedShops: []
      }
 
    };
  },
 
  methods: {
    //获取所有店铺名字
    getDeviceInfo() {
      // 获取所有外部设备的店铺名称
      axiosInstanceInstance.get('/fume/device').then((result) => {
        result.data.data.forEach((item) => {
          this.outside.shopnames.push(item.diName);
        });
        this.outside.displayedShopnames = this.outside.shopnames.slice(
          0,
          this.outside.pageSize
        );
        if (this.outside.shopnames.length <= this.outside.pageSize) {
          this.outside.allDataLoaded = true;
        }
      });
      //从内部接口获取实时数据的所有店铺名称
      axiosInstanceInstance
        .get('https://fyami.com.cn/device/min/value/real_time', {
          params: { page: 1, per_page: 20 }
        })
        .then((result) => {
          // 保存内部接口获取的所有信息
          this.getData = result.data.data;
          result.data.data.forEach((item) => {
            this.inner.shopnames.push(item.siteName);
          });
          this.inner.displayedShopnames = this.inner.shopnames.slice(
            0,
            this.inner.pageSize
          );
          if (this.inner.shopnames.length <= this.inner.pageSize) {
            this.inner.allDataLoaded = true;
          }
        });
    },
    loadMore() {
      this.outside.isLoading = true;
      setTimeout(() => {
        const startIndex = this.outside.currentPage * this.outside.pageSize;
        const endIndex = startIndex + this.outside.pageSize;
        this.outside.displayedShopnames =
          this.outside.displayedShopnames.concat(
            this.outside.shopnames.slice(startIndex, endIndex)
          );
        this.outside.currentPage++;
        if (
          this.outside.displayedShopnames.length ===
          this.outside.shopnames.length
        ) {
          this.outside.allDataLoaded = true;
          this.outside.isall = true;
        }
        this.outside.isLoading = false;
      }, 100);
    },
    loadMoreInner() {
      this.inner.isLoading = true;
      setTimeout(() => {
        const startIndex = this.inner.currentPage * this.inner.pageSize;
        const endIndex = startIndex + this.inner.pageSize;
        this.inner.displayedShopnames = this.inner.displayedShopnames.concat(
          this.inner.shopnames.slice(startIndex, endIndex)
        );
        this.inner.currentPage++;
        if (
          this.inner.displayedShopnames.length === this.inner.shopnames.length
        ) {
          this.inner.allDataLoaded = true;
          this.inner.isall = true;
        }
        this.inner.isLoading = false;
      }, 100);
    },
    // 过滤数据
    filterData(keyword) {
      return this.outside.shopnames.filter((item) => item.includes(keyword));
    },
 
    // 处理搜索
    handleSearch() {
      if (this.outside.searchText != '') {
        this.outside.displayedShopnames = this.filterData(
          this.outside.searchText
        );
        this.outside.currentPage = 1; // 重置页码
        this.outside.allDataLoaded =
          this.outside.displayedShopnames === this.outside.shopnames.length;
      } else {
        // 加载默认数量的
        this.outside.displayedShopnames = this.outside.shopnames.slice(
          0,
          this.outside.pageSize
        );
        if (this.outside.shopnames.length <= this.outside.pageSize) {
          this.outside.allDataLoaded.value = true;
        }
        this.outside.checkedShops = [];
      }
    },
 
    // 处理搜索
    handleSearchInner() {
      if (this.inner.searchText != '') {
        this.inner.displayedShopnames = this.filterData(this.inner.searchText);
        this.inner.currentPage = 1; // 重置页码
        this.inner.allDataLoaded =
          this.inner.displayedShopnames === this.inner.shopnames.length;
      } else {
        // 加载默认数量的
        this.inner.displayedShopnames = this.inner.shopnames.slice(
          0,
          this.inner.pageSize
        );
        if (this.inner.shopnames.length <= this.inner.pageSize) {
          this.inner.allDataLoaded.value = true;
        }
        this.inner.checkedShops = [];
      }
    },
    // 外部设备全选
    handleCheckAllChangeOutside(val) {
      this.outside.checkedShops = val ? this.outside.displayedShopnames : [];
      this.outside.isIndeterminate = false;
    },
    handleCheckedCitiesChangOutside(value) {
      const checkedCount = value.length;
      this.outside.checkAll =
        checkedCount === this.outside.displayedShopnames.length;
      this.outside.isIndeterminate =
        checkedCount > 0 &&
        checkedCount < this.outside.displayedShopnames.length;
    },
 
    // 内部设备全选
    handleCheckAllChangeInner(val) {
      this.inner.checkedShops = val ? this.inner.shopnames : [];
      this.inner.isIndeterminate = false;
    },
    handleCheckedCitiesChangeInner(value) {
      const checkedCount = value.length;
      this.inner.checkAll = checkedCount === this.inner.shopnames.length;
      this.inner.isIndeterminate =
        checkedCount > 0 && checkedCount < this.inner.shopnames.length;
    },
 
    // 判断一个数组是否包含该元素
    hasElement(array, element) {
      return array.includes(element);
    },
 
    //根据所选店铺求请并渲染仪表盘
    request() {
      // 外部设备
      if (this.outside.checkedShops.length != 0) {
        let temp = this.outside.checkedShops.join();
        let params = {};
        if (this.outside.checkedShops.length != 0) {
          params['shops'] = temp;
        }
        axiosInstanceInstance
          .get('/fume/lastest', { params: params })
          .then((result) => {
            this.outside.realTimeData = result.data.data;
            console.log('66', this.outside.realTimeData);
            // console.log('长度为:',this.outside.realTimeData.length);
            // 渲染折线图
            // this.updateCharts();
          });
      }
 
      // 选择了内部设备
      if (this.inner.checkedShops.length != 0) {
        // 清空数据
        this.inner.inFumeValue = [];
        this.getData.forEach((item) => {
          let itemOne = item.siteName;
          // 拿到选中的店铺对应的浓度值
          if (this.hasElement(this.inner.checkedShops, itemOne)) {
            this.inner.inFumeValue.push(item);
          }
        });
        console.log(this.inner.inFumeValue);
      }
 
      // 合并
      setTimeout(() => {
        // 试点设备排在前面
        this.totalData = [
          ...this.inner.inFumeValue,
          ...this.outside.realTimeData
        ];
        console.log('总选数据', this.totalData);
        console.log('长度为:', this.totalData.length);
      }, 200);
      console.log('调用了');
    },
 
    // 点击按钮触发
    show() {
      // 
      this.button.setButton = true
      // 当取消选择时,防止图形还保留在页面。
      if (this.outside.checkedShops.length == 0) {
        this.outside.realTimeData = [];
      }
      if (this.inner.checkedShops.length == 0) {
        this.inner.inFumeValue = [];
      }
      // 根据所选的店铺请求数据
      this.request();
      this.button.setButton = false
      // 定时更新
      setInterval(() => {
        this.request();
      }, this.timeInterval);
    }
  },
  mounted() {
    // 获取所有店铺名字
    this.getDeviceInfo();
    // 优先展示浏览器缓存中的
    // this.getOutsideData()
  }
};
</script>
 
<template>
  <div>
    <el-collapse v-model="activeNames">
      <el-collapse-item name="1">
        <template #title>
          <el-tooltip
            class="box-item"
            effect="dark"
            content="点击可折叠"
            placement="right-start"
          >
            <h2 style="margin-left: 10px">监控配置</h2>
          </el-tooltip>
        </template>
 
        <el-card shadow="always" class="form-card">
          <h1>监测点配置</h1>
          <br />
          <el-form label-width="120px">
            <el-form-item label="试点设备">
              <el-checkbox
                v-model="inner.checkAll"
                :indeterminate="inner.isIndeterminate"
                @change="handleCheckAllChangeInner"
                >全选</el-checkbox
              >
              <el-checkbox-group
                v-model="inner.checkedShops"
                @change="handleCheckedCitiesChangeInner"
                class="inner-checkbox-group"
              >
                <el-checkbox
                  v-for="shop in inner.displayedShopnames"
                  :key="shop"
                  :label="shop"
                  >{{ shop }}
                </el-checkbox>
              </el-checkbox-group>
            </el-form-item>
            <div class="input-search">
              <el-input
                type="text"
                v-model="inner.searchText"
                placeholder="搜索店铺名称"
                @input="handleSearchInner"
              />
            </div>
 
            <div>
              <el-button
                type="primary"
                v-if="!inner.allDataLoaded && !inner.isLoading && !inner.isall"
                @click="loadMoreInner"
                >加载更多</el-button
              >
              <el-button
                type="primary"
                loading
                v-if="!inner.allDataLoaded && inner.isLoading"
                @click="loadMoreInner"
                >加载更多</el-button
              >
              <div>已选择试点设备数量为:{{ inner.checkedShops.length }}</div>
            </div>
            <br />
            <hr />
            <br />
 
            <el-form-item label="其他设备">
              <el-checkbox
                v-model="outside.checkAll"
                :indeterminate="outside.isIndeterminate"
                @change="handleCheckAllChangeOutside"
                >全选</el-checkbox
              >
 
              <el-checkbox-group
                v-model="outside.checkedShops"
                @change="handleCheckedCitiesChangOutside"
              >
                <el-checkbox
                  v-for="shop in outside.displayedShopnames"
                  :key="shop"
                  :label="shop"
                  >{{ shop }}
                </el-checkbox>
              </el-checkbox-group>
            </el-form-item>
 
            <div class="input-search">
              <el-input
                type="text"
                v-model="outside.searchText"
                placeholder="搜索店铺名称"
                @input="handleSearch"
              />
            </div>
 
            <div>
              <el-button
                type="primary"
                v-if="
                  !outside.allDataLoaded && !outside.isLoading && !outside.isall
                "
                @click="loadMore"
                >加载更多</el-button
              >
              <el-button
                type="primary"
                loading
                v-if="!outside.allDataLoaded && outside.isLoading"
                @click="loadMore"
                >加载更多</el-button
              >
              <div>已选择其他设备数量为:{{ outside.checkedShops.length }}</div>
            </div>
            <!-- <el-form-item > -->
 
            <div class="time-interval">
              实时更新间隔为:{{ timeInterval / 1000 }}秒
            </div>
 
            <!-- </el-form-item> -->
          </el-form>
        </el-card>
      </el-collapse-item>
    </el-collapse>
  </div>
 
  <div>
    <el-tooltip
      class="box-item"
      effect="dark"
      content="点击展示实时数据"
      placement="top-start"
    >
      <el-button type="success" :loading="button.setButton" @click="show" style="margin-left: 10px">
        设置
      </el-button>
    </el-tooltip>
    <el-switch
      v-model="save"
      class="save-switch"
      active-text="保存设置"
      inactive-text="不保存设置"
    >
    </el-switch>
  </div>
 
  <div>
    <el-row :gutter="20">
      <el-col
        :span="6"
        v-for="(device, index) in totalData"
        :key="device.mvStatCode"
      >
        <!-- 内部设备 -->
        <el-card v-if="index < inner.inFumeValue.length"  class="card-font-color" height="1900px">
          <template #header>
            <div class="card-header">{{ device.siteName }} 
              <img src="@/assets/inner_device.jpg" class="icon-inner"/>
            </div>
           
          </template>
          <div class="report-time-text">数据发布时间:{{ device.time }}</div>
          <DashBoard :data="device.value"></DashBoard>
 
          <div >设备编号:{{ device.mnCode }}</div>
 
          <div class="horizontal-line"></div>
          
          <div class="status" :class="{ exceed: device.value > 1 }">
            {{ device.value >= 1 ? '超标' : '' }}
          </div>
          <br />
          <br />
          <br />
        </el-card>
        <!-- 外部设备 -->
        <el-card v-else class="card-font-color">
          <template #header>
            <div class="card-header">
              {{ device.diName }}
            </div>
          </template>
          <div  class="report-time-text">数据发布时间:{{ device.mvDataTime }}</div>
          <DashBoard :data="device.mvFumeConcentration2"></DashBoard>
 
          <div class="imag-container">
            <img src="@/assets/wind.jpg" class="image"/>
          <span class="chart-below-text"> 风机电流(A):{{ device.mvFanElectricity }} </span>
         
          <span class="chart-below-text2">
            <img src="@/assets/purifier.jpg" class="image"/>
            净化器电流(A):{{ device.mvPurifierElectricity }}
          </span>
         </div>
         <div class="horizontal-line"></div>
 
          <div>设备编号:{{ device.mvStatCode }}</div>
 
          <div class="horizontal-line"></div>
 
          <div>设备供应商:{{ device.diSupplier }}</div>
          <div
            class="status"
            :class="{ exceed: device.mvFumeConcentration2 >= 1 }"
          >
            {{ device.mvFumeConcentration2 >= 1 ? '超标' : '' }}
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>
 
<style lang="scss" scoped>
 
.time-interval {
  display: flex;
  justify-content: right;
  font-size: 16px;
}
.form-card {
  margin: 20px 10px;
  // width: 96%;
  border: 1px solid #ebeef5;
  border-radius: 4px;
 
}
.inner-checkbox-group {
  margin-left: 15px;
}
.el-card {
  margin-bottom: 10px;
  border-radius: 15px;
  margin-left: 5px;
}
.card-header {
  // display: flex;
  // align-items: center;
  // position: center;
  text-align: center;
  position: relative;
}
.card-header-item {
  display: flex;
  text-align: right;
}
 
.outside-leble {
  margin-top: 10px;
}
.inner-leble {
  margin-top: 10px;
}
// 分割线
.line-marign {
  margin: 20px 0;
}
.el-dialog {
  width: 700px;
}
.dashBorder-area {
  margin-left: 10px;
}
.dashboard {
  margin-bottom: 20px;
  border: #1de01d;
}
.chart-below-text2{
  float: right;
}
.image {
  height: 18px;
}
.icon-inner {
  position: relative;
  top: -20px;
  right: -115px;
  width: 50px;
  height: 50px;
}
.dashboard-title {
  font-size: 20px;
  text-align: center;
  padding: 10px 0;
  background-color: #f5f7fa;
}
 
.report-time-text {
  font-size: 12px;
  color: #999999;
}
 
.card-font-color {
  color: #000000;
}
 
 
 
 
 
/* 超标 文字效果*/
.status {
  font-size: 18px;
  color: #ff4d4f;
  font-weight: bold;
  margin-top: 5px;
}
 
.exceed {
  color: #ff4d4f;
}
 
/* 未超标 */
.status1 {
  font-size: 18px;
  color: #1de01d;
  font-weight: bold;
}
 
.exceed1 {
  color: #1de01d;
}
.blank {
  height: 200px;
}
 
// 按钮
.el-button {
  margin-top: 20px;
}
// 分割线上下距离
.divider-margin {
  margin: 10px 0px;
  border: 1px solid gray;
}
 
.el-input {
  width: calc(100% / 6);
  // margin-left: 70px;
}
 
.save-switch {
  margin-top: 20px;
  margin-left: 20px;
}
:deep() .el-card_body {
  padding: 0px;
  margin: 0px;
}
.horizontal-line {
  position: relative;
  height: 1px;
  margin: 10px 0px;
}
.horizontal-line::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background-color: rgb(221, 217, 217);
}
</style>