| | |
| | | /** |
| | | * @description 触发打印 |
| | | */ |
| | | triggerPrint = (item, data, formdata) => { |
| | | console.log(item) |
| | | console.log(data) |
| | | console.log(formdata) |
| | | if (!item.verify || !item.verify.Template || !item.verify.linkUrl) { |
| | | triggerPrint = (btn, data, formlist = []) => { |
| | | let formdata = {} |
| | | formlist.forEach(_data => { |
| | | formdata[_data.key] = _data.value |
| | | }) |
| | | |
| | | if (!btn.verify || !btn.verify.Template || !btn.verify.linkUrl) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '请完善打印验证信息!', |
| | |
| | | return |
| | | } |
| | | |
| | | let printlist = [] |
| | | let templates = [] |
| | | |
| | | this.setState({loadingUuid: btn.uuid}) |
| | | |
| | | new Promise(resolve => { |
| | | let param = { |
| | | func: 's_PrintTemplateMGetData', |
| | | Type: 'Y', |
| | | ID: item.verify.Template |
| | | } |
| | | if (btn.intertype === 'inner' && !btn.innerFunc) { |
| | | formdata.TemplateID = btn.verify.Template |
| | | templates.push(btn.verify.Template) |
| | | |
| | | if (options.cloudServiceApi) { |
| | | param.rduri = options.cloudServiceApi.replace('dostars', 'dostar') |
| | | } |
| | | if (btn.Ot === 'notRequired') { |
| | | printlist.push(formdata) |
| | | } else { |
| | | printlist = data.map(cell => { |
| | | let _cell = {...cell, ...formdata} |
| | | |
| | | |
| | | Api.getLocalConfig(param).then(res => { |
| | | if (res.status) { |
| | | |
| | | if (!res.ConfigParam) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '未获取到打印模板信息!', |
| | | duration: 15 |
| | | }) |
| | | resolve(false) |
| | | } else { |
| | | let configParam = '' |
| | | |
| | | try { |
| | | configParam = JSON.parse(window.decodeURIComponent(window.atob(res.ConfigParam))) |
| | | } catch (e) { |
| | | configParam = '' |
| | | } |
| | | |
| | | if (!configParam) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '打印模板解析错误!', |
| | | duration: 15 |
| | | }) |
| | | return _cell |
| | | }) |
| | | } |
| | | resolve('getTemp') |
| | | } else { |
| | | this.getprintdata(btn, data, formdata, formlist).then(result => { |
| | | printlist = result.list.map(item => { |
| | | if (item.TemplateID) { |
| | | templates.push(item.TemplateID) |
| | | } else { |
| | | resolve(configParam) |
| | | item.TemplateID = btn.verify.Template |
| | | } |
| | | } |
| | | } else { |
| | | this.execError(res, item) |
| | | resolve(false) |
| | | } |
| | | }) |
| | | }).then(res => { |
| | | console.log(res) |
| | | if (!res) return |
| | | return item |
| | | }) |
| | | |
| | | if (!socket || socket.readyState !== 1 || socket.url !== 'ws://' + item.verify.linkUrl) { |
| | | socket = new WebSocket('ws://' + item.verify.linkUrl) |
| | | } |
| | | // 打开Socket |
| | | socket.onopen = () =>{ |
| | | if (!item.printer) { |
| | | let request = { |
| | | requestID: '', |
| | | version: '', |
| | | cmd: 'getPrinters' |
| | | } |
| | | socket.send(JSON.stringify(request)) |
| | | } else { |
| | | let printdata = { |
| | | cmd: 'print', |
| | | requestID: '', |
| | | version: '', |
| | | task: { |
| | | taskID: '1', |
| | | preview: false, |
| | | printer: item.printer, |
| | | documents: [ |
| | | { |
| | | documentID: '9890000106027', |
| | | contents: [ |
| | | { |
| | | data: { |
| | | barcode: '12345' |
| | | }, |
| | | templateURL: '{"Version":"","Title":"1234","Author":"U000000001","Description":"","PrintTempNO":"","PageSetting":{"Width":210,"Height":297,"Left":"0","Right":"0","Top":"0","Bottom":"0","Landscape":false},"PageHeader":[],"ReportHeader":{"Control":[{"Name":"","Type":"barcode","Value":"","Field":"barcode","Left":71,"Top":32,"Width":52,"Height":26,"Rotate":0,"BorderSize":0.1,"BorderColor":"black","Align":"center","VerticalAlign":"middle","BackColor":"white","ForeColor":"black","BarcodeType":"code128","BarcodeWidth":31,"BarcodeHeight":10,"BarcodeLabel":true,"LabelSize":12}]},"ReportFooter":[],"PageFooter":[]}' |
| | | } |
| | | ] |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | |
| | | socket.send(JSON.stringify(printdata)) |
| | | } |
| | | } |
| | | // 监听消息 |
| | | socket.onmessage = (event) => { |
| | | let data = JSON.parse(event.data) |
| | | |
| | | if (data.defaultPrinter) { |
| | | let printdata = { |
| | | cmd: 'print', |
| | | requestID: '', |
| | | version: '', |
| | | task: { |
| | | taskID: '1', |
| | | preview: false, |
| | | printer: data.defaultPrinter, |
| | | documents: [ |
| | | { |
| | | documentID: '9890000106027', |
| | | contents: [ |
| | | { |
| | | data: { |
| | | barcode: '12345' |
| | | }, |
| | | templateURL: '{"Version":"","Title":"1234","Author":"U000000001","Description":"","PrintTempNO":"","PageSetting":{"Width":210,"Height":297,"Left":"0","Right":"0","Top":"0","Bottom":"0","Landscape":false},"PageHeader":[],"ReportHeader":{"Control":[{"Name":"","Type":"barcode","Value":"","Field":"barcode","Left":71,"Top":32,"Width":52,"Height":26,"Rotate":0,"BorderSize":0.1,"BorderColor":"black","Align":"center","VerticalAlign":"middle","BackColor":"white","ForeColor":"black","BarcodeType":"code128","BarcodeWidth":31,"BarcodeHeight":10,"BarcodeLabel":true,"LabelSize":12}]},"ReportFooter":[],"PageFooter":[]}' |
| | | } |
| | | ] |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | |
| | | socket.send(JSON.stringify(printdata)) |
| | | } |
| | | } |
| | | |
| | | socket.onerror = () => { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '无法连接到:' + item.verify.linkUrl, |
| | | duration: 10 |
| | | resolve(result.next) |
| | | }) |
| | | } |
| | | }) |
| | | }).then(res => { |
| | | if (!res) return |
| | | |
| | | templates = Array.from(new Set(templates)) // 去重 |
| | | |
| | | let deffers = templates.map(tempId => { |
| | | return new Promise(resolve => { |
| | | let param = { |
| | | func: 's_PrintTemplateMGetData', |
| | | Type: 'Y', |
| | | ID: tempId |
| | | } |
| | | |
| | | // socket = new WebSocket('ws://127.0.0.1:13529') |
| | | if (options.cloudServiceApi) { |
| | | param.rduri = options.cloudServiceApi.replace('dostars', 'dostar') |
| | | } |
| | | |
| | | Api.getLocalConfig(param).then(result => { |
| | | result.tempId = tempId |
| | | resolve(result) |
| | | }) |
| | | }) |
| | | }) |
| | | |
| | | // // 打开Socket |
| | | // socket.onopen = function(event) { |
| | | // // 监听消息 |
| | | // socket.onmessage = function(event) |
| | | // { |
| | | // //取打印机信息的返回是在这里,所以第一次的打印比较麻烦,看是不是可以在调打印前先判断你有没有存打印机名 |
| | | // //,没有就调getPrinters来取打印机去设置,要是调了打印再调取打印机,第一条打印任务就要在这里重发,就太麻烦了 |
| | | // //提前取打印机就只能用127.0.0.1:13529来取,这个地址就要写死了 |
| | | // console.log('Client received a message',event); |
| | | // }; |
| | | return Promise.all(deffers) |
| | | }).then(result => { |
| | | if (!result) return |
| | | |
| | | // // 监听Socket的关闭 |
| | | // socket.onclose = function(event) |
| | | // { |
| | | // console.log('Client notified socket has closed',event); |
| | | // }; |
| | | let errorMsg = '' |
| | | let _temps = {} |
| | | |
| | | // }; |
| | | result.forEach(res => { |
| | | if (res.status && !errorMsg) { |
| | | let _temp = this.getPrintConfigParam(res) |
| | | |
| | | if (_temp.error) { |
| | | errorMsg = { |
| | | ErrCode: 'N', |
| | | message: _temp.error, |
| | | ErrMesg: _temp.error, |
| | | status: false |
| | | } |
| | | } else { |
| | | _temps[res.tempId] = _temp.config |
| | | } |
| | | } else if (!errorMsg) { |
| | | errorMsg = res |
| | | } |
| | | }) |
| | | |
| | | if (!errorMsg) { |
| | | this.execPrint(btn, printlist, _temps) |
| | | } else { |
| | | this.execError(errorMsg, btn) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | getprintdata = (btn, data, formdata, formlist) => { |
| | | const { setting } = this.props |
| | | |
| | | let _list = [] |
| | | return new Promise(resolve => { |
| | | let params = [] |
| | | let param = { |
| | | BID: this.props.BID |
| | | } |
| | | |
| | | if (btn.Ot === 'notRequired') { |
| | | let _param = { ...param, ...formdata } |
| | | params.push(_param) |
| | | } else if (btn.Ot === 'requiredSgl') { |
| | | param[setting.primaryKey] = data[0][setting.primaryKey] |
| | | |
| | | let _param = { ...param, ...formdata } |
| | | |
| | | params.push(_param) |
| | | } else if (btn.Ot === 'requiredOnce') { |
| | | let ids = data.map(d => { return d[setting.primaryKey]}) |
| | | ids = ids.filter(Boolean) |
| | | ids = ids.join(',') |
| | | |
| | | param[setting.primaryKey] = ids |
| | | |
| | | let _param = { ...param, ...formdata } |
| | | |
| | | params.push(_param) |
| | | } else if (btn.Ot === 'required') { |
| | | params = data.map((cell, index) => { |
| | | let _param = { ...param } |
| | | _param[setting.primaryKey] = cell[setting.primaryKey] |
| | | |
| | | formlist.forEach(_data => { |
| | | if (index !== 0 && _data.readin && cell.hasOwnProperty(_data.key)) { |
| | | _param[_data.key] = cell[_data.key] |
| | | } else { |
| | | _param[_data.key] = _data.value |
| | | } |
| | | }) |
| | | return _param |
| | | }) |
| | | } |
| | | |
| | | if (btn.intertype === 'inner') { |
| | | params = params.map(_param => { |
| | | _param.func = btn.innerFunc |
| | | |
| | | return _param |
| | | }) |
| | | |
| | | if (params.length <= 20) { |
| | | let deffers = params.map(par => { |
| | | return new Promise(resolve => { |
| | | Api.genericInterface(par).then(res => { |
| | | resolve(res) |
| | | }) |
| | | }) |
| | | }) |
| | | Promise.all(deffers).then(result => { |
| | | let errorMsg = '' |
| | | result.forEach(res => { |
| | | if (res.status) { |
| | | _list.push(res.data) |
| | | } else { |
| | | errorMsg = res |
| | | } |
| | | }) |
| | | if (!errorMsg) { |
| | | resolve({next: 'getTemp', list: _list}) |
| | | } else { |
| | | this.execError(errorMsg, btn) |
| | | resolve({next: false, list: _list}) |
| | | } |
| | | }) |
| | | } else { |
| | | this.printInnerLoopRequest(params, btn, _list, resolve) |
| | | } |
| | | } else { |
| | | this.printOuterLoopRequest(params, btn, _list, resolve) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | /** |
| | | * @description 外部请求循环执行 |
| | | */ |
| | | printOuterLoopRequest = (params, btn, _list, _resolve) => { |
| | | let param = params.shift() |
| | | |
| | | new Promise(resolve => { |
| | | // 内部请求 |
| | | if (btn.innerFunc) { |
| | | param.func = btn.innerFunc |
| | | // 存在内部函数时,数据预处理 |
| | | Api.genericInterface(param).then(res => { |
| | | if (res.status) { |
| | | delete res.ErrCode |
| | | delete res.ErrMesg |
| | | delete res.message |
| | | delete res.status |
| | | |
| | | // 使用处理后的数据调用外部接口 |
| | | resolve(res) |
| | | } else { |
| | | this.execError(res, btn) |
| | | resolve(false) |
| | | _resolve({next: false, list: _list}) |
| | | } |
| | | }) |
| | | } else { |
| | | resolve(param) |
| | | } |
| | | }).then(res => { |
| | | if (!res) return |
| | | // 外部请求 |
| | | |
| | | if (this.props.menuType === 'HS') { |
| | | if (btn.sysInterface === 'true' && options.cloudServiceApi) { |
| | | res.rduri = options.cloudServiceApi |
| | | } else if (btn.sysInterface !== 'true') { |
| | | res.rduri = btn.interface |
| | | } |
| | | } else { |
| | | if (btn.sysInterface === 'true') { |
| | | res.rduri = window.GLOB.mainSystemApi || window.GLOB.subSystemApi |
| | | } else { |
| | | res.rduri = btn.interface |
| | | } |
| | | } |
| | | |
| | | if (btn.outerFunc) { |
| | | res.func = btn.outerFunc |
| | | } |
| | | |
| | | res.appkey = window.GLOB.appkey || '' // 外部请求时,统一添加appkey |
| | | |
| | | return Api.genericInterface(res) |
| | | }).then(response => { |
| | | if (!response) return |
| | | // 回调请求 |
| | | if (response.status) { |
| | | // 一次请求成功,进行下一项请求 |
| | | if (params.length === 0) { |
| | | _resolve({next: 'getTemp', list: _list}) |
| | | } else { |
| | | this.printOuterLoopRequest(params, btn, _list, _resolve) |
| | | } |
| | | } else { |
| | | this.execError(response, btn) |
| | | _resolve({next: false, list: _list}) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | /** |
| | | * @description 内部请求循环执行 |
| | | */ |
| | | printInnerLoopRequest = (params, btn, _list, _resolve) => { |
| | | let param = params.shift() |
| | | |
| | | Api.genericInterface(param).then(res => { |
| | | if (res.status) { |
| | | _list.push(res.data) |
| | | |
| | | if (params.length === 0) { |
| | | _resolve({next: 'getTemp', list: _list}) |
| | | } else { |
| | | this.printInnerLoopRequest(params, btn, _list, _resolve) |
| | | } |
| | | } else { |
| | | this.execError(res, btn) |
| | | _resolve({next: false, list: _list}) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | getPrintConfigParam = (res) => { |
| | | let error = '' |
| | | let configParam = '' |
| | | let _configparam = '' |
| | | |
| | | if (!res.ConfigParam) { |
| | | error = '未获取到打印模板信息!' |
| | | } else { |
| | | try { |
| | | configParam = JSON.parse(window.decodeURIComponent(window.atob(res.ConfigParam))) |
| | | } catch (e) { |
| | | configParam = '' |
| | | } |
| | | |
| | | if (!configParam) { |
| | | error = '打印模板解析错误!' |
| | | } else { |
| | | let control = configParam.elements.map(element => { |
| | | let item = { |
| | | Name: element.name || '', |
| | | Type: element.type, |
| | | Value: element.value || '', |
| | | Field: element.field || '', |
| | | Left: element.left, |
| | | Top: element.top, |
| | | Width: element.width, |
| | | Height: element.height, |
| | | Rotate: element.rotate, |
| | | BorderSize: element.borderSize / 10, |
| | | BorderColor: element.borderColor, |
| | | Align: element.align, |
| | | VerticalAlign: element.vertialAlign, |
| | | BackColor: element.background, |
| | | ForeColor: 'black' |
| | | } |
| | | |
| | | if (!item.Width || !item.Height) { |
| | | item.Type = 'line' |
| | | item.Value = '' |
| | | item.Field = '' |
| | | item.FontFamily = element.fontFamily || '' |
| | | item.FontSize = element.fontSize || '' |
| | | item.FontStyle = (!element.fontWeight || element.fontWeight === 'normal') ? 'regular' : element.fontWeight |
| | | item.Padding = 0 |
| | | item.Trimming = '' |
| | | } else if (item.Type === 'image') { |
| | | item.ImageWidth = element.imgWidth |
| | | item.ImageHeight = element.imgHeight |
| | | item.Trimming = '' |
| | | } else if (item.Type === 'text') { |
| | | item.FontFamily = element.fontFamily |
| | | item.FontSize = element.fontSize |
| | | item.FontStyle = element.fontWeight === 'normal' ? 'regular' : element.fontWeight |
| | | item.Padding = element.padding / 2 |
| | | item.Trimming = '' |
| | | } else if (item.Type === 'barcode') { |
| | | item.BarcodeType = element.barcodeType |
| | | item.BarcodeWidth = element.barcodeWidth |
| | | item.BarcodeHeight = element.barcodeHeight |
| | | item.BarcodeLabel = element.barcodeLabel |
| | | item.LabelSize = element.fontSize |
| | | } else if (item.Type === 'qrcode') { |
| | | item.Type = 'barcode' |
| | | item.BarcodeType = element.barcodeType |
| | | item.BarcodeWidth = element.qrcodeWidth |
| | | item.BarcodeHeight = element.qrcodeWidth |
| | | item.BarcodeLabel = false |
| | | } |
| | | return item |
| | | }) |
| | | |
| | | _configparam = { |
| | | Version: '', |
| | | Title: configParam.name, |
| | | Author: sessionStorage.getItem('UserID'), |
| | | Description: configParam.remark, |
| | | PrintTempNO: configParam.PrintTempNO, |
| | | PageSetting: { |
| | | Width: configParam.width, |
| | | Height: configParam.height, |
| | | Left: '0', |
| | | Right: '0', |
| | | Top: '0', |
| | | Bottom: '0', |
| | | Landscape: false |
| | | }, |
| | | PageHeader: [], |
| | | ReportHeader: { |
| | | Control: control |
| | | }, |
| | | ReportFooter: [], |
| | | PageFooter: [] |
| | | } |
| | | } |
| | | } |
| | | |
| | | return { |
| | | error: error, |
| | | config: _configparam |
| | | } |
| | | } |
| | | |
| | | execPrint = (item, list, template) => { |
| | | let printdata = { |
| | | cmd: 'print', |
| | | requestID: '', |
| | | version: '', |
| | | task: { |
| | | taskID: Utils.getuuid(), |
| | | preview: false, |
| | | printer: item.printer, |
| | | documents: list.map(cell => { |
| | | return { |
| | | documentID: Utils.getuuid(), |
| | | contents: [ |
| | | { |
| | | data: cell, |
| | | templateURL: JSON.stringify(template[cell.TemplateID]) |
| | | } |
| | | ] |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | console.log(JSON.stringify(printdata)) |
| | | 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: ''}) |
| | | notification.success({ |
| | | top: 92, |
| | | message: '打印请求已发出。', |
| | | duration: 2 |
| | | }) |
| | | socket.send(JSON.stringify(printdata)) |
| | | } |
| | | } |
| | | // 打开Socket |
| | | socket.onopen = () =>{ |
| | | if (!item.printer) { |
| | | let request = { |
| | | requestID: '', |
| | | version: '', |
| | | cmd: 'getPrinters' |
| | | } |
| | | socket.send(JSON.stringify(request)) |
| | | } else { |
| | | this.setState({loadingUuid: ''}) |
| | | notification.success({ |
| | | top: 92, |
| | | message: '打印请求已发出。', |
| | | duration: 2 |
| | | }) |
| | | socket.send(JSON.stringify(printdata)) |
| | | } |
| | | } |
| | | // 监听消息 |
| | | socket.onmessage = (event) => { |
| | | let data = '' |
| | | |
| | | if (event.data) { |
| | | try { |
| | | data = JSON.parse(event.data) |
| | | } catch { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: event.data, |
| | | duration: 10 |
| | | }) |
| | | this.setState({loadingUuid: ''}) |
| | | data = '' |
| | | } |
| | | } |
| | | |
| | | if (data && data.defaultPrinter) { |
| | | printdata.task.printer = data.defaultPrinter |
| | | this.setState({loadingUuid: ''}) |
| | | notification.success({ |
| | | top: 92, |
| | | message: '打印请求已发出。', |
| | | duration: 2 |
| | | }) |
| | | socket.send(JSON.stringify(printdata)) |
| | | } |
| | | } |
| | | |
| | | socket.onerror = () => { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '无法连接到:' + item.verify.linkUrl, |
| | | duration: 10 |
| | | }) |
| | | this.setState({loadingUuid: ''}) |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | this.setState({ |
| | | visible: false |
| | | }) |
| | | } else if (btn.OpenType === 'excelOut' || btn.OpenType === 'excelIn') { // 导出excel |
| | | this.setState({ |
| | | loadingUuid: '' |
| | | }) |
| | | } |
| | | |
| | | this.setState({ |
| | | loadingUuid: '' |
| | | }) |
| | | |
| | | this.refreshdata(btn, 'success') |
| | | } |
| | |
| | | message.error(res.message || res.ErrMesg) |
| | | } |
| | | |
| | | if (btn.OpenType === 'excelOut' || btn.OpenType === 'excelIn') { |
| | | this.setState({ |
| | | loadingUuid: '' |
| | | }) |
| | | } |
| | | this.setState({ |
| | | loadingUuid: '' |
| | | }) |
| | | |
| | | this.refreshdata(btn, 'error') |
| | | } |