|
@@ -118,7 +118,8 @@ export default {
|
|
|
role_id: null,
|
|
|
role_name: '',
|
|
|
activeName: 'huan-ban',
|
|
|
- member_id: null
|
|
|
+ member_id: null,
|
|
|
+ onlineDevice: []
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
@@ -149,6 +150,34 @@ export default {
|
|
|
{ headerName: '绑定人', field: 'member_name', sortable: true, filter: 'agTextColumnFilter', minWidth: 140, valueFormatter: this.formatterName },
|
|
|
// { headerName: '所属位置', field: 'full_name', sortable: true, filter: 'agTextColumnFilter', minWidth: 140 },
|
|
|
{ headerName: '设备标识码', field: 'eth_mac', sortable: true, filter: 'agTextColumnFilter', minWidth: 150 },
|
|
|
+ { headerName: '连接状态', field: 'online_state', sortable: false, filter: 'agTextColumnFilter', minWidth: 120,
|
|
|
+ filterParams: {
|
|
|
+ textCustomComparator: (filter, value, filterText) => {
|
|
|
+ const filterTextLowerCase = filterText.toLowerCase()
|
|
|
+ const valueLowerCase = value.toString().toLowerCase()
|
|
|
+ switch (filter) {
|
|
|
+ case 'contains':
|
|
|
+ return valueLowerCase.indexOf(filterTextLowerCase) >= 0
|
|
|
+ case 'notContains':
|
|
|
+ return valueLowerCase.indexOf(filterTextLowerCase) === -1
|
|
|
+ case 'equals':
|
|
|
+ return valueLowerCase === filterTextLowerCase
|
|
|
+ case 'notEqual':
|
|
|
+ return valueLowerCase !== filterTextLowerCase
|
|
|
+ case 'startsWith':
|
|
|
+ return valueLowerCase.indexOf(filterTextLowerCase) === 0
|
|
|
+ case 'endsWith':
|
|
|
+ var index = valueLowerCase.lastIndexOf(filterTextLowerCase)
|
|
|
+ return index >= 0 && index === (valueLowerCase.length - filterTextLowerCase.length)
|
|
|
+ default:
|
|
|
+ // should never happen
|
|
|
+ console.warn('invalid filter type ' + filter)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ cellRenderer: this.onlineStateFormatter
|
|
|
+ },
|
|
|
{ headerName: '有线IP地址', field: 'eth_ip', sortable: true, filter: 'agTextColumnFilter', minWidth: 150 },
|
|
|
{ headerName: '设备型号', field: 'model', sortable: true, filter: 'agTextColumnFilter', minWidth: 150 },
|
|
|
{ headerName: '出厂编号', field: 'code', sortable: true, filter: 'agTextColumnFilter', minWidth: 150 },
|
|
@@ -183,7 +212,7 @@ export default {
|
|
|
minWidth: 100,
|
|
|
resizable: false,
|
|
|
sortable: false
|
|
|
- },
|
|
|
+ }
|
|
|
// {
|
|
|
// headerName: '管理', field: 'shop_id',
|
|
|
// cellRendererFramework: 'ButtonCellRender',
|
|
@@ -219,6 +248,7 @@ export default {
|
|
|
this.gridApi = this.gridOptions.api
|
|
|
this.getList()
|
|
|
this.initWebSocket()
|
|
|
+ this.deviceOnlineWebSocket()
|
|
|
},
|
|
|
beforeDestroy() {
|
|
|
clearTimeout(this.timer)
|
|
@@ -269,6 +299,34 @@ export default {
|
|
|
// }
|
|
|
// })
|
|
|
},
|
|
|
+ deviceOnlineWebSocket: function() {
|
|
|
+ var stockbase = DeviceUrl.replace('http', 'ws')
|
|
|
+ this.websock1 = new WebSocket(stockbase + '/deviceonline/' + this.$store.getters.uuid)
|
|
|
+ this.websock1.onopen = this.deviceOnlineWebsocketonopen
|
|
|
+ this.websock1.onerror = this.deviceOnlineWebsocketonerror
|
|
|
+ this.websock1.onmessage = this.deviceOnlineWebsocketonmessage
|
|
|
+ this.websock1.onclose = this.deviceOnlineWebsocketclose
|
|
|
+ },
|
|
|
+ deviceOnlineWebsocketonopen: function() {
|
|
|
+ console.log('WebSocket连接成功')
|
|
|
+ },
|
|
|
+ deviceOnlineWebsocketonerror: function(e) {
|
|
|
+ console.log('WebSocket连接发生错误')
|
|
|
+ },
|
|
|
+ deviceOnlineWebsocketonmessage: function(e) {
|
|
|
+ this.onlineDevice = JSON.parse(e.data)
|
|
|
+ if (this.tableData !== null) {
|
|
|
+ this.tableData.forEach(item => {
|
|
|
+ const mac = this.onlineDevice.filter(p => p.toLowerCase() === item.eth_mac.toLowerCase())[0]
|
|
|
+ item.online_state = (mac !== undefined && mac !== null) ? '在线' : '离线'
|
|
|
+ })
|
|
|
+ const tableData = [...this.tableData]
|
|
|
+ this.$set(this, 'tableData', tableData)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ deviceOnlineWebsocketclose: function(e) {
|
|
|
+ console.log('connection closed (' + e.code + ')')
|
|
|
+ },
|
|
|
/** 选择行变化时,记录选中的行数据 */
|
|
|
selectFun(val) {
|
|
|
this.multipleSelection = val
|
|
@@ -290,6 +348,19 @@ export default {
|
|
|
this.gridApi.sizeColumnsToFit()
|
|
|
API_Device.getList(this.params).then(response => {
|
|
|
this.loading = false
|
|
|
+ response.data.forEach(item => {
|
|
|
+ if (this.onlineDevice.length > 0) {
|
|
|
+ const mac = this.onlineDevice.filter(p => p.toLowerCase() === item.eth_mac.toLowerCase())[0]
|
|
|
+ // console.log('在线设备1', mac)
|
|
|
+ if (mac !== undefined && mac !== null) {
|
|
|
+ item['online_state'] = '在线'
|
|
|
+ } else {
|
|
|
+ item['online_state'] = '离线'
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ item['online_state'] = '离线'
|
|
|
+ }
|
|
|
+ })
|
|
|
this.tableData = response.data
|
|
|
this.pageData = {
|
|
|
page_no: response.page_no,
|
|
@@ -386,6 +457,8 @@ export default {
|
|
|
},
|
|
|
filterModifed(param) {
|
|
|
const model = param.api.getFilterModel()
|
|
|
+ // 连接状态不经过服务器过滤
|
|
|
+ delete model.online_state
|
|
|
this.params.filter = JSON.stringify(model)
|
|
|
this.getList()
|
|
|
},
|
|
@@ -477,6 +550,14 @@ export default {
|
|
|
},
|
|
|
fanhui() {
|
|
|
this.formshow = false
|
|
|
+ },
|
|
|
+ /** 设备连接状态格式化 **/
|
|
|
+ onlineStateFormatter(params) {
|
|
|
+ if (params.value === '在线') {
|
|
|
+ return '<span style="color:green;">在线</span>'
|
|
|
+ } else {
|
|
|
+ return '<span style="color:gray;">离线</span>'
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|