|
|
@@ -1,15 +1,10 @@
|
|
|
<script>
|
|
|
-import {
|
|
|
- ThirdPartyDevice,
|
|
|
- PowerAction
|
|
|
-} from '@/constant'
|
|
|
+import { PowerAction } from '@/constant'
|
|
|
import { publish } from '@/utils/mqtt'
|
|
|
import {
|
|
|
- Status,
|
|
|
+ RELAY_KEY,
|
|
|
GET_MULTI_POWER_TIMING,
|
|
|
SET_MULTI_POWER_TIMING,
|
|
|
- addListener,
|
|
|
- removeListener,
|
|
|
addInjectListener,
|
|
|
removeInjectListener
|
|
|
} from '@/utils/adapter'
|
|
|
@@ -38,36 +33,19 @@ export default {
|
|
|
data () {
|
|
|
return {
|
|
|
status: 0,
|
|
|
- retryCount: 0,
|
|
|
- cardInfo: null
|
|
|
+ retryCount: 0
|
|
|
}
|
|
|
},
|
|
|
mounted () {
|
|
|
this.$timer = -1
|
|
|
- addListener(this.device.id, this.onMessage)
|
|
|
addInjectListener(this.device.id, this.onInjectMessage)
|
|
|
+ this.onSync()
|
|
|
},
|
|
|
beforeDestroy () {
|
|
|
clearTimeout(this.$timer)
|
|
|
- removeListener(this.device.id, this.onMessage)
|
|
|
removeInjectListener(this.device.id, this.onInjectMessage)
|
|
|
},
|
|
|
methods: {
|
|
|
- onMessage (value) {
|
|
|
- const multiCard = value[ThirdPartyDevice.MULTI_FUNCTION_CARD]
|
|
|
- if (multiCard.status === Status.OK) {
|
|
|
- if (!this.cardInfo) {
|
|
|
- const { connectIndex, portIndex } = multiCard.powers[0]
|
|
|
- const type = multiCard.powers.find(({ type }) => type === '屏体电源' || type === '默认')?.type || multiCard.powers.find(({ type }) => !!type)?.type
|
|
|
- this.cardInfo = { type, connectIndex, portIndex }
|
|
|
- if (type) {
|
|
|
- this.onSync()
|
|
|
- } else {
|
|
|
- this.status = 4
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
onInjectMessage (message) {
|
|
|
if (message.messageId === this.$messageId) {
|
|
|
this.$messageId = null
|
|
|
@@ -83,7 +61,7 @@ export default {
|
|
|
switch (message.function) {
|
|
|
case GET_MULTI_POWER_TIMING:
|
|
|
clearTimeout(this.$timer)
|
|
|
- this.sendTasks(data.data)
|
|
|
+ this.sendTasks(data.data.filter(({ connectIndex, portIndex }) => connectIndex !== RELAY_KEY && portIndex !== RELAY_KEY))
|
|
|
break
|
|
|
case SET_MULTI_POWER_TIMING:
|
|
|
clearTimeout(this.$timer)
|
|
|
@@ -102,29 +80,22 @@ export default {
|
|
|
clearTimeout(this.$timer)
|
|
|
})
|
|
|
},
|
|
|
- createTasks () {
|
|
|
- const type = this.cardInfo.type
|
|
|
- return this.tasks.map(task => {
|
|
|
- return {
|
|
|
- ...task,
|
|
|
- type
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
sendTasks (tasks) {
|
|
|
- const data = []
|
|
|
- const { connectIndex, portIndex } = this.cardInfo
|
|
|
- const currTasks = tasks.find(item => item.connectIndex === connectIndex && item.portIndex === portIndex)?.conditions
|
|
|
- if (currTasks) {
|
|
|
- const { change, data: newTasks } = this.checkAndTransfromTasks(currTasks)
|
|
|
- if (change) {
|
|
|
- this.status = 1
|
|
|
+ if (tasks.length) {
|
|
|
+ let needUpdate = false
|
|
|
+ const data = []
|
|
|
+ for (let i = 0; i < tasks.length; i++) {
|
|
|
+ const { enable, conditions, ...options } = tasks[i]
|
|
|
+ const { change, data: newTasks } = this.checkAndTransfromTasks(conditions)
|
|
|
+ needUpdate = needUpdate || change
|
|
|
data.push({
|
|
|
- connectIndex,
|
|
|
- portIndex,
|
|
|
+ ...options,
|
|
|
enable: true,
|
|
|
conditions: newTasks.map(({ status, ...task }) => task)
|
|
|
})
|
|
|
+ }
|
|
|
+ if (needUpdate) {
|
|
|
+ this.status = 1
|
|
|
this.$timer = setTimeout(this.retry, 5000)
|
|
|
this.sendTopic(SET_MULTI_POWER_TIMING, {
|
|
|
sn: this.device.serialNumber,
|