From e5fc2d92b1036aabf9ffc2c9706ed401bd9735c8 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 09 九月 2021 18:14:29 +0800 Subject: [PATCH] 2021-09-09 --- src/tabviews/zshare/actionList/printbutton/index.jsx | 274 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 228 insertions(+), 46 deletions(-) diff --git a/src/tabviews/zshare/actionList/printbutton/index.jsx b/src/tabviews/zshare/actionList/printbutton/index.jsx index d22fe81..95a955f 100644 --- a/src/tabviews/zshare/actionList/printbutton/index.jsx +++ b/src/tabviews/zshare/actionList/printbutton/index.jsx @@ -211,17 +211,17 @@ let printlist = [] let templates = [] - let printCount = 1 + let printCount = +(formdata.printCount || formdata.PrintCount || formdata.printcount || formdata.Printcount || 1) - if (formdata.printCount && typeof(formdata.printCount) === 'number' && formdata.printCount >= 1) { - printCount = formdata.printCount + if (isNaN(printCount) || printCount < 1) { + printCount = 1 } new Promise(resolve => { if (btn.intertype === 'system') { // 浣跨敤绯荤粺鏃讹紝鐩存帴浠庤〃鏍兼垨琛ㄥ崟涓�夊彇鏁版嵁 let printcell = {} - printcell.printType = formdata.printType || '' + printcell.printType = formdata.printType || formdata.PrintType || formdata.printtype || formdata.Printtype || '' printcell.printCount = printCount printcell.templateID = btn.verify.Template || '' @@ -245,12 +245,13 @@ // 绯荤粺鎵撳嵃鏁版嵁锛屾牎楠宒ata瀛楁 if (btn.verify.printMode !== 'custom' && (!cell.data || cell.data.length === 0)) return - cell.templateID = cell.templateID || btn.verify.Template - cell.printType = cell.printType || formdata.printType || '' + cell.templateID = cell.templateID || cell.TemplateID || cell.Templateid || cell.templateid || btn.verify.Template + cell.printType = cell.printType || cell.PrintType || cell.printtype || cell.Printtype || formdata.printType || formdata.PrintType || formdata.printtype || formdata.Printtype || '' - let _printCount = printCount - if (cell.printCount && typeof(cell.printCount) === 'number' && cell.printCount >= 1) { - _printCount = cell.printCount + let _printCount = +(cell.printCount || cell.PrintCount || cell.printcount || cell.Printcount || 0) + + if (isNaN(_printCount) || _printCount < 1) { + _printCount = printCount } cell.printCount = _printCount @@ -380,6 +381,186 @@ // eslint-disable-next-line let func = new Function('data', 'form', 'printer', 'notification', btn.verify.printFunc) func(printlist, formdata, btn.verify, notification) + + // 鑷畾涔夋墦鍗扮ず渚� + // let defaultPrinter = printer.defaultPrinter || 'lackprinter' + // let printers = {} + // let getuuid = () => { + // let uuid = [] + // let _options = '0123456789abcdefghigklmnopqrstuv' + // for (let i = 0; i < 32; i++) { + // uuid.push(_options.substr(Math.floor(Math.random() * 0x20), 1)) + // } + // uuid = uuid.join('') + // return uuid + // } + // if (printer.printerTypeList && printer.printerTypeList.length > 0) { + // printer.printerTypeList.forEach(cell => { + // if (cell.printer) { + // printers[cell.Value] = cell.printer + // } + // }) + // } + + // let jdList = [] + // let otherList = [] + // data.forEach(item => { + // if (item.CustomData) { + // item.CustomData = JSON.parse(item.CustomData.replace(/\n/g,"\\n").replace(/\r/g,"\\r")) + // } + // if (item.PrintData) { + // item.PrintData = JSON.parse(item.PrintData.replace(/\n/g,"\\n").replace(/\r/g,"\\r")) + // item.PrintData.data = {...form, ...item.PrintData.data} + // } + + // if (!item.PrintData) { + // return + // } + + // if (item.PrintData.ectype === 'jdpop') { + // jdList.push(item) + // } else { + // otherList.push(item) + // } + // }) + + // if (jdList.length === 0 && otherList.length === 0) { + // notification.warning({ + // top: 92, + // message: '鏃犳墦鍗版暟鎹紒', + // duration: 5 + // }) + // return + // } + + // let execPrint = (list, linkUrl) => { + // let printdata = {} + + // list.forEach(res => { + // let _printer = defaultPrinter + + // if (res.printType && printers[res.printType]) { + // _printer = printers[res.printType] + // } + + // printdata[_printer] = printdata[_printer] || [] + + // printdata[_printer].push(res) + // }) + + // let printerList = [] + + // Object.keys(printdata).forEach(printer => { + // let _documents = [] + // printdata[printer].forEach(item => { + // let _cell = { + // documentID: getuuid(), + // contents: [] + // } + + // if (item.PrintData) { + // _cell.contents.push(item.PrintData) + // } + // if (item.CustomData) { + // _cell.contents.push(item.CustomData) + // } + + // for (let i = 0; i < item.printCount; i++) { + // _documents.push(_cell) + // } + // }) + // printerList.push({ + // cmd: 'print', + // requestID: '', + // version: '', + // task: { + // taskID: getuuid(), + // preview: false, + // printer: printer, + // documents: _documents + // } + // }) + // }) + + // let lackItems = printerList.filter(cell => cell.task.printer === 'lackprinter')[0] + + // let socket = new WebSocket('ws://' + linkUrl) + + // // 鎵撳紑Socket + // socket.onopen = () =>{ + // if (lackItems) { + // let request = { + // requestID: '', + // version: '', + // cmd: 'getPrinters' + // } + // socket.send(JSON.stringify(request)) + // } else { + // printerList.forEach(cell => { + // socket.send(JSON.stringify(cell).replace(/\\r/g,"\r").replace(/\\n/g,"\n")) + // }) + + // notification.success({ + // top: 92, + // message: '鎵撳嵃璇锋眰宸插彂鍑恒��', + // duration: 2 + // }) + // } + // } + // // 鐩戝惉娑堟伅 + // socket.onmessage = (event) => { + // let data = '' + + // if (event.data) { + // try { + // data = JSON.parse(event.data) + // } catch (e) { + // notification.warning({ + // top: 92, + // message: event.data, + // duration: 10 + // }) + // data = '' + // } + // } + + // if (data && data.cmd === 'getPrinters' && data.status) { + // printerList.forEach(cell => { + // if (cell.task.printer === 'lackprinter') { + // cell.task.printer = data.defaultPrinter + // } + // socket.send(JSON.stringify(cell).replace(/\\r/g,"\r").replace(/\\n/g,"\n")) + // }) + + // notification.success({ + // top: 92, + // message: '鎵撳嵃璇锋眰宸插彂鍑恒��', + // duration: 2 + // }) + // } else if (data && data.message && !data.status) { + // notification.warning({ + // top: 92, + // message: data.message, + // duration: 10 + // }) + // } + // } + + // socket.onerror = () => { + // notification.warning({ + // top: 92, + // message: '鏃犳硶杩炴帴鍒�:' + linkUrl, + // duration: 10 + // }) + // } + // } + + // if (jdList.length > 0) { + // execPrint(jdList, '127.0.0.1:13529') + // } + // if (otherList.length > 0) { + // execPrint(otherList, '127.0.0.1:13528') + // } } catch (e) { console.warn(e) @@ -860,7 +1041,7 @@ task: { taskID: Utils.getuuid(), preview: false, - printer: printer, + printer: printer === 'lackprinter' ? '' : printer, documents: [_cell] } }) @@ -907,19 +1088,19 @@ return } - let lackItems = printerList.filter(cell => cell.task.printer === 'lackprinter')[0] + // let lackItems = printerList.filter(cell => cell.task.printer === 'lackprinter')[0] if (!socket || socket.readyState !== 1 || socket.url !== 'ws://' + btn.verify.linkUrl) { socket = new WebSocket('ws://' + btn.verify.linkUrl) } else { - if (lackItems) { - let request = { - requestID: '', - version: '', - cmd: 'getPrinters' - } - socket.send(JSON.stringify(request)) - } else { + // if (lackItems) { + // let request = { + // requestID: '', + // version: '', + // cmd: 'getPrinters' + // } + // socket.send(JSON.stringify(request)) + // } else { this.syncMessageSend(printerList) this.execSuccess({ @@ -928,19 +1109,19 @@ ErrMesg: '鎵撳嵃璇锋眰宸插彂鍑恒��', status: true }) - } + // } } // 鎵撳紑Socket socket.onopen = () =>{ - if (lackItems) { - let request = { - requestID: '', - version: '', - cmd: 'getPrinters' - } - socket.send(JSON.stringify(request)) - } else { + // if (lackItems) { + // let request = { + // requestID: '', + // version: '', + // cmd: 'getPrinters' + // } + // socket.send(JSON.stringify(request)) + // } else { this.syncMessageSend(printerList) this.execSuccess({ @@ -949,7 +1130,7 @@ ErrMesg: '鎵撳嵃璇锋眰宸插彂鍑恒��', status: true }) - } + // } } // 鐩戝惉娑堟伅 socket.onmessage = (event) => { @@ -958,7 +1139,7 @@ if (event.data) { try { data = JSON.parse(event.data) - } catch { + } catch (e) { this.execError({ ErrCode: 'N', message: event.data, @@ -970,23 +1151,24 @@ } } - if (data && data.cmd === 'getPrinters' && data.status) { - printerList = printerList.map(cell => { - if (cell.task.printer === 'lackprinter') { - cell.task.printer = data.defaultPrinter - } - return cell - }) + // if (data && data.cmd === 'getPrinters' && data.status) { + // printerList = printerList.map(cell => { + // if (cell.task.printer === 'lackprinter') { + // cell.task.printer = data.defaultPrinter + // } + // return cell + // }) - this.syncMessageSend(printerList) + // this.syncMessageSend(printerList) - this.execSuccess({ - ErrCode: 'S', - message: '', - ErrMesg: '鎵撳嵃璇锋眰宸插彂鍑恒��', - status: true - }) - } else if (data && data.message && !data.status) { + // this.execSuccess({ + // ErrCode: 'S', + // message: '', + // ErrMesg: '鎵撳嵃璇锋眰宸插彂鍑恒��', + // status: true + // }) + // } else if (data && data.message && !data.status) { + if (data && data.message && !data.status) { this.execError({ ErrCode: 'N', message: data.message, @@ -1345,7 +1527,7 @@ label = btn.label icon = btn.icon || '' } else if (show === 'link') { - label = <span>{btn.label}{btn.icon ? <Icon type={btn.icon}/> : ''}</span> + label = <span>{btn.label}{btn.icon ? <Icon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span> icon = '' } else if (show === 'icon') { icon = btn.icon || '' -- Gitblit v1.8.0