king
2024-06-21 b78198e00a34eaa2b0a761bb6f42bf14e7771883
src/views/printTemplate/index.jsx
@@ -20,6 +20,7 @@
  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'
@@ -35,7 +36,9 @@
class PrintTemplate extends Component {
  state = {
    config: null,
    oriConfig: null,
    ID: null,
    langName: '',
    editItemId: '',
    editItemType: '',
    fields: [],
@@ -67,16 +70,24 @@
  }
  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 () {
@@ -88,7 +99,7 @@
      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
@@ -156,8 +167,8 @@
        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
@@ -214,7 +225,7 @@
              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 => {
@@ -261,7 +272,7 @@
              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 => {
@@ -407,6 +418,7 @@
      this.handleResize()
      this.setState({
        config: _config,
        oriConfig: fromJS(_config).toJS(),
        editItemId: _config.uuid,
        editItemType: _config.type,
        formlist: getpageform(_config)
@@ -779,9 +791,16 @@
  }
  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!',
@@ -878,6 +897,7 @@
        })
      }
      this.setState({
        oriConfig: fromJS(config).toJS(),
        saveloading: false
      })
    })
@@ -950,13 +970,13 @@
  }
  render () {
    const { debug } = this.state
    const { debug, langName } = this.state
    
    return (
      <div className="print-template">
        <DndProvider backend={HTML5Backend}>
          <header className="print-header-container ant-menu-dark">
            模板制作
            模板制作{langName}
            <div>快捷键:Delete(删除元素)、ctrl + q(复制元素)</div>
          </header>
          <aside className="tools">