| | |
| | | import moment from 'moment' |
| | | import {connect} from 'react-redux' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Button, Modal, notification, message } from 'antd' |
| | | import { Button, Modal, notification, message, Icon } from 'antd' |
| | | |
| | | import Api from '@/api' |
| | | import Utils from '@/utils/utils.js' |
| | |
| | | // 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 = {} |
| | | // 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: new Date().getTime().toString(), |
| | | // 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: new Date().getTime().toString(), |
| | | // 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) |
| | | |
| | |
| | | if (event.data) { |
| | | try { |
| | | data = JSON.parse(event.data) |
| | | } catch { |
| | | } catch (e) { |
| | | this.execError({ |
| | | ErrCode: 'N', |
| | | message: event.data, |
| | |
| | | {this.getModels()} |
| | | </div> |
| | | } else { // icon、text、 all 卡片 |
| | | let label = '' |
| | | let icon = '' |
| | | |
| | | if (show === 'button') { |
| | | label = btn.label |
| | | icon = btn.icon || '' |
| | | } else if (show === 'link') { |
| | | label = <span>{btn.label}{btn.icon ? <Icon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span> |
| | | icon = '' |
| | | } else if (show === 'icon') { |
| | | icon = btn.icon || '' |
| | | // } else if (show === 'text') { |
| | | } else { |
| | | label = btn.label |
| | | } |
| | | |
| | | return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}> |
| | | <Button |
| | | type="link" |
| | |
| | | loading={loading} |
| | | disabled={disabled} |
| | | style={btn.style} |
| | | icon={show === 'text' ? '' : (btn.icon || '')} |
| | | icon={icon} |
| | | onClick={() => {this.actionTrigger()}} |
| | | >{show === 'icon' && btn.icon ? '' : btn.label}</Button> |
| | | >{label}</Button> |
| | | {this.getModels()} |
| | | </div> |
| | | } |