|
|
@@ -11,187 +11,230 @@
|
|
|
/>
|
|
|
<confirm-dialog
|
|
|
ref="editDialog"
|
|
|
- :title="dialogTitle"
|
|
|
+ title="新增网关"
|
|
|
@confirm="onConfirm"
|
|
|
>
|
|
|
<div class="c-grid-form u-align-self--center">
|
|
|
- <span class="c-grid-form__label u-required">名称</span>
|
|
|
- <el-input
|
|
|
- v-model.trim="gateway.name"
|
|
|
- placeholder="最多30个字符"
|
|
|
- maxlength="30"
|
|
|
- clearable
|
|
|
+ <span class="c-grid-form__label u-required">厂商</span>
|
|
|
+ <schema-select
|
|
|
+ ref="manufacturer"
|
|
|
+ v-model="item.manufacturerKey"
|
|
|
+ class="u-width"
|
|
|
+ placeholder="请选择厂商"
|
|
|
+ :schema="manufacturerSelectSchema"
|
|
|
/>
|
|
|
- <span class="c-grid-form__label u-required">地址</span>
|
|
|
+ <span class="c-grid-form__label u-required">型号</span>
|
|
|
<el-input
|
|
|
- v-model.trim="gateway.ip"
|
|
|
- placeholder="网关网络地址"
|
|
|
+ v-model.trim="item.model"
|
|
|
+ placeholder="最多50个字符"
|
|
|
+ maxlength="50"
|
|
|
clearable
|
|
|
/>
|
|
|
- <span class="c-grid-form__label u-required">MAC</span>
|
|
|
+ <span class="c-grid-form__label u-required">服务器地址</span>
|
|
|
<el-input
|
|
|
- v-model.trim="gateway.mac"
|
|
|
- class="u-width--sm"
|
|
|
- placeholder="ff:ff:ff:ff:ff:ff"
|
|
|
- maxlength="17"
|
|
|
+ v-model.trim="item.ip"
|
|
|
+ placeholder="10.180.88.84"
|
|
|
clearable
|
|
|
/>
|
|
|
- <span class="c-grid-form__label">账号</span>
|
|
|
- <el-input v-model.trim="gateway.account" />
|
|
|
- <span class="c-grid-form__label">密码</span>
|
|
|
+ <span class="c-grid-form__label u-required">服务器账号</span>
|
|
|
+ <el-input v-model.trim="item.account" />
|
|
|
+ <span class="c-grid-form__label u-required">服务器密码</span>
|
|
|
<el-input
|
|
|
- v-model.trim="gateway.password"
|
|
|
+ v-model.trim="item.password"
|
|
|
class="u-password"
|
|
|
/>
|
|
|
+ <span class="c-grid-form__label u-required">唯一标识</span>
|
|
|
+ <el-input
|
|
|
+ v-model.trim="item.identifier"
|
|
|
+ placeholder="最多50个字符"
|
|
|
+ maxlength="50"
|
|
|
+ clearable
|
|
|
+ />
|
|
|
</div>
|
|
|
</confirm-dialog>
|
|
|
- <device-dialog ref="deviceDialog" />
|
|
|
- <plc-dialog ref="plcDialog" />
|
|
|
- <sensor-dialog ref="sensorDialog" />
|
|
|
+ <table-dialog
|
|
|
+ ref="tableDialog"
|
|
|
+ title="关联设备"
|
|
|
+ :schema="deviceSchema"
|
|
|
+ />
|
|
|
+ <mesh-dialog ref="meshDialog" />
|
|
|
</wrapper>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { validMAC } from '@/utils/validate'
|
|
|
import {
|
|
|
+ ThirdPartyDevice,
|
|
|
+ ThirdPartyDeviceInfo,
|
|
|
+ SensorToThirdPartyMap
|
|
|
+} from '@/constant'
|
|
|
+import {
|
|
|
+ getManufacturersByType,
|
|
|
getGateways,
|
|
|
addGateway,
|
|
|
- updateGateway,
|
|
|
deleteGateway
|
|
|
} from '@/api/external'
|
|
|
-import PLCDialog from './components/PLCDialog.vue'
|
|
|
-import SensorDialog from './components/SensorDialog.vue'
|
|
|
+import { getFollowThirdPartyDevicesByThirdPartyDevice } from '@/api/mesh'
|
|
|
+import MeshDialog from '../components/MeshDialog.vue'
|
|
|
+
|
|
|
+const sensors = Object.values(SensorToThirdPartyMap)
|
|
|
|
|
|
export default {
|
|
|
name: 'GatewayList',
|
|
|
components: {
|
|
|
- plcDialog: PLCDialog,
|
|
|
- SensorDialog
|
|
|
+ MeshDialog
|
|
|
},
|
|
|
data () {
|
|
|
+ const manufacturerSelectSchema = {
|
|
|
+ remote: this.getManufacturersByType,
|
|
|
+ value: 'manufacturerKey',
|
|
|
+ label: 'manufacturerName'
|
|
|
+ }
|
|
|
+
|
|
|
return {
|
|
|
- gateway: {},
|
|
|
+ item: {},
|
|
|
+ manufacturerSelectSchema,
|
|
|
schema: {
|
|
|
list: getGateways,
|
|
|
buttons: [
|
|
|
{ type: 'add', on: this.onAdd }
|
|
|
],
|
|
|
filters: [
|
|
|
+ { key: 'manufacturerKey', type: 'select', placeholder: '厂商', ...manufacturerSelectSchema },
|
|
|
{ key: 'boundFlag', type: 'select', placeholder: '使用情况', options: [
|
|
|
- { value: 0, label: '未使用' },
|
|
|
- { value: 1, label: '已使用' }
|
|
|
+ { value: 0, label: '已使用' },
|
|
|
+ { value: 1, label: '未使用' }
|
|
|
] },
|
|
|
- { key: 'name', type: 'search', placeholder: '网关名称' }
|
|
|
+ { key: 'identifier', type: 'search', placeholder: '唯一标识' }
|
|
|
],
|
|
|
cols: [
|
|
|
- { prop: 'name', label: '名称' },
|
|
|
- { prop: 'ip', label: '地址' },
|
|
|
- { type: 'tag', render: ({ status }) => status === 1
|
|
|
- ? { type: 'success', label: '在线' }
|
|
|
- : { type: 'danger', label: '离线' } },
|
|
|
+ { prop: 'manufacturerName', label: '厂商' },
|
|
|
+ { prop: 'model', label: '型号' },
|
|
|
+ { prop: 'ip', label: '服务器地址' },
|
|
|
+ { prop: 'identifier', label: '唯一标识' },
|
|
|
{ label: '使用情况', type: 'tag', render: ({ bound }) => bound
|
|
|
? { type: 'success', label: '已使用' }
|
|
|
: { type: 'primary', label: '未使用' } },
|
|
|
- { type: 'invoke', width: 280, render: [
|
|
|
- { label: '编辑', on: this.onEdit },
|
|
|
- { label: 'PLC', on: this.onEditPLC },
|
|
|
- { label: '传感器', on: this.onEditSensor },
|
|
|
- { label: '相关设备', allow: ({ bound }) => bound, on: this.onViewDevice },
|
|
|
- { label: '删除', on: this.onDel }
|
|
|
- ] }
|
|
|
+ { type: 'invoke', render: [
|
|
|
+ { label: '关联设备', on: this.onViewDevices },
|
|
|
+ { label: '所属网点', allow: ({ bound }) => bound, on: this.onViewMesh },
|
|
|
+ { label: '删除', allow: ({ bound }) => !bound, on: this.onDel }
|
|
|
+ ], width: 200 }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ deviceSchema: {
|
|
|
+ nonPagination: true,
|
|
|
+ list: this.getFollowThirdPartyDevicesByThirdPartyDevice,
|
|
|
+ cols: [
|
|
|
+ { prop: 'type', label: '设备类型' },
|
|
|
+ { prop: 'manufacturerName', label: '厂商' },
|
|
|
+ { prop: 'model', label: '型号' },
|
|
|
+ { prop: 'identifier', label: '唯一标识' }
|
|
|
]
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
- computed: {
|
|
|
- dialogTitle () {
|
|
|
- return this.gateway.id ? '编辑网关' : '新增网关'
|
|
|
- }
|
|
|
- },
|
|
|
methods: {
|
|
|
+ getManufacturersByType () {
|
|
|
+ return getManufacturersByType(ThirdPartyDevice.GATEWAY)
|
|
|
+ },
|
|
|
onAdd () {
|
|
|
- this.gateway = {
|
|
|
- name: '',
|
|
|
+ this.item = {
|
|
|
+ identifier: '',
|
|
|
+ manufacturerKey: '',
|
|
|
+ model: '',
|
|
|
ip: '',
|
|
|
- mac: '',
|
|
|
account: '',
|
|
|
password: ''
|
|
|
}
|
|
|
this.$refs.editDialog.show()
|
|
|
},
|
|
|
- onEdit ({ id, name, ip, mac, account, password }) {
|
|
|
- this.$gateway = { id, name, ip, mac, account, password }
|
|
|
- this.gateway = { id, name, ip, mac, account, password }
|
|
|
- this.$refs.editDialog.show()
|
|
|
- },
|
|
|
onConfirm (done) {
|
|
|
- const gateway = this.gateway
|
|
|
- if (!gateway.name) {
|
|
|
+ if (!this.item.manufacturerKey) {
|
|
|
this.$message({
|
|
|
type: 'warning',
|
|
|
- message: '请填写网关名称'
|
|
|
+ message: '请选择厂商'
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
- if (!gateway.ip) {
|
|
|
+ if (!this.item.model) {
|
|
|
this.$message({
|
|
|
type: 'warning',
|
|
|
- message: '请填写网关地址'
|
|
|
+ message: '请填写型号'
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
- if (!gateway.mac) {
|
|
|
+ if (!this.item.identifier) {
|
|
|
this.$message({
|
|
|
type: 'warning',
|
|
|
- message: '请填写MAC'
|
|
|
+ message: '请填写唯一标识'
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
- if (!validMAC(gateway.mac)) {
|
|
|
+ if (!this.item.ip) {
|
|
|
this.$message({
|
|
|
type: 'warning',
|
|
|
- message: 'MAC格式不正确,例 ff:ff:ff:ff:ff:ff'
|
|
|
+ message: '请填写网关服务器地址'
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
- if (!gateway.account !== !gateway.password) {
|
|
|
+ if (!this.item.account) {
|
|
|
this.$message({
|
|
|
type: 'warning',
|
|
|
- message: '账号密码必须同时填写'
|
|
|
+ message: '请填写网关服务器账号'
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
- if (gateway.id) {
|
|
|
- this.onConfirmEdit(gateway, done)
|
|
|
- } else {
|
|
|
- this.onConfirmAdd(gateway, done)
|
|
|
+ if (!this.item.password) {
|
|
|
+ this.$message({
|
|
|
+ type: 'warning',
|
|
|
+ message: '请填写网关服务器密码'
|
|
|
+ })
|
|
|
+ return
|
|
|
}
|
|
|
- },
|
|
|
- onConfirmAdd (gateway, done) {
|
|
|
- addGateway(gateway).then(() => {
|
|
|
+ const key = this.item.manufacturerKey
|
|
|
+ addGateway({
|
|
|
+ manufacturerName: this.$refs.manufacturer.getOptions().find(({ value }) => value === key).label,
|
|
|
+ ...this.item
|
|
|
+ }).then(() => {
|
|
|
done()
|
|
|
- this.$refs.table.resetCondition()
|
|
|
+ this.$refs.table.resetCondition({
|
|
|
+ manufacturerKey: key,
|
|
|
+ identifier: this.item.identifier
|
|
|
+ })
|
|
|
})
|
|
|
},
|
|
|
- onConfirmEdit (gateway, done) {
|
|
|
- updateGateway(gateway).then(() => {
|
|
|
- done()
|
|
|
- this.$refs.table.pageTo()
|
|
|
+ onDel (item) {
|
|
|
+ deleteGateway(item).then(() => {
|
|
|
+ this.$refs.table.decrease(1)
|
|
|
})
|
|
|
},
|
|
|
- onDel (gateway) {
|
|
|
- deleteGateway(gateway).then(() => {
|
|
|
- this.$refs.table.decrease(1)
|
|
|
+ onViewDevices ({ id }) {
|
|
|
+ this.$gatewayId = id
|
|
|
+ this.$refs.tableDialog.show()
|
|
|
+ },
|
|
|
+ getFollowThirdPartyDevicesByThirdPartyDevice () {
|
|
|
+ return getFollowThirdPartyDevicesByThirdPartyDevice(this.$gatewayId, [
|
|
|
+ ...sensors,
|
|
|
+ ThirdPartyDevice.PLC
|
|
|
+ ]).then(({ data }) => {
|
|
|
+ return { data: data.filter(({ instance }) => instance).map(this.transformThirdPartyDevice) }
|
|
|
})
|
|
|
},
|
|
|
+ transformThirdPartyDevice ({ nodeType, instance }) {
|
|
|
+ const { manufacturerName, model, identifier } = instance
|
|
|
+ return {
|
|
|
+ type: ThirdPartyDeviceInfo[nodeType],
|
|
|
+ manufacturerName, model, identifier
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onViewMesh ({ id }) {
|
|
|
+ this.$refs.meshDialog.show(id)
|
|
|
+ },
|
|
|
onEditPLC ({ id }) {
|
|
|
this.$refs.plcDialog.show(id)
|
|
|
},
|
|
|
onEditSensor ({ id }) {
|
|
|
this.$refs.sensorDialog.show(id)
|
|
|
- },
|
|
|
- onViewDevice ({ id }) {
|
|
|
- this.$refs.deviceDialog.show(id)
|
|
|
}
|
|
|
}
|
|
|
}
|