zmc
2023-07-11 77a108bd860c737449b46809f6e8a4e1242e5e3b
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
<!-- 自动从接口获取数据 生成仪表盘 -->
 
<script lang="ts">
import axios from 'axios';
import * as echarts from 'echarts';
 
export default {
  data() {
    return {
      loading:false,
      smogData: [
        // {
        //     "time": "2023-06-24 13:23",
        //     "value": 0.04,
        //     "mnCode": "31011020175002"
        // },
        // {
        //     "time": "2023-06-24 00:42",
        //     "value": 0.04,
        //     "mnCode": "31011020175004"
        // },
        // {
        //     "time": "2023-05-24 20:39",
        //     "value": 0.06,
        //     "mnCode": "31011020175008"
        // },
        // {
        //     "time": "2023-06-24 13:38",
        //     "value": 0.66,
        //     "mnCode": "64480047078091"
        // },
        // {
        //     "time": "2023-05-24 20:39",
        //     "value": 0.8,
        //     "mnCode": "31011020175006"
        // },
        // {
        //     "time": "2023-06-24 13:38",
        //     "value": 0.69,
        //     "mnCode": "64480047078099"
        // },
        // {
        //     "time": "2023-05-24 20:39",
        //     "value": 0.8,
        //     "mnCode": "31011020175026"
        // },
        
    ],//从后端放回的值
      chartData: [], //从图像返回的值
    };
  },
  mounted() {
      this.loading = true
       //自动获取接口全部数据
      axios.get('https://fyami.com.cn/device/min/value/real_time', { params: { "page": 1, "per_page": 20 } }).then((result) => {
      this.smogData = result.data.data
      console.log(this.smogData);
      this.loading = false
    });
   
   
  },
 
  methods: {
  showMore(){
    this.smogData.forEach((device) => {
        const chartDom = document.querySelector(`#chart-${device.mnCode}`) //根据选择器获取元素,并且只返回元素中的第一个
        const chart = echarts.init(chartDom)
 
        this.chartData = {
        value: device.value,
        axisLabel: {
          show: true,
          textStyle: {
            color: '#666'
          },
          formatter: function (value) {
            return value;
          }
        },
        detail: {
          formatter: function (value) {
            return value + 'mg/m³';
          },
          textStyle: {
            fontSize: 10,
            fontWeight: 'bold'
          },
          offsetCenter: [0, '30%']
        },
        title: {
          show: true,
          text: '设备油烟浓度',
          textStyle: {
            color: '#999',
            fontSize: 14
          },
          offsetCenter: [0, '-30%']
        },
        axisLine: {
          lineStyle: {
            width: 10,
            color: [
              [0.2, '#67e0e3'],
              [0.8, '#37a2da'],
              [1, '#fd666d']
            ]
          }
        },
        splitLine: {
          show: true,
          length: 10,
          lineStyle: {
            color: 'auto',
          }
        },
        axisTick: {
          show: true,
          length: 15,
          lineStyle: {
            color: 'auto',
          }
        }
      };
        
        chart.setOption({
          tooltip: {
          formatter: '{a}: <br/> {c}mg/m³'
        },
        series: [
          {
            name: '油烟浓度',
            type: 'gauge',
            min: 0,
            max: 2,
            splitNumber: 10,
            axisLabel: this.chartData.axisLabel,
            detail: this.chartData.detail,
            data: [{ value: this.chartData.value, name: '' }],
            title: this.chartData.title,
            axisLine: this.chartData.axisLine,
            splitLine: this.chartData.splitLine,
            axisTick: this.chartData.axisTick
          }
        ]
      });
      })
  }
 
    },
  }
</script>
 
<template>
  <div style="margin: 5px;">
    <span style="color: #b1b3b8;" >实时数据</span>
  </div>
 
  <hr style="margin-top: 10px;"/>
 
  <div >
    <el-button @click="showMore" style="margin-top: 20px;margin-left: 20px">展示</el-button>
    
  </div>
  <div v-loading="loading" > 
    <!-- 根据设备编号个数动态生成仪表盘 -->
    <el-row :gutter="20">
      <el-col :span="12" v-for="device in smogData" :key="device.mnCode">
        <div class="chart-container">
          <div class="chart-title">设备{{ device.mnCode }}</div>
          <div class="chart-content">
            <div :id="'chart-' + device.mnCode" class="chartClass"></div>
          </div>
          <div>
            <span>浓度值为:{{ device.value }}</span>
            <br/>
            产生时间:{{ device.time}}
          </div>
        </div>
        <!-- <br v-if="index % 4 == 0"/> -->
      </el-col>
    </el-row>
  </div>
</template>
 
 
 
 
<style lang="scss" scoped>
.chart-container {
  background-color: #f9f9f9;
  padding: 20px;
  border-radius: 4px;
}
 
.chart-title {
  font-size: 16px;
  font-weight: 600;
}
 
.chart-content {
  margin-top: 10px;
}
 
.chartClass {
  height: 300px;
}
</style>