|
|
@@ -11,105 +11,119 @@
|
|
|
<template v-else>
|
|
|
<template v-if="gateway">
|
|
|
<div class="c-sibling-item--v c-info">
|
|
|
- <div class="l-flex--row has-bottom-padding u-bold">
|
|
|
+ <div class="l-flex--row c-sibling-item--v u-bold">
|
|
|
<span class="c-sibling-item">网关信息</span>
|
|
|
<span
|
|
|
- class="c-sibling-item c-info__edit u-pointer"
|
|
|
+ class="c-sibling-item u-color--blue u-font-size--sm has-active"
|
|
|
@click="onUnbindGateway"
|
|
|
>
|
|
|
<i class="el-icon-edit" />
|
|
|
解绑
|
|
|
</span>
|
|
|
</div>
|
|
|
- <div class="l-flex--row c-info__block">
|
|
|
- <div class="l-flex--row l-flex__fill c-info__item">
|
|
|
+ <div class="l-flex--row c-sibling-item--v c-info__block">
|
|
|
+ <div class="l-flex--row l-flex__fill c-sibling-item">
|
|
|
<div class="l-flex__none c-info__title">名称</div>
|
|
|
<auto-text
|
|
|
class="l-flex__fill c-info__value"
|
|
|
:text="gateway.name"
|
|
|
/>
|
|
|
</div>
|
|
|
- <div class="l-flex--row l-flex__fill c-info__item">
|
|
|
+ <div class="l-flex--row l-flex__fill c-sibling-item">
|
|
|
<div class="l-flex__none c-info__title">地址</div>
|
|
|
<div class="l-flex__fill c-info__value">{{ gateway.ip }}</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
<div class="c-sibling-item--v far c-info">
|
|
|
- <div class="l-flex--row has-bottom-padding u-bold">
|
|
|
+ <div class="l-flex--row c-sibling-item--v u-bold">
|
|
|
<span class="c-sibling-item">PLC信息</span>
|
|
|
+ <i
|
|
|
+ v-if="plcOptions.loading"
|
|
|
+ class="c-sibling-item el-icon-loading"
|
|
|
+ />
|
|
|
<span
|
|
|
- class="c-sibling-item c-info__edit u-pointer"
|
|
|
+ v-else-if="!plcOptions.error"
|
|
|
+ class="c-sibling-item u-color--blue u-font-size--sm has-active"
|
|
|
@click="onBindPLC"
|
|
|
>
|
|
|
<i class="el-icon-edit" />
|
|
|
绑定
|
|
|
</span>
|
|
|
</div>
|
|
|
+ <warning
|
|
|
+ v-if="plcOptions.error"
|
|
|
+ @click="getBoundPLCs"
|
|
|
+ />
|
|
|
<div
|
|
|
- v-if="plcs.length === 0"
|
|
|
- class="u-color--info"
|
|
|
+ v-if="!plcOptions.loading && plcOptions.list.length === 0"
|
|
|
+ class="c-sibling-item--v u-font-size--sm u-color--info"
|
|
|
>
|
|
|
暂未绑定
|
|
|
</div>
|
|
|
<div
|
|
|
- v-for="plc in plcs"
|
|
|
+ v-for="plc in plcOptions.list"
|
|
|
:key="plc.id"
|
|
|
- class="l-flex--row c-info__block"
|
|
|
+ class="l-flex--row c-sibling-item--v c-info__block"
|
|
|
>
|
|
|
- <div class="l-flex--row l-flex__fill c-info__item">
|
|
|
+ <div class="l-flex--row l-flex__fill c-sibling-item">
|
|
|
<div class="l-flex__none c-info__title">
|
|
|
<span
|
|
|
- class="c-info__edit u-pointer"
|
|
|
+ class="c-sibling-item u-color--blue u-font-size--sm has-active"
|
|
|
@click="onUnbindPLC(plc)"
|
|
|
>
|
|
|
解绑
|
|
|
</span>
|
|
|
- 名称
|
|
|
+ <span class="c-sibling-item">
|
|
|
+ 名称
|
|
|
+ </span>
|
|
|
</div>
|
|
|
<auto-text
|
|
|
class="l-flex__fill c-info__value"
|
|
|
:text="plc.thirdPartyDevice.name"
|
|
|
/>
|
|
|
</div>
|
|
|
- <div class="l-flex--row l-flex__fill c-info__item">
|
|
|
+ <div class="l-flex--row l-flex__fill c-sibling-item">
|
|
|
<div class="l-flex__none c-info__title">地址</div>
|
|
|
<div class="l-flex__fill c-info__value">{{ plc.thirdPartyDevice.identifier }}</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
<div class="c-sibling-item--v far c-info">
|
|
|
- <div class="l-flex--row has-bottom-padding u-bold">传感器信息</div>
|
|
|
+ <div class="l-flex--row c-sibling-item--v u-bold">
|
|
|
+ <span class="c-sibling-item">传感器信息</span>
|
|
|
+ <i
|
|
|
+ v-if="sensorOptions.loading"
|
|
|
+ class="c-sibling-item el-icon-loading"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
<warning
|
|
|
v-if="sensorOptions.error"
|
|
|
@click="getSensors"
|
|
|
/>
|
|
|
- <div v-else-if="sensorOptions.loading">
|
|
|
- <i class="el-icon el-icon-loading" />
|
|
|
- </div>
|
|
|
<div
|
|
|
- v-else-if="sensorOptions.list.length === 0"
|
|
|
- class="u-color--info"
|
|
|
+ v-if="!sensorOptions.loading && sensorOptions.list.length === 0"
|
|
|
+ class="c-sibling-item--v u-font-size--sm u-color--info"
|
|
|
>
|
|
|
暂未绑定
|
|
|
</div>
|
|
|
<div
|
|
|
v-for="sensor in sensorOptions.list"
|
|
|
:key="sensor.id"
|
|
|
- class="l-flex--row c-info__block"
|
|
|
+ class="l-flex--row c-sibling-item--v c-info__block"
|
|
|
>
|
|
|
- <div class="l-flex--row l-flex__fill c-info__item">
|
|
|
+ <div class="l-flex--row l-flex__fill c-sibling-item">
|
|
|
<div class="l-flex__none c-info__title">名称</div>
|
|
|
<auto-text
|
|
|
class="l-flex__fill c-info__value"
|
|
|
:text="sensor.name"
|
|
|
/>
|
|
|
</div>
|
|
|
- <div class="l-flex--row l-flex__fill c-info__item">
|
|
|
+ <div class="l-flex--row l-flex__fill c-sibling-item">
|
|
|
<div class="l-flex__none c-info__title">标识</div>
|
|
|
<div class="l-flex__fill c-info__value">{{ sensor.identifier }}</div>
|
|
|
</div>
|
|
|
- <div class="l-flex--row l-flex__fill c-info__item">
|
|
|
+ <div class="l-flex--row l-flex__fill c-sibling-item">
|
|
|
<div class="l-flex__none c-info__title">类型</div>
|
|
|
<div class="l-flex__fill c-info__value">{{ sensor.type }}</div>
|
|
|
</div>
|
|
|
@@ -142,15 +156,16 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+import { ThirdPartyDevice } from '@/constant'
|
|
|
import {
|
|
|
getGateway,
|
|
|
- getGateways,
|
|
|
bindGateway,
|
|
|
getBoundPLCs,
|
|
|
getPLCs,
|
|
|
bindPLC,
|
|
|
unbind,
|
|
|
- getSensors
|
|
|
+ getSensors,
|
|
|
+ getThirdPartyDevices
|
|
|
} from '@/api/external'
|
|
|
|
|
|
export default {
|
|
|
@@ -165,8 +180,13 @@ export default {
|
|
|
return {
|
|
|
loading: false,
|
|
|
error: false,
|
|
|
- info: null,
|
|
|
+ gatewayProxy: null,
|
|
|
deviceType: 'GATEWAY',
|
|
|
+ plcOptions: {
|
|
|
+ list: [],
|
|
|
+ loading: false,
|
|
|
+ error: false
|
|
|
+ },
|
|
|
sensorOptions: {
|
|
|
list: [],
|
|
|
loading: false,
|
|
|
@@ -204,52 +224,39 @@ export default {
|
|
|
}
|
|
|
default:
|
|
|
return {
|
|
|
- list: getGateways,
|
|
|
+ list: getThirdPartyDevices,
|
|
|
+ condition: { deviceType: ThirdPartyDevice.GATEWAY },
|
|
|
+ filters: [
|
|
|
+ { key: 'name', type: 'search', placeholder: '网关名称' }
|
|
|
+ ],
|
|
|
cols: [
|
|
|
{ prop: 'name', label: '名称' },
|
|
|
- { prop: 'ip', label: '地址' }
|
|
|
+ { prop: 'ip', label: '地址' },
|
|
|
+ { prop: 'remark', label: '备注' }
|
|
|
]
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
gateway () {
|
|
|
- return this.info?.gateway?.thirdPartyDevice
|
|
|
- },
|
|
|
- plcs () {
|
|
|
- return this.info?.plcs || []
|
|
|
+ return this.gatewayProxy?.thirdPartyDevice
|
|
|
}
|
|
|
},
|
|
|
created () {
|
|
|
- this.getInfo()
|
|
|
+ this.getGateway()
|
|
|
},
|
|
|
methods: {
|
|
|
- getInfo (type) {
|
|
|
+ getGateway () {
|
|
|
if (this.loading) {
|
|
|
return
|
|
|
}
|
|
|
this.loading = true
|
|
|
this.error = false
|
|
|
-
|
|
|
- let arr
|
|
|
- if (this.info && type) {
|
|
|
- switch (type) {
|
|
|
- case 'PLC':
|
|
|
- arr = [Promise.resolve(this.info.gateway), this.getBoundPLCs()]
|
|
|
- break
|
|
|
- default:
|
|
|
- arr = [this.getGateway(), this.getBoundPLCs()]
|
|
|
- break
|
|
|
- }
|
|
|
- } else {
|
|
|
- arr = [this.getGateway(), this.getBoundPLCs()]
|
|
|
- }
|
|
|
-
|
|
|
- this.info = null
|
|
|
- Promise.all(arr).then(
|
|
|
- data => {
|
|
|
- this.info = {
|
|
|
- gateway: data[0],
|
|
|
- plcs: data[1]
|
|
|
+ getGateway(this.device.id).then(
|
|
|
+ gateway => {
|
|
|
+ this.gatewayProxy = gateway
|
|
|
+ if (gateway) {
|
|
|
+ this.getBoundPLCs()
|
|
|
+ this.getSensors()
|
|
|
}
|
|
|
},
|
|
|
() => {
|
|
|
@@ -257,21 +264,33 @@ export default {
|
|
|
}
|
|
|
).finally(() => {
|
|
|
this.loading = false
|
|
|
- if (this.gateway) {
|
|
|
- this.getSensors()
|
|
|
- }
|
|
|
})
|
|
|
},
|
|
|
- getGateway () {
|
|
|
- return getGateway(this.device.id)
|
|
|
- },
|
|
|
getBoundPLCs () {
|
|
|
- return getBoundPLCs(this.device.id)
|
|
|
+ this.plcOptions.loading = true
|
|
|
+ this.plcOptions.error = false
|
|
|
+ getBoundPLCs(this.device.id).then(
|
|
|
+ data => {
|
|
|
+ this.plcOptions.list = data
|
|
|
+ },
|
|
|
+ () => {
|
|
|
+ this.plcOptions.error = true
|
|
|
+ }
|
|
|
+ ).finally(() => {
|
|
|
+ this.plcOptions.loading = false
|
|
|
+ })
|
|
|
},
|
|
|
onChoosen ({ value, done }) {
|
|
|
(this.deviceType === 'PLC' ? bindPLC : bindGateway)(this.device.id, value.id).then(() => {
|
|
|
done()
|
|
|
- this.getInfo(this.deviceType)
|
|
|
+ switch (this.deviceType) {
|
|
|
+ case 'PLC':
|
|
|
+ this.getBoundPLCs()
|
|
|
+ break
|
|
|
+ default:
|
|
|
+ this.getGateway()
|
|
|
+ break
|
|
|
+ }
|
|
|
})
|
|
|
},
|
|
|
onBindGateway () {
|
|
|
@@ -279,25 +298,19 @@ export default {
|
|
|
this.$refs.chooseDialog.show()
|
|
|
},
|
|
|
onUnbindGateway () {
|
|
|
- if (this.plcs.length) {
|
|
|
- this.$message({
|
|
|
- type: 'warning',
|
|
|
- message: '请先解绑所有PLC'
|
|
|
- })
|
|
|
- return
|
|
|
- }
|
|
|
this.$confirm(
|
|
|
- '解绑网关?',
|
|
|
+ `解绑网关 ${this.gateway.name}?`,
|
|
|
+ '操作确认',
|
|
|
{ type: 'warning' }
|
|
|
).then(() => {
|
|
|
- unbind(this.info.gateway.id).then(() => {
|
|
|
- this.info = null
|
|
|
+ unbind(this.gatewayProxy.id).then(() => {
|
|
|
+ this.gatewayProxy = null
|
|
|
})
|
|
|
})
|
|
|
},
|
|
|
getPLCs (params) {
|
|
|
return getPLCs({
|
|
|
- gatewayId: this.gateway.id,
|
|
|
+ gatewayId: this.gatewayProxy.id,
|
|
|
...params
|
|
|
})
|
|
|
},
|
|
|
@@ -308,17 +321,18 @@ export default {
|
|
|
onUnbindPLC (plc) {
|
|
|
this.$confirm(
|
|
|
`解绑PLC ${plc.thirdPartyDevice.name}?`,
|
|
|
+ '操作确认',
|
|
|
{ type: 'warning' }
|
|
|
).then(() => {
|
|
|
unbind(plc.id).then(() => {
|
|
|
- this.plcs.splice(this.plcs.indexOf(plc), 1)
|
|
|
+ this.plcOptions.list.splice(this.plcOptions.list.indexOf(plc), 1)
|
|
|
})
|
|
|
})
|
|
|
},
|
|
|
getSensors () {
|
|
|
this.sensorOptions.loading = true
|
|
|
this.sensorOptions.error = false
|
|
|
- getSensors(this.gateway.id).then(
|
|
|
+ getSensors(this.gatewayProxy.id).then(
|
|
|
({ data }) => {
|
|
|
this.sensorOptions.list = data.map(sensor => {
|
|
|
sensor.type = ['烟雾', '温度', '光照', '水浸'][sensor.sensorType]
|