|
|
@@ -27,14 +27,17 @@ export default {
|
|
|
data () {
|
|
|
return {
|
|
|
status: 0,
|
|
|
+ retryCount: 1,
|
|
|
cardInfo: null
|
|
|
}
|
|
|
},
|
|
|
mounted () {
|
|
|
+ this.$timer = -1
|
|
|
addListener(this.device.id, this.onMessage)
|
|
|
addInjectListener(this.device.id, this.onInjectMessage)
|
|
|
},
|
|
|
beforeDestroy () {
|
|
|
+ clearTimeout(this.$timer)
|
|
|
removeListener(this.device.id, this.onMessage)
|
|
|
removeInjectListener(this.device.id, this.onInjectMessage)
|
|
|
},
|
|
|
@@ -68,10 +71,15 @@ export default {
|
|
|
}
|
|
|
switch (message.function) {
|
|
|
case GET_MULTI_POWER_TIMING:
|
|
|
- this.status = 1
|
|
|
- this.sendTasks(data.data)
|
|
|
+ clearTimeout(this.$timer)
|
|
|
+ if (this.retryCount > 0) {
|
|
|
+ this.checkTasks(data.data)
|
|
|
+ } else {
|
|
|
+ this.sendTasks(data.data)
|
|
|
+ }
|
|
|
break
|
|
|
case SET_MULTI_POWER_TIMING:
|
|
|
+ clearTimeout(this.$timer)
|
|
|
this.status = 2
|
|
|
break
|
|
|
default:
|
|
|
@@ -80,8 +88,11 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
onSync () {
|
|
|
+ this.$timer = setTimeout(this.retry, 5000)
|
|
|
this.sendTopic(GET_MULTI_POWER_TIMING, { sn: this.device.serialNumber }).then(messageId => {
|
|
|
this.$messageId = messageId
|
|
|
+ }, () => {
|
|
|
+ clearTimeout(this.$timer)
|
|
|
})
|
|
|
},
|
|
|
createTasks () {
|
|
|
@@ -94,6 +105,7 @@ export default {
|
|
|
})
|
|
|
},
|
|
|
sendTasks (tasks) {
|
|
|
+ this.status = 1
|
|
|
const data = []
|
|
|
const { connectIndex, portIndex } = this.cardInfo
|
|
|
const currTasks = tasks.find(item => item.connectIndex === connectIndex && item.portIndex === portIndex)?.conditions
|
|
|
@@ -115,7 +127,7 @@ export default {
|
|
|
conditions: this.createTasks()
|
|
|
})
|
|
|
}
|
|
|
- console.log(data)
|
|
|
+ this.$timer = setTimeout(this.retry, 5000)
|
|
|
this.sendTopic(SET_MULTI_POWER_TIMING, {
|
|
|
sn: this.device.serialNumber,
|
|
|
taskInfo: data
|
|
|
@@ -130,8 +142,30 @@ export default {
|
|
|
tasks: this.tasks
|
|
|
})
|
|
|
})
|
|
|
+ }, () => {
|
|
|
+ clearTimeout(this.$timer)
|
|
|
})
|
|
|
},
|
|
|
+ retry () {
|
|
|
+ this.retryCount += 1
|
|
|
+ this.status = 1
|
|
|
+ this.onSync()
|
|
|
+ },
|
|
|
+ checkTasks (tasks) {
|
|
|
+ const { connectIndex, portIndex } = this.cardInfo
|
|
|
+ const currTasks = tasks.find(item => item.connectIndex === connectIndex && item.portIndex === portIndex)?.conditions
|
|
|
+ if (currTasks) {
|
|
|
+ const map = {}
|
|
|
+ this.tasks.forEach(({ flag }) => {
|
|
|
+ map[flag] = true
|
|
|
+ })
|
|
|
+ if (currTasks.some(({ flag }) => map[flag])) {
|
|
|
+ this.status = 2
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.sendTasks(tasks)
|
|
|
+ },
|
|
|
sendTopic (invoke, inputs) {
|
|
|
const timestamp = `${Date.now()}`
|
|
|
const messageId = `${invoke}_${timestamp}`
|
|
|
@@ -148,14 +182,32 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
render (h) {
|
|
|
+ if (this.status === 3 || this.status === 4) {
|
|
|
+ return h('el-tooltip', {
|
|
|
+ props: {
|
|
|
+ content: this.status === 3 ? '连接失败,请联系管理员' : '无可用端口,请联系管理员',
|
|
|
+ placement: 'left',
|
|
|
+ enterable: false
|
|
|
+ }
|
|
|
+ }, [
|
|
|
+ h('el-tag', {
|
|
|
+ staticClass: 'o-tag u-readonly',
|
|
|
+ props: {
|
|
|
+ size: 'medium',
|
|
|
+ 'disable-transitions': true,
|
|
|
+ type: 'danger'
|
|
|
+ }
|
|
|
+ }, '失败')
|
|
|
+ ])
|
|
|
+ }
|
|
|
return h('el-tag', {
|
|
|
staticClass: 'o-tag u-readonly',
|
|
|
props: {
|
|
|
size: 'medium',
|
|
|
'disable-transitions': true,
|
|
|
- type: ['primary', 'warning', 'success', 'danger', 'danger'][this.status]
|
|
|
+ type: ['primary', 'warning', 'success'][this.status]
|
|
|
}
|
|
|
- }, ['同步中', '等待中', '成功', '失败', '无目标'][this.status])
|
|
|
+ }, ['等待', this.retryCount === 0 ? '同步中' : `重试(${this.retryCount})`, '成功'][this.status])
|
|
|
}
|
|
|
}
|
|
|
</script>
|