cuikaidong
2025-06-12 64931370717723655d4ecec4802dcdc54ec015f5
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
<template>
  <a-spin :spinning='load' tip='加载中...'>
    <a-card :bordered='false'>
      <!-- 查询区域 -->
      <div class='table-page-search-wrapper'>
        <a-form layout='inline' @keyup.enter.native='searchQuery'>
          <a-row :gutter='24'>
            <a-col :md='6' :sm='8'>
              <a-form-item label='终端编号'>
                <a-input placeholder='请输入终端编号' v-model='queryParam.serverCode'></a-input>
              </a-form-item>
            </a-col>
            <a-col :md='6' :sm='8'>
              <a-form-item label='终端名称'>
                <a-input placeholder='请输入终端名称' v-model='queryParam.serverName'></a-input>
              </a-form-item>
            </a-col>
            <a-col :span='8'>
            <span style='float: left;overflow: hidden;' class='table-page-search-submitButtons'>
              <a-button type='primary' @click='searchQuery' icon='search'>查询</a-button>
              <a-button type='primary' @click='searchReset' icon='reload' style='margin-left: 8px'>重置</a-button>
              <a-button @click='handleAdd' type='primary' icon='plus' style='margin-left: 8px'>新增</a-button>
            </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <div>
        <a-table
          class='j-table-force-nowrap'
          ref='table'
          size='small'
          bordered
          rowKey='id'
          :columns='columns'
          :dataSource='dataSource'
          :pagination='ipagination'
          :loading='loading'
          :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type:'radio'}"
          :customRow='clickThenSelect'
          @change='handleTableChange'
        >
          <!--状态渲染模板-->
          <span slot='guardState' slot-scope='guardState'>
            <a-badge v-if='guardState===0' status='error' />
            <a-badge v-if='guardState===1' status='success' />
            <span v-if='guardState===1'>已连接</span>
            <span v-if='guardState===0'>未连接</span>
          </span>
          <template slot='customRenderStatus' slot-scope='collectState'>
            <a-tag v-if='collectState===1' color='green'>运行</a-tag>
            <a-tag v-if='collectState===0' color='orange'>停止</a-tag>
          </template>
 
          <span slot='action' slot-scope='text, record'>
          <span v-if='record.collectState == 0'>
            <a @click='collectPut(record)'>启动</a>
          </span>
          <span v-else>
            <a @click='collectPut(record)'>停止</a>
          </span>
          <a-divider type='vertical' />
            <a @click='addDeploy(record)'>下发配置</a>
          <a-divider type='vertical' />
             <a href='javascript:;' @click='collectData(record)'>实时数据</a>
          <a-divider type='vertical' />
          <a-dropdown>
            <a class='ant-dropdown-link'>
              更多 <a-icon type='down' />
            </a>
            <a-menu slot='overlay'>
              <a-menu-item>
<!--                <a href='javascript:;' >编辑</a>-->
                <a :href="record.address" target="_blank">采集终端</a>
              </a-menu-item>
              <a-menu-item>
                <a href='javascript:;' @click='handleEdit(record)'>编辑</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title='确定删除吗?' @confirm='() => handleDelete(record.id)'>
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
              <a-menu-item>
                 <a href='javascript:;' @click='handleLog(record)'>获取日志</a>
              </a-menu-item>
              <a-menu-item>
                <a href='javascript:;' @click='handleInflux(record)'>InfluxDB配置</a>
              </a-menu-item>
              <a-menu-item>
                <a href='javascript:;' @click='handleMqtt(record)'>MQTT配置</a>
              </a-menu-item>
              <a-menu-item>
                <a href='javascript:;' @click='handleCollect(record)'>更新采集软件</a>
              </a-menu-item>
              <a-menu-item>
                <a href='javascript:;' @click='handleAuthorize(record)'>授权</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
        </a-table>
      </div>
      <!-- table区域-end -->
 
      <!-- 表单区域 -->
      <unit-model ref='modalForm' @ok='modalFormOk' :project-classify='projectClassify' />
      <log-model ref='logModalForm' @ok='modalFormOk' />
      <influx-model ref='influxModalForm' @ok='modalFormOk' />
      <mqtt-model ref='mqttModalForm' @ok='modalFormOk' />
      <authorize-model ref='authorizeModalForm' @ok='modalFormOk' />
      <collect-model ref='collectModalForm' @ok='modalFormOk' />
      <!-- 实时数据 -->
      <parameter-address ref='modalAddress' @ok='modalFormOk' :server-id='serverId' />
    </a-card>
  </a-spin>
</template>
 
<script>
import ParameterAddress from '../collectData/ParameterAddress'
import AuthorizeModel from './modules/AuthorizeModel'
import CollectModel from './modules/CollectModel'
import MqttModel from './modules/MqttModel'
import UnitModel from './modules/ServerModel'
import LogModel from './modules/ObtainLogModel'
import InfluxModel from './modules/InfluxDBModel'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JDictSelectTag from '@/components/dict/JDictSelectTag'
import JInput from '@/components/jeecg/JInput'
import JEllipsis from '@/components/jeecg/JEllipsis'
import { getAction, httpAction } from '@/api/manage'
import store from '@/store/'
 
export default {
  name: 'MonthExamineManager',
  mixins: [JeecgListMixin],
  components: {
    ParameterAddress,
    CollectModel,
    AuthorizeModel,
    MqttModel,
    InfluxModel,
    UnitModel,
    LogModel,
    JDictSelectTag,
    JInput,
    JEllipsis
  },
  data() {
    return {
      serverId: '',
      projectClassify: this.projectId,
      columns: [
        {
          title: '',
          dataIndex: '',
          key: 'rowIndex',
          width: 40,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '终端编号',
          align: 'center',
          dataIndex: 'serverCode',
          width: 60
        },
        {
          title: '终端名称',
          align: 'center',
          dataIndex: 'serverName',
          width: 130
        },
        {
          title: '终端地址',
          align: 'center',
          dataIndex: 'serverAddress',
          width: 100
        },
        {
          title: '终端状态',
          align: 'center',
          dataIndex: 'guardState',
          width: 65,
          scopedSlots: { customRender: 'guardState' }
        },
        {
          title: '采集状态',
          align: 'center',
          dataIndex: 'collectState',
          width: 65,
          scopedSlots: { customRender: 'customRenderStatus' },
          filterMultiple: false
        },
        {
          title: '采集版本号',
          align: 'center',
          dataIndex: 'collectVersion',
          width: 80
        },
        {
          title: '配置版本号',
          align: 'center',
          dataIndex: 'deployVersion',
          width: 135
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: 260,
          scopedSlots: { customRender: 'action' }
        }
      ],
      load: false,
      url: {
        list: '/serve/deploy/list',
        put: '/serve/deploy/collect/put',
        deploy: '/serve/deploy/deploy/document',
        delete: '/serve/deploy/delete'
      }
    }
  },
  props: ['projectId', 'tree'],
  mounted() {
    this.initWebSocket()
  },
  watch: {
    projectId: {
      handler(newVal, oldVal) {
        this.loadData()
        this.projectClassify = newVal
      }
    }
  },
  beforeDestroy() {
    // 离开页面生命周期函数
    this.websock.close()
    console.log('WebSocket关闭连接成功')
  },
  methods: {
    collectData(record) {
      this.serverId = record.id
      this.$refs.modalAddress.openMqtt()
    },
    initWebSocket: function() {
      // WebSocket与普通的请求所用协议有所不同,ws等同于http,wss等同于https
      var userId = store.getters.userInfo.id
      var url = window._CONFIG['domianURL'].replace('https://', 'wss://').replace('http://', 'ws://') + '/websocket/' + userId
      this.websock = new WebSocket(url)
      this.websock.onopen = this.websocketOnopen
      this.websock.onerror = this.websocketOnerror
      this.websock.onmessage = this.websocketOnmessage
      this.websock.onclose = this.websocketOnclose
    },
    websocketOnopen: function() {
      console.log('WebSocket连接成功')
    },
    websocketOnerror: function(e) {
      console.log('WebSocket连接发生错误')
      this.reconnect()
    },
    websocketOnmessage: function(e) {
      const that = this
      console.log('-----接收消息-------', e.data)
      var data = eval('(' + e.data + ')') //解析对象
      // 日志
      if (data.cmd == 'log') {
        //系统通知
        this.$refs.logModalForm.websocket(data)
      } else if (data.cmd == 'start') {
        this.load = false
        if (data.state == '1') {
          that.$message.success(data.message)
          this.loadData()
          // that.$emit('ok', res.result)
        } else if (data.state == '0') {
          that.$message.warning(data.message)
        }
      } else if (data.cmd == 'collect') {
        this.dataSource.forEach(item => {
          if (item.serverCode == data.id) {
            if (data.message1 != null) {
              item.guardState = data.message1
            } else {
              item.collectState = parseInt(data.message)
            }
          }
        })
      } else if (data.cmd == 'version') {
        this.dataSource.forEach(item => {
          if (item.serverCode == data.id) {
            if (data.state !== 'null' && data.state != null) {
              if (item.latestCollectVersion == null) {
                item.collectVersion = '空/' + data.state
              } else {
                item.collectVersion = item.latestCollectVersion + '/' + data.state
              }
            }
            if (data.message !== 'null' && data.message != null) {
              if (item.latestDeployVersion == null) {
                item.deployVersion = '空/' + data.message
              } else {
                item.deployVersion = item.latestDeployVersion + '/' + data.message
              }
            }
          }
        })
      }
    },
    // 查询终端列表
    loadData(arg) {
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      this.onClearSelected()
      var params = this.getQueryParams()//查询条件
      params.projectClassifyId = this.projectId
      this.loading = true
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          this.dataSource = res.result.records
          this.ipagination.total = res.result.total
          if (res.result.records.length > 0) {
            this.selectedRowKeys[0] = this.dataSource[0].id
          }
          this.dataSource.forEach(item => {
            let collectVersion = ''
            if (item.latestCollectVersion == null || item.latestCollectVersion == '') {
              collectVersion = '空'
            } else {
              collectVersion = item.latestCollectVersion
            }
            collectVersion += '/'
            if (item.newCollectVersion == null || item.guardState == 0) {
              collectVersion += '空'
            } else {
              collectVersion += item.newCollectVersion
            }
            // 采集软件
            item.collectVersion = collectVersion
            // 配置文件
            let deployVersion = ''
            if (item.latestDeployVersion == null || item.latestDeployVersion == '') {
              deployVersion = '空'
            } else {
              deployVersion = item.latestDeployVersion
            }
            deployVersion += '/'
            if (item.newDeployVersion == null || item.guardState == 0) {
              deployVersion += '空'
            } else {
              deployVersion += item.newDeployVersion
            }
            item.deployVersion = deployVersion
          })
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
        this.loading = false
      })
 
    },
    clickThenSelect(record) {
      return {
        on: {
          click: () => {
            this.onSelectChange(record.id.split(','), [record])
          }
        }
      }
    },
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },
    modalFormOk(val) {
      // 调用父组件方法
      this.$emit('tree')
      // 新增/修改 成功时,重载列表
      this.loadData()
      this.selectedRowKeys = [val.id]
    },
    searchQuery() {
      this.loadData()
      this.onClearSelected()
    },
    searchReset() {
      this.queryParam = {}
      this.loadData()
      this.onClearSelected()
    },
    handleEdit(record) {
      this.$refs.modalForm.edit(record)
      this.$refs.modalForm.title = '编辑'
      this.$refs.modalForm.disableSubmit = false
    },
    handleLog(record) {
      if (record.guardState == 0) {
        this.$message.warning('终端未连接!')
      } else {
        this.$refs.logModalForm.edit(record)
      }
    },
    handleInflux(record) {
      this.$refs.influxModalForm.edit(record)
    },
    handleMqtt(record) {
      this.$refs.mqttModalForm.edit(record)
    },
    handleAuthorize(record) {
      this.$refs.authorizeModalForm.edit(record)
      if (record.authorize != null) {
        this.$refs.authorizeModalForm.title = '更新授权信息'
      } else {
        this.$refs.authorizeModalForm.title = '添加授权信息'
      }
    },
    handleCollect(record) {
      let that = this
      if (record.guardState == 0) {
        that.$message.warning('终端未连接!')
      } else {
        this.$refs.collectModalForm.edit(record)
        if (record.newCollectVersion != null) {
          this.$refs.collectModalForm.title = '更新采集软件'
        } else {
          this.$refs.collectModalForm.title = '上传采集软件'
        }
      }
    },
    // 启停采集软件
    collectPut(formData) {
      if (this.load) {
        that.$message.warning('请稍后再试!')
        return
      }
      let that = this
      if (formData.guardState == 0) {
        that.$message.warning('终端未连接!')
      } else {
        this.load = true
        httpAction(this.url.put, formData, 'put')
        // 延时判断是否启动暂停成功
        setTimeout(() => {
          if (this.load) {
            that.$message.warning('请稍后再试!')
            this.load = false
          }
        }, 5000)
      }
    },
    // 生成配置文件
    addDeploy(formData) {
      if (formData.guardState == 0) {
        this.$message.warning('终端未连接!')
      } else if (formData.collectState == 1) {
        this.$message.warning('请暂停采集软件再生成配置!')
      } else {
        this.loading = true
        getAction(this.url.deploy, { id: formData.id }).then((res) => {
          this.loading = false
          if (res.success) {
            this.loadData()
            this.$message.success(res.message)
          }
          if (res.code === 510) {
            this.$message.warning(res.message)
          }
        })
      }
    }
  }
}
</script>