licp
2024-05-13 7b5549dd6115d42eda331916fdb38ac806169c9b
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
<template>
  <div>
    <basic-container>
      <el-form label-width="100px" :inline="true">
        <el-form-item label="设备:" required>
          <el-select
            v-model="deviceId"
            placeholder="请选择"
            @change="getMqttLists"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.name"
              :value="item.device_id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="时间:">
          <el-radio-group
            v-model="checkboxGroup3"
            size="small"
            @change="destroyTimerAgainStart"
          >
            <el-radio-button v-for="city in cities" :label="city" :key="city">{{
              city
            }}</el-radio-button>
          </el-radio-group>
        </el-form-item>
      </el-form>
    </basic-container>
    <basic-container>
      <div
        v-if="!largeAreaChartList.length > 0"
        style="height: 75vh; padding-top: 0.4em; display: flex; align-items: center; justify-content: center;"
      >
        暂无数据
      </div>
      <el-row>
        <el-col
          v-for="(v, k) in largeAreaChartList"
          :key="k"
          style="height: 40vh; padding-top: 0.4em;"
          :span="12"
          ><largeAreaChart
            ref="largeAreaChartRef"
            v-if="largeAreaChartList.length > 0"
            :key="k"
            :yAxisMonth="v.yAxisMonth"
            :seriesData="v.listData"
            :otherData="v"
          />
        </el-col>
      </el-row>
    </basic-container>
  </div>
</template>
 
<script>
import largeAreaChart from './components/largeAreaChart.vue'
import { getDeviceId, mqttList } from '@/api/equipment/equipment'
 
export default {
  components: {
    largeAreaChart: largeAreaChart
  },
  data() {
    return {
      largeAreaChartList: [],
      cities: ['1 分钟', '3 分钟', '5 分钟', '10 分钟'],
      checkboxGroup3: '1 分钟',
      options: [],
      deviceId: '',
      timer: ''
    }
  },
  async created() {
    await this.getDeviceIdFun()
    this.getMqttLists()
  },
  mounted() {
    this.destroyTimerAgainStart()
  },
  beforeDestroy() {
    console.log(`output->销毁了定时器`)
    clearInterval(this.timer)
  },
  methods: {
    async getDeviceIdFun() {
      await getDeviceId().then((res) => {
        this.options = res.data.data
        this.deviceId = this.options[0].device_id
      })
    },
    async getMqttLists() {
      const obj = Object.assign({
        deviceId: this.deviceId,
        collectionTime: this.checkboxGroup3.split(' ')[0]
      })
      this.largeAreaChartList = []
      await mqttList(obj).then((res) => {
        let data = res.data.data
        data.forEach((i) => {
          i.listData = []
          i.yAxisMonth = []
          if (i.listMqttTableData.length > 0) {
            i.deviceId = i.listMqttTableData[0].deviceId
          }
          i.listMqttTableData.forEach((j) => {
            i.listData.push(j.value)
            i.yAxisMonth.push(j.collectionTime)
          })
          i.listMqttTableData = []
        })
        this.largeAreaChartList = data
      })
    },
    destroyTimerAgainStart() {
      clearInterval(this.timer)
      this.timer = setInterval(
        this.getMqttLists,
        1000 * 60 * this.checkboxGroup3.split(' ')[0]
      )
    }
  }
}
</script>
 
<style></style>