chemicals.vue 8.5 KB
Newer Older
Administrator's avatar
Administrator committed
1
<template>
冯超鹏's avatar
冯超鹏 committed
2
  <div class="app-container">
Administrator's avatar
Administrator committed
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
    <el-form :inline="true" :model="formSearch" class="demo-form-inline">
      <el-form-item label="设备编号">
        <el-input v-model="formSearch.deviceNum" placeholder="输入完整设备编号"></el-input>
      </el-form-item>
      <el-form-item label="设备名称">
        <el-input v-model="formSearch.deviceName" placeholder="设备名称"></el-input>
      </el-form-item>
      <el-form-item label="设备类型">
        <el-select
          v-model="formSearch.deviceType"
          style="margin-left: 20px;"
          placeholder="请选择"
        >
          <el-option
            v-for="item in optionTypes"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="状态">
        <el-select
          v-model="formSearch.deviceStatus"
          style="margin-left: 20px;"
          placeholder="请选择"
        >
          <el-option
            v-for="item in optionStatus"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>
冯超鹏's avatar
冯超鹏 committed
44
    <el-table :key="tableKey" v-loading="loading" :data="device" border fit highlight-current-rows>
Administrator's avatar
Administrator committed
45
      <el-table-column align="center" label="ID" width="80">
冯超鹏's avatar
冯超鹏 committed
46 47 48 49 50 51 52 53 54
        <template slot-scope="scope">
          <span>{{ scope.row.id }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="设备编号" width="150">
        <template slot-scope="scope">
          <span @click="handleCopy(scope.row.devicenum,$event)">{{ scope.row.devicenum }}</span>
        </template>
      </el-table-column>
Administrator's avatar
Administrator committed
55
      <el-table-column align="center" label="设备名称" width="200">
冯超鹏's avatar
冯超鹏 committed
56 57 58 59
        <template slot-scope="scope">
          <span>{{ scope.row.username }}</span>
        </template>
      </el-table-column>
Administrator's avatar
Administrator committed
60
      <el-table-column align="center" label="设备详情">
冯超鹏's avatar
冯超鹏 committed
61
        <template slot-scope="scope">
Administrator's avatar
Administrator committed
62
          <span>{{ scope.row.deviceinfo }}</span>
冯超鹏's avatar
冯超鹏 committed
63 64
        </template>
      </el-table-column>
Administrator's avatar
Administrator committed
65
      <el-table-column align="center" label="设备类型" width="150">
冯超鹏's avatar
冯超鹏 committed
66
        <template slot-scope="scope">
Administrator's avatar
Administrator committed
67
          <span>{{ scope.row.tname }}</span>
冯超鹏's avatar
冯超鹏 committed
68 69
        </template>
      </el-table-column>
Administrator's avatar
Administrator committed
70
      <el-table-column align="center" label="检测介质" width="170">
冯超鹏's avatar
冯超鹏 committed
71
        <template slot-scope="scope">
Administrator's avatar
Administrator committed
72
          <span>{{ scope.row.gas }}</span>
冯超鹏's avatar
冯超鹏 committed
73 74
        </template>
      </el-table-column>
Administrator's avatar
Administrator committed
75
      <el-table-column align="center" label="检测值" width="100">
冯超鹏's avatar
冯超鹏 committed
76
        <template slot-scope="scope">
Administrator's avatar
Administrator committed
77
          <span>{{ scope.row.nd }}</span>
冯超鹏's avatar
冯超鹏 committed
78 79
        </template>
      </el-table-column>
Administrator's avatar
Administrator committed
80
      <el-table-column align="center" label="单位" width="100">
冯超鹏's avatar
冯超鹏 committed
81
        <template slot-scope="scope">
Administrator's avatar
Administrator committed
82
          <span>{{ scope.row.danwei }}</span>
冯超鹏's avatar
冯超鹏 committed
83 84
        </template>
      </el-table-column>
Administrator's avatar
Administrator committed
85
      <el-table-column align="center" label="实时状态" width="120">
冯超鹏's avatar
冯超鹏 committed
86 87 88 89 90 91
        <template slot-scope="scope">
          <span>
            <el-tag :type=" scope.row.status_name=='正常' ? 'success' : 'warning' " effect="dark">{{ scope.row.status_name }}</el-tag>
          </span>
        </template>
      </el-table-column>
Administrator's avatar
Administrator committed
92
      <el-table-column align="center" label="状态" width="70">
冯超鹏's avatar
冯超鹏 committed
93
        <template slot-scope="scope">
Administrator's avatar
Administrator committed
94 95
          <span v-if="scope.row.status_name=='正常' " :style="{color:( scope.row.devicestatus==1 ? '#67C23A' : '#F56C6C' )}">{{ scope.row.devicestatus==1 ? '正常' : '错误' }}</span>
          <span v-if="scope.row.status_name!='正常' " :style="{color:( scope.row.status_name=='正常' ? '#67C23A' : '#F56C6C' )}">{{ scope.row.status_name=='正常' ? '正常' : '异常' }}</span>
冯超鹏's avatar
冯超鹏 committed
96 97
        </template>
      </el-table-column>
Administrator's avatar
Administrator committed
98 99
      <el-table-column align="center" label="最后更新时间" width="170">
        <template slot-scope="scope">
Administrator's avatar
Administrator committed
100
          <span v-if="scope.row.update_time > 0">{{ scope.row.update_time | parseTime('{y}-{m}-{d} {h}:{i}:{s}') }}</span>
Administrator's avatar
Administrator committed
101 102
        </template>
      </el-table-column>
冯超鹏's avatar
冯超鹏 committed
103
    </el-table>
Administrator's avatar
Administrator committed
104 105 106 107 108 109 110 111
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="formSearch.page"
      :limit.sync="formSearch.limit"
      :page-sizes="[10,30,80]"
      @pagination="devicelist"
    />
冯超鹏's avatar
冯超鹏 committed
112
  </div>
Administrator's avatar
Administrator committed
113 114 115
</template>

<script>
冯超鹏's avatar
冯超鹏 committed
116 117
import { control } from '@/api/device';
import Pagination from '@/components/Pagination'; // 分页
118
import websocketurl from '@/api/configurl';
冯超鹏's avatar
冯超鹏 committed
119 120 121 122 123 124 125 126 127 128 129 130
import clip from '@/utils/clipboard';
export default {
  name: 'Devicetype',
  components: { Pagination },
  data() {
    return {
      tableKey: 0,
      loading: true,
      device: [],
      type: 2,
      total: 0,
      paper: undefined,
冯超鹏's avatar
冯超鹏 committed
131
      timer: '',
Administrator's avatar
Administrator committed
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
      formSearch: {
        deviceNum: '',
        deviceName: '',
        deviceType: 0,
        deviceStatus: 0,
        userId: 0,
        page: 1,
        limit: 10,
      },
      optionStatus: [{
        value: 0,
        label: '全部',
      }, {
        value: 1,
        label: '正常',
      }, {
        value: 2,
        label: '错误',
      }, {
        value: 3,
        label: '传感器故障',
      }, {
        value: 4,
        label: '报警',
      }, {
        value: 5,
        label: '低报',
      }, {
        value: 6,
        label: '高报',
      }, {
        value: 7,
        label: '通信故障',
      }, {
        value: 8,
        label: '超量程',
      }, {
        value: 9,
        label: '离线',
      }, {
        value: 10,
        label: '电量低',
      }, {
        value: 11,
        label: '主电故障',
      }, {
        value: 12,
        label: '备电故障',
      }, {
        value: 13,
        label: '无此节点',
      }, {
        value: 14,
        label: '低电压',
      }, {
        value: 15,
        label: '故障',
      }, {
        value: 16,
        label: '报警联动',
      }],
      optionTypes: [{
        value: 0,
        label: '全部',
      }, {
        value: 1,
        label: '工业探测器',
      }, {
        value: 5,
        label: '压力监测设备',
      }, {
        value: 10,
        label: '温度变送器',
      }],
冯超鹏's avatar
冯超鹏 committed
206 207 208 209
    };
  },
  created() {
    this.devicelist(); // 设备状态
210
    this.initWebSocket();
冯超鹏's avatar
冯超鹏 committed
211 212 213
  },

  methods: {
Administrator's avatar
Administrator committed
214 215 216 217
    onSubmit() {
      this.formSearch.page = 1;
      this.devicelist();
    },
冯超鹏's avatar
冯超鹏 committed
218
    devicelist() {
Administrator's avatar
Administrator committed
219 220
      const limit = this.formSearch.limit;
      const page = this.formSearch.page;
冯超鹏's avatar
冯超鹏 committed
221
      this.loading = true;
Administrator's avatar
Administrator committed
222
      control(page, limit, this.type, this.formSearch)
冯超鹏's avatar
冯超鹏 committed
223 224 225 226 227 228 229 230 231 232 233 234 235
        .then(response => {
          var devicetype = response.data['devicelist'];
          this.device = devicetype;
          this.device.forEach((element, index) => {
            element['index'] = (page - 1) * limit + index + 1;
          });
          this.total = response.data.count;
          this.loading = false;
        })
        .catch(err => {
          console.log(err);
        });
    },
236 237 238 239 240 241 242 243 244
    initWebSocket(){ // 初始化weosocket
      const wsuri = websocketurl.chemicalsUrl;
      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方法发送数据
冯超鹏's avatar
冯超鹏 committed
245 246 247
      this.timer = setInterval(() => {
        this.websocketsend();
      }, 5000);
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
    },
    websocketonerror(){ // 连接建立失败重连
      this.$notify({
        title: '警告',
        message: '建立链接失败,正在重连',
        type: 'warning',
      });
      this.initWebSocket();
    },
    websocketonmessage(e){ // 数据接收
      const redata = JSON.parse(e.data);
      this.device = redata.data.devicelist;
      this.total = redata.data.count;
    },
    websocketsend(){ // 数据发送
Administrator's avatar
Administrator committed
263 264
      this.formSearch.userId = localStorage.getItem('userinfoid');
      this.websock.send(JSON.stringify(this.formSearch));
265 266 267 268 269
    },
    websocketclose(e){ // 关闭
      console.log('断开连接', e);
      this.$notify({
        title: '警告',
冯超鹏's avatar
冯超鹏 committed
270
        message: '危化监测长连接已断开',
271 272
        type: 'warning',
      });
冯超鹏's avatar
冯超鹏 committed
273
      clearInterval(this.timer);
274
    },
冯超鹏's avatar
冯超鹏 committed
275 276 277 278 279 280 281 282 283 284 285 286
    handleClick(tab) {
      this.type = tab.$attrs.tid;
      this.devicelist();
    },
    handleCopy(text, event) {
      clip(text, event);
    },
    handleCopyphone(text, event){
      clip(text, event);
    },
  },
};
Administrator's avatar
Administrator committed
287 288 289 290
</script>

<style>
</style>