Browse Source

盒管理 绑定标签

master
z_yu 3 years ago
parent
commit
8f63f56129
  1. 70
      src/views/components/BindingTagDlg.vue

70
src/views/components/BindingTagDlg.vue

@ -1,6 +1,6 @@
<template>
<div>
<el-dialog class="bindingDialog" :title="bindingTitle" :visible.sync="bindingVisible" :close-on-click-modal="false" :before-close="handleClose" @opened="opened">
<el-dialog ref="dialog" class="bindingDialog" :title="bindingTitle" :visible.sync="bindingVisible" :close-on-click-modal="false" :before-close="handleClose" @opened="opened">
<span class="dialog-right-top" />
<span class="dialog-left-bottom" />
<div class="setting-dialog">
@ -132,26 +132,13 @@ export default {
this.step4Message = '标签读取成功后,开始绑定档案'
this.step5Message = '当前标签与档案绑定成功'
},
opened() {
RFID.checkStatus({ op: 'RFID_CheckStatus', sDevID: 'D001' }).then((res) => {
async checkStatus(param) {
return RFID.checkStatus(param).then((res) => {
res = JSON.parse(res)
if (res.code === '0') {
this.step = 2
this.step1Message = '连接成功'
RFID.readEpc({ op: 'RFID_ReadEpc', sDevID: 'D001' }).then((res) => {
res = JSON.parse(res)
console.log(res)
if (res.code === '0') {
this.step = 3
this.step2Message = '已放入标签'
} else if (res.code === '-2') {
this.errorStep = 2
this.step2Message = '未读取到标签,请重新放入'
} else {
this.errorStep = 2
this.step2Message = '读取标签失败'
}
})
return true
} else {
this.errorStep = 1
if (res.code === '-1') {
@ -160,11 +147,54 @@ export default {
this.step1Message = '读写器超时未响应(例如终端读写服务未开启或网络异常)'
}
}
}).catch(() => {
this.errorStep = 1
this.step1Message = '连接失败,请检查网络'
})
},
async readEpc(param) {
return new Promise((resolve, reject) => {
RFID.readEpc(param).then(res => {
res = JSON.parse(res)
if (res.code === '0') {
this.step = 3
this.step2Message = '已放入标签'
resolve()
} else if (res.code === '2') {
this.errorStep = 2
this.step2Message = '未读取到标签,请重新放入'
setTimeout(() => {
resolve(this.readEpc(param))
}, 1000)
} else {
this.errorStep = 2
this.step2Message = '读取标签失败'
reject()
}
})
})
},
async tryConnect(param) {
let res
let err
const MAX_NUM_RETRIES = 3
for (let i = 0; i < MAX_NUM_RETRIES; i++) {
try {
res = await this.checkStatus(param)
break
} catch (e) {
err = e
this.errorStep = 1
this.step1Message = '连接失败,请检查网络'
}
}
if (res) return res
setTimeout(() => {
this.$refs.dialog.handleClose()
}, 3000)
throw err
},
async opened() {
await this.tryConnect({ op: 'RFID_CheckStatus', sDevID: 'D001' })
await this.readEpc({ op: 'RFID_ReadEpc', sDevID: 'D001' })
},
//
handleClose(done) {
this.coverBindingVisible = false

Loading…
Cancel
Save