userStatistics.vue 6.08 KB
Newer Older
1 2 3 4 5 6
<template>
  <div class="app-container">
    <el-tooltip v-for=" item in deviceListType " :key="item.id" class="item" effect="dark" :content=" '设备分类下总数量' + item.counnum" placement="top">
      <el-button>{{ item.tname }}</el-button>
    </el-tooltip>
    <el-badge :value="devicenum" class="item" type="primary">
冯超鹏's avatar
冯超鹏 committed
7
      <el-button size="small">用户总数</el-button>
8 9 10 11
    </el-badge>
    <el-table :data="countdata" stripe style="width: 100%">
      <el-table-column prop="date" label="姓名" width="180">
        <template slot-scope="scope">
12
          <span>{{ scope.row.name }}</span>
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
        </template>
      </el-table-column>
      <el-table-column prop="name" label="工业探测器" width="170">
        <template slot-scope="scope">
          <span style="margin-left: 10px; color: #13CE66;">{{ scope.row.type_1 }}<span style="color: #878D99;">  个设备</span></span>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="家用报警器" width="170">
        <template slot-scope="scope">
          <span style="margin-left: 10px; color: #13CE66;">{{ scope.row.type_2 }}<span style="color: #878D99;">  个设备</span></span>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="家用报警器(IOT)" width="170">
        <template slot-scope="scope">
          <span style="margin-left: 10px; color: #13CE66;">{{ scope.row.type_4 }}<span style="color: #878D99;">  个设备</span></span>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="压力监测设备" width="170">
        <template slot-scope="scope">
          <span style="margin-left: 10px; color: #13CE66;">{{ scope.row.type_5 }}<span style="color: #878D99;">  个设备</span></span>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="烟雾感应设备" width="170">
        <template slot-scope="scope">
          <span style="margin-left: 10px; color: #13CE66;">{{ scope.row.type_6 }}<span style="color: #878D99;">  个设备</span></span>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="烟雾感应设备(联通)" width="170">
        <template slot-scope="scope">
          <span style="margin-left: 10px; color: #13CE66;">{{ scope.row.type_7 }}<span style="color: #878D99;">  个设备</span></span>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="家用报警器(RTU)" width="170">
        <template slot-scope="scope">
          <span style="margin-left: 10px; color: #13CE66;">{{ scope.row.type_8 }}<span style="color: #878D99;">  个设备</span></span>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="液位探测器" width="170">
        <template slot-scope="scope">
          <span style="margin-left: 10px; color: #13CE66;">{{ scope.row.type_9 }}<span style="color: #878D99;">  个设备</span></span>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="温度变送器" width="170">
        <template slot-scope="scope">
          <span style="margin-left: 10px; color: #13CE66;">{{ scope.row.type_10 }}<span style="color: #878D99;">  个设备</span></span>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="消防报警及联动设备" width="170">
        <template slot-scope="scope">
          <span style="margin-left: 10px; color: #13CE66;">{{ scope.row.type_11 }}<span style="color: #878D99;">  个设备</span></span>
        </template>
      </el-table-column>
    </el-table>
    <el-tooltip placement="top" content="tooltip">
      <back-to-top :custom-style="myBackToTopStyle" :visibility-height="300" :back-position="50" transition-name="fade" />
    </el-tooltip>
  </div>
</template>

<script>
import { deviceTypeList } from '@/api/device';
冯超鹏's avatar
冯超鹏 committed
74
import websocketurl from '@/api/configurl';
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
import BackToTop from '@/components/BackToTop';
export default {
  components: { BackToTop },
  data() {
    return {
      deviceListType: [], // 设备分类
      countdata: [],
      websock: null,
      devicenum: undefined,
      type: {
        token: undefined,
        id: '1',
      },
      timer: undefined,
      myBackToTopStyle: {
        right: '50px',
        bottom: '50px',
        width: '40px',
        height: '40px',
        'border-radius': '4px',
        'line-height': '45px', // Please keep consistent with height to center vertically
        background: '#e7eaf1', // The background color of the button
      },
    };
  },
  created() {
    this.getList();// 设备分类
    this.initWebSocket();
  },
  destroyed() {
    this.websock.close(); // 离开路由之后断开websocket连接
  },
  methods: {
    getList() {
      deviceTypeList()
        .then(response => {
          var devicetype = response.data;
          this.deviceListType = devicetype['devicetype'];
        })
        .catch(err => {
          console.log(err);
        });
    },
    initWebSocket(){ // 初始化weosocket
冯超鹏's avatar
冯超鹏 committed
119
      const wsuri = websocketurl.baseURL;
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
      this.websock = new WebSocket(wsuri);
      this.websock.onmessage = this.websocketonmessage;
      this.websock.onopen = this.websocketonopen;
      this.websock.onerror = this.websocketonerror;
      this.websock.onclose = this.websocketclose;
    },
    websocketonopen(){ // 连接建立之后执行send方法发送数据
      console.log('连接成功');
    },
    websocketonerror(){ // 连接建立失败重连
      this.$notify({
        title: '警告',
        message: '建立链接失败,正在重连',
        type: 'warning',
      });
      this.initWebSocket();
    },
    websocketonmessage(e){ // 数据接收
      const redata = JSON.parse(e.data);
      this.countdata = redata.data.userdata;
      this.devicenum = redata.data.usercount;
    },
    websocketsend(){ // 数据发送
      this.websock.send(JSON.stringify(this.type));
    },
    websocketclose(e){ // 关闭
      console.log('断开连接', e);
      this.$notify({
        title: '警告',
冯超鹏's avatar
冯超鹏 committed
149
        message: '用户统计长连接已断开',
150 151 152 153 154 155 156 157 158
        type: 'warning',
      });
    },
  },
};
</script>

<style>
</style>