| | |
| | | import { DndProvider } from 'react-dnd' |
| | | import { is, fromJS } from 'immutable' |
| | | import HTML5Backend from 'react-dnd-html5-backend' |
| | | import { Card, notification, Row, Button, Modal, Input, Icon } from 'antd' |
| | | import { Card, notification, Row, Button, Modal, Input, Switch } from 'antd' |
| | | import { ArrowUpOutlined, ArrowDownOutlined, CaretRightOutlined, ArrowRightOutlined, ArrowLeftOutlined } from '@ant-design/icons' |
| | | import DragElement from './dragelement' |
| | | import MutilForm from './mutilform' |
| | | import SourceElement from './dragelement/source' |
| | |
| | | qrurl, |
| | | imgurl |
| | | } from './option.js' |
| | | import { langs } from '@/store/options' |
| | | import Utils from '@/utils/utils.js' |
| | | import printCtrl from './print.js' |
| | | import Api from '@/api' |
| | |
| | | class PrintTemplate extends Component { |
| | | state = { |
| | | config: null, |
| | | oriConfig: null, |
| | | ID: null, |
| | | langName: '', |
| | | editItemId: '', |
| | | editItemType: '', |
| | | fields: [], |
| | |
| | | upPlus: 1, |
| | | upMinus: 1, |
| | | leftPlus: 1, |
| | | leftMinus: 1 |
| | | leftMinus: 1, |
| | | debug: true |
| | | } |
| | | |
| | | getclickpoint = (e) => { |
| | |
| | | } |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | let _param = window.atob(this.props.match.params.param) |
| | | let _params = {} |
| | | _param.split('&').forEach(cell => { |
| | | let _cell = cell.split('=') |
| | | _params[_cell[0]] = _cell[1] |
| | | }) |
| | | try { |
| | | let param = JSON.parse(window.decodeURIComponent(window.atob(this.props.match.params.param))) |
| | | |
| | | this.setState({ |
| | | ID: _params.ID |
| | | }) |
| | | if (param.lang) { |
| | | sessionStorage.setItem('lang', param.lang) |
| | | } |
| | | |
| | | this.setState({ |
| | | langName: sessionStorage.getItem('lang') !== 'zh-CN' && langs[sessionStorage.getItem('lang')] ? `(${langs[sessionStorage.getItem('lang')]})` : '', |
| | | ID: param.ID |
| | | }) |
| | | } catch (e) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '模板信息解析错误!', |
| | | duration: 5 |
| | | }) |
| | | } |
| | | } |
| | | |
| | | componentDidMount () { |
| | |
| | | let cy = position.cy |
| | | let _selectItem = null |
| | | |
| | | let _config = JSON.parse(JSON.stringify(this.state.config)) |
| | | let _config = fromJS(this.state.config).toJS() |
| | | |
| | | _config.elements.forEach(element => { |
| | | let x = +element.left |
| | |
| | | return |
| | | } |
| | | |
| | | let _selectItem = JSON.parse(JSON.stringify(this.state.config.elements.filter(ele => ele.uuid === this.state.editItemId)[0])) |
| | | let _preItem = JSON.parse(JSON.stringify(_selectItem)) |
| | | let _selectItem = fromJS(this.state.config.elements.filter(ele => ele.uuid === this.state.editItemId)[0]).toJS() |
| | | let _preItem = fromJS(_selectItem).toJS() |
| | | |
| | | let position = this.getclickpoint(e) |
| | | let cx = position.cx |
| | |
| | | let result = this.resetItem(_selectItem) |
| | | |
| | | if (!is(fromJS(result), fromJS(_preItem))) { |
| | | _preItem = JSON.parse(JSON.stringify(result)) |
| | | _preItem = fromJS(result).toJS() |
| | | this.FormRef.resetForm(result) |
| | | |
| | | config.elements = config.elements.map(item => { |
| | |
| | | let result = this.resetItem(fromJS(_selectItem).toJS()) |
| | | |
| | | if (!is(fromJS(result), fromJS(_preItem))) { |
| | | _preItem = JSON.parse(JSON.stringify(result)) |
| | | _preItem = fromJS(result).toJS() |
| | | this.FormRef.resetForm(result) |
| | | |
| | | config.elements = config.elements.map(item => { |
| | |
| | | if (keyCode === 46 && editItemId && editItemType !== 'Template') { |
| | | this.deleteItem() |
| | | } |
| | | if (e.ctrlKey && keyCode === 81 && editItemId && editItemType !== 'Template') { |
| | | this.copyItem() |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | resetbox = () => { |
| | | const { config } = this.state |
| | | const { config, debug } = this.state |
| | | |
| | | let ratio = (config.height || 1) / (config.width || 1) |
| | | |
| | | document.getElementById('darea').style.height = parseInt(document.getElementById('darea').style.width) * ratio + 'px' |
| | | |
| | | printCtrl.sketch(config, null) |
| | | printCtrl.sketch(config, null, debug) |
| | | } |
| | | |
| | | resetview () { |
| | | const { config, editItemId } = this.state |
| | | const { config, editItemId, debug } = this.state |
| | | |
| | | printCtrl.sketch(config, editItemId) |
| | | printCtrl.sketch(config, editItemId, debug) |
| | | } |
| | | |
| | | /** |
| | |
| | | this.handleResize() |
| | | this.setState({ |
| | | config: _config, |
| | | oriConfig: fromJS(_config).toJS(), |
| | | editItemId: _config.uuid, |
| | | editItemType: _config.type, |
| | | formlist: getpageform(_config) |
| | |
| | | } else { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: result.ErrMesg, |
| | | message: result.message, |
| | | duration: 5 |
| | | }) |
| | | } |
| | |
| | | |
| | | let deffers = tables.map(name => { |
| | | return new Promise(resolve => { |
| | | Api.getSystemConfig({func: 'sPC_Get_FieldName', TBName: name}).then(res => { |
| | | Api.getCloudConfig({func: 'sPC_Get_FieldName', TBName: name}).then(res => { |
| | | resolve(res) |
| | | }) |
| | | }) |
| | |
| | | if (error) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: error.ErrMesg, |
| | | message: error.message, |
| | | duration: 5 |
| | | }) |
| | | return |
| | |
| | | } else if (res.type === 'qrcode') { |
| | | res.url = qrurl |
| | | } else if (res.type === 'image') { |
| | | if (res.value && res.value.length > 0) { |
| | | let url = res.value[0].url || res.value[0].response |
| | | res.value = url || '' |
| | | } else { |
| | | res.value = '' |
| | | } |
| | | res.url = imgurl |
| | | } |
| | | |
| | |
| | | }) |
| | | } |
| | | |
| | | copyItem = () => { |
| | | const { editItemId, config, fields } = this.state |
| | | |
| | | let cell = config.elements.filter(item => item.uuid === editItemId)[0] |
| | | |
| | | if (!cell) return |
| | | |
| | | let item = {...cell} |
| | | |
| | | item.left = item.left + parseInt(item.width / 4) |
| | | item.top = item.top + parseInt(item.height / 4) |
| | | item.uuid = Utils.getuuid() |
| | | |
| | | if (item.left + item.width > config.width) { |
| | | item.left = config.width - item.width |
| | | } |
| | | if (item.top + item.height > config.height) { |
| | | item.top = config.height - item.height |
| | | } |
| | | |
| | | let _config = fromJS(config).toJS() |
| | | |
| | | _config.elements.push(item) |
| | | |
| | | let _formlist = [] |
| | | if (item.type === 'text') { |
| | | _formlist = getTextForm(item, fields) |
| | | } else if (item.type === 'barcode') { |
| | | _formlist = getBarcodeForm(item, fields) |
| | | } else if (item.type === 'qrcode') { |
| | | _formlist = getQrcodeForm(item, fields) |
| | | } else if (item.type === 'image') { |
| | | _formlist = getImageForm(item, fields) |
| | | } |
| | | |
| | | this.setState({ |
| | | config: _config, |
| | | editItemId: item.uuid, |
| | | editItemType: item.type, |
| | | formlist: _formlist |
| | | }, () => { |
| | | this.resetview() |
| | | }) |
| | | } |
| | | |
| | | deleteItem = () => { |
| | | const _this = this |
| | | const that = this |
| | | const { editItemId, config } = this.state |
| | | |
| | | confirm({ |
| | |
| | | onOk() { |
| | | config.elements = config.elements.filter(item => item.uuid !== editItemId) |
| | | |
| | | _this.setState({ |
| | | that.setState({ |
| | | config: config, |
| | | editItemId: config.uuid, |
| | | editItemType: config.type, |
| | | formlist: getpageform(config) |
| | | }, () => { |
| | | _this.resetview() |
| | | that.resetview() |
| | | }) |
| | | }, |
| | | onCancel() {} |
| | |
| | | } |
| | | |
| | | submitConfig = () => { |
| | | const { config } = this.state |
| | | const { config, oriConfig } = this.state |
| | | |
| | | if (config.height / config.width > 10 || config.width / config.height > 10) { |
| | | if (is(fromJS(config), fromJS(oriConfig))) { |
| | | notification.success({ |
| | | top: 92, |
| | | message: '当前模板未修改,无需保存。', |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } else if (config.height / config.width > 10 || config.width / config.height > 10) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '纸张纵横比不可超过10!', |
| | |
| | | |
| | | try { |
| | | _config = window.btoa(window.encodeURIComponent(JSON.stringify(config))) |
| | | } catch { |
| | | } catch (e) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '编译错误!', |
| | |
| | | } |
| | | |
| | | new Promise(resolve => { |
| | | printCtrl.sketch(config, null).then(res => { |
| | | Api.fileuploadbase64(res, 'cloud').then(result => { // 图片上传,并获取图片路径 |
| | | printCtrl.sketch(config, null, false).then(res => { |
| | | let param = { |
| | | Base64Img: res |
| | | } |
| | | |
| | | if (window.GLOB.cloudServiceApi) { |
| | | param.rduri = window.GLOB.cloudServiceApi |
| | | param.userid = sessionStorage.getItem('CloudUserID') || '' |
| | | param.LoginUID = sessionStorage.getItem('CloudLoginUID') || '' |
| | | } |
| | | |
| | | Api.fileuploadbase64(param).then(result => { // 图片上传,并获取图片路径 |
| | | if (result.status) { |
| | | resolve(Utils.getcloudurl(result.Images)) |
| | | let url = result.Images |
| | | let baseurl = '' |
| | | |
| | | if (window.GLOB.cloudServiceApi) { |
| | | baseurl = window.GLOB.cloudServiceApi.replace(/webapi(.*)$/, '') |
| | | } else { |
| | | baseurl = window.GLOB.baseurl |
| | | } |
| | | |
| | | url = url.match(/^http/) || url.match(/^\/\//) ? url : baseurl + url |
| | | |
| | | resolve(url) |
| | | } else { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: result.ErrMesg, |
| | | message: result.message, |
| | | duration: 5 |
| | | }) |
| | | this.setState({ |
| | |
| | | } else { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: res.ErrMesg, |
| | | message: res.message, |
| | | duration: 5 |
| | | }) |
| | | } |
| | | this.setState({ |
| | | oriConfig: fromJS(config).toJS(), |
| | | saveloading: false |
| | | }) |
| | | }) |
| | |
| | | }) |
| | | } |
| | | |
| | | changeDebug = (val) => { |
| | | this.setState({ |
| | | debug: val |
| | | }, () => { |
| | | this.resetview() |
| | | }) |
| | | } |
| | | |
| | | render () { |
| | | const { debug, langName } = this.state |
| | | |
| | | return ( |
| | | <div className="print-template"> |
| | | <DndProvider backend={HTML5Backend}> |
| | | <header className="print-header-container ant-menu-dark">模板制作</header> |
| | | <header className="print-header-container ant-menu-dark"> |
| | | 模板制作{langName} |
| | | <div>快捷键:Delete(删除元素)、ctrl + q(复制元素)</div> |
| | | </header> |
| | | <aside className="tools"> |
| | | <Card className="tool-bar" title="工具栏"> |
| | | {printItems.map((item, index) => { |
| | |
| | | })} |
| | | </Card> |
| | | <Card className="move-bar" title="整体移动"> |
| | | <Input addonBefore={<Icon title="距上" type="arrow-up" />} addonAfter={<Icon onClick={() => this.updatePosition('upPlus')} type="plus" />} onChange={(e) => this.change(e, 'upPlus')} value={this.state.upPlus} /> |
| | | <Input addonBefore={<Icon title="距上" type="arrow-up" />} addonAfter={<Icon onClick={() => this.updatePosition('upMinus')} type="minus" />} onChange={(e) => this.change(e, 'upMinus')} value={this.state.upMinus} /> |
| | | <Input addonBefore={<Icon title="距左" type="arrow-left" />} addonAfter={<Icon onClick={() => this.updatePosition('leftPlus')} type="plus" />} onChange={(e) => this.change(e, 'leftPlus')} value={this.state.leftPlus} /> |
| | | <Input addonBefore={<Icon title="距左" type="arrow-left" />} addonAfter={<Icon onClick={() => this.updatePosition('leftMinus')} type="minus" />} onChange={(e) => this.change(e, 'leftMinus')} value={this.state.leftMinus} /> |
| | | <Input addonBefore={<ArrowUpOutlined/>} addonAfter={<CaretRightOutlined onClick={() => this.updatePosition('upMinus')}/>} onChange={(e) => this.change(e, 'upMinus')} value={this.state.upMinus} /> |
| | | <Input addonBefore={<ArrowDownOutlined/>} addonAfter={<CaretRightOutlined onClick={() => this.updatePosition('upPlus')}/>} onChange={(e) => this.change(e, 'upPlus')} value={this.state.upPlus} /> |
| | | <Input addonBefore={<ArrowLeftOutlined/>} addonAfter={<CaretRightOutlined onClick={() => this.updatePosition('leftMinus')}/>} onChange={(e) => this.change(e, 'leftMinus')} value={this.state.leftMinus} /> |
| | | <Input addonBefore={<ArrowRightOutlined/>} addonAfter={<CaretRightOutlined onClick={() => this.updatePosition('leftPlus')}/>} onChange={(e) => this.change(e, 'leftPlus')} value={this.state.leftPlus} /> |
| | | <div style={{marginTop: '10px'}}> |
| | | <span>调试模式:</span><Switch checked={debug} onChange={this.changeDebug} /> |
| | | </div> |
| | | </Card> |
| | | </aside> |
| | | <div className="switchbox" onClick={this.switchbox}></div> |