From 123034aeb4e1528a8d884aae7936ea688cb1b6a0 Mon Sep 17 00:00:00 2001 From: XingCheng3 <1773407212@qq.com> Date: Fri, 29 May 2026 14:41:29 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=A8=8B=E5=BA=8F=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E9=80=89=E6=8B=A9=E6=97=B6=E5=8D=B3=E5=86=99=E5=85=A5?= =?UTF-8?q?PLC=EF=BC=8C=E7=A1=AE=E8=AE=A4=E4=B8=8A=E7=BA=BF=E4=B8=8D?= =?UTF-8?q?=E5=86=8D=E9=87=8D=E5=A4=8D=E5=86=99=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DeviceUpLineBarCodeDJ/index.vue | 42 +++++++++++++------ .../DeviceUpLineBarCodeZT/index.vue | 42 +++++++++++++------ 2 files changed, 60 insertions(+), 24 deletions(-) diff --git a/src/views/EquipmentManagement/DeviceUpLineBarCodeDJ/index.vue b/src/views/EquipmentManagement/DeviceUpLineBarCodeDJ/index.vue index 3c20c54..daeba88 100644 --- a/src/views/EquipmentManagement/DeviceUpLineBarCodeDJ/index.vue +++ b/src/views/EquipmentManagement/DeviceUpLineBarCodeDJ/index.vue @@ -981,7 +981,8 @@ export default { } }, - /** 实际执行 PLC 写值上线流程;成功后写入手动上线记录 */ + /** 实际执行 PLC 写值上线流程;成功后写入手动上线记录 + * 注意:程序版本已在选择弹窗确认时写入 PLC,此处不再重复写 */ async doPartLoad(opName) { const result = opName === this.opNameList[0] ? this.ws1Result : this.ws2Result const partLoadStatus = opName === this.opNameList[0] ? this.ws1PartLoadStatus : this.ws2PartLoadStatus @@ -998,8 +999,6 @@ export default { } try { - const r1 = await this.writePLCValue(opName, PROGRAM_VERSION_TAG_ID, programVersion) - if (r1.data.code != 0) throw new Error(r1.data.msg || '程序版本写入失败') const r2 = await this.writePLCValue(opName, '205015', 'true') if (r2.data.code == 0) { partLoadStatus.success = true @@ -1061,20 +1060,29 @@ export default { this.versionDialog.visible = true }, - /** 首次扫码:从数据库取该物料最近一次的程序版本,直接回填,不弹窗 */ + /** 首次扫码:从数据库取该物料最近一次的程序版本,直接回填 + 写PLC,不弹窗 */ async autoFillFirstVersion(opName) { const result = opName === this.opNameList[0] ? this.ws1Result : this.ws2Result const partCode = result.扫码物料编码 || '' if (!partCode) return const historyList = await this.loadHistoryVersions(partCode) - if (historyList && historyList.length > 0) { - result.程序版本 = historyList[0] - this.setLastUsedVersion(opName, historyList[0]) + if (!historyList || historyList.length === 0) return + const version = historyList[0] + try { + const r = await this.writePLCValue(opName, PROGRAM_VERSION_TAG_ID, version) + if (r.data.code != 0) { + this.$message.error('程序版本写入PLC失败:' + (r.data.msg || '')) + return + } + result.程序版本 = version + this.setLastUsedVersion(opName, version) + } catch (error) { + this.$message.error('程序版本写入PLC失败:' + error.message) } }, - /** "选择程序版本"弹窗确定:把版本回填到对应工位,不自动上线 */ - confirmVersionDialog() { + /** "选择程序版本"弹窗确定:把版本回填 + 立即写入 PLC,不自动上线 */ + async confirmVersionDialog() { const version = this.versionDialog.selectedVersion ? this.versionDialog.selectedVersion.toString() : '' if (!version) { this.$message.warning('请选择或输入程序版本!') @@ -1082,9 +1090,19 @@ export default { } const opName = this.versionDialog.opName const result = opName === this.opNameList[0] ? this.ws1Result : this.ws2Result - result.程序版本 = version - this.setLastUsedVersion(opName, version) - this.versionDialog.visible = false + try { + const r = await this.writePLCValue(opName, PROGRAM_VERSION_TAG_ID, version) + if (r.data.code != 0) { + this.$message.error('程序版本写入PLC失败:' + (r.data.msg || '')) + return + } + result.程序版本 = version + this.setLastUsedVersion(opName, version) + this.versionDialog.visible = false + this.$message.success('程序版本已写入 PLC') + } catch (error) { + this.$message.error('程序版本写入PLC失败:' + error.message) + } }, /** 读取该工位上一次使用的程序版本(localStorage) */ diff --git a/src/views/EquipmentManagement/DeviceUpLineBarCodeZT/index.vue b/src/views/EquipmentManagement/DeviceUpLineBarCodeZT/index.vue index 5e76f88..7540a6d 100644 --- a/src/views/EquipmentManagement/DeviceUpLineBarCodeZT/index.vue +++ b/src/views/EquipmentManagement/DeviceUpLineBarCodeZT/index.vue @@ -981,7 +981,8 @@ export default { } }, - /** 实际执行 PLC 写值上线流程;成功后写入手动上线记录 */ + /** 实际执行 PLC 写值上线流程;成功后写入手动上线记录 + * 注意:程序版本已在选择弹窗确认时写入 PLC,此处不再重复写 */ async doPartLoad(opName) { const result = opName === this.opNameList[0] ? this.ws1Result : this.ws2Result const partLoadStatus = opName === this.opNameList[0] ? this.ws1PartLoadStatus : this.ws2PartLoadStatus @@ -998,8 +999,6 @@ export default { } try { - const r1 = await this.writePLCValue(opName, PROGRAM_VERSION_TAG_ID, programVersion) - if (r1.data.code != 0) throw new Error(r1.data.msg || '程序版本写入失败') const r2 = await this.writePLCValue(opName, '205015', 'true') if (r2.data.code == 0) { partLoadStatus.success = true @@ -1061,20 +1060,29 @@ export default { this.versionDialog.visible = true }, - /** 首次扫码:从数据库取该物料最近一次的程序版本,直接回填,不弹窗 */ + /** 首次扫码:从数据库取该物料最近一次的程序版本,直接回填 + 写PLC,不弹窗 */ async autoFillFirstVersion(opName) { const result = opName === this.opNameList[0] ? this.ws1Result : this.ws2Result const partCode = result.扫码物料编码 || '' if (!partCode) return const historyList = await this.loadHistoryVersions(partCode) - if (historyList && historyList.length > 0) { - result.程序版本 = historyList[0] - this.setLastUsedVersion(opName, historyList[0]) + if (!historyList || historyList.length === 0) return + const version = historyList[0] + try { + const r = await this.writePLCValue(opName, PROGRAM_VERSION_TAG_ID, version) + if (r.data.code != 0) { + this.$message.error('程序版本写入PLC失败:' + (r.data.msg || '')) + return + } + result.程序版本 = version + this.setLastUsedVersion(opName, version) + } catch (error) { + this.$message.error('程序版本写入PLC失败:' + error.message) } }, - /** "选择程序版本"弹窗确定:把版本回填到对应工位,不自动上线 */ - confirmVersionDialog() { + /** "选择程序版本"弹窗确定:把版本回填 + 立即写入 PLC,不自动上线 */ + async confirmVersionDialog() { const version = this.versionDialog.selectedVersion ? this.versionDialog.selectedVersion.toString() : '' if (!version) { this.$message.warning('请选择或输入程序版本!') @@ -1082,9 +1090,19 @@ export default { } const opName = this.versionDialog.opName const result = opName === this.opNameList[0] ? this.ws1Result : this.ws2Result - result.程序版本 = version - this.setLastUsedVersion(opName, version) - this.versionDialog.visible = false + try { + const r = await this.writePLCValue(opName, PROGRAM_VERSION_TAG_ID, version) + if (r.data.code != 0) { + this.$message.error('程序版本写入PLC失败:' + (r.data.msg || '')) + return + } + result.程序版本 = version + this.setLastUsedVersion(opName, version) + this.versionDialog.visible = false + this.$message.success('程序版本已写入 PLC') + } catch (error) { + this.$message.error('程序版本写入PLC失败:' + error.message) + } }, /** 读取该工位上一次使用的程序版本(localStorage) */