实现了服务的增删改查、设备增加
This commit is contained in:
38
src/api/modules/edgeServer.api.js
Normal file
38
src/api/modules/edgeServer.api.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import { handlePost } from '../tools'
|
||||
|
||||
export default ({ service, request, serviceForMock, requestForMock, mock, faker, tools }) => ({
|
||||
/**
|
||||
* @description 方法名称
|
||||
* @param {Object} data 请求携带的信息
|
||||
*/
|
||||
VERIFY_SERVER (url, username, password) {
|
||||
return request({
|
||||
auth: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
method: 'post',
|
||||
url: url + '/Admin/ServerSettingsRequest'
|
||||
})
|
||||
},
|
||||
|
||||
MODIFY_SERVER (url, username, password, data) {
|
||||
return request({
|
||||
auth: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
data: data,
|
||||
method: 'post',
|
||||
url: url + '/Admin/ServerSettingsModify'
|
||||
})
|
||||
},
|
||||
|
||||
ADD_SERVER: (data) => handlePost(request, data),
|
||||
UPDATE_SERVER: (data) => handlePost(request, data),
|
||||
REMOVE_SERVER: (data) => handlePost(request, data),
|
||||
|
||||
QUERY_SERVERS () {
|
||||
return request({ url: '?query=servers' })
|
||||
}
|
||||
})
|
||||
@@ -1,8 +1,4 @@
|
||||
const handlePost = (request, data) => (request({
|
||||
url: '',
|
||||
method: 'post',
|
||||
data
|
||||
}))
|
||||
import { handlePost } from '../tools'
|
||||
|
||||
export default ({ service, request, serviceForMock, requestForMock, mock, faker, tools }) => ({
|
||||
/**
|
||||
@@ -14,7 +10,7 @@ export default ({ service, request, serviceForMock, requestForMock, mock, faker,
|
||||
UPDATE_NODE: (data) => handlePost(request, data),
|
||||
REMOVE_NODE: (data) => handlePost(request, data),
|
||||
|
||||
QUERY_NODE () {
|
||||
QUERY_NODES () {
|
||||
return request({ url: '?query=nodes' })
|
||||
},
|
||||
|
||||
|
||||
@@ -84,3 +84,9 @@ export function errorCreate (msg) {
|
||||
errorLog(error)
|
||||
throw error
|
||||
}
|
||||
|
||||
export const handlePost = (request, data) => (request({
|
||||
url: '',
|
||||
method: 'post',
|
||||
data
|
||||
}))
|
||||
|
||||
@@ -23,5 +23,12 @@ export const menuAside = supplementPath([
|
||||
{ path: '/scada_configure', title: 'SCADA节点配置' },
|
||||
{ path: '/scada_query', title: 'SCADA数据查询' }
|
||||
]
|
||||
},
|
||||
{
|
||||
title: '采集服务管理',
|
||||
children: [
|
||||
{ path: '/edge_server_configure', title: '服务配置' },
|
||||
{ path: '/edge_server_monitor', title: '服务监控' }
|
||||
]
|
||||
}
|
||||
])
|
||||
|
||||
@@ -39,6 +39,24 @@ const frameIn = [
|
||||
},
|
||||
component: _import('scada/scadaQuery')
|
||||
},
|
||||
{
|
||||
path: 'edge_server_configure',
|
||||
name: 'edge_server_configure',
|
||||
meta: {
|
||||
title: '服务配置',
|
||||
auth: true
|
||||
},
|
||||
component: _import('edgeServer/edgeServerConfigure')
|
||||
},
|
||||
{
|
||||
path: 'edge_server_monitor',
|
||||
name: 'edge_server_monitor',
|
||||
meta: {
|
||||
title: '服务监控',
|
||||
auth: true
|
||||
},
|
||||
component: _import('edgeServer/edgeServerMonitor')
|
||||
},
|
||||
// 系统 前端日志
|
||||
{
|
||||
path: 'log',
|
||||
|
||||
283
src/views/edgeServer/edgeServerConfigure/index.vue
Normal file
283
src/views/edgeServer/edgeServerConfigure/index.vue
Normal file
@@ -0,0 +1,283 @@
|
||||
<template>
|
||||
<d2-container>
|
||||
<d2-crud
|
||||
ref="d2Crud"
|
||||
:columns="columns"
|
||||
:data="data"
|
||||
:rowHandle="rowHandle"
|
||||
add-title="新增服务"
|
||||
edit-title="修改服务配置"
|
||||
:add-template="addTemplate"
|
||||
:edit-template="editTemplate"
|
||||
:form-options="formOptions"
|
||||
:add-rules="addRules"
|
||||
@row-add="handleRowAdd"
|
||||
@row-edit="handleRowEdit"
|
||||
@row-remove="handleRowRemove"
|
||||
@dialog-cancel="handleDialogCancel">
|
||||
<el-button slot="header" style="margin-bottom: 5px" @click="addRow">新增</el-button>
|
||||
</d2-crud>
|
||||
</d2-container>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { assign, each } from 'lodash'
|
||||
|
||||
const genRanHex = size => [...Array(size)].map(() => Math.floor(Math.random() * 16).toString(16).toUpperCase()).join('')
|
||||
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
columns: [
|
||||
{
|
||||
title: '序号',
|
||||
key: 'id'
|
||||
},
|
||||
{
|
||||
title: '名称',
|
||||
key: 'name'
|
||||
},
|
||||
{
|
||||
title: 'URL',
|
||||
key: 'url'
|
||||
},
|
||||
{
|
||||
title: '端口',
|
||||
key: 'port'
|
||||
},
|
||||
{
|
||||
title: '绑定地址',
|
||||
key: 'address'
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
key: 'create_date'
|
||||
},
|
||||
{
|
||||
title: '备注',
|
||||
key: 'note'
|
||||
}
|
||||
],
|
||||
data: [],
|
||||
serverSettings: {},
|
||||
rowHandle: {
|
||||
minWidth: '200',
|
||||
edit: {
|
||||
icon: 'el-icon-edit',
|
||||
text: '编辑',
|
||||
size: 'small',
|
||||
show (index, row) {
|
||||
if (row.showEditButton) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
},
|
||||
remove: {
|
||||
icon: 'el-icon-delete',
|
||||
size: 'small',
|
||||
fixed: 'right',
|
||||
confirm: true,
|
||||
show (index, row) {
|
||||
if (row.showRemoveButton) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
},
|
||||
addTemplate: {
|
||||
deviceName: {
|
||||
title: '服务名称',
|
||||
value: 'Edge:' + genRanHex(12)
|
||||
},
|
||||
uniqueID: {
|
||||
title: '唯一标识',
|
||||
value: '',
|
||||
component: {
|
||||
disabled: true,
|
||||
placeholder: '采集服务唯一标识,测试成功后返回'
|
||||
}
|
||||
},
|
||||
url: {
|
||||
title: 'URL',
|
||||
value: '',
|
||||
component: {
|
||||
span: 12
|
||||
}
|
||||
},
|
||||
port: {
|
||||
title: '端口',
|
||||
value: 522,
|
||||
component: {
|
||||
span: 12
|
||||
}
|
||||
},
|
||||
userName: {
|
||||
title: '用户名',
|
||||
value: 'admin',
|
||||
component: {
|
||||
span: 12
|
||||
}
|
||||
},
|
||||
password: {
|
||||
title: '密码',
|
||||
value: '123456',
|
||||
component: {
|
||||
span: 12,
|
||||
'show-password': true
|
||||
}
|
||||
},
|
||||
address: {
|
||||
title: '绑定地址',
|
||||
value: '',
|
||||
component: {
|
||||
placeholder: '请填入绑定EdgeManager实例的地址,比如http://xxx.xxx:xxxx'
|
||||
}
|
||||
}
|
||||
},
|
||||
editTemplate: {
|
||||
address: {
|
||||
title: '绑定地址',
|
||||
component: {
|
||||
placeholder: '仅可以修改已绑定EdgeManager实例的地址'
|
||||
}
|
||||
}
|
||||
},
|
||||
formOptions: {
|
||||
labelWidth: '80px',
|
||||
labelPosition: 'left',
|
||||
saveLoading: false,
|
||||
saveButtonText: '测试',
|
||||
saveButtonType: 'text'
|
||||
},
|
||||
addRules: {
|
||||
deviceName: [{ required: true, type: 'string', message: '服务名称不可为空', trigger: 'blur' }],
|
||||
url: [{ required: true, type: 'string', message: '服务地址不可为空', trigger: 'blur' }],
|
||||
port: [{ required: true, type: 'integer', transform: v => +v, message: '端口号必须指定,且需为(0, 65535]内的正整数', trigger: 'blur' }],
|
||||
userName: [{ required: true, message: '用户名不可为空', trigger: 'blur' }],
|
||||
password: [{ required: true, type: 'string', message: '密码不可为空', trigger: 'blur' }],
|
||||
address: [{ type: 'url', message: '绑定地址必须为合法URL', trigger: 'blur' }]
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async getServers () {
|
||||
try {
|
||||
const res = await this.$api.QUERY_SERVERS()
|
||||
this.data = each(res, (o) => (
|
||||
assign(o, {
|
||||
showEditButton: true,
|
||||
showRemoveButton: true
|
||||
})
|
||||
))
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
},
|
||||
// 普通的新增
|
||||
addRow () {
|
||||
this.$refs.d2Crud.showDialog({
|
||||
mode: 'add'
|
||||
})
|
||||
},
|
||||
async handleRowAdd (row, done) {
|
||||
this.formOptions.saveLoading = true
|
||||
try {
|
||||
// 定义测试动作
|
||||
if (this.formOptions.saveButtonText === '测试') {
|
||||
this.serverSettings = await this.$api.VERIFY_SERVER('http://' + row.url + ':' + row.port, row.userName, row.password)
|
||||
if (this.serverSettings) {
|
||||
this.$message({
|
||||
message: '测试通过!',
|
||||
type: 'success'
|
||||
})
|
||||
}
|
||||
this.formOptions.saveLoading = false
|
||||
each(Object.keys(row), (p) => {
|
||||
this.addTemplate[p].value = row[p]
|
||||
})
|
||||
this.addTemplate.uniqueID.value = this.serverSettings.Content.ServerInfoConfig.UniqueId
|
||||
this.$refs.d2Crud.showDialog({
|
||||
mode: 'add'
|
||||
})
|
||||
this.formOptions.saveButtonText = '添加'
|
||||
this.formOptions.saveButtonType = 'success'
|
||||
// 定义添加动作
|
||||
} else {
|
||||
this.serverSettings.Content.ServerInfoConfig.DeviceName = row.deviceName
|
||||
this.serverSettings.Content.ServerInfoConfig.CaptureURL = row.address
|
||||
console.log(this.serverSettings.Content.ServerInfoConfig)
|
||||
await this.$api.MODIFY_SERVER(
|
||||
'http://' + row.url + ':' + row.port,
|
||||
row.userName,
|
||||
row.password,
|
||||
{ data: this.serverSettings.Content }
|
||||
)
|
||||
await this.$api.ADD_SERVER({
|
||||
action: 'add_server',
|
||||
name: row.deviceName,
|
||||
url: row.url,
|
||||
port: row.port,
|
||||
address: row.address
|
||||
})
|
||||
this.$message({
|
||||
message: '添加成功',
|
||||
type: 'success'
|
||||
})
|
||||
this.getServers()
|
||||
done()
|
||||
}
|
||||
} catch (e) {
|
||||
this.$message({
|
||||
message: '测试/添加失败!',
|
||||
type: 'error'
|
||||
})
|
||||
console.log(e)
|
||||
}
|
||||
},
|
||||
async handleRowEdit ({ index, row }, done) {
|
||||
this.formOptions.saveLoading = true
|
||||
this.serverSettings.Content.ServerInfoConfig.CaptureURL = row.address
|
||||
await this.$api.MODIFY_SERVER(
|
||||
'http://' + row.url + ':' + row.port,
|
||||
row.userName,
|
||||
row.password,
|
||||
{ data: this.serverSettings.Content }
|
||||
)
|
||||
await this.$api.UPDATE_SERVER({
|
||||
action: 'update_server',
|
||||
id: row.id,
|
||||
address: row.address
|
||||
})
|
||||
this.$message({
|
||||
message: '编辑成功',
|
||||
type: 'success'
|
||||
})
|
||||
done()
|
||||
this.formOptions.saveLoading = false
|
||||
},
|
||||
async handleRowRemove ({ index, row }, done) {
|
||||
await this.$api.REMOVE_SERVER({
|
||||
action: 'remove_server',
|
||||
id: row.id
|
||||
})
|
||||
this.$message({
|
||||
message: '删除成功',
|
||||
type: 'success'
|
||||
})
|
||||
done()
|
||||
},
|
||||
handleDialogCancel (done) {
|
||||
this.$message({
|
||||
message: '用户放弃改动',
|
||||
type: 'warning'
|
||||
})
|
||||
done()
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
this.getServers()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -193,7 +193,7 @@ export default {
|
||||
methods: {
|
||||
async getNodes () {
|
||||
try {
|
||||
const res = await this.$api.QUERY_NODE()
|
||||
const res = await this.$api.QUERY_NODES()
|
||||
this.data = each(res, (o) => (
|
||||
assign(o, {
|
||||
showEditButton: true,
|
||||
|
||||
Reference in New Issue
Block a user