| | |
| | | } |
| | | |
| | | componentDidMount () { |
| | | const { position } = this.props |
| | | |
| | | if (position === 'toolbar') { |
| | | MKEmitter.addListener('triggerBtnId', this.actionTrigger) |
| | | } |
| | | MKEmitter.addListener('triggerBtnId', this.actionTrigger) |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps (nextProps) { |
| | |
| | | } |
| | | MKEmitter.removeListener('triggerBtnId', this.actionTrigger) |
| | | } |
| | | |
| | | /** |
| | | * @description 按钮状态改变 |
| | | */ |
| | | updateStatus = (type) => { |
| | | if (type === 'start') { |
| | | this.setState({ |
| | | loading: true |
| | | }) |
| | | } else if (type === 'over') { |
| | | this.setState({ |
| | | loading: false |
| | | }) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 触发按钮操作 |
| | | */ |
| | | actionTrigger = (triggerId, record) => { |
| | | actionTrigger = (triggerId, record, type) => { |
| | | const { Tab, BID, btn, selectedData, setting } = this.props |
| | | const { loading } = this.state |
| | | const { loading, disabled } = this.state |
| | | |
| | | if ((triggerId && btn.uuid !== triggerId) || loading) return |
| | | if ((triggerId && btn.uuid !== triggerId) || loading || disabled) return |
| | | |
| | | if (((Tab && Tab.supMenu) || setting.supModule) && !BID) { |
| | | notification.warning({ |
| | |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } else if (type === 'linkbtn' && selectedData && selectedData.length === 1) { |
| | | if (record[0].$Index !== selectedData[0].$Index) { |
| | | return |
| | | } |
| | | } |
| | | |
| | | let _this = this |
| | |
| | | } |
| | | |
| | | if (btn.execMode === 'pop') { |
| | | this.updateStatus('start') |
| | | let modal = this.state.btnconfig |
| | | if (!modal && btn.modal) { |
| | | modal = this.handleModelConfig(btn.modal) |
| | | } |
| | | |
| | | this.setState({ |
| | | loading: true, |
| | | tabledata: data, |
| | | btnconfig: modal |
| | | }, () => { |
| | | this.improveAction() |
| | | }) |
| | | } else if (btn.execMode === 'prompt') { |
| | | this.updateStatus('start') |
| | | this.setState({ loading: true }) |
| | | confirm({ |
| | | title: this.state.dict['main.action.confirm.tip'], |
| | | onOk() { |
| | | _this.triggerPrint(data) |
| | | }, |
| | | onCancel() { |
| | | _this.updateStatus('over') |
| | | _this.setState({ loading: false }) |
| | | } |
| | | }) |
| | | } else { |
| | |
| | | |
| | | try { |
| | | // eslint-disable-next-line |
| | | let func = new Function('data', 'form', 'printer', 'notification', btn.verify.printFunc) |
| | | func(printlist, formdata, btn.verify, notification) |
| | | let func = new Function('data', 'form', 'printer', 'notification', 'Api', 'systemType', btn.verify.printFunc) |
| | | func(printlist, formdata, btn.verify, notification, Api, window.GLOB.systemType) |
| | | |
| | | // 自定义打印示例 |
| | | // let defaultPrinter = printer.defaultPrinter || 'lackprinter' |
| | |
| | | // for (let i = 0; i < 32; i++) { |
| | | // uuid.push(_options.substr(Math.floor(Math.random() * 0x20), 1)) |
| | | // } |
| | | // uuid = uuid.join('') |
| | | // return uuid |
| | | // return uuid.join('') |
| | | // } |
| | | // if (printer.printerTypeList && printer.printerTypeList.length > 0) { |
| | | // printer.printerTypeList.forEach(cell => { |
| | |
| | | // }) |
| | | // } |
| | | |
| | | // 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} |
| | | // } |
| | | // let jdList = []; |
| | | // let jdNewList = []; |
| | | // let otherList = []; |
| | | // let _map = new Map() |
| | | // data.forEach(m => { |
| | | // if (!m.print_data || m.print_data.length === 0) return |
| | | |
| | | // if (!item.PrintData) { |
| | | // return |
| | | // } |
| | | // m.print_data.forEach(n => { |
| | | // if (n.InsideBill) { |
| | | // if (_map.has(n.InsideBill)) { |
| | | // return |
| | | // } |
| | | // _map.set(n.InsideBill, true) |
| | | // } |
| | | // if (n.CustomData) { |
| | | // n.CustomData = JSON.parse(n.CustomData.replace(/\n/g,"\\n").replace(/\r/g,"\\r")) |
| | | // } |
| | | |
| | | // if (item.PrintData.ectype === 'jdpop') { |
| | | // jdList.push(item) |
| | | // } else { |
| | | // otherList.push(item) |
| | | // } |
| | | // if (n.hasOwnProperty('StdTemplate')) { |
| | | // jdNewList.push(n); |
| | | // return |
| | | // } else if (!n.PrintData) { |
| | | // return |
| | | // } |
| | | |
| | | // n.PrintData = JSON.parse(n.PrintData.replace(/\n/g,"\\n").replace(/\r/g,"\\r")) |
| | | // n.PrintData.data = {...form, ...n.PrintData.data} |
| | | |
| | | // if (n.PrintData.ectype === 'jdpop') { |
| | | // jdList.push(n) |
| | | // } else { |
| | | // otherList.push(n) |
| | | // } |
| | | // }) |
| | | // }) |
| | | |
| | | // if (jdList.length === 0 && otherList.length === 0) { |
| | | // if (jdList.length === 0 && otherList.length === 0 && jdNewList.length === 0) { |
| | | // notification.warning({ |
| | | // top: 92, |
| | | // message: '无打印数据!', |
| | |
| | | // return |
| | | // } |
| | | |
| | | // let execPrint = (list, linkUrl) => { |
| | | // let printdata = {} |
| | | // let execPrint = (list, linkUrl, type) => { |
| | | // let printdata = {}; |
| | | // let printerList = []; |
| | | |
| | | // list.forEach(res => { |
| | | // let _printer = defaultPrinter |
| | | // if (type === 'jd') { |
| | | // printerList = list.map(m => { |
| | | // 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 (m.printType && printers[m.printType]) { |
| | | // _printer = printers[m.printType]; |
| | | // } |
| | | |
| | | // if (item.PrintData) { |
| | | // _cell.contents.push(item.PrintData) |
| | | // return { |
| | | // orderType: "print", |
| | | // parameters: { |
| | | // printName: _printer === 'lackprinter' ? '' : _printer, |
| | | // tempUrl: m.StdTemplate, |
| | | // customTempUrl: m.CusTemplate, |
| | | // customData: [m.CustomData], |
| | | // printData: [m.PrintData] |
| | | // } |
| | | // } |
| | | // if (item.CustomData) { |
| | | // _cell.contents.push(item.CustomData) |
| | | // }) |
| | | // } else { |
| | | // list.forEach(res => { |
| | | // let _printer = defaultPrinter |
| | | |
| | | // if (res.printType && printers[res.printType]) { |
| | | // _printer = printers[res.printType] |
| | | // } |
| | | |
| | | // for (let i = 0; i < item.printCount; i++) { |
| | | // printdata[_printer] = printdata[_printer] || [] |
| | | |
| | | // printdata[_printer].push(res) |
| | | // }) |
| | | |
| | | // 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) |
| | | // } |
| | | |
| | | // _documents.push(_cell) |
| | | // } |
| | | // }) |
| | | // printerList.push({ |
| | | // cmd: 'print', |
| | | // requestID: '', |
| | | // version: '', |
| | | // task: { |
| | | // taskID: getuuid(), |
| | | // preview: false, |
| | | // printer: printer === 'lackprinter' ? '' : printer, |
| | | // documents: _documents |
| | | // } |
| | | // }) |
| | | // }) |
| | | // 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")) |
| | | // }) |
| | | // printerList.forEach((cell, i) => { |
| | | // setTimeout(() => { |
| | | // socket.send(JSON.stringify(cell).replace(/\\r/g,"\r").replace(/\\n/g,"\n")) |
| | | // }, 1000 * i) |
| | | // }); |
| | | |
| | | // notification.success({ |
| | | // top: 92, |
| | | // message: '打印请求已发出。', |
| | | // duration: 2 |
| | | // }) |
| | | // } |
| | | // } |
| | | // // 监听消息 |
| | | // socket.onmessage = (event) => { |
| | |
| | | // } |
| | | // } |
| | | |
| | | // 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) { |
| | | // if (data && data.message && !data.status) { |
| | | // notification.warning({ |
| | | // top: 92, |
| | | // message: data.message, |
| | |
| | | // } |
| | | // } |
| | | |
| | | // if (jdNewList.length > 0) { |
| | | // execPrint(jdNewList, '127.0.0.1:9113', 'jd'); |
| | | // } |
| | | // if (jdList.length > 0) { |
| | | // execPrint(jdList, '127.0.0.1:13529') |
| | | // } |
| | |
| | | |
| | | try { |
| | | // eslint-disable-next-line |
| | | let evalfunc = eval('(true && function (data, form, printer, notification) {' + btn.verify.printFunc + '})') |
| | | evalfunc(printlist, formdata, btn.verify, notification) |
| | | 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({ |
| | |
| | | */ |
| | | execError = (res) => { |
| | | const { btn } = this.props |
| | | const { btnconfig } = this.state |
| | | |
| | | if (res.ErrCode === 'E') { |
| | | Modal.error({ |
| | |
| | | this.setState({ |
| | | loading: false |
| | | }) |
| | | |
| | | if (btnconfig && btnconfig.setting && btnconfig.setting.errFocus) { |
| | | MKEmitter.emit('mkFC', 'focus', btnconfig.setting.errFocus) |
| | | } |
| | | |
| | | if (btn.execError !== 'never') { |
| | | MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execError, btn) |
| | |
| | | message: res.message, |
| | | duration: 5 |
| | | }) |
| | | this.updateStatus('over') |
| | | this.setState({ loading: false }) |
| | | } else if (!_LongParam || (btn.execMode === 'pop' && _LongParam.type !== 'Modal')) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '未获取到按钮配置信息!', |
| | | duration: 5 |
| | | }) |
| | | this.updateStatus('over') |
| | | this.setState({ loading: false }) |
| | | } else { |
| | | _LongParam = updateForm(_LongParam) |
| | | _LongParam = this.handleModelConfig(_LongParam) |
| | |
| | | * @description 模态框(表单),确认 |
| | | */ |
| | | handleOk = () => { |
| | | const { btnconfig } = this.state |
| | | this.formRef.handleConfirm().then(res => { |
| | | this.setState({ |
| | | visible: false |
| | | }) |
| | | if (btnconfig.setting.finish !== 'unclose') { |
| | | this.setState({ |
| | | visible: false |
| | | }) |
| | | } |
| | | this.triggerPrint(this.state.tabledata, res) |
| | | }) |
| | | } |
| | |
| | | */ |
| | | handleCancel = () => { |
| | | this.setState({ |
| | | loading: false, |
| | | visible: false |
| | | }) |
| | | this.updateStatus('over') |
| | | } |
| | | |
| | | modelconfirm = () => { |
| | |
| | | result.push({ |
| | | key: item.field, |
| | | readonly: item.readonly === 'true', |
| | | readin: _readin, |
| | | readin: item.readin !== 'false' && item.readin !== 'top', |
| | | fieldlen: _fieldlen, |
| | | type: item.type, |
| | | value: _initval |
| | |
| | | _this.triggerPrint(tabledata, result) |
| | | }, |
| | | onCancel() { |
| | | _this.updateStatus('over') |
| | | _this.setState({ loading: false }) |
| | | } |
| | | }) |
| | | } |
| | |
| | | |
| | | const mapStateToProps = (state) => { |
| | | return { |
| | | tabviews: state.tabviews, |
| | | menuType: state.editLevel |
| | | } |
| | | } |