suerprisePlus
2024-05-30 d4c810f9803aa13d806724a5f4f71fe85abac38e
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
<template>
  <div style="padding-top: 10px">
    <dv-capsule-chart :config="config" style="width: 430px; height: 230px" />
  </div>
</template>
 
<script>
import { statisticNettyMqtt } from '@/api/iot/netty';
export default {
  data() {
    return {
      // emqx统计信息
      static: {},
      config: {},
      timer: null,
      mqtt: this.$store.state.user.mqtt,
    };
  },
  created() {
    this.statisticMqtt();
  },
 
  mounted() {},
  beforeDestroy() {
    this.clearData();
  },
  methods: {
    /** 查询mqtt统计*/
    statisticMqtt() {
      if (this.mqtt) {
        statisticNettyMqtt().then((response) => {
          this.static = response.data;
          this.config = {
            data: [
              {
                name: '今日接收',
                value: this.static['today_received'],
              },
              {
                name: '今日发送',
                value: this.static['today_send'],
              },
              {
                name: '订阅总数',
                value: this.static['subscribe_total'],
              },
              {
                name: '发布消息',
                value: this.static['send_total'],
              },
              {
                name: '接收消息',
                value: this.static['receive_total'],
              },
              {
                name: '认证次数',
                value: this.static['auth_total'],
              },
              {
                name: '认证成功',
                value: this.static['auth_total'],
              },
            ],
            unit: '次数',
            showValue: true,
          };
          this.switper();
        });
      } else {
        this.config = {
          data: [
            {
              name: '今日接收',
              value: 6000,
            },
            {
              name: '今日发送',
              value: 5000,
            },
            {
              name: '订阅总数',
              value: 4000,
            },
            {
              name: '发布消息',
              value: 3000,
            },
            {
              name: '接收消息',
              value: 2000,
            },
            {
              name: '认证次数',
              value: 1000,
            },
            {
              name: '认证成功',
              value: 1000,
            },
          ],
          unit: '次数',
          showValue: true,
        };
        this.switper();
      }
    },
    clearData() {
      if (this.timer) {
        clearInterval(this.timer);
        this.timer = null;
      }
    },
    //轮询
    switper() {
      if (this.timer) {
        return;
      }
      let looper = (a) => {
        this.statisticMqtt();
      };
      this.timer = setInterval(looper, 60000);
    },
  },
};
</script>