2022-08-13 16:20:48 +08:00
|
|
|
|
<template>
|
2022-08-17 00:05:22 +08:00
|
|
|
|
<el-container>
|
|
|
|
|
|
<el-aside width="15%">
|
|
|
|
|
|
<div class="menu-box">
|
|
|
|
|
|
<el-card class="box-card">
|
|
|
|
|
|
<div slot="header" class="menu-header">
|
|
|
|
|
|
<div class="header-title">设备</div>
|
|
|
|
|
|
<el-dropdown size="small" style="vertical-align: middle;" @command="handleCommand">
|
|
|
|
|
|
<el-button type="primary" round>
|
|
|
|
|
|
<i class="el-icon-s-tools" style="font-size:14px;"></i><i class="el-icon-arrow-down el-icon--right"
|
|
|
|
|
|
style="font-size:14px;"></i>
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
<el-dropdown-menu slot="dropdown">
|
|
|
|
|
|
<el-dropdown-item command="add">新加设备</el-dropdown-item>
|
|
|
|
|
|
<el-dropdown-item command="del">删除设备</el-dropdown-item>
|
|
|
|
|
|
<el-dropdown-item>设备重启</el-dropdown-item>
|
|
|
|
|
|
<el-dropdown-item>导入配置</el-dropdown-item>
|
|
|
|
|
|
<el-dropdown-item>导出配置</el-dropdown-item>
|
|
|
|
|
|
</el-dropdown-menu>
|
|
|
|
|
|
</el-dropdown>
|
|
|
|
|
|
</div>
|
2022-08-13 16:20:48 +08:00
|
|
|
|
|
2022-08-17 00:05:22 +08:00
|
|
|
|
<el-menu :style="{ 'borderRight': 'none' }" :defaultActive="deviceActiveStatus" @select="getDeviceConfigure">
|
|
|
|
|
|
<el-menu-item class="serve-item" shadow="always" v-for="(item, i) in deviceData" :key="i" :index="i + ''">
|
|
|
|
|
|
<div style="position:relative;">
|
|
|
|
|
|
<div style="display:inline-block;">{{ item.name }}</div>
|
|
|
|
|
|
<div
|
2022-08-20 00:11:27 +08:00
|
|
|
|
:class="{ 'device-status': true, 'device-status-online': item.status, 'device-status-offline': !item.status }">
|
2022-08-13 16:20:48 +08:00
|
|
|
|
</div>
|
2022-08-17 00:05:22 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</el-menu-item>
|
|
|
|
|
|
</el-menu>
|
|
|
|
|
|
|
|
|
|
|
|
</el-card>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-aside>
|
|
|
|
|
|
<el-main :style="{ padding: '10px' }">
|
|
|
|
|
|
<el-card class="box-card">
|
|
|
|
|
|
<div slot="header" style=" position: relative;">
|
|
|
|
|
|
<div class="header-title">设备配置</div>
|
|
|
|
|
|
<el-button class="header-button" type="primary" @click="setDeviceConfigure">应用</el-button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<device-configure ref="deviceConfigure" :defaultDeviceName="defaultDeviceName"
|
|
|
|
|
|
:defaultFormData="defaultFormData" />
|
|
|
|
|
|
</el-card>
|
|
|
|
|
|
<el-card class="box-card" style="margin-top:5px;">
|
2022-08-18 14:21:08 +08:00
|
|
|
|
<d2-crud ref="d2Crud" :columns="columns" :data="devicePointData" :rowHandle="rowHandle" add-title="新增"
|
|
|
|
|
|
edit-title="绑定" :add-template="addTemplate" :add-rules="addRules" :form-options="formOptions"
|
|
|
|
|
|
@row-add="addDevicePoint" @row-edit="devicePointBandingNode" @row-remove="delDevicePoint"
|
|
|
|
|
|
@dialog-cancel="handleDialogCancel" @banding="bandingNodeTemplate" @cell-data-change="handleCellDataChange"
|
|
|
|
|
|
@form-data-change="handleFormDataChange">
|
2022-08-17 00:05:22 +08:00
|
|
|
|
<el-button slot="header" style="margin-bottom: 5px" @click="addRow">新增</el-button>
|
|
|
|
|
|
</d2-crud>
|
|
|
|
|
|
</el-card>
|
|
|
|
|
|
</el-main>
|
|
|
|
|
|
</el-container>
|
2022-08-13 16:20:48 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
2022-08-17 00:05:22 +08:00
|
|
|
|
import { each, assign, unset, filter, isArray, map } from 'lodash'
|
|
|
|
|
|
|
2022-08-13 16:20:48 +08:00
|
|
|
|
export default {
|
2022-08-14 18:30:55 +08:00
|
|
|
|
props: {
|
2022-08-17 00:05:22 +08:00
|
|
|
|
server: {
|
|
|
|
|
|
default: {
|
|
|
|
|
|
id: 0,
|
|
|
|
|
|
url: '',
|
|
|
|
|
|
port: ''
|
|
|
|
|
|
}
|
2022-08-14 18:30:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
components: {
|
|
|
|
|
|
DeviceConfigure: () => import('./deviceConfigure')
|
|
|
|
|
|
},
|
2022-08-18 23:09:51 +08:00
|
|
|
|
data () {
|
2022-08-14 18:30:55 +08:00
|
|
|
|
return {
|
|
|
|
|
|
active: '',
|
|
|
|
|
|
columns: [
|
|
|
|
|
|
{
|
|
|
|
|
|
title: '序号',
|
|
|
|
|
|
key: 'id'
|
2022-08-13 16:20:48 +08:00
|
|
|
|
},
|
2022-08-14 18:30:55 +08:00
|
|
|
|
{
|
|
|
|
|
|
title: '名称',
|
|
|
|
|
|
key: '@Name',
|
|
|
|
|
|
component: {
|
|
|
|
|
|
size: 'small'
|
|
|
|
|
|
}
|
2022-08-13 16:20:48 +08:00
|
|
|
|
},
|
2022-08-14 18:30:55 +08:00
|
|
|
|
{
|
|
|
|
|
|
title: '绑定',
|
|
|
|
|
|
key: '@Binding'
|
|
|
|
|
|
|
2022-08-13 16:20:48 +08:00
|
|
|
|
},
|
2022-08-14 18:30:55 +08:00
|
|
|
|
{
|
|
|
|
|
|
title: '地址',
|
|
|
|
|
|
key: '@Address',
|
|
|
|
|
|
component: {
|
|
|
|
|
|
name: 'el-input',
|
|
|
|
|
|
size: 'small'
|
|
|
|
|
|
}
|
2022-08-13 16:20:48 +08:00
|
|
|
|
},
|
2022-08-14 18:30:55 +08:00
|
|
|
|
{
|
|
|
|
|
|
title: '类型',
|
2022-08-18 14:21:08 +08:00
|
|
|
|
key: '@DataTypeCode',
|
2022-08-14 18:30:55 +08:00
|
|
|
|
component: {
|
2022-08-18 14:21:08 +08:00
|
|
|
|
name: 'el-select',
|
|
|
|
|
|
size: 'small',
|
|
|
|
|
|
options: [
|
|
|
|
|
|
{
|
|
|
|
|
|
value: 'string',
|
|
|
|
|
|
label: 'string (字符串)'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
value: 'int',
|
|
|
|
|
|
label: 'int (整数)'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
value: 'float',
|
|
|
|
|
|
label: 'float (浮点数)'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
value: 'bool',
|
|
|
|
|
|
label: 'bool (逻辑值)'
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
2022-08-14 18:30:55 +08:00
|
|
|
|
}
|
2022-08-13 16:20:48 +08:00
|
|
|
|
},
|
2022-08-14 18:30:55 +08:00
|
|
|
|
{
|
|
|
|
|
|
title: '采集周期',
|
|
|
|
|
|
key: '@RequestInterval',
|
|
|
|
|
|
component: {
|
|
|
|
|
|
name: 'el-input',
|
|
|
|
|
|
size: 'small'
|
|
|
|
|
|
}
|
2022-08-13 16:20:48 +08:00
|
|
|
|
},
|
2022-08-14 18:30:55 +08:00
|
|
|
|
{
|
|
|
|
|
|
title: '长度',
|
|
|
|
|
|
key: '@Length',
|
|
|
|
|
|
component: {
|
|
|
|
|
|
name: 'el-input',
|
|
|
|
|
|
size: 'small'
|
|
|
|
|
|
}
|
2022-08-13 16:20:48 +08:00
|
|
|
|
},
|
2022-08-14 18:30:55 +08:00
|
|
|
|
{
|
|
|
|
|
|
title: '说明',
|
|
|
|
|
|
key: '@Description',
|
|
|
|
|
|
component: {
|
|
|
|
|
|
name: 'el-input',
|
|
|
|
|
|
size: 'small'
|
|
|
|
|
|
}
|
2022-08-13 16:20:48 +08:00
|
|
|
|
},
|
2022-08-14 18:30:55 +08:00
|
|
|
|
{
|
|
|
|
|
|
title: '当前值',
|
|
|
|
|
|
key: '@Value',
|
|
|
|
|
|
component: {
|
|
|
|
|
|
name: 'el-input',
|
|
|
|
|
|
size: 'small'
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
],
|
|
|
|
|
|
rowHandle: {
|
|
|
|
|
|
minWidth: '200',
|
|
|
|
|
|
custom: [
|
|
|
|
|
|
{
|
|
|
|
|
|
text: '绑定',
|
|
|
|
|
|
size: 'mini',
|
|
|
|
|
|
emit: 'banding',
|
2022-08-18 23:09:51 +08:00
|
|
|
|
show (index, row) {
|
2022-08-14 18:30:55 +08:00
|
|
|
|
if (row.showBindButton) {
|
|
|
|
|
|
return true
|
|
|
|
|
|
}
|
|
|
|
|
|
return false
|
2022-08-13 16:20:48 +08:00
|
|
|
|
}
|
2022-08-14 18:30:55 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
text: '发送',
|
|
|
|
|
|
size: 'mini',
|
2022-08-18 23:09:51 +08:00
|
|
|
|
show (index, row) {
|
2022-08-14 18:30:55 +08:00
|
|
|
|
if (row.showSendButton) {
|
|
|
|
|
|
return true
|
|
|
|
|
|
}
|
|
|
|
|
|
return false
|
2022-08-13 16:20:48 +08:00
|
|
|
|
}
|
2022-08-14 18:30:55 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
text: '复制',
|
|
|
|
|
|
size: 'mini',
|
2022-08-18 23:09:51 +08:00
|
|
|
|
show (index, row) {
|
2022-08-14 18:30:55 +08:00
|
|
|
|
if (row.showCopyButton) {
|
|
|
|
|
|
return true
|
|
|
|
|
|
}
|
|
|
|
|
|
return false
|
2022-08-13 16:20:48 +08:00
|
|
|
|
}
|
2022-08-14 18:30:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
],
|
|
|
|
|
|
remove: {
|
|
|
|
|
|
size: 'mini',
|
|
|
|
|
|
|
|
|
|
|
|
confirm: true,
|
2022-08-18 23:09:51 +08:00
|
|
|
|
show (index, row) {
|
2022-08-14 18:30:55 +08:00
|
|
|
|
if (row.showRemoveButton) {
|
|
|
|
|
|
return true
|
2022-08-13 16:20:48 +08:00
|
|
|
|
}
|
2022-08-14 18:30:55 +08:00
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
formOptions: {
|
|
|
|
|
|
modal: false,
|
|
|
|
|
|
saveLoading: false,
|
|
|
|
|
|
showOverflowTooltip: true
|
|
|
|
|
|
},
|
|
|
|
|
|
addTemplate: {
|
|
|
|
|
|
'@Name': {
|
|
|
|
|
|
title: '名称'
|
2022-08-13 16:20:48 +08:00
|
|
|
|
},
|
2022-08-14 18:30:55 +08:00
|
|
|
|
'@Address': {
|
|
|
|
|
|
title: '地址'
|
2022-08-13 16:20:48 +08:00
|
|
|
|
},
|
2022-08-18 14:21:08 +08:00
|
|
|
|
'@DisplayName': {
|
|
|
|
|
|
title: '显示名称'
|
|
|
|
|
|
},
|
2022-08-14 18:30:55 +08:00
|
|
|
|
'@RequestType': {
|
2022-08-18 14:21:08 +08:00
|
|
|
|
title: '请求类型'
|
|
|
|
|
|
},
|
|
|
|
|
|
'@DataTypeCode': {
|
|
|
|
|
|
title: '数据类型',
|
|
|
|
|
|
component: {
|
|
|
|
|
|
name: 'el-select',
|
|
|
|
|
|
|
|
|
|
|
|
options: [
|
|
|
|
|
|
{
|
|
|
|
|
|
value: 'string',
|
|
|
|
|
|
label: 'string (字符串)'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
value: 'int',
|
|
|
|
|
|
label: 'int (整数)'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
value: 'float',
|
|
|
|
|
|
label: 'float (浮点数)'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
value: 'bool',
|
|
|
|
|
|
label: 'bool (逻辑值)'
|
|
|
|
|
|
}
|
|
|
|
|
|
],
|
|
|
|
|
|
span: 12
|
|
|
|
|
|
}
|
2022-08-13 16:20:48 +08:00
|
|
|
|
},
|
2022-08-14 18:30:55 +08:00
|
|
|
|
'@RequestInterval': {
|
|
|
|
|
|
title: '采集周期(ms)'
|
2022-08-13 16:20:48 +08:00
|
|
|
|
},
|
2022-08-14 18:30:55 +08:00
|
|
|
|
'@Length': {
|
|
|
|
|
|
title: '长度'
|
2022-08-13 16:20:48 +08:00
|
|
|
|
},
|
2022-08-14 18:30:55 +08:00
|
|
|
|
'@Description': {
|
|
|
|
|
|
title: '说明'
|
2022-08-13 16:20:48 +08:00
|
|
|
|
},
|
2022-08-14 18:30:55 +08:00
|
|
|
|
'@Value': {
|
|
|
|
|
|
title: '当前值'
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
addRules: {
|
|
|
|
|
|
'@Name': [{ required: true, type: 'string', message: '请输入名称', trigger: 'blur' }],
|
2022-08-18 14:21:08 +08:00
|
|
|
|
'@Address': [{ required: true, type: 'string', message: '请输入地址', trigger: 'blur' }],
|
|
|
|
|
|
'@DisplayName': [{ required: true, type: 'string', message: '请输入显示名称', trigger: 'blur' }],
|
|
|
|
|
|
'@RequestType': [{ required: true, type: 'string', message: '请输入请求类型', trigger: 'blur' }],
|
|
|
|
|
|
'@DataTypeCode': [{ required: true, type: 'string', message: '请选择类型', trigger: 'blur' }],
|
2022-08-20 18:17:53 +08:00
|
|
|
|
'@RequestInterval': [{ required: true, message: '请输入采集周期(ms)', trigger: 'blur' }]
|
2022-08-14 18:30:55 +08:00
|
|
|
|
},
|
2022-08-17 00:05:22 +08:00
|
|
|
|
serverData: {},
|
2022-08-14 18:30:55 +08:00
|
|
|
|
devicePointData: [],
|
|
|
|
|
|
nodeCodeData: [],
|
|
|
|
|
|
workingSubclasses: [],
|
|
|
|
|
|
dialogVisible: false,
|
|
|
|
|
|
deviceActiveStatus: '0',
|
|
|
|
|
|
defaultDeviceName: '',
|
|
|
|
|
|
defaultFormData: {},
|
|
|
|
|
|
deviceData: [],
|
|
|
|
|
|
deviceConfigure: {}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
watch: {
|
2022-08-17 00:05:22 +08:00
|
|
|
|
server: {
|
2022-08-18 23:09:51 +08:00
|
|
|
|
handler (val) {
|
2022-08-17 00:05:22 +08:00
|
|
|
|
this.serverData = val
|
2022-08-14 18:30:55 +08:00
|
|
|
|
this.getDevice()
|
2022-08-20 00:11:27 +08:00
|
|
|
|
if (val.id) {
|
|
|
|
|
|
this.getDeviceStatus()
|
|
|
|
|
|
}
|
2022-08-14 18:30:55 +08:00
|
|
|
|
},
|
|
|
|
|
|
immediate: true
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
2022-08-18 23:09:51 +08:00
|
|
|
|
addRow () {
|
2022-08-14 18:30:55 +08:00
|
|
|
|
this.$refs.d2Crud.showDialog({
|
|
|
|
|
|
mode: 'add'
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
2022-08-18 23:09:51 +08:00
|
|
|
|
handleFormDataChange ({ key }) {
|
2022-08-14 18:30:55 +08:00
|
|
|
|
if (key === 'workingSubclass') {
|
|
|
|
|
|
const { workingSubclass } = this.$refs.d2Crud.formData
|
|
|
|
|
|
this.getCodesByWorkingSubclass(workingSubclass)
|
|
|
|
|
|
this.$refs.d2Crud.$forceUpdate()
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2022-08-18 23:09:51 +08:00
|
|
|
|
handleCellDataChange ({ rowIndex, row }) {
|
2022-08-14 18:30:55 +08:00
|
|
|
|
this.devicePointData[rowIndex] = row
|
|
|
|
|
|
},
|
2022-08-18 23:09:51 +08:00
|
|
|
|
bandingNodeTemplate ({ index }) {
|
2022-08-14 18:30:55 +08:00
|
|
|
|
this.$refs.d2Crud.showDialog({
|
|
|
|
|
|
mode: 'edit',
|
2022-08-17 00:05:22 +08:00
|
|
|
|
rowIndex: index,
|
2022-08-14 18:30:55 +08:00
|
|
|
|
template: {
|
|
|
|
|
|
workingSubclass: {
|
|
|
|
|
|
title: '工序编码',
|
|
|
|
|
|
value: '',
|
|
|
|
|
|
component: {
|
|
|
|
|
|
name: 'el-select',
|
|
|
|
|
|
options: this.workingSubclasses,
|
|
|
|
|
|
span: 12
|
2022-08-13 16:20:48 +08:00
|
|
|
|
}
|
2022-08-14 18:30:55 +08:00
|
|
|
|
},
|
|
|
|
|
|
nodeCode: {
|
|
|
|
|
|
title: '节点名称',
|
|
|
|
|
|
value: '',
|
|
|
|
|
|
component: {
|
|
|
|
|
|
name: 'el-select',
|
|
|
|
|
|
options: this.nodeCodeData,
|
|
|
|
|
|
span: 12
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
2022-08-18 23:09:51 +08:00
|
|
|
|
handleDialogCancel (done) {
|
2022-08-14 18:30:55 +08:00
|
|
|
|
this.$message({
|
|
|
|
|
|
message: '用户取消保存',
|
|
|
|
|
|
type: 'warning'
|
|
|
|
|
|
})
|
|
|
|
|
|
done()
|
|
|
|
|
|
},
|
2022-08-18 23:09:51 +08:00
|
|
|
|
handleCommand (command) {
|
2022-08-14 18:30:55 +08:00
|
|
|
|
switch (command) {
|
|
|
|
|
|
case 'add':
|
|
|
|
|
|
this.addDevice()
|
|
|
|
|
|
break
|
|
|
|
|
|
case 'del':
|
|
|
|
|
|
this.delDevice()
|
|
|
|
|
|
break
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2022-08-18 23:09:51 +08:00
|
|
|
|
async getCodesByWorkingSubclass (workingSubclass) {
|
2022-08-14 18:30:55 +08:00
|
|
|
|
try {
|
|
|
|
|
|
const nodeCode = await this.$api.QUERY_CODES(workingSubclass)
|
2022-08-20 17:03:52 +08:00
|
|
|
|
const nodeCodeData = []
|
2022-08-14 18:30:55 +08:00
|
|
|
|
each(nodeCode, (o) => {
|
|
|
|
|
|
nodeCodeData.push({ value: o, label: o })
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
this.nodeCodeData = nodeCodeData
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
this.$refs.d2Crud.handleFormTemplateMode('nodeCode').component.options = this.nodeCodeData
|
|
|
|
|
|
this.$refs.d2Crud.$forceUpdate()
|
|
|
|
|
|
})
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.log(e)
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2022-08-18 23:09:51 +08:00
|
|
|
|
async getworkingSubclasses () {
|
2022-08-14 18:30:55 +08:00
|
|
|
|
try {
|
|
|
|
|
|
const workingSubclasses = await this.$api.QUERY_WORKING_SUBCLASSES()
|
2022-08-20 17:03:52 +08:00
|
|
|
|
const workingSubclassesData = []
|
2022-08-14 18:30:55 +08:00
|
|
|
|
each(workingSubclasses, (o) => {
|
|
|
|
|
|
workingSubclassesData.push({ value: o, label: o })
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
this.workingSubclasses = workingSubclassesData
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.log(e)
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2022-08-18 23:09:51 +08:00
|
|
|
|
async getDevice () {
|
2022-08-14 18:30:55 +08:00
|
|
|
|
try {
|
2022-08-17 00:05:22 +08:00
|
|
|
|
this.deviceData = await this.$api.GET_DEVICE(this.serverData.id)
|
2022-08-14 18:30:55 +08:00
|
|
|
|
if (this.deviceData.length > 0) {
|
|
|
|
|
|
this.getDeviceConfigure(this.deviceActiveStatus)
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.log(e)
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2022-08-18 23:09:51 +08:00
|
|
|
|
async getDeviceConfigure (e) {
|
2022-08-14 18:30:55 +08:00
|
|
|
|
this.deviceActiveStatus = e
|
|
|
|
|
|
this.devicePointData = [] // 当切换设备时把保存configure、point的数据清空
|
|
|
|
|
|
this.defaultDeviceName = ''
|
|
|
|
|
|
const deviceData = await this.$api.GET_DEVICE_CONFIGURE(this.deviceData[e].id)
|
2022-08-17 00:05:22 +08:00
|
|
|
|
|
2022-08-14 18:30:55 +08:00
|
|
|
|
if (deviceData[0].conf) {
|
|
|
|
|
|
const conf = JSON.parse(deviceData[0].conf)
|
2022-08-17 00:05:22 +08:00
|
|
|
|
if (conf.DeviceTypeName !== undefined) {
|
|
|
|
|
|
this.defaultDeviceName = conf.DeviceTypeName
|
2022-08-14 18:30:55 +08:00
|
|
|
|
this.defaultFormData = conf
|
|
|
|
|
|
}
|
|
|
|
|
|
// 获取point信息
|
|
|
|
|
|
if (conf.RequestNode !== undefined && conf.RequestNode.length > 0) {
|
|
|
|
|
|
this.devicePointData = each(conf.RequestNode, (o, i) => (
|
|
|
|
|
|
assign(o, {
|
|
|
|
|
|
id: i + 1,
|
|
|
|
|
|
showBindButton: true,
|
|
|
|
|
|
showSendButton: true,
|
|
|
|
|
|
showCopyButton: true,
|
|
|
|
|
|
showRemoveButton: true
|
2022-08-13 16:20:48 +08:00
|
|
|
|
})
|
2022-08-14 18:30:55 +08:00
|
|
|
|
))
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-08-13 16:20:48 +08:00
|
|
|
|
},
|
2022-08-18 23:09:51 +08:00
|
|
|
|
addDevice () {
|
2022-08-14 18:30:55 +08:00
|
|
|
|
this.$prompt('输入设备名称', '新加设备', {
|
|
|
|
|
|
confirmButtonText: '确定',
|
|
|
|
|
|
inputPattern: /^[\s\S]*.*[^\s][\s\S]*$/,
|
|
|
|
|
|
inputErrorMessage: '请输入设备名称'
|
|
|
|
|
|
}).then(({ value }) => {
|
2022-08-17 00:05:22 +08:00
|
|
|
|
this.$api.ADD_DEVICE({ action: 'add_device', name: value, server_id: this.serverData.id })
|
2022-08-20 00:11:27 +08:00
|
|
|
|
this.getDevice()
|
2022-08-14 18:30:55 +08:00
|
|
|
|
this.$message({
|
|
|
|
|
|
message: '新加设备成功',
|
|
|
|
|
|
type: 'success'
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
2022-08-18 23:09:51 +08:00
|
|
|
|
async delDevice () {
|
2022-08-20 17:03:52 +08:00
|
|
|
|
const deviceConfigure = await this.$api.GET_HSLSERVER_CONFIGURE('http://' + this.serverData.url + ':' + this.serverData.port, 'admin', process.env.VUE_APP_HSLSERVER_PASSWORD)
|
2022-08-17 00:05:22 +08:00
|
|
|
|
let deviceNode = deviceConfigure.Content.Settings.GroupNode[0].DeviceNode
|
|
|
|
|
|
if (deviceNode !== undefined && isArray(deviceNode)) {
|
|
|
|
|
|
deviceNode = filter(deviceNode, item => {
|
|
|
|
|
|
return item['@Name'] === this.deviceData[this.deviceActiveStatus].name ? null : item
|
|
|
|
|
|
})
|
|
|
|
|
|
deviceConfigure.Content.Settings.GroupNode[0].DeviceNode = deviceNode
|
|
|
|
|
|
} else {
|
|
|
|
|
|
unset(deviceConfigure, 'Content.Settings.GroupNode[0].DeviceNode')
|
|
|
|
|
|
}
|
2022-08-18 14:21:08 +08:00
|
|
|
|
|
2022-08-14 18:30:55 +08:00
|
|
|
|
try {
|
2022-08-20 14:34:31 +08:00
|
|
|
|
await this.$api.SET_HSLSERVER_CONFIGURE('http://' + this.serverData.url + ':' + this.serverData.port, 'admin', process.env.VUE_APP_HSLSERVER_PASSWORD, { data: deviceConfigure.Content })
|
2022-08-14 18:30:55 +08:00
|
|
|
|
await this.$api.DEL_DEVICE({ action: 'remove_device', id: this.deviceData[this.deviceActiveStatus].id })
|
|
|
|
|
|
this.$message({
|
|
|
|
|
|
message: '删除设备成功',
|
|
|
|
|
|
type: 'success'
|
|
|
|
|
|
})
|
2022-08-13 16:20:48 +08:00
|
|
|
|
this.getDevice()
|
2022-08-14 18:30:55 +08:00
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.log(e)
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2022-08-18 23:09:51 +08:00
|
|
|
|
async addDevicePoint (row, done) {
|
2022-08-14 18:30:55 +08:00
|
|
|
|
this.formOptions.saveLoading = true
|
2022-08-17 00:05:22 +08:00
|
|
|
|
if (!this.$refs.deviceConfigure.defaultDeviceTypeNameValue) {
|
2022-08-14 18:30:55 +08:00
|
|
|
|
this.$message({
|
|
|
|
|
|
message: '请先应用设备配置',
|
|
|
|
|
|
type: 'error'
|
|
|
|
|
|
})
|
|
|
|
|
|
done(false)
|
|
|
|
|
|
} else {
|
2022-08-20 18:17:53 +08:00
|
|
|
|
if (row['@DataTypeCode'] === 'string' && !row['@Length']) {
|
|
|
|
|
|
this.$message({
|
|
|
|
|
|
message: '数据类型为string,长度不能为空',
|
|
|
|
|
|
type: 'error'
|
|
|
|
|
|
})
|
2022-08-20 23:23:30 +08:00
|
|
|
|
this.formOptions.saveLoading = false
|
2022-08-20 18:17:53 +08:00
|
|
|
|
return false
|
|
|
|
|
|
}
|
2022-08-20 23:23:30 +08:00
|
|
|
|
assign(row, {id:this.devicePointData.length + 1, showBindButton:true, showCopyButton:true, showRemoveButton:true, showSendButton:true, })
|
2022-08-14 18:30:55 +08:00
|
|
|
|
this.devicePointData.push(row)
|
|
|
|
|
|
done()
|
|
|
|
|
|
}
|
|
|
|
|
|
this.formOptions.saveLoading = false
|
|
|
|
|
|
},
|
2022-08-20 00:11:27 +08:00
|
|
|
|
|
2022-08-18 23:09:51 +08:00
|
|
|
|
async delDevicePoint ({ index, row }, done) {
|
2022-08-20 23:23:30 +08:00
|
|
|
|
this.$delete(this.devicePointData, index)
|
2022-08-14 18:30:55 +08:00
|
|
|
|
done()
|
|
|
|
|
|
},
|
2022-08-18 23:09:51 +08:00
|
|
|
|
async getDevicePoint () {
|
2022-08-17 00:05:22 +08:00
|
|
|
|
const data = { action: 'add_node', server_id: this.serverData.id, device_id: this.deviceData[this.deviceActiveStatus].id }
|
2022-08-14 18:30:55 +08:00
|
|
|
|
try {
|
|
|
|
|
|
this.devicePointData = await this.$api.GET_DEVICE_POINT(data)
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.log(e)
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2022-08-18 23:09:51 +08:00
|
|
|
|
async devicePointBandingNode ({ index, row }, done) {
|
2022-08-20 23:23:30 +08:00
|
|
|
|
this.$set(this.devicePointData[index], '@Binding', row.nodeCode)
|
2022-08-14 18:30:55 +08:00
|
|
|
|
done()
|
|
|
|
|
|
},
|
2022-08-18 23:09:51 +08:00
|
|
|
|
async setDeviceConfigure () {
|
2022-08-14 18:30:55 +08:00
|
|
|
|
try {
|
2022-08-18 14:21:08 +08:00
|
|
|
|
// 验证表单
|
|
|
|
|
|
this.$refs.deviceConfigure.$refs.form.validate((valid) => {
|
|
|
|
|
|
if (!valid) {
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2022-08-20 17:03:52 +08:00
|
|
|
|
const deviceConfigure = await this.$api.GET_HSLSERVER_CONFIGURE('http://' + this.serverData.url + ':' + this.serverData.port, 'admin', process.env.VUE_APP_HSLSERVER_PASSWORD)
|
|
|
|
|
|
const deviceConfigureModelValue = this.$refs.deviceConfigure.deviceConfigureModelValue
|
2022-08-14 18:30:55 +08:00
|
|
|
|
if (this.devicePointData.length > 0) {
|
2022-08-20 00:11:27 +08:00
|
|
|
|
let devicePointData = this.devicePointData
|
|
|
|
|
|
devicePointData = each(devicePointData, (item) => {
|
2022-08-20 18:17:53 +08:00
|
|
|
|
if (item['@DataTypeCode'] !== 'string') {
|
|
|
|
|
|
unset(item, '@Length')
|
|
|
|
|
|
}
|
2022-08-17 00:05:22 +08:00
|
|
|
|
unset(item, 'id')
|
|
|
|
|
|
unset(item, 'showBindButton')
|
|
|
|
|
|
unset(item, 'showCopyButton')
|
|
|
|
|
|
unset(item, 'showRemoveButton')
|
|
|
|
|
|
unset(item, 'showSendButton')
|
|
|
|
|
|
item['@Binding'] = item['@Binding'] || ''
|
|
|
|
|
|
})
|
2022-08-20 00:11:27 +08:00
|
|
|
|
deviceConfigureModelValue.RequestNode = devicePointData
|
2022-08-17 00:05:22 +08:00
|
|
|
|
}
|
2022-08-20 18:17:53 +08:00
|
|
|
|
|
2022-08-20 00:11:27 +08:00
|
|
|
|
deviceConfigureModelValue['@Name'] = this.deviceData[this.deviceActiveStatus].name
|
2022-08-17 00:05:22 +08:00
|
|
|
|
let deviceNode = deviceConfigure.Content.Settings.GroupNode[0].DeviceNode || []
|
|
|
|
|
|
let isExist = false
|
|
|
|
|
|
if (deviceNode !== undefined) {
|
|
|
|
|
|
deviceNode = isArray(deviceNode) ? deviceNode : [deviceNode]
|
|
|
|
|
|
deviceNode = map(deviceNode, (item) => {
|
|
|
|
|
|
if (item['@Name'] === this.deviceData[this.deviceActiveStatus].name) {
|
|
|
|
|
|
isExist = true
|
2022-08-20 00:11:27 +08:00
|
|
|
|
item = deviceConfigureModelValue
|
2022-08-17 00:05:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
return item
|
|
|
|
|
|
})
|
2022-08-14 18:30:55 +08:00
|
|
|
|
}
|
2022-08-17 00:05:22 +08:00
|
|
|
|
|
|
|
|
|
|
if (!isExist) {
|
2022-08-20 00:11:27 +08:00
|
|
|
|
deviceNode.push(deviceConfigureModelValue)
|
2022-08-17 00:05:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
deviceConfigure.Content.Settings.GroupNode[0].DeviceNode = deviceNode
|
2022-08-20 14:34:31 +08:00
|
|
|
|
await this.$api.SET_HSLSERVER_CONFIGURE('http://' + this.serverData.url + ':' + this.serverData.port, 'admin', process.env.VUE_APP_HSLSERVER_PASSWORD, { data: deviceConfigure.Content })
|
2022-08-20 00:11:27 +08:00
|
|
|
|
deviceConfigureModelValue.DeviceTypeName = this.$refs.deviceConfigure.defaultDeviceTypeNameValue
|
2022-08-14 18:30:55 +08:00
|
|
|
|
const data = {
|
|
|
|
|
|
action: 'update_device',
|
2022-08-20 00:11:27 +08:00
|
|
|
|
conf: JSON.stringify(deviceConfigureModelValue),
|
2022-08-14 18:30:55 +08:00
|
|
|
|
id: this.deviceData[this.deviceActiveStatus].id
|
|
|
|
|
|
}
|
|
|
|
|
|
this.$api.SET_DEVICE_CONFIGURE(data)
|
|
|
|
|
|
this.$message({
|
|
|
|
|
|
message: '操作成功',
|
|
|
|
|
|
type: 'success'
|
|
|
|
|
|
})
|
2022-08-20 00:11:27 +08:00
|
|
|
|
this.$emit('changeServerConfig', 't')
|
2022-08-14 18:30:55 +08:00
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.log(e)
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2022-08-20 17:03:52 +08:00
|
|
|
|
|
2022-08-20 00:11:27 +08:00
|
|
|
|
async getDeviceStatus () {
|
2022-08-20 14:34:31 +08:00
|
|
|
|
const res = await this.$api.GET_SERVER_DEVICE_STATUS('http://' + this.serverData.url + ':' + this.serverData.port, 'admin', process.env.VUE_APP_HSLSERVER_PASSWORD)
|
2022-08-20 00:11:27 +08:00
|
|
|
|
if (res) {
|
|
|
|
|
|
this.$emit('changeStatus', 'online')
|
|
|
|
|
|
const deviceStatus = {}
|
|
|
|
|
|
each(res.Content.__deviceList, (item) => {
|
|
|
|
|
|
deviceStatus[item.__name] = {
|
|
|
|
|
|
status: item.__requestEnable,
|
|
|
|
|
|
name: item.__name
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2022-08-14 18:30:55 +08:00
|
|
|
|
each(this.deviceData, (item) => {
|
2022-08-20 00:11:27 +08:00
|
|
|
|
if (deviceStatus[item.name]) {
|
|
|
|
|
|
item.status = deviceStatus[item.name].status
|
2022-08-14 18:30:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
2022-08-20 00:11:27 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
this.$emit('changeStatus', false)
|
|
|
|
|
|
}
|
2022-08-13 16:20:48 +08:00
|
|
|
|
}
|
2022-08-14 18:30:55 +08:00
|
|
|
|
},
|
2022-08-18 23:09:51 +08:00
|
|
|
|
mounted () {
|
2022-08-14 18:30:55 +08:00
|
|
|
|
this.getDevice()
|
|
|
|
|
|
this.getworkingSubclasses()
|
2022-08-20 00:11:27 +08:00
|
|
|
|
this.getDeviceStatus()
|
2022-08-14 18:30:55 +08:00
|
|
|
|
}
|
2022-08-13 16:20:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.menu-box {
|
2022-08-17 00:05:22 +08:00
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
|
padding: 10px;
|
|
|
|
|
|
vertical-align: middle;
|
2022-08-13 16:20:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.el-dropdown {
|
2022-08-17 00:05:22 +08:00
|
|
|
|
vertical-align: top;
|
2022-08-13 16:20:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.el-dropdown+.el-dropdown {
|
2022-08-17 00:05:22 +08:00
|
|
|
|
margin-left: 15px;
|
2022-08-13 16:20:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.el-icon-arrow-down {
|
2022-08-17 00:05:22 +08:00
|
|
|
|
font-size: 12px;
|
2022-08-13 16:20:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.menu-header {
|
2022-08-17 00:05:22 +08:00
|
|
|
|
position: relative;
|
2022-08-13 16:20:48 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.header-title {
|
2022-08-17 00:05:22 +08:00
|
|
|
|
width: 60%;
|
|
|
|
|
|
display: inline-block;
|
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
|
font-size: 20px;
|
|
|
|
|
|
color: black;
|
|
|
|
|
|
vertical-align: middle;
|
2022-08-13 16:20:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.header-button {
|
2022-08-17 00:05:22 +08:00
|
|
|
|
float: right;
|
|
|
|
|
|
vertical-align: middle;
|
2022-08-13 16:20:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.serve-item {
|
2022-08-17 00:05:22 +08:00
|
|
|
|
border: none;
|
|
|
|
|
|
margin-bottom: 10px;
|
|
|
|
|
|
box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
outline: 0;
|
|
|
|
|
|
border-radius: 4px;
|
2022-08-13 16:20:48 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.device-status {
|
2022-08-17 00:05:22 +08:00
|
|
|
|
width: 10px;
|
|
|
|
|
|
height: 10px;
|
|
|
|
|
|
border-radius: 50%;
|
2022-08-13 16:20:48 +08:00
|
|
|
|
|
2022-08-17 00:05:22 +08:00
|
|
|
|
right: 0;
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
top: 50%;
|
|
|
|
|
|
transform: translate(0, -50%);
|
2022-08-13 16:20:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.device-status-online {
|
2022-08-17 00:05:22 +08:00
|
|
|
|
background-color: #67c23a;
|
2022-08-13 16:20:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.device-status-offline {
|
2022-08-17 00:05:22 +08:00
|
|
|
|
background-color: #ccc;
|
2022-08-13 16:20:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
</style>
|