修复设备配置页面测试出现的多个BUG

This commit is contained in:
wu
2022-08-14 18:30:55 +08:00
parent 2d5e542593
commit 36068feed9
4 changed files with 536 additions and 532 deletions

View File

@@ -39,11 +39,11 @@ export default ({ service, request, serviceForMock, requestForMock, mock, faker,
QUERY_SERVE_MONITORING () {
return request({ url: '?query=working_subclasses' })
},
GET_DEVICE(serve_id){
return request({ url: '?query=device_list&id='+serve_id })
GET_DEVICE (serveId) {
return request({ url: '?query=device_list&id=' + serveId })
},
GET_DEVICE_STATUS(serve_id){
return request({ url: '?query=device_status&id='+serve_id })
GET_DEVICE_STATUS (serveId) {
return request({ url: '?query=device_status&id=' + serveId })
},
ADD_DEVICE: (data) => handlePost(request, data),
DEL_DEVICE: (data) => handlePost(request, data),
@@ -72,4 +72,7 @@ export default ({ service, request, serviceForMock, requestForMock, mock, faker,
GET_DEVICE_CONFIGURE (id) {
return request({ url: '?query=device&id=' + id })
},
GET_SERVE_MONITORING () {
return request({ url: '?query=all_status' })
}
})

View File

@@ -66,22 +66,20 @@
</el-card>
</el-main>
</el-container>
</template>
<script>
import { each,assign,omit } from 'lodash'
import { each, assign } from 'lodash'
export default {
props: {
server_id: {
default: 0
},
}
},
components: {
DeviceConfigure: () => import('./deviceConfigure'),
DeviceConfigure: () => import('./deviceConfigure')
},
data () {
return {
@@ -101,7 +99,7 @@ export default {
},
{
title: '绑定',
key: '@Binding',
key: '@Binding'
},
{
@@ -198,7 +196,7 @@ export default {
}
return false
}
},
}
},
formOptions: {
modal: false,
@@ -206,36 +204,36 @@ export default {
showOverflowTooltip: true
},
addTemplate: {
"@Name": {
'@Name': {
title: '名称'
},
"@Address": {
'@Address': {
title: '地址'
},
"@RequestType": {
'@RequestType': {
title: '类型'
},
"@RequestInterval": {
'@RequestInterval': {
title: '采集周期(ms)'
},
"@Length": {
'@Length': {
title: '长度'
},
"@Description": {
'@Description': {
title: '说明'
},
"@Value": {
'@Value': {
title: '当前值'
}
},
addRules: {
"@Name": [{ required: true, type: 'string', message: '请输入名称', trigger: 'blur' }],
"@Address": [{ required: true, message: '请输入地址', trigger: 'blur' }],
"@RequestType": [{ required: true, type: 'string', message: '请选择类型', trigger: 'blur' }],
"@RequestInterval": [{ required: true, message: '请输入采集周期(ms)', trigger: 'blur' }],
"@Length": [{ required: true, message: '请输入长度', trigger: 'blur' }],
"@Value": [{ required: true, message: '请输入当前值', trigger: 'blur' }],
'@Name': [{ required: true, type: 'string', message: '请输入名称', trigger: 'blur' }],
'@Address': [{ required: true, message: '请输入地址', trigger: 'blur' }],
'@RequestType': [{ required: true, type: 'string', message: '请选择类型', trigger: 'blur' }],
'@RequestInterval': [{ required: true, message: '请输入采集周期(ms)', trigger: 'blur' }],
'@Length': [{ required: true, message: '请输入长度', trigger: 'blur' }],
'@Value': [{ required: true, message: '请输入当前值', trigger: 'blur' }]
},
serverId: 0,
devicePointData: [],
@@ -247,7 +245,6 @@ export default {
defaultFormData: {},
deviceData: [],
deviceConfigure: {}
}
},
watch: {
@@ -257,7 +254,7 @@ export default {
this.getDevice()
},
immediate: true
},
}
},
methods: {
addRow () {
@@ -266,21 +263,21 @@ export default {
})
},
handleFormDataChange ({ key }) {
if (key === 'working_subclass') {
const { working_subclass } = this.$refs.d2Crud.formData
this.getCodesByWorkingSubclass(working_subclass)
if (key === 'workingSubclass') {
const { workingSubclass } = this.$refs.d2Crud.formData
this.getCodesByWorkingSubclass(workingSubclass)
this.$refs.d2Crud.$forceUpdate()
}
},
handleCellDataChange ({ rowIndex, key, value, row }) {
this.$refs.deviceConfigure.deviceConfigureModelValue.RequestNode[rowIndex]
handleCellDataChange ({ rowIndex, row }) {
this.devicePointData[rowIndex] = row
this.setDeviceConfigure()
},
bandingNodeTemplate () {
this.$refs.d2Crud.showDialog({
mode: 'edit',
template: {
working_subclass: {
workingSubclass: {
title: '工序编码',
value: '',
component: {
@@ -289,7 +286,7 @@ export default {
span: 12
}
},
node_code: {
nodeCode: {
title: '节点名称',
value: '',
component: {
@@ -297,7 +294,7 @@ export default {
options: this.nodeCodeData,
span: 12
}
},
}
}
})
@@ -306,7 +303,7 @@ export default {
this.$message({
message: '用户取消保存',
type: 'warning'
});
})
done()
},
handleCommand (command) {
@@ -322,25 +319,24 @@ export default {
async getCodesByWorkingSubclass (workingSubclass) {
try {
const nodeCode = await this.$api.QUERY_CODES(workingSubclass)
let nodeCodeData = []
const nodeCodeData = []
each(nodeCode, (o) => {
nodeCodeData.push({ value: o, label: o })
}
)
this.nodeCodeData = nodeCodeData
this.$nextTick(() => {
this.$refs.d2Crud.handleFormTemplateMode('node_code').component.options = this.nodeCodeData
this.$refs.d2Crud.handleFormTemplateMode('nodeCode').component.options = this.nodeCodeData
this.$refs.d2Crud.$forceUpdate()
})
} catch (e) {
console.log(e)
}
},
async getworkingSubclasses () {
try {
const workingSubclasses = await this.$api.QUERY_WORKING_SUBCLASSES()
let workingSubclassesData = []
const workingSubclassesData = []
each(workingSubclasses, (o) => {
workingSubclassesData.push({ value: o, label: o })
}
@@ -363,16 +359,16 @@ export default {
async getDeviceConfigure (e) {
this.deviceActiveStatus = e
this.devicePointData = [] // 当切换设备时把保存configure、point的数据清空
this.defaultDeviceName =[]
this.defaultDeviceName = ''
const deviceData = await this.$api.GET_DEVICE_CONFIGURE(this.deviceData[e].id)
if (deviceData[0].conf) {
let conf = JSON.parse(deviceData[0].conf)
if(conf["@Name"] != undefined){
this.defaultDeviceName = conf["@Name"]
const conf = JSON.parse(deviceData[0].conf)
if (conf['@Name'] !== undefined) {
this.defaultDeviceName = conf['@Name']
this.defaultFormData = conf
}
// 获取point信息
if(conf.RequestNode != undefined && conf.RequestNode.length > 0){
if (conf.RequestNode !== undefined && conf.RequestNode.length > 0) {
this.devicePointData = each(conf.RequestNode, (o, i) => (
assign(o, {
id: i + 1,
@@ -392,22 +388,21 @@ export default {
inputPattern: /^[\s\S]*.*[^\s][\s\S]*$/,
inputErrorMessage: '请输入设备名称'
}).then(({ value }) => {
this.$api.ADD_DEVICE({ action: "add_device", name: value, server_id: this.serverId })
this.$api.ADD_DEVICE({ action: 'add_device', name: value, server_id: this.serverId })
that.getDevice()
this.$message({
message: '新加设备成功',
type: 'success'
});
})
})
},
async delDevice () {
try {
await this.$api.DEL_DEVICE({ action: "remove_device", id: this.deviceData[this.deviceActiveStatus].id })
await this.$api.DEL_DEVICE({ action: 'remove_device', id: this.deviceData[this.deviceActiveStatus].id })
this.$message({
message: '删除设备成功',
type: 'success'
});
})
this.getDevice()
} catch (e) {
console.log(e)
@@ -415,11 +410,18 @@ export default {
},
async addDevicePoint (row, done) {
this.formOptions.saveLoading = true
if (!this.$refs.defaultDeviceTypeNameValue) {
this.$message({
message: '请先应用设备配置',
type: 'error'
})
done(false)
} else {
this.devicePointData.push(row)
this.$refs.deviceConfigure.deviceConfigureModelValue.RequestNode = this.devicePointData
await this.setDeviceConfigure()
await this.getDevice()
done()
}
this.formOptions.saveLoading = false
},
async delDevicePoint ({ index, row }, done) {
@@ -435,20 +437,26 @@ export default {
console.log(e)
}
},
async devicePointBandingNode({ index, row }) {
this.$refs.deviceConfigure.deviceConfigureModelValue.RequestNode[index]['@binding'] = row.node_code
async devicePointBandingNode ({ index, row }, done) {
this.devicePointData[index]['@Binding'] = row.nodeCode
this.setDeviceConfigure()
done()
},
async setDeviceConfigure () {
try {
let deviceConfigure = await this.$api.GET_HSLSERVER_CONFIGURE('http://8.sctmes.com:20522','admin','123456')
const deviceConfigure = await this.$api.GET_HSLSERVER_CONFIGURE('http://8.sctmes.com:20522', 'admin', '123456')
if (this.devicePointData.length > 0) {
this.$refs.deviceConfigure.deviceConfigureModelValue.RequestNode = this.devicePointData
}
console.log(this.$refs.deviceConfigure.deviceConfigureModelValue)
deviceConfigure.Content.Settings.GroupNode[0].DeviceNode = [this.$refs.deviceConfigure.deviceConfigureModelValue]
await this.$api.SET_HSLSERVER_CONFIGURE('http://8.sctmes.com:20522', 'admin', '123456', { data: deviceConfigure.Content })
const data = {
"action": "update_device",
"conf": JSON.stringify(this.$refs.deviceConfigure.deviceConfigureModelValue),
"id": this.deviceData[this.deviceActiveStatus].id
action: 'update_device',
conf: JSON.stringify(this.$refs.deviceConfigure.deviceConfigureModelValue),
id: this.deviceData[this.deviceActiveStatus].id
}
this.$api.SET_DEVICE_CONFIGURE(data)
this.$message({
message: '操作成功',
@@ -461,13 +469,12 @@ export default {
getDeviceStatus () {
this.$api.GET_DEVICE_STATUS(this.serverId).then(res => {
each(this.deviceData, (item) => {
if(res.devices[item.id] ){
item.status = data.devices[item.id]
if (item.id in res.device_status) {
item.status = res.device_status[item.id]
}
})
this.$emit('changeStatus',res.server)
this.$emit('changeStatus', res.server_status)
})
}
},
mounted () {

View File

@@ -29,7 +29,6 @@
</el-date-picker>
</template>
</el-form-item>
</el-form>
</div>
@@ -45,7 +44,7 @@ export default {
default: false
},
defaultDeviceName: {
default: Object.keys(deviceConfigureFormItemData)[0]
default: ''
},
defaultFormData: {
default: () => []
@@ -58,10 +57,8 @@ export default {
watch: {
defaultDeviceName: {
handler (val) {
if(val){
this.defaultDeviceTypeNameValue = val
this.deviceChange(val)
}
},
immediate: true
},
@@ -70,7 +67,7 @@ export default {
this.setDeviceDefaultFormItemValue(val)
},
immediate: true
},
}
},
data () {
return {
@@ -79,26 +76,25 @@ export default {
deviceConfigureModelValue: {},
deviceSelectedVlaue: '',
deviceTypeData: [
],
]
}
},
methods: {
deviceChange (e) {
// 获取所有字符串的key 用于v-model渲染
let deviceConfigureModelValue = {}
const deviceConfigureModelValue = {}
each(deviceConfigureFormItemData[e], (item) => {
if (item.type === 'time') {
deviceConfigureModelValue[item.key] = item.defaultValue ? item.defaultValue : new Date()
} else {
deviceConfigureModelValue[item.key] = item.defaultValue ? item.defaultValue : ""
deviceConfigureModelValue[item.key] = item.defaultValue ? item.defaultValue : ''
}
})
this.deviceConfigureModelValue = deviceConfigureModelValue
this.deviceConfigureFormItem = deviceConfigureFormItemData[e]
},
setDeviceDefaultFormItemValue (val) {
let deviceConfigureModelValue = {}
const deviceConfigureModelValue = {}
each(deviceConfigureFormItemData[this.defaultDeviceTypeNameValue], (item) => {
if (item.type === 'time') {
deviceConfigureModelValue[item.key] = val[item.key] ? val[item.key] : new Date()

View File

@@ -46,7 +46,7 @@ const genRanHex = size => [...Array(size)].map(() => Math.floor(Math.random() *
export default {
components: {
Device: () => import('./device'),
Device: () => import('./device')
},
data () {
return {
@@ -133,7 +133,7 @@ export default {
{
text: '设备配置',
size: 'small',
emit: 'set-device',
emit: 'set-device'
}
]
},
@@ -341,14 +341,12 @@ export default {
this.isDrawerShow = true
},
changeSelectedServerStatus (status) {
this.selectedServerData.status = status ? status : 'offline'
this.selectedServerData.status = status || 'offline'
}
},
mounted () {
this.getServers()
}
}
</script>