From acc9d2d321b8337731a16439ae9579968eaa3682 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 18 May 2026 15:57:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20wprList=20=E6=89=B9=E9=87=8F=E5=96=B7?= =?UTF-8?q?=E7=A0=81=E6=94=B9=E4=B8=BA=E5=8D=95=E8=AF=B7=E6=B1=82,=20?= =?UTF-8?q?=E5=8D=95/=E6=89=B9=E5=85=B1=E7=94=A8=20tdata=5Flist=20?= =?UTF-8?q?=E5=85=A5=E5=8F=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 抽出 _postCoder + rowToTdata 公共逻辑 - batchSendToCoder 改为一次 POST 携带整批 tdata_list, 后端走 CQI+JDI 队列 - 单条 sendToCoder 也走同一接口, 列表长度=1 - 按钮加批量级 loading Co-Authored-By: Claude Opus 4.7 (1M context) --- src/views/wpm_bx/wprList.vue | 79 +++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 33 deletions(-) diff --git a/src/views/wpm_bx/wprList.vue b/src/views/wpm_bx/wprList.vue index 237b7e90..a43fd34f 100644 --- a/src/views/wpm_bx/wprList.vue +++ b/src/views/wpm_bx/wprList.vue @@ -12,6 +12,7 @@ 批量喷码 { that.$message.warning("请先设置打印机"); } }, - //喷码: 通过名为'喷码模板'的标签模板向喷码机下发产品编号 + //把 wpr 行转成模板渲染数据 + rowToTdata(row){ + return { + number: row.number, + name: (row.material_name||'').split('|')[0], + ofrom_name: this.ofromName, + ofrom_batch: this.ofromBatch, + }; + }, + //下发喷码: 单行入队 1 条 sendToCoder(row){ let that = this; if (that.coderLoadingIds[row.id]) return; - let coder_ip = localStorage.getItem('coder_ip') || ''; - let coder_port = localStorage.getItem('coder_port') || ''; - let coder_field = localStorage.getItem('coder_field') || ''; - if (!coder_ip) { - that.$message.error('请先在右上角"喷码设置"配置喷码IP'); - return; - } - that.coderLoadingIds = { ...that.coderLoadingIds, [row.id]: true }; - let templateName = '喷码模板'; - let tdata = { - number: row.number, - name: (row.material_name||'').split('|')[0], - ofrom_name: that.ofromName, - ofrom_batch: that.ofromBatch, - }; let release = () => { let map = { ...that.coderLoadingIds }; delete map[row.id]; that.coderLoadingIds = map; }; - that.$API.cm.labeltemplate.list.req({name: templateName, page: 0}).then((res) => { - let list = Array.isArray(res) ? res : (res && res.results) || []; - let template = list.find(t => t.name === templateName); - if (!template) { - that.$message.error(`未找到标签模板: ${templateName}`); - release(); - return; - } - let body = {tdata, coder_ip}; - if (coder_port) body.coder_port = Number(coder_port); - if (coder_field) body.coder_field = coder_field; - that.$API.cm.labeltemplate.sendToCoder.req(template.id, body).then(() => { - that.$message.success("喷码下发成功"); - }).finally(release); - }).catch(release); + that.coderLoadingIds = { ...that.coderLoadingIds, [row.id]: true }; + that._postCoder([that.rowToTdata(row)]) + .then(() => that.$message.success("喷码下发成功")) + .finally(release); }, handleSelectionChange(rows){ this.selectedRows = rows; }, + //批量喷码: 一次请求入队 N 条 batchSendToCoder(){ let that = this; - that.selectedRows.forEach(row => { - that.sendToCoder(row); + if (!that.selectedRows.length || that.batchCoderLoading) return; + let tdataList = that.selectedRows.map(r => that.rowToTdata(r)); + that.batchCoderLoading = true; + that._postCoder(tdataList) + .then(() => that.$message.success(`已入队 ${tdataList.length} 条`)) + .finally(() => { that.batchCoderLoading = false; }); + }, + //公共: 查模板 + 拼 body + 调接口 + _postCoder(tdataList){ + let that = this; + let coder_ip = localStorage.getItem('coder_ip') || ''; + let coder_port = localStorage.getItem('coder_port') || ''; + let coder_field = localStorage.getItem('coder_field') || ''; + if (!coder_ip) { + that.$message.error('请先在右上角"喷码设置"配置喷码IP'); + return Promise.reject(new Error('no coder_ip')); + } + let templateName = '喷码模板'; + return that.$API.cm.labeltemplate.list.req({name: templateName, page: 0}).then((res) => { + let list = Array.isArray(res) ? res : (res && res.results) || []; + let template = list.find(t => t.name === templateName); + if (!template) { + that.$message.error(`未找到标签模板: ${templateName}`); + return Promise.reject(new Error('no template')); + } + let body = {tdata_list: tdataList, coder_ip}; + if (coder_port) body.coder_port = Number(coder_port); + if (coder_field) body.coder_field = coder_field; + return that.$API.cm.labeltemplate.sendToCoder.req(template.id, body); }); }, //本地更新数据