| | |
| | | |
| | | Object.keys(cell).forEach(key => { |
| | | let _key = key.toLowerCase() |
| | | |
| | | if (/^\$/.test(_key)) return |
| | | |
| | | _cell[_key] = cell[key] |
| | | }) |
| | | |
| | |
| | | execCustomPrint = (printlist, formdata) => { |
| | | const { btn } = this.props |
| | | |
| | | this.execSuccess({ |
| | | ErrCode: '-1', |
| | | message: '', |
| | | status: true |
| | | }) |
| | | let callback = null |
| | | |
| | | if (/callback\(\)/.test(btn.verify.printFunc)) { |
| | | callback = () => { |
| | | this.execSuccess({ |
| | | ErrCode: '-1', |
| | | message: '', |
| | | status: true |
| | | }) |
| | | } |
| | | } else { |
| | | this.execSuccess({ |
| | | ErrCode: '-1', |
| | | message: '', |
| | | status: true |
| | | }) |
| | | } |
| | | |
| | | try { |
| | | // eslint-disable-next-line |
| | | let func = new Function('data', 'form', 'printer', 'notification', 'Api', 'systemType', btn.verify.printFunc) |
| | | func(printlist, formdata, btn.verify, notification, Api, window.GLOB.systemType) |
| | | let func = new Function('data', 'form', 'printer', 'notification', 'Api', 'systemType', 'callback', btn.verify.printFunc) |
| | | func(printlist, formdata, btn.verify, notification, Api, window.GLOB.systemType, callback) |
| | | |
| | | // 自定义打印示例 |
| | | // let defaultPrinter = printer.defaultPrinter || 'lackprinter' |
| | |
| | | } catch (e) { |
| | | console.warn(e) |
| | | |
| | | try { |
| | | // eslint-disable-next-line |
| | | let evalfunc = eval('(true && function (data, form, printer, notification, Api, systemType) {' + btn.verify.printFunc + '})') |
| | | evalfunc(printlist, formdata, btn.verify, notification, Api, window.GLOB.systemType) |
| | | } catch (error) { |
| | | console.warn(error) |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '自定义函数执行错误!', |
| | | duration: 5 |
| | | }) |
| | | } |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '自定义函数执行错误!', |
| | | duration: 5 |
| | | }) |
| | | } |
| | | } |
| | | |
| | |
| | | return |
| | | } |
| | | |
| | | if (printerList.length === 0) { |
| | | this.execSuccess({ |
| | | ErrCode: '-1', |
| | | message: '未获取到打印信息!', |
| | | status: true |
| | | }) |
| | | return |
| | | } |
| | | |
| | | if (!socket || socket.readyState !== 1 || socket.url !== 'ws://' + btn.verify.linkUrl) { |
| | | socket = new WebSocket('ws://' + btn.verify.linkUrl) |
| | | } else { |
| | | this.syncMessageSend(printerList) |
| | | |
| | | this.execSuccess({ |
| | | ErrCode: 'S', |
| | | message: '打印请求已发出。', |
| | | status: true |
| | | this.syncMessageSend(printerList, () => { |
| | | this.execSuccess({ |
| | | ErrCode: 'S', |
| | | message: '打印请求已发出。', |
| | | status: true |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | // 打开Socket |
| | | socket.onopen = () =>{ |
| | | this.syncMessageSend(printerList) |
| | | |
| | | this.execSuccess({ |
| | | ErrCode: 'S', |
| | | message: '打印请求已发出。', |
| | | status: true |
| | | this.syncMessageSend(printerList, () => { |
| | | this.execSuccess({ |
| | | ErrCode: 'S', |
| | | message: '打印请求已发出。', |
| | | status: true |
| | | }) |
| | | }) |
| | | } |
| | | // 监听消息 |
| | |
| | | } |
| | | } |
| | | |
| | | syncMessageSend = (list) => { |
| | | syncMessageSend = (list, callback) => { |
| | | let param = list.shift() |
| | | |
| | | if (socket && param) { |
| | | socket.send(JSON.stringify(param)) |
| | | if (socket) { |
| | | try { |
| | | socket.send(JSON.stringify(param)) |
| | | } catch(e) { |
| | | console.warn('打印请求发送失败!') |
| | | } |
| | | } |
| | | |
| | | if (list && list.length > 0) { |
| | | setTimeout(() => {this.syncMessageSend(list)}, 3000) |
| | | if (list.length > 0) { |
| | | setTimeout(() => { |
| | | this.syncMessageSend(list, callback) |
| | | }, 3000) |
| | | } else { |
| | | callback() |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 操作成功后处理 |
| | | * 1、excel导出,成功后取消导出按钮加载中状态 |