From cf05ec76538bbf6373c2e199894247ed8d52d0b8 Mon Sep 17 00:00:00 2001
From: wu <2468489804@qq.com>
Date: Sat, 20 Aug 2022 00:11:27 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=B4=A6=E5=8F=B7=E5=AF=86?=
=?UTF-8?q?=E7=A0=81=E5=BD=95=E5=85=A5&=E6=B7=BB=E5=8A=A0=E6=9C=8D?=
=?UTF-8?q?=E5=8A=A1=E8=AE=BE=E5=A4=87=E7=8A=B6=E6=80=81&=E4=BC=98?=
=?UTF-8?q?=E5=8C=96=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/api/modules/edgeServer.api.js | 16 +-
.../edgeServer/edgeServerConfigure/device.vue | 112 +++++++++++---
.../edgeServer/edgeServerConfigure/index.vue | 75 ++++++----
.../edgeServer/edgeServerMonitor/index.vue | 139 +++++++++++++-----
4 files changed, 252 insertions(+), 90 deletions(-)
diff --git a/src/api/modules/edgeServer.api.js b/src/api/modules/edgeServer.api.js
index 8fb9591..2085635 100644
--- a/src/api/modules/edgeServer.api.js
+++ b/src/api/modules/edgeServer.api.js
@@ -72,18 +72,26 @@ export default ({ service, request, serviceForMock, requestForMock, mock, faker,
GET_DEVICE_CONFIGURE (id) {
return request({ url: '?query=device&id=' + id })
},
- GET_SERVE_DEVICE_MONITORING (url, username, password, deviceName) {
+ GET_SERVE_DEVICE_MONITORING (url, username, password) {
return request({
auth: {
username: username,
password: password
},
- method: 'get',
- url: url + '/Edge/DeviceData?data=' + deviceName
+ url: url + '/Edge/DeviceData?data=/'
})
},
GET_ALL_DEVICES () {
return request({ url: '?query=all_devices' })
},
- SET_SERVER_EXEC: (data) => handlePost(request, data)
+ SET_SERVER_EXEC: (data) => handlePost(request, data),
+ GET_SERVER_DEVICE_STATUS (url, username, password) {
+ return request({
+ auth: {
+ username: username,
+ password: password
+ },
+ url: url + '/Edge/DeviceData?data=__status'
+ })
+ }
})
diff --git a/src/views/edgeServer/edgeServerConfigure/device.vue b/src/views/edgeServer/edgeServerConfigure/device.vue
index 4597285..1ac8de1 100644
--- a/src/views/edgeServer/edgeServerConfigure/device.vue
+++ b/src/views/edgeServer/edgeServerConfigure/device.vue
@@ -25,7 +25,7 @@
{{ item.name }}
+ :class="{ 'device-status': true, 'device-status-online': item.status, 'device-status-offline': !item.status }">
@@ -54,6 +54,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
@@ -284,6 +299,19 @@ export default {
'@RequestInterval': [{ required: true, message: '请输入采集周期(ms)', trigger: 'blur' }],
'@Length': [{ required: true, message: '请输入长度', trigger: 'blur' }]
},
+ dialogFormVisible: false,
+ userForm: {
+ username: '',
+ password: ''
+ },
+ userRules: {
+ username: [
+ { required: true, message: '请输入账号', trigger: 'blur' }
+ ],
+ password: [
+ { required: true, message: '请输入密码', trigger: 'blur' }
+ ]
+ },
serverData: {},
devicePointData: [],
nodeCodeData: [],
@@ -301,6 +329,9 @@ export default {
handler (val) {
this.serverData = val
this.getDevice()
+ if (val.id) {
+ this.getDeviceStatus()
+ }
},
immediate: true
}
@@ -433,14 +464,13 @@ export default {
}
},
addDevice () {
- const that = this
this.$prompt('输入设备名称', '新加设备', {
confirmButtonText: '确定',
inputPattern: /^[\s\S]*.*[^\s][\s\S]*$/,
inputErrorMessage: '请输入设备名称'
}).then(({ value }) => {
this.$api.ADD_DEVICE({ action: 'add_device', name: value, server_id: this.serverData.id })
- that.getDevice()
+ this.getDevice()
this.$message({
message: '新加设备成功',
type: 'success'
@@ -448,7 +478,10 @@ export default {
})
},
async delDevice () {
- const deviceConfigure = await this.$api.GET_HSLSERVER_CONFIGURE('http://' + this.serverData.url + ':' + this.serverData.port, 'admin', '123456')
+ // 校验是否已经有账号和密码
+ const userInfo = this.getUserInfo()
+
+ const deviceConfigure = await this.$api.GET_HSLSERVER_CONFIGURE('http://' + this.serverData.url + ':' + this.serverData.port, userInfo.username, userInfo.password)
let deviceNode = deviceConfigure.Content.Settings.GroupNode[0].DeviceNode
if (deviceNode !== undefined && isArray(deviceNode)) {
deviceNode = filter(deviceNode, item => {
@@ -460,7 +493,7 @@ export default {
}
try {
- await this.$api.SET_HSLSERVER_CONFIGURE('http://' + this.serverData.url + ':' + this.serverData.port, 'admin', '123456', { data: deviceConfigure.Content })
+ await this.$api.SET_HSLSERVER_CONFIGURE('http://' + this.serverData.url + ':' + this.serverData.port, userInfo.username, userInfo.password, { data: deviceConfigure.Content })
await this.$api.DEL_DEVICE({ action: 'remove_device', id: this.deviceData[this.deviceActiveStatus].id })
this.$message({
message: '删除设备成功',
@@ -487,10 +520,10 @@ export default {
}
this.formOptions.saveLoading = false
},
+
async delDevicePoint ({ index, row }, done) {
this.devicePointData.splice(index, 1)
this.$refs.deviceConfigure.deviceConfigureModelValue.RequestNode = this.devicePointData
-
await this.setDeviceConfigure()
done()
},
@@ -507,7 +540,17 @@ export default {
this.setDeviceConfigure()
done()
},
+ setUserInfo () {
+ this.$refs.userForm.validate((valid) => {
+ if (valid) {
+ sessionStorage.setItem(this.serverData.id, JSON.stringify(this.userForm))
+ this.dialogFormVisible = false
+ }
+ })
+ },
async setDeviceConfigure () {
+ // 校验是否已经有账号和密码
+ const userInfo = this.getUserInfo()
try {
// 验证表单
this.$refs.deviceConfigure.$refs.form.validate((valid) => {
@@ -515,10 +558,11 @@ export default {
return false
}
})
- const deviceConfigure = await this.$api.GET_HSLSERVER_CONFIGURE('http://' + this.serverData.url + ':' + this.serverData.port, 'admin', '123456')
+ const deviceConfigure = await this.$api.GET_HSLSERVER_CONFIGURE('http://' + this.serverData.url + ':' + this.serverData.port, userInfo.username, userInfo.password)
+ const deviceConfigureModelValue = this.$refs.deviceConfigure.deviceConfigureModelValue
if (this.devicePointData.length > 0) {
- const devicePointData = this.devicePointData
- each(devicePointData, (item) => {
+ let devicePointData = this.devicePointData
+ devicePointData = each(devicePointData, (item) => {
unset(item, 'id')
unset(item, 'showBindButton')
unset(item, 'showCopyButton')
@@ -526,9 +570,9 @@ export default {
unset(item, 'showSendButton')
item['@Binding'] = item['@Binding'] || ''
})
- this.$refs.deviceConfigure.deviceConfigureModelValue.RequestNode = devicePointData
+ deviceConfigureModelValue.RequestNode = devicePointData
}
- this.$refs.deviceConfigure.deviceConfigureModelValue['@Name'] = this.deviceData[this.deviceActiveStatus].name
+ deviceConfigureModelValue['@Name'] = this.deviceData[this.deviceActiveStatus].name
let deviceNode = deviceConfigure.Content.Settings.GroupNode[0].DeviceNode || []
let isExist = false
if (deviceNode !== undefined) {
@@ -536,21 +580,21 @@ export default {
deviceNode = map(deviceNode, (item) => {
if (item['@Name'] === this.deviceData[this.deviceActiveStatus].name) {
isExist = true
- item = this.$refs.deviceConfigure.deviceConfigureModelValue
+ item = deviceConfigureModelValue
}
return item
})
}
if (!isExist) {
- deviceNode.push(this.$refs.deviceConfigure.deviceConfigureModelValue)
+ deviceNode.push(deviceConfigureModelValue)
}
deviceConfigure.Content.Settings.GroupNode[0].DeviceNode = deviceNode
- await this.$api.SET_HSLSERVER_CONFIGURE('http://' + this.serverData.url + ':' + this.serverData.port, 'admin', '123456', { data: deviceConfigure.Content })
- this.$refs.deviceConfigure.deviceConfigureModelValue.DeviceTypeName = this.$refs.deviceConfigure.defaultDeviceTypeNameValue
+ await this.$api.SET_HSLSERVER_CONFIGURE('http://' + this.serverData.url + ':' + this.serverData.port, userInfo.username, userInfo.password, { data: deviceConfigure.Content })
+ deviceConfigureModelValue.DeviceTypeName = this.$refs.deviceConfigure.defaultDeviceTypeNameValue
const data = {
action: 'update_device',
- conf: JSON.stringify(this.$refs.deviceConfigure.deviceConfigureModelValue),
+ conf: JSON.stringify(deviceConfigureModelValue),
id: this.deviceData[this.deviceActiveStatus].id
}
this.$api.SET_DEVICE_CONFIGURE(data)
@@ -558,25 +602,45 @@ export default {
message: '操作成功',
type: 'success'
})
+ this.$emit('changeServerConfig', 't')
} catch (e) {
console.log(e)
}
},
- getDeviceStatus () {
- this.$api.GET_DEVICE_STATUS(this.serverData.id).then(res => {
- each(this.deviceData, (item) => {
- if (item.id in res.device_status) {
- item.status = res.device_status[item.id]
+ getUserInfo () {
+ const userInfo = sessionStorage.getItem(this.serverData.id)
+ if (!userInfo) {
+ this.dialogFormVisible = true
+ return false
+ }
+ return JSON.parse(userInfo)
+ },
+ async getDeviceStatus () {
+ const userInfo = this.getUserInfo()
+ const res = await this.$api.GET_SERVER_DEVICE_STATUS('http://' + this.serverData.url + ':' + this.serverData.port, userInfo.username, userInfo.password)
+ if (res) {
+ this.$emit('changeStatus', 'online')
+ const deviceStatus = {}
+ each(res.Content.__deviceList, (item) => {
+ deviceStatus[item.__name] = {
+ status: item.__requestEnable,
+ name: item.__name
}
})
- this.$emit('changeStatus', res.server_status)
- })
+ each(this.deviceData, (item) => {
+ if (deviceStatus[item.name]) {
+ item.status = deviceStatus[item.name].status
+ }
+ })
+ } else {
+ this.$emit('changeStatus', false)
+ }
}
},
mounted () {
this.getDevice()
this.getworkingSubclasses()
- // setInterval(this.getDeviceStatus, 2000)
+ this.getDeviceStatus()
}
}
diff --git a/src/views/edgeServer/edgeServerConfigure/index.vue b/src/views/edgeServer/edgeServerConfigure/index.vue
index 85966e3..a07ff8d 100644
--- a/src/views/edgeServer/edgeServerConfigure/index.vue
+++ b/src/views/edgeServer/edgeServerConfigure/index.vue
@@ -16,7 +16,7 @@
@row-remove="handleRowRemove"
@dialog-cancel="handleDialogCancel"
@set-device="drawerShow"
- @exec="handleDialogFormVisible">
+ @exec="setServerExec">
新增
@@ -24,6 +24,7 @@
size="95%"
:append-to-body='true'
:visible.sync="isDrawerShow"
+ @close="closeDrawer"
>
前置服务 {{selectedServerData.name}} URL:{{selectedServerData.url}}
@@ -35,10 +36,11 @@
-
+
-
+
+
@@ -48,8 +50,7 @@
@@ -359,33 +360,43 @@ export default {
})
done()
},
- setServerExec () {
- this.$refs.form.validate(async (valid) => {
+
+ async setServerExec ({ row }) {
+ let userInfo = sessionStorage.getItem(row.id)
+ this.dialogFormServerId = row.id
+ if (!userInfo) {
+ this.dialogFormVisible = true
+ return false
+ }
+ userInfo = JSON.parse(userInfo)
+
+ try {
+ await this.$api.SET_SERVER_EXEC({
+ action: 'exec',
+ server_id: row.id,
+ command: 'server_restart',
+ username: userInfo.username,
+ password: userInfo.password
+ })
+ this.$message({
+ message: '服务应用请求成功,请求动作已添加至请求队列中,请从服务监控页面查看结果',
+ type: 'success'
+ })
+ this.dialogFormServerId = 0
+ this.getServers()
+ this.dialogFormVisible = false
+ } catch (e) {
+ console.log(e)
+ }
+ },
+ handleDialogFormVisible () {
+ this.$refs.form.validate((valid) => {
if (valid) {
- try {
- await this.$api.SET_SERVER_EXEC({
- action: 'exec',
- server_id: this.dialogFormServerId,
- command: 'server_restart',
- username: this.form.username,
- password: this.form.password
- })
- this.$message({
- message: '服务应用请求成功,请求动作已添加至请求队列中,请从服务监控页面查看结果',
- type: 'success'
- })
- this.dialogFormServerId = 0
- this.dialogFormVisible = false
- } catch (e) {
- console.log(e)
- }
+ sessionStorage.setItem(this.dialogFormServerId, JSON.stringify(this.form))
+ this.dialogFormVisible = false
}
})
},
- handleDialogFormVisible ({ row }) {
- this.dialogFormServerId = row.id
- this.dialogFormVisible = true
- },
handleDialogCancel (done) {
this.$message({
message: '用户放弃改动',
@@ -404,10 +415,16 @@ export default {
this.server = { id: row.id, url: row.url, port: row.port }
this.isDrawerShow = true
},
+ closeDrawer () {
+ this.server = { id: 0, url: '', port: '' }
+ },
changeSelectedServerStatus (status) {
this.selectedServerData.status = status || 'offline'
+ },
+ changeSelectedServerConfig (updated) {
+ this.getServers()
+ this.selectedServerData.updated = updated || 'f'
}
-
},
mounted () {
this.getServers()
diff --git a/src/views/edgeServer/edgeServerMonitor/index.vue b/src/views/edgeServer/edgeServerMonitor/index.vue
index 96e3fa3..9a3a7c1 100644
--- a/src/views/edgeServer/edgeServerMonitor/index.vue
+++ b/src/views/edgeServer/edgeServerMonitor/index.vue
@@ -1,6 +1,6 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+