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:
parent
8881997c89
commit
acc9d2d321
|
|
@ -12,6 +12,7 @@
|
||||||
<el-button
|
<el-button
|
||||||
type="warning"
|
type="warning"
|
||||||
:disabled="selectedRows.length === 0"
|
:disabled="selectedRows.length === 0"
|
||||||
|
:loading="batchCoderLoading"
|
||||||
@click="batchSendToCoder"
|
@click="batchSendToCoder"
|
||||||
>批量喷码</el-button>
|
>批量喷码</el-button>
|
||||||
<el-input
|
<el-input
|
||||||
|
|
@ -129,6 +130,7 @@ export default {
|
||||||
scQr_code:'',
|
scQr_code:'',
|
||||||
wprList:[],
|
wprList:[],
|
||||||
selectedRows:[],
|
selectedRows:[],
|
||||||
|
batchCoderLoading: false,
|
||||||
digitNum:3,
|
digitNum:3,
|
||||||
wprTableHeight:500,
|
wprTableHeight:500,
|
||||||
printer_name:localStorage.getItem("printer_name"),
|
printer_name:localStorage.getItem("printer_name"),
|
||||||
|
|
@ -343,53 +345,64 @@ that.$API.wpm.prints.req(printer_ip, obj).then((response) => {
|
||||||
that.$message.warning("请先设置打印机");
|
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){
|
sendToCoder(row){
|
||||||
let that = this;
|
let that = this;
|
||||||
if (that.coderLoadingIds[row.id]) return;
|
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 release = () => {
|
||||||
let map = { ...that.coderLoadingIds };
|
let map = { ...that.coderLoadingIds };
|
||||||
delete map[row.id];
|
delete map[row.id];
|
||||||
that.coderLoadingIds = map;
|
that.coderLoadingIds = map;
|
||||||
};
|
};
|
||||||
that.$API.cm.labeltemplate.list.req({name: templateName, page: 0}).then((res) => {
|
that.coderLoadingIds = { ...that.coderLoadingIds, [row.id]: true };
|
||||||
let list = Array.isArray(res) ? res : (res && res.results) || [];
|
that._postCoder([that.rowToTdata(row)])
|
||||||
let template = list.find(t => t.name === templateName);
|
.then(() => that.$message.success("喷码下发成功"))
|
||||||
if (!template) {
|
.finally(release);
|
||||||
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);
|
|
||||||
},
|
},
|
||||||
handleSelectionChange(rows){
|
handleSelectionChange(rows){
|
||||||
this.selectedRows = rows;
|
this.selectedRows = rows;
|
||||||
},
|
},
|
||||||
|
//批量喷码: 一次请求入队 N 条
|
||||||
batchSendToCoder(){
|
batchSendToCoder(){
|
||||||
let that = this;
|
let that = this;
|
||||||
that.selectedRows.forEach(row => {
|
if (!that.selectedRows.length || that.batchCoderLoading) return;
|
||||||
that.sendToCoder(row);
|
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);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
//本地更新数据
|
//本地更新数据
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue