| | |
| | | formdata[_data.key] = _data.value |
| | | }) |
| | | |
| | | // btn.verify.printFunc = ` |
| | | // let _data = data[0] |
| | | // _data = JSON.parse(_data) |
| | | |
| | | // let socket = new WebSocket(_data.wsaddr) |
| | | |
| | | // // 打开Socket |
| | | // socket.onopen = () => { |
| | | // notification.success({ |
| | | // top: 92, |
| | | // message: '打印请求已发出。', |
| | | // duration: 2 |
| | | // }) |
| | | // socket.send(JSON.stringify(_data.data)) |
| | | // } |
| | | // // 监听消息 |
| | | // socket.onmessage = (event) => { |
| | | // let data = '' |
| | | |
| | | // if (event.data) { |
| | | // try { |
| | | // data = JSON.parse(event.data) |
| | | // } catch { |
| | | // notification.warning({ |
| | | // top: 92, |
| | | // message: event.data, |
| | | // duration: 10 |
| | | // }) |
| | | // data = '' |
| | | // } |
| | | // } |
| | | |
| | | // if (data && data.message && !data.status) { |
| | | // notification.warning({ |
| | | // top: 92, |
| | | // message: data.message, |
| | | // duration: 10 |
| | | // }) |
| | | // } |
| | | // } |
| | | |
| | | // socket.onerror = () => { |
| | | // notification.warning({ |
| | | // top: 92, |
| | | // message: '无法连接到:' + _data.wsaddr, |
| | | // duration: 10 |
| | | // }) |
| | | // } |
| | | // ` |
| | | |
| | | if ( |
| | | !btn.verify || |
| | | (btn.verify.printMode === 'normal' && (!btn.verify.Template || !btn.verify.linkUrl)) || |
| | | (btn.verify.printMode === 'custom' && !btn.verify.printFunc) |
| | | (btn.verify.printMode === 'custom' && (!btn.verify.printFunc || !btn.verify.linkUrl)) |
| | | ) { |
| | | notification.warning({ |
| | | top: 92, |
| | |
| | | }) |
| | | } |
| | | |
| | | execCustomPrint = (btn, printdata) => { |
| | | execCustomPrint = (item, printlist) => { |
| | | this.setState({loadingUuid: ''}) |
| | | |
| | | try { |
| | | // eslint-disable-next-line |
| | | let func = new Function('data', 'notification', btn.verify.printFunc) // 最后一个参数当函数体来执行,前面的参数当成函数体的参数。 |
| | | func(printdata, notification) |
| | | } catch (e) { |
| | | console.warn(e) |
| | | if (!socket || socket.readyState !== 1 || socket.url !== 'ws://' + item.verify.linkUrl) { |
| | | socket = new WebSocket('ws://' + item.verify.linkUrl) |
| | | } else { |
| | | if (!item.printer) { |
| | | let request = { |
| | | requestID: '', |
| | | version: '', |
| | | cmd: 'getPrinters' |
| | | } |
| | | socket.send(JSON.stringify(request)) |
| | | } else { |
| | | this.setState({loadingUuid: ''}) |
| | | try { |
| | | // eslint-disable-next-line |
| | | let func = new Function('socket', 'data', 'printer', 'notification', item.verify.printFunc) |
| | | func(socket, printlist, item.printer, notification) |
| | | } catch (e) { |
| | | console.warn(e) |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '自定义函数执行错误!', |
| | | duration: 10 |
| | | }) |
| | | } |
| | | } |
| | | } |
| | | // 打开Socket |
| | | socket.onopen = () =>{ |
| | | if (!item.printer) { |
| | | let request = { |
| | | requestID: '', |
| | | version: '', |
| | | cmd: 'getPrinters' |
| | | } |
| | | socket.send(JSON.stringify(request)) |
| | | } else { |
| | | this.setState({loadingUuid: ''}) |
| | | try { |
| | | // eslint-disable-next-line |
| | | let func = new Function('socket', 'data', 'printer', 'notification', item.verify.printFunc) |
| | | func(socket, printlist, item.printer, notification) |
| | | } catch (e) { |
| | | console.warn(e) |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '自定义函数执行错误!', |
| | | duration: 10 |
| | | }) |
| | | } |
| | | } |
| | | } |
| | | // 监听消息 |
| | | socket.onmessage = (event) => { |
| | | let data = '' |
| | | |
| | | if (event.data) { |
| | | try { |
| | | data = JSON.parse(event.data) |
| | | } catch { |
| | | data = '' |
| | | notification.warning({ |
| | | top: 92, |
| | | message: event.data, |
| | | duration: 10 |
| | | }) |
| | | this.setState({loadingUuid: ''}) |
| | | } |
| | | } |
| | | |
| | | if (data && data.cmd === 'getPrinters' && data.status) { |
| | | this.setState({loadingUuid: ''}) |
| | | try { |
| | | // eslint-disable-next-line |
| | | let func = new Function('socket', 'data', 'printer', 'notification', item.verify.printFunc) |
| | | func(socket, printlist, data.defaultPrinter, notification) |
| | | } catch (e) { |
| | | console.warn(e) |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '自定义函数执行错误!', |
| | | duration: 10 |
| | | }) |
| | | } |
| | | } else if (data && data.message && !data.status) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: data.message, |
| | | duration: 10 |
| | | }) |
| | | this.setState({loadingUuid: ''}) |
| | | } |
| | | } |
| | | |
| | | socket.onerror = () => { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '无法连接到:' + item.verify.linkUrl, |
| | | duration: 10 |
| | | }) |
| | | this.setState({loadingUuid: ''}) |
| | | } |
| | | } |
| | | |
| | |
| | | result.forEach(res => { |
| | | if (res.status) { |
| | | if (btn.verify.printMode === 'custom') { |
| | | // _list.push(res.data) |
| | | _list.push('{"status": true,"message": "","ErrCode": "","ErrMesg": "", "wsaddr": "ws://127.0.0.1:13529","wstype": "local/server","data": [{"cmd": "print","requestID": "202003091036391803ACEAAE08DF7454599AEA243D8959F","version": "1.0","task": {"taskID": "202003091036391803ACEAAE08DF7454599AEA243D8959F","preview": false,"printer": "Microsoft Print To PDF", "documents": [{"documentID": "05512003090002A243D8959F","contents": [{"data": {"Bill": "05512003090002","ReturnProduct": ""},"templateURL": "http://css.positecgroup.com/template/warespaceprint01/2020010810525789956968_U000000001.srt","ectype": "jdpop"}]}]}} ]}') |
| | | _list.push(res) |
| | | } else { |
| | | res.data.forEach(_item => { |
| | | _list.push({data: _item, count: res.printCount}) |
| | |
| | | return Api.genericInterface(_callbackparam) |
| | | } else if (response.status) { |
| | | if (btn.verify.printMode === 'custom') { |
| | | _list.push(response.data) |
| | | _list.push(response) |
| | | } else { |
| | | response.data.forEach(_item => { |
| | | _list.push({data: _item, count: response.printCount}) |
| | |
| | | |
| | | if (response.status) { |
| | | if (btn.verify.printMode === 'custom') { |
| | | _list.push(response.data) |
| | | _list.push(response) |
| | | } else { |
| | | response.data.forEach(_item => { |
| | | _list.push({data: _item, count: response.printCount}) |
| | |
| | | Api.genericInterface(param).then(res => { |
| | | if (res.status) { |
| | | if (btn.verify.printMode === 'custom') { |
| | | _list.push(res.data) |
| | | _list.push(res) |
| | | } else { |
| | | res.data.forEach(_item => { |
| | | _list.push({data: _item, count: res.printCount}) |