hailu
2023-12-17 7bf7f4969afaa8ccc57cb161427b800d7c3f7c2e
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
<template>
    <div style="padding-left:20px;">
        <el-row :gutter="80">
            <el-col :xs="24" :sm="24" :md="24" :lg="10" :xl="10">
                <el-descriptions :column="1" border :title="title">
                    <!-- 设备升级-->
                    <el-descriptions-item :labelStyle="statusColor">
                        <template slot="label">
                            <svg-icon icon-class="ota" />
                            OTA升级
                        </template>
                        <el-link :underline="false" style="line-height:28px;font-size:16px;padding-right:10px;">Version
                            {{ deviceInfo.firmwareVersion }}</el-link>
                        <el-button type="success" size="mini" style="float:right;"
                            @click="getLatestFirmware(deviceInfo.deviceId)"
                            :disabled="deviceInfo.status != 3">检查更新</el-button>
                    </el-descriptions-item>
                    <!-- bool类型-->
                    <el-descriptions-item v-for="(item, index) in deviceInfo.boolList" :key="index"
                        :labelStyle="statusColor">
                        <template slot="label">
                            <i class="el-icon-open"></i>
                            {{ item.name }}
                        </template>
                        <el-switch v-model="item.shadow" @change="publishThingsModel(deviceInfo, item)" active-text=""
                            inactive-text="" active-value="1" inactive-value="0" style="min-width:100px;"
                            :disabled="shadowUnEnable" />
                    </el-descriptions-item>
 
                    <!-- enum类型-->
                    <el-descriptions-item v-for="(item, index) in deviceInfo.enumList" :key="index"
                        :labelStyle="statusColor">
                        <template slot="label">
                            <i class="el-icon-s-unfold"></i>
                            {{ item.name }}
                        </template>
                        <el-select v-model="item.shadow" placeholder="请选择" @change="publishThingsModel(deviceInfo, item)"
                            clearable :disabled="shadowUnEnable">
                            <el-option v-for="subItem in item.enumList" :key="subItem.value" :label="subItem.text"
                                :value="subItem.value" />
                        </el-select>
                    </el-descriptions-item>
 
                    <!-- string类型-->
                    <el-descriptions-item v-for="(item, index) in deviceInfo.stringList" :key="index"
                        :labelStyle="statusColor">
                        <template slot="label">
                            <i class="el-icon-tickets"></i>
                            {{ item.name }}
                        </template>
                        <el-input v-model="item.shadow" placeholder="请输入字符串" :disabled="shadowUnEnable">
                            <el-button slot="append" icon="el-icon-s-promotion"
                                @click="publishThingsModel(deviceInfo, item)" style="font-size:20px;"
                                title="指令发送"></el-button>
                        </el-input>
                    </el-descriptions-item>
 
                    <!-- array类型-->
                    <el-descriptions-item v-for="(item, index) in deviceInfo.arrayList" :key="index"
                        :labelStyle="statusColor">
                        <template slot="label">
                            <i class="el-icon-tickets"></i>
                            {{ item.name }}
                        </template>
                        <el-input v-model="item.shadow" placeholder="请输入英文逗号分隔的字符串" :disabled="shadowUnEnable">
                            <el-button slot="append" icon="el-icon-s-promotion"
                                @click="publishThingsModel(deviceInfo, item)" style="font-size:20px;"
                                title="指令发送"></el-button>
                        </el-input>
                    </el-descriptions-item>
 
                    <!-- decimal类型-->
                    <el-descriptions-item v-for="(item, index) in deviceInfo.decimalList" :key="index"
                        :labelStyle="statusColor">
                        <template slot="label">
                            <i class="el-icon-star-off"></i>
                            {{ item.name }}
                        </template>
                        <el-input v-model="item.shadow" type="number" placeholder="请输入小数 " :disabled="shadowUnEnable">
                            <el-button slot="append" icon="el-icon-s-promotion"
                                @click="publishThingsModel(deviceInfo, item)" style="font-size:20px;"
                                title="指令发送"></el-button>
                        </el-input>
                    </el-descriptions-item>
 
                    <!-- integer类型-->
                    <el-descriptions-item v-for="(item, index) in deviceInfo.integerList" :key="index"
                        :labelStyle="statusColor">
                        <template slot="label">
                            <i class="el-icon-paperclip"></i>
                            {{ item.name }}
                        </template>
                        <el-input v-model="item.shadow" type="integer" placeholder="请输入整数 " :disabled="shadowUnEnable">
                            <el-button slot="append" icon="el-icon-s-promotion"
                                @click="publishThingsModel(deviceInfo, item)" style="font-size:20px;"
                                title="指令发送"></el-button>
                        </el-input>
                    </el-descriptions-item>
                </el-descriptions>
 
                <!-- 监测数据-->
                <el-descriptions :column="2" border style="margin:40px 0;" title="监测数据">
                    <el-descriptions-item v-for="(item, index) in deviceInfo.readOnlyList" :key="index">
                        <template slot="label">
                            <i class="el-icon-odometer"></i>
                            {{ item.name }}
                        </template>
                        <el-link type="primary"  :underline="false"> {{ getShowValue(item) }}</el-link> 
                        <!-- <el-link type="primary" v-if="item.name == '系统状态'" :underline="false">
                            {{ getShowValue(item) }}
                        </el-link>
                        <el-link type="primary" v-else :underline="false">{{ item.shadow }}
                            {{ item.unit == null ? "--" : item.unit }}</el-link> -->
                    </el-descriptions-item>
                </el-descriptions>
 
                <!---设备状态(影子模式,value值不会更新)-->
                <el-descriptions :column="1" border size="mini" v-if="deviceInfo.isShadow == 1 && deviceInfo.status != 3">
                    <template slot="title">
                        <span style="font-size:14px;color:#606266;">设备离线时状态</span>
                    </template>
                    <!-- bool类型-->
                    <el-descriptions-item v-for="(item, index) in deviceInfo.boolList" :key="index">
                        <template slot="label">
                            <i class="el-icon-open"></i>
                            {{ item.name }}
                        </template>
                        <el-switch v-model="item.value" size="mini" active-text="" inactive-text="" active-value="1"
                            inactive-value="0" style="min-width:100px;" disabled />
                    </el-descriptions-item>
 
                    <!-- enum类型-->
                    <el-descriptions-item v-for="(item, index) in deviceInfo.enumList" :key="index">
                        <template slot="label">
                            <i class="el-icon-s-unfold"></i>
                            {{ item.name }}
                        </template>
                        <el-select v-model="item.value" placeholder="请选择" clearable size="mini" disabled>
                            <el-option v-for="subItem in item.enumList" :key="subItem.value" :label="subItem.text"
                                :value="subItem.value" />
                        </el-select>
                    </el-descriptions-item>
 
                    <!-- string类型-->
                    <el-descriptions-item v-for="(item, index) in deviceInfo.stringList" :key="index">
                        <template slot="label">
                            <i class="el-icon-tickets"></i>
                            {{ item.name }}
                        </template>
                        {{ item.value }} {{ item.unit ? item.unit : "" }}
                    </el-descriptions-item>
 
                    <!-- array类型-->
                    <el-descriptions-item v-for="(item, index) in deviceInfo.arrayList" :key="index">
                        <template slot="label">
                            <i class="el-icon-tickets"></i>
                            {{ item.name }}
                        </template>
                        {{ item.value }} {{ item.unit ? item.unit : "" }}
                    </el-descriptions-item>
 
                    <!-- decimal类型-->
                    <el-descriptions-item v-for="(item, index) in deviceInfo.decimalList" :key="index">
                        <template slot="label">
                            <i class="el-icon-star-off"></i>
                            {{ item.name }}
                        </template>
                        {{ item.value }} {{ item.unit ? item.unit : "" }}
                    </el-descriptions-item>
 
                    <!-- integer类型-->
                    <el-descriptions-item v-for="(item, index) in deviceInfo.integerList" :key="index">
                        <template slot="label">
                            <i class="el-icon-paperclip"></i>
                            {{ item.name }}
                        </template>
                        {{ item.value }} {{ item.unit ? item.unit : "" }}
                    </el-descriptions-item>
                </el-descriptions>
            </el-col>
 
            <el-col :xs="24" :sm="24" :md="24" :lg="14" :xl="14" v-if="deviceInfo.readOnlyList.length > 0">
                <el-row :gutter="20"
                    style="background-color:#F5F7FA;padding:20px 20px 10px 10px;border-radius:15px;margin-right:5px;">
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="8" v-for="(item, index) in deviceInfo.readOnlyList"
                        :key="index">
                        <el-card shadow="hover" style="border-radius:30px;margin-bottom:20px;"
                            v-if="item.id == 'SYS_STATUS'">
                            <div style="height: 230px;position: relative;">
                                <div style="text-align:center;font-size:36px;padding-top: 100px;font-weight: 600;">{{
                                    getShowValue(item) }}</div>
                                <div
                                    style="text-align:center;font-size:16px;font-weight: 500;width:100%;position: absolute;bottom: 3px;">
                                    系统状态 </div>
                            </div>
                        </el-card>
                        <el-card shadow="hover" style="border-radius:30px;margin-bottom:20px;" v-else>
                            <div ref="map" style="height:230px;width:180px;margin:0 auto;"></div>
                        </el-card>
                    </el-col>
                </el-row>
            </el-col>
        </el-row>
 
        <!-- 添加或修改产品固件对话框 -->
        <el-dialog title="设备固件升级" :visible.sync="openFirmware" width="600px" append-to-body>
            <div v-if="firmware == null || deviceInfo.firmwareVersion >= firmware.version"
                style="text-align:center;font-size:16px;"><i class="el-icon-success" style="color:#67C23A;"></i>
                已经是最新版本,不需要升级</div>
            <el-descriptions :column="1" border size="large"
                v-if="firmware != null && deviceInfo.firmwareVersion < firmware.version"
                :labelStyle='{ "width": "100px", "font-weight": "bold" }'>
                <template slot="title">
                    <el-link icon="el-icon-success" type="success" :underline="false"> 可以升级到以下版本</el-link>
                </template>
                <el-descriptions-item label="固件名称">{{ firmware.firmwareName }}</el-descriptions-item>
                <el-descriptions-item label="所属产品">{{ firmware.productName }}</el-descriptions-item>
                <el-descriptions-item label="固件版本">Version {{ firmware.version }}</el-descriptions-item>
                <el-descriptions-item label="下载地址">
                    <el-link :href="getDownloadUrl(firmware.filePath)" :underline="false" type="primary">{{
                        getDownloadUrl(firmware.filePath) }}</el-link>
                </el-descriptions-item>
                <el-descriptions-item label="固件描述">{{ firmware.remark }}</el-descriptions-item>
            </el-descriptions>
            <div slot="footer" class="dialog-footer">
                <el-button type="success" @click="otaUpgrade"
                    v-if="firmware != null && deviceInfo.firmwareVersion < firmware.version">升 级</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>
 
<script>
import {
    getDeviceRunningStatus
} from "@/api/iot/device"
import {
    getLatestFirmware,
} from "@/api/iot/firmware";
import {
    cacheJsonThingsModel
} from "@/api/iot/model";
import * as echarts from 'echarts';
 
export default {
    name: "running-status",
    components: {},
    props: {
        device: {
            type: Object,
            default: null
        }
    },
    watch: {
        // 获取到父组件传递的device后,刷新列表
        // device: function (newVal, oldVal) {
        //     console.log('设备运行状态组件接收到新的设备信息:', newVal);
        //     if (newVal && newVal.deviceId != 0) {
        //         getDeviceRunningStatus(newVal.deviceId).then(response => {
        //             this.deviceInfo = response.data;
        //             this.updateDeviceStatus(this.deviceInfo);
        //             this.$nextTick(function () {
        //                 this.MonitorChart();
        //             });
        //         });
        //         this.connectMqtt();
        //     }
        // }
    },
    data() {
        return {
            // 控制模块标题
            title: "设备控制 ",
            // 未启用设备影子
            shadowUnEnable: false,
            // 控制项标题背景
            statusColor: {
                background: '#67C23A',
                color: '#fff',
            },
            // 最新固件信息
            firmware: {},
            // 打开固件对话框
            openFirmware: false,
            // 遮罩层
            loading: true,
            // 设备信息
            deviceInfo: {
                boolList: [],
                enumList: [],
                stringList: [],
                integerList: [],
                decimalList: [],
                arrayList: [],
                readOnlyList: []
            },
            // 监测图表
            monitorChart: [{
                chart: {},
                data: {
                    id: '',
                    name: '',
                    value: ''
                },
            }],
        }
    },
    created() {
    },
    mounted() {
        console.log('设备运行状态组件接收到新的设备信息:', this.device);
        if (this.device && this.device.deviceId != 0) {
            getDeviceRunningStatus(this.device.deviceId).then(response => {
                this.deviceInfo = response.data;
                this.updateDeviceStatus(this.deviceInfo);
                this.$nextTick(function () {
                    this.MonitorChart();
                });
            });
            this.connectMqtt();
        }
    },
    methods: {
        getShowValue(item) {
            if (item.shadow == null || item.shadow == undefined || item.shadow == '') {
                return '暂无数据'
                return false
            }
            for (let i = 0; i < item.enumList.length; i++) {
                if (item.value == item.enumList[i].shadow) {
                    return item.enumList[i].text+item.unit?item.unit:''
                }
            }
        },
        /* 连接Mqtt消息服务器 */
        async connectMqtt() {
            if (this.$mqttTool.client == null) {
                await this.$mqttTool.connect(this.vuex_token);
            }
            this.mqttCallback();
        },
        /* Mqtt回调处理 */
        mqttCallback() {
            this.$mqttTool.client.on('message', (topic, message, buffer) => {
                let topics = topic.split('/');
                let productId = topics[1];
                let deviceNum = topics[2];
                message = JSON.parse(message.toString());
                if (topics[3] == 'status') {
                    console.log('接收到【设备状态-运行】主题:', topic);
                    console.log('接收到【设备状态-运行】内容:', message);
                    // 更新列表中设备的状态
                    if (this.deviceInfo.serialNumber == deviceNum) {
                        this.deviceInfo.status = message.status;
                        this.deviceInfo.isShadow = message.isShadow;
                        this.deviceInfo.rssi = message.rssi;
                        this.updateDeviceStatus(this.deviceInfo);
                    }
                }
                if (topics[3] == 'property' || topics[3] == 'function') {
                    console.log('接收到【物模型】主题:', topic);
                    console.log('接收到【物模型】内容:', message);
                    // 更新列表中设备的属性
                    if (this.deviceInfo.serialNumber == deviceNum) {
                        for (let j = 0; j < message.length; j++) {
                            let isComplete = false;
                            // 布尔类型
                            for (let k = 0; k < this.deviceInfo.boolList.length && !isComplete; k++) {
                                if (this.deviceInfo.boolList[k].id == message[j].id) {
                                    this.deviceInfo.boolList[k].shadow = message[j].value;
                                    isComplete = true;
                                    break;
                                }
                            }
                            // 枚举类型
                            for (let k = 0; k < this.deviceInfo.enumList.length && !isComplete; k++) {
                                if (this.deviceInfo.enumList[k].id == message[j].id) {
                                    this.deviceInfo.enumList[k].shadow = message[j].value;
                                    isComplete = true;
                                    break;
                                }
                            }
                            // 字符串类型
                            for (let k = 0; k < this.deviceInfo.stringList.length && !isComplete; k++) {
                                if (this.deviceInfo.stringList[k].id == message[j].id) {
                                    this.deviceInfo.stringList[k].shadow = message[j].value;
                                    isComplete = true;
                                    break;
                                }
                            }
                            // 数组类型
                            for (let k = 0; k < this.deviceInfo.arrayList.length && !isComplete; k++) {
                                if (this.deviceInfo.arrayList[k].id == message[j].id) {
                                    this.deviceInfo.arrayList[k].shadow = message[j].value;
                                    isComplete = true;
                                    break;
                                }
                            }
                            // 整数类型
                            for (let k = 0; k < this.deviceInfo.integerList.length && !isComplete; k++) {
                                if (this.deviceInfo.integerList[k].id == message[j].id) {
                                    this.deviceInfo.integerList[k].shadow = message[j].value;
                                    isComplete = true;
                                    break;
                                }
                            }
                            // 小数类型
                            for (let k = 0; k < this.deviceInfo.decimalList.length && !isComplete; k++) {
                                if (this.deviceInfo.decimalList[k].id == message[j].id) {
                                    this.deviceInfo.decimalList[k].shadow = message[j].value;
                                    isComplete = true;
                                    break;
                                }
                            }
                            // 监测数据
                            for (let k = 0; k < this.deviceInfo.readOnlyList.length && !isComplete; k++) {
                                if (this.deviceInfo.readOnlyList[k].id == message[j].id) {
                                    this.deviceInfo.readOnlyList[k].shadow = message[j].value;
                                    // 更新图表
                                    for (let m = 0; m < this.monitorChart.length; m++) {
                                        if (message[j].id == this.monitorChart[m].data.id) {
                                            let data = [{
                                                value: message[j].value,
                                                name: this.monitorChart[m].data.name
                                            }];
                                            this.monitorChart[m].chart.setOption({
                                                series: [{
                                                    data: data
                                                }]
                                            });
                                            break;
                                        }
                                    }
                                    isComplete = true;
                                    break;
                                }
                            }
                        }
                    }
                }
            });
        },
        /** 发布物模型 类型(1=属性,2=功能) */
        publishThingsModel(device, model) {
            // 获取缓存的Json物模型
            cacheJsonThingsModel(device.productId).then(response => {
                let thingsModel = JSON.parse(response.data);
                let type = 0;
                for (let i = 0; i < thingsModel.functions.length; i++) {
                    if (model.id == thingsModel.functions[i].id) {
                        type = 2;
                        break;
                    }
                }
                if (type == 0) {
                    for (let i = 0; i < thingsModel.properties.length; i++) {
                        if (model.id == thingsModel.properties[i].id) {
                            type = 1;
                            break;
                        }
                    }
                }
                if (type != 0) {
                    this.mqttPublish(type, device, model);
                }
            });
        },
        /** 
         * Mqtt发布消息
         * @type 类型(1=属性,2=功能,3=OTA升级,4=实时监测)
         * @device 设备
         * @model 物模型
         * */
        mqttPublish(type, device, model) {
            let topic = "";
            let message = ""
            if (type == 1) {
                if (device.status == 3) {
                    // 属性,在线模式
                    topic = "/" + device.productId + "/" + device.serialNumber + "/property-online/get";
                } else if (device.isShadow) {
                    // 属性,离线模式
                    topic = "/" + device.productId + "/" + device.serialNumber + "/property-offline/post";
                }
                message = '[{"id":"' + model.id + '","value":"' + model.shadow + '"}]';
            } else if (type == 2) {
                if (device.status == 3) {
                    // 功能,在线模式
                    topic = "/" + device.productId + "/" + device.serialNumber + "/function-online/get";
 
                } else if (device.isShadow) {
                    // 功能,离线模式
                    topic = "/" + device.productId + "/" + device.serialNumber + "/function-offline/post";
                }
                message = '[{"id":"' + model.id + '","value":"' + model.shadow + '"}]';
            } else if (type == 3) {
                // OTA升级
                topic = "/" + device.productId + "/" + device.serialNumber + "/ota/get";
                message = '{"version":' + this.firmware.version + ',"downloadUrl":"' + this.getDownloadUrl(this.firmware.filePath) + '"}';
            } else {
                return;
            }
            if (topic != "") {
                // 发布
                this.$mqttTool.publish(topic, message, model.name).then(res => {
                    this.$modal.notifySuccess(res);
                }).catch(res => {
                    this.$modal.notifyError(res);
                });
            }
        },
 
        /** 更新设备状态 */
        updateDeviceStatus(device) {
            if (device.status == 3) {
                this.statusColor.background = '#12d09f';
                this.title = "在线模式";
            } else {
                if (device.isShadow == 1) {
                    this.statusColor.background = '#409EFF';
                    this.title = "影子模式";
                } else {
                    this.statusColor.background = '#909399';
                    this.title = "离线模式";
                    this.shadowUnEnable = true;
                }
            }
            this.$emit('statusEvent', this.deviceInfo.status);
        },
        /** 设备升级 */
        otaUpgrade() {
            let model = {};
            model.name = "设备升级"
            this.mqttPublish(3, this.deviceInfo, model);
            this.openFirmware = false;
        },
        /** 获取最新固件 */
        getLatestFirmware(deviceId) {
            getLatestFirmware(deviceId).then(response => {
                this.firmware = response.data;
                this.openFirmware = true;
            });
        },
        // 取消按钮
        cancel() {
            this.openFirmware = false;
        },
        // 获取下载路径前缀
        getDownloadUrl(path) {
            return window.location.origin + process.env.VUE_APP_BASE_API + path;
        },
        /**监测图表统计*/
        MonitorChart() {
            let that = this
            for (let i = 0; i < this.deviceInfo.readOnlyList.length; i++) {
                if (this.deviceInfo.readOnlyList[i].id == "SYS_STATUS") {
                    //跳过当前循环
                    continue;
                } else {
                    this.monitorChart[i] = {
                        chart: echarts.init(this.$refs.map[i - 1]),
                        data: {
                            id: this.deviceInfo.readOnlyList[i].id,
                            name: this.deviceInfo.readOnlyList[i].name,
                            value: this.deviceInfo.readOnlyList[i].shadow
                        }
                    };
                }
                var option;
                option = {
                    tooltip: {
                        formatter: ' {b} <br/> {c}' + this.deviceInfo.readOnlyList[i].unit && this.deviceInfo.readOnlyList[i].shadow != null && this.deviceInfo.readOnlyList[i].shadow != null && this.deviceInfo.readOnlyList[i].shadow != undefined ? this.deviceInfo.readOnlyList[i].unit : ''
                    },
                    series: [{
                        name: this.deviceInfo.readOnlyList[i].type,
                        type: 'gauge',
                        min: this.deviceInfo.readOnlyList[i].min ? this.deviceInfo.readOnlyList[i].min : 0,
                        max: this.deviceInfo.readOnlyList[i].max ? this.deviceInfo.readOnlyList[i].max : 10,
                        colorBy: 'data',
                        splitNumber: 10,
                        radius: '100%',
                        // 分割线
                        splitLine: {
                            distance: 4,
                        },
                        axisLabel: {
                            fontSize: 10,
                            distance: 10
                        },
                        // 刻度线
                        axisTick: {
                            distance: 4,
                        },
                        // 仪表盘轴线
                        axisLine: {
                            lineStyle: {
                                width: 8,
                                color: [
                                    [0.2, '#409EFF'], // 0~20% 
                                    [0.8, '#12d09f'], // 40~60%
                                    [1, '#F56C6C'], // 80~100%
                                ],
                                opacity: 0.3
                            }
 
                        },
                        pointer: {
                            icon: 'triangle',
                            length: '60%',
                            width: 7
                        },
                        progress: {
                            show: true,
                            width: 8,
                        },
                        detail: {
                            valueAnimation: true,
                            formatter: function (value) {
                                console.log(value);
                                if (value||value==0) {
                                    // value 有值,你可以在这里处理 value
                                    return `${value} ${that.deviceInfo.readOnlyList[i].unit?that.deviceInfo.readOnlyList[i].unit:''}`;
                                } else {
                                    return '暂无数据'; // 例如,你可以返回 'N/A'
                                }
                            },
                            offsetCenter: [0, "80%"],
                            fontSize: 20,
                        },
                        data: [{
                            value: this.deviceInfo.readOnlyList[i].shadow,
                            name: this.deviceInfo.readOnlyList[i].name
                        }],
                        title: {
                            offsetCenter: [0, "115%"],
                            fontSize: 16
                        }
                    }]
                };
                console.log(option);
                option && this.monitorChart[i].chart.setOption(option);
            }
        }
    },
}
</script>