From 9a9650c758bd84bef0739aa8949627af666bb1c1 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 31 七月 2020 10:07:42 +0800 Subject: [PATCH] 2020-07-31 --- src/tabviews/zshare/actionList/printbutton/index.jsx | 128 ++++++++++++++++++++++-------------------- 1 files changed, 67 insertions(+), 61 deletions(-) diff --git a/src/tabviews/zshare/actionList/printbutton/index.jsx b/src/tabviews/zshare/actionList/printbutton/index.jsx index 692bc69..75f4e11 100644 --- a/src/tabviews/zshare/actionList/printbutton/index.jsx +++ b/src/tabviews/zshare/actionList/printbutton/index.jsx @@ -203,7 +203,9 @@ } else { this.getprintdata(btn, data, formdata, formlist).then(result => { if (result.next) { - printlist = result.list.map(cell => { + result.list.forEach(cell => { + if (!cell.data || cell.data.length === 0) return + cell.templateID = cell.templateID || btn.verify.Template cell.printType = cell.printType || formdata.printType || '' @@ -216,7 +218,7 @@ templates.push(cell.templateID) - return cell + printlist.push(cell) }) } @@ -700,73 +702,76 @@ let printerList = [] Object.keys(printdata).forEach(printer => { - let _documents = [] Object.keys(template).forEach(key => { let _datalist = printdata[printer].filter(cell => cell.templateID === key) - - if (_datalist.length > 0) { - let _data = [] - _datalist.forEach(res => { - res.data.forEach(_cell => { - for (let i = 0; i < res.printCount; i++) { - _data.push({...formdata, ..._cell}) - } - }) - }) - let _fields = Array.from(new Set(template[key].fields)) - let _nonEFields = Array.from(new Set(template[key].nonEFields)) - let lacks = [] - let emptys = [] - - _data.forEach(d => { - _fields.forEach(f => { - if (!d.hasOwnProperty(f)) { - lacks.push(f) - } else if (_nonEFields.includes(f) && !d[f] && d[f] !== 0) { - emptys.push(f) - } - }) + if (_datalist.length === 0) return + + let _data = [] + _datalist.forEach(res => { + res.data.forEach(_cell => { + for (let i = 0; i < res.printCount; i++) { + _data.push({...formdata, ..._cell}) + } }) - + }) + + let _fields = Array.from(new Set(template[key].fields)) + let _nonEFields = Array.from(new Set(template[key].nonEFields)) + let lacks = [] + let emptys = [] + + _data.forEach(d => { + _fields.forEach(f => { + if (!d.hasOwnProperty(f)) { + lacks.push(f) + } else if (_nonEFields.includes(f) && !d[f] && d[f] !== 0) { + emptys.push(f) + } + }) + }) + + if (lacks.length > 0 || emptys.length > 0) { + lacks = Array.from(new Set(lacks)) + emptys = Array.from(new Set(emptys)) + + _errors.push({ + title: template[key].config.Title, + lacks: lacks, + emptys: emptys + }) + } + + let results = [] + let num = 100 + for(let i = 0, len = _data.length; i < len; i += num){ + results.push(_data.slice(i, i + num)) + } + + results.forEach(result => { let _cell = { documentID: Utils.getuuid(), contents: [ { - data: _data, + data: result, templateURL: JSON.stringify(template[key].config) } ] } - if (lacks.length > 0 || emptys.length > 0) { - lacks = Array.from(new Set(lacks)) - emptys = Array.from(new Set(emptys)) - - _errors.push({ - title: template[key].config.Title, - lacks: lacks, - emptys: emptys - }) - } - - _documents.push(_cell) - } - }) - - if (_documents.length > 0) { - printerList.push({ - cmd: 'print', - requestID: Utils.getuuid(), - version: Utils.getuuid(), - task: { - taskID: Utils.getuuid(), - preview: false, - printer: printer, - documents: _documents - } + printerList.push({ + cmd: 'print', + requestID: Utils.getuuid(), + version: Utils.getuuid(), + task: { + taskID: Utils.getuuid(), + preview: false, + printer: printer, + documents: [_cell] + } + }) }) - } + }) }) if (list.length === 0) { @@ -821,8 +826,8 @@ } socket.send(JSON.stringify(request)) } else { - printerList.forEach(cell => { - socket.send(JSON.stringify(cell)) + printerList.forEach((cell, index) => { + setTimeout(() => {socket.send(JSON.stringify(cell))}, 500 * index) }) this.execSuccess({ @@ -833,6 +838,7 @@ }) } } + // 鎵撳紑Socket socket.onopen = () =>{ if (lackItems) { @@ -843,8 +849,8 @@ } socket.send(JSON.stringify(request)) } else { - printerList.forEach(cell => { - socket.send(JSON.stringify(cell)) + printerList.forEach((cell, index) => { + setTimeout(() => {socket.send(JSON.stringify(cell))}, 500 * index) }) this.execSuccess({ @@ -875,11 +881,11 @@ } if (data && data.cmd === 'getPrinters' && data.status) { - printerList.forEach(cell => { + printerList.forEach((cell, index) => { if (cell.task.printer === 'lackprinter') { cell.task.printer = data.defaultPrinter } - socket.send(JSON.stringify(cell)) + setTimeout(() => {socket.send(JSON.stringify(cell))}, 500 * index) }) this.execSuccess({ -- Gitblit v1.8.0