From d27383e2d625a6ab82269c6067687525d09d8081 Mon Sep 17 00:00:00 2001 From: z_yu <1534695664@qq.com> Date: Sat, 17 Sep 2022 09:41:08 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A6=BB=E7=BA=BF=E6=A8=A1=E5=BC=8FRFID?= =?UTF-8?q?=E8=A7=A3=E9=99=A4=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lendManage/mixins/lending.js | 265 ++++++++++-------- 1 file changed, 153 insertions(+), 112 deletions(-) diff --git a/src/views/archivesManage/lendManage/mixins/lending.js b/src/views/archivesManage/lendManage/mixins/lending.js index 30ac1f8..89b4b42 100644 --- a/src/views/archivesManage/lendManage/mixins/lending.js +++ b/src/views/archivesManage/lendManage/mixins/lending.js @@ -57,13 +57,13 @@ export const lendingCrud = { devId: '', devIp: '', timer: null, - flagNum: 0, + // flagNum: 0, unbindWarnLoading: false, tipIndex: 0, ase: 0, - tagType: null, - arcId: null, - aseTid: null, + tagType: null, // 不需要 + arcId: null, // 不需要 + aseTid: null, // 不需要 isFlag: false, isKey: false } @@ -165,66 +165,82 @@ export const lendingCrud = { }, // 写epc async writeEPC() { - if (this.isFlag) { - this.tagType = this.tipTable[this.tipIndex].tagType - this.arcId = this.tipTable[this.tipIndex].archivesId - this.aseTid = this.tipTable[this.tipIndex].tid - } + this.tagType = this.tipTable[this.tipIndex].tagType + this.arcId = this.tipTable[this.tipIndex].archivesId + this.aseTid = this.tipTable[this.tipIndex].tid this.flagNum++ - this.btnDisabled = true - this.unbindWarnLoading = true + // this.btnDisabled = true + // this.unbindWarnLoading = true return new Promise(async(resolve, reject) => { const params = { op: 'RFID_WriteEPC', sDevID: this.devId, EAS: this.ase, Type: this.tagType, Code: this.arcId, Tid: this.aseTid, ip: this.devIp } - let writeRes = await RFID.writeEPC(params) - writeRes = JSON.parse(writeRes) - if (writeRes.code === '0') { - this.isKey = !this.isKey - // 判断是解除还是恢复 - if (this.ase === 0) { - this.tipTable[this.tipIndex].warnState = '已解除' - } else { - this.tipTable[this.tipIndex].warnState = '已恢复' + const MAX_NUM_RETRIES = 3 + for (let i = 0; i < MAX_NUM_RETRIES; i++) { + let writeRes = await RFID.writeEPC(params) + console.log('writeRes', writeRes) + writeRes = JSON.parse(writeRes) + if (writeRes.code === '0') { + this.isKey = !this.isKey + // 判断是解除还是恢复 + if (this.ase === 0) { + this.tipTable[this.tipIndex].warnState = '已解除' + // Vue.set(this.tipTable[this.tipIndex], 'warnState', '已解除') + // console.log(this.tipTable[this.tipIndex]) + // Vue.set(this.tipTable, this.tipIndex, this.tipTable[this.tipIndex]) + // this.tipTable.splice(this.tipIndex, 0) + } else { + this.tipTable[this.tipIndex].warnState = '已恢复' + } + break } - this.btnDisabled = false - this.unbindWarnLoading = false - - // this.tipIndex = this.tipIndex + 1 - if (this.tipIndex !== this.tipTable.length) { - this.flagNum = 0 - this.btnDisabled = true - this.unbindWarnLoading = true - clearTimeout(this.timer) - this.timer = setTimeout(() => { - resolve(this.writeEPC()) - }, 2000) - } else { - clearTimeout(this.timer) - setTimeout(() => { - const index = this.tipTable.findIndex((item) => item.warnState === '解除失败' || item.warnState === '恢复失败') - if (index === -1) { - let params - if (this.ase === 0) { - params = this.lendSelections.map(item => item.orderNo) - } else { - params = this.lendSelections.map(item => item.id) - } - console.log(params) - // 全部成功之后确认借出 / 归还 - this.confirmLendOrReturn(this.ase, params, this.lendSelections) - } else { - this.alarmErrorTip() - } - }, 4000) + if (i === 3) { + if (this.ase === 0) { + this.tipTable[this.tipIndex].warnState = '解除失败' + } else { + this.tipTable[this.tipIndex].warnState = '恢复失败' + } + resolve() } - // resolve() - } else if (writeRes.code === '-1') { - this.releaseAlarmErrorHandle(resolve, '标签损坏或丢失,需要用户自主去解除或恢复电子标签绑定') - // reject() - } else if (writeRes.code === '-1000') { - this.releaseAlarmErrorHandle(resolve, '读写器超时未响应') - // reject() } + resolve() + // this.btnDisabled = false + // this.unbindWarnLoading = false + // this.tipIndex = this.tipIndex + 1 + // if (this.tipIndex !== this.tipTable.length) { + // this.flagNum = 0 + // this.btnDisabled = true + // this.unbindWarnLoading = true + // clearTimeout(this.timer) + // this.timer = setTimeout(() => { + // resolve(this.writeEPC()) + // }, 2000) + // } else { + // clearTimeout(this.timer) + // setTimeout(() => { + // const index = this.tipTable.findIndex((item) => item.warnState === '解除失败' || item.warnState === '恢复失败') + // if (index === -1) { + // let params + // if (this.ase === 0) { + // params = this.lendSelections.map(item => item.orderNo) + // } else { + // params = this.lendSelections.map(item => item.id) + // } + // console.log(params) + // // 全部成功之后确认借出 / 归还 + // this.confirmLendOrReturn(this.ase, params, this.lendSelections) + // } else { + // this.alarmErrorTip() + // } + // }, 4000) + // } + // resolve() + // } else if (writeRes.code === '-1') { + // this.releaseAlarmErrorHandle(resolve, '标签损坏或丢失,需要用户自主去解除或恢复电子标签绑定') + // // reject() + // } else if (writeRes.code === '-1000') { + // this.releaseAlarmErrorHandle(resolve, '读写器超时未响应') + // // reject() + // } }) }, async getDevId() { @@ -243,33 +259,30 @@ export const lendingCrud = { } }) }, - readEpc(param) { + readEpc(devParam, tipTableIndex) { return new Promise((resolve, reject) => { - RFID.readEpc(param).then(res => { + RFID.readEpc(devParam).then(res => { res = JSON.parse(res) if (res.code && res.code === '0') { - this.$message.success('已放入标签') - // 判断table内的标签和桌面读取标签比较 - this.tipTable.map((item, index) => { - res.data.map((item1, index1) => { - if (item.tid === item1.tid) { - this.isFlag = true - console.log('index', index) - this.tipIndex = index - resolve(this.writeEPC()) - } else { - console.log('index2', index) - this.isFlag = false - this.$message.error('请注意,未读到正确的档案标签') - } - }) - }) + if (res.data.find((item) => { + return this.tipTable[tipTableIndex].tid === item.tid + })) { + this.isFlag = true + // console.log('index', index) + this.tipIndex = tipTableIndex + resolve(this.writeEPC()) + } else { + // 没有读取到标签数量加1 + this.isKey = !this.isKey + this.tipTable[tipTableIndex].warnState = '未读取到该标签' + resolve() + } } else if (res.code && res.code === '-2') { this.$message.error('未读取到标签,请重新放入') clearTimeout(this.timer) this.timer = setTimeout(() => { - resolve(this.readEpc(param)) + resolve(this.readEpc(devParam, tipTableIndex)) }, 2000) } else { this.$message.error('读取标签失败') @@ -279,13 +292,35 @@ export const lendingCrud = { }) }, async opened(ase) { + console.log(11111) + this.btnDisabled = true this.ase = ase const devInfo = await this.getDevId() this.devId = devInfo.deviceId this.devIp = devInfo.deviceIp + ':' + devInfo.devicePort await this.tryConnect({ op: 'RFID_CheckStatus', sDevID: devInfo.deviceId, ip: this.devIp }) - await this.readEpc({ op: 'RFID_ReadEpc', sDevID: devInfo.deviceId, ip: this.devIp }) - // await this.writeEPC(ase) + for (let tipTableIndex = 0; tipTableIndex < this.tipTable.length; tipTableIndex++) { + console.log('tipTableIndex', tipTableIndex) + if (this.tipTable[tipTableIndex].warnState !== '已解除' && this.tipTable[tipTableIndex].warnState !== '已恢复' && this.tipTable[tipTableIndex].warnState !== '解除失败' && this.tipTable[tipTableIndex].warnState !== '恢复失败') { + await this.readEpc({ op: 'RFID_ReadEpc', sDevID: devInfo.deviceId, ip: this.devIp }, tipTableIndex) + } + } + if (this.tipTable.filter((item) => { return item.warnState === '未读取到该标签' }).length > 0) { + this.btnDisabled = false + this.unbindWarnLoading = false + } else if (this.tipTable.filter((item) => { return item.warnState === '解除失败' || item.warnState === '恢复失败' }).length > 0) { + this.btnDisabled = true + this.unbindWarnLoading = false + if (this.ase === 0) { + this.$message.error('借阅成功n条数据' + ' ' + '借阅失败' + this.lendSelections.length + '条数据') + } else { + this.$message.error('归还成功n条数据' + ' ' + '归还失败' + this.lendSelections.length + '条数据') + } + } else { + this.btnDisabled = false + this.unbindWarnLoading = false + this.$message.success('解绑/恢复成功n条数据') + } }, async checkStatus(param) { return RFID.checkStatus(param).then((res) => { @@ -309,13 +344,19 @@ export const lendingCrud = { for (let i = 0; i < MAX_NUM_RETRIES; i++) { try { res = await this.checkStatus(param) + console.log(2222) break } catch (e) { err = e this.$message.error('连接失败,请检查网络') } } - if (res) return res + if (res) { + console.log(3333) + return res + } + this.btnDisabled = false + this.unbindWarnLoading = false throw err }, // 只要有一条未解除/恢复成功即errorTip @@ -329,39 +370,39 @@ export const lendingCrud = { this.crud.refresh() }, // 写epc不成功时的操作提示 -1 / -1000 - releaseAlarmErrorHandle(resolve, message) { - if (this.flagNum >= 3) { - if (this.ase === 0) { - this.tipTable[this.tipIndex].warnState = '解除失败' - } else { - this.tipTable[this.tipIndex].warnState = '恢复失败' - } - this.btnDisabled = false - this.unbindWarnLoading = false - this.tipIndex = this.tipIndex + 1 - this.flagNum = 0 - this.$message({ - message: message, - type: 'error' - }) - } - if (this.tipIndex !== this.tipTable.length) { - this.btnDisabled = true - this.unbindWarnLoading = true - clearTimeout(this.timer) - this.timer = setTimeout(() => { - resolve(this.writeEPC()) - }, 2000) - } else { - clearTimeout(this.timer) - this.timer = setTimeout(() => { - const findErrorArray = this.tipTable.map((item) => item.warnState === '解除失败' || item.warnState === '恢复失败') - if (findErrorArray.length === this.tipTable.length) { - this.alarmErrorTip() - } - }, 2000) - } - }, + // releaseAlarmErrorHandle(resolve, message) { + // if (this.flagNum >= 3) { + // if (this.ase === 0) { + // this.tipTable[this.tipIndex].warnState = '解除失败' + // } else { + // this.tipTable[this.tipIndex].warnState = '恢复失败' + // } + // this.btnDisabled = false + // this.unbindWarnLoading = false + // this.tipIndex = this.tipIndex + 1 + // this.flagNum = 0 + // this.$message({ + // message: message, + // type: 'error' + // }) + // } + // if (this.tipIndex !== this.tipTable.length) { + // this.btnDisabled = true + // this.unbindWarnLoading = true + // clearTimeout(this.timer) + // this.timer = setTimeout(() => { + // resolve(this.writeEPC()) + // }, 2000) + // } else { + // clearTimeout(this.timer) + // this.timer = setTimeout(() => { + // const findErrorArray = this.tipTable.map((item) => item.warnState === '解除失败' || item.warnState === '恢复失败') + // if (findErrorArray.length === this.tipTable.length) { + // this.alarmErrorTip() + // } + // }, 2000) + // } + // }, // 导出接口调用 downloadApi() { console.log(this.selections)