feat: wprList 批量喷码改为单请求, 单/批共用 tdata_list 入参

- 抽出 _postCoder + rowToTdata 公共逻辑
- batchSendToCoder 改为一次 POST 携带整批 tdata_list, 后端走 CQI+JDI 队列
- 单条 sendToCoder 也走同一接口, 列表长度=1
- 按钮加批量级 loading

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
caoqianming 2026-05-18 15:57:30 +08:00
parent 8881997c89
commit acc9d2d321
1 changed files with 46 additions and 33 deletions

View File

@ -12,6 +12,7 @@
<el-button
type="warning"
:disabled="selectedRows.length === 0"
:loading="batchCoderLoading"
@click="batchSendToCoder"
>批量喷码</el-button>
<el-input
@ -129,6 +130,7 @@ export default {
scQr_code:'',
wprList:[],
selectedRows:[],
batchCoderLoading: false,
digitNum:3,
wprTableHeight:500,
printer_name:localStorage.getItem("printer_name"),
@ -343,53 +345,64 @@ that.$API.wpm.prints.req(printer_ip, obj).then((response) => {
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);
});
},
//