king
2022-10-27 83592b5c2dcbfd0a91d36dfa89f1a6cbe95ab1d1
src/views/tabledesign/index.jsx
@@ -12,6 +12,7 @@
import Utils, { setGLOBFuncs } from '@/utils/utils.js'
import antdZhCN from 'antd/es/locale/zh_CN'
import MKEmitter from '@/utils/events.js'
import { getTables } from '@/utils/utils-custom.js'
import SourceElement from '@/templates/zshare/dragsource'
import asyncComponent from '@/utils/asyncComponent'
import Source from './source'
@@ -25,6 +26,7 @@
const _locale = antdZhCN
const MenuForm = asyncComponent(() => import('./menuform'))
const PopView = asyncComponent(() => import('./popview'))
const TableNodes = asyncComponent(() => import('@/menu/tablenodes'))
const TableSource = asyncComponent(() => import('./tablesource'))
const Header = asyncComponent(() => import('@/menu/header'))
@@ -55,6 +57,8 @@
    config: null,
    comloading: false,
    settingshow: true,
    view: null,
    popConfig: null
  }
  UNSAFE_componentWillMount() {
@@ -141,6 +145,9 @@
        let node = document.getElementById('save-modal-config')
        if (!node) {
          node = document.getElementById('save-pop-config')
        }
        if (!node) {
          node = document.getElementById('save-config')
        }
@@ -164,6 +171,8 @@
  }
  triggerMenuSave = () => {
    if (this.state.view === 'popview') return
    this.submitConfig()
  }
@@ -212,22 +221,101 @@
  }
  initPopview = (card, btn) => {
    const { oriConfig, config } = this.state
    const { config } = this.state
    if (!is(fromJS(oriConfig), fromJS(config))) {
      notification.warning({
        top: 92,
        message: '配置已修改,请保存!',
        duration: 5
      })
    if (!this.checkBase()) {
      return
    }
    let _btn = fromJS(btn).toJS()
    _btn.MenuName = config.MenuName + '-' + card.name + '-' + btn.label
    _btn.ParentMenuID = config.uuid
    this.props.history.push('/popdesign/' + window.btoa(window.encodeURIComponent((JSON.stringify(_btn)))))
    if (_btn.config) {
      _btn.config.uuid = _btn.uuid
      _btn.config.MenuID = _btn.uuid
      _btn.config.ParentId = card.uuid
      _btn.config.MenuName = _btn.label
    } else {
      _btn.config = {
        uuid: _btn.uuid,
        MenuID: _btn.uuid,
        ParentId: card.uuid,
        enabled: false,
        MenuName: _btn.label,
        tables: config.tables || [],
        Template: 'BaseTable',
        components: [{
          uuid: Utils.getuuid(),
          type: 'table',
          width: 24,
          name: '主表',
          subtype: 'basetable',
          isNew: true
        }],
        viewType: 'popview',
        style: { backgroundColor: '#ffffff', backgroundImage: '', paddingTop: '16px', paddingBottom: '40px', paddingLeft: '16px', paddingRight: '16px' }
      }
    }
    this.setState({view: 'popview', popConfig: _btn})
  }
  submitPopConfig = (btnconfig) => {
    let config = fromJS(this.state.config).toJS()
    config.components.forEach(item => {
      if (item.type === 'tabs') {
        item.subtabs.forEach(tab => {
          if (btnconfig.ParentId !== tab.components[0].uuid) return
          tab.components[0].action.forEach(btn => {
            if (btn.OpenType === 'popview' && btn.uuid === btnconfig.uuid) {
              btn.config = btnconfig
            }
          })
          tab.components[0].cols.forEach(col => {
            if (col.type !== 'action') return
            col.elements.forEach(btn => {
              if (btn.OpenType === 'popview' && btn.uuid === btnconfig.uuid) {
                btn.config = btnconfig
              }
            })
          })
          tab.components[0].$tables = getTables(tab.components[0])
        })
      } else if (item.uuid === btnconfig.ParentId) {
        item.action.forEach(btn => {
          if (btn.OpenType === 'popview' && btn.uuid === btnconfig.uuid) {
            btn.config = btnconfig
          }
        })
        item.cols.forEach(col => {
          if (col.type !== 'action') return
          col.elements.forEach(btn => {
            if (btn.OpenType === 'popview' && btn.uuid === btnconfig.uuid) {
              btn.config = btnconfig
            }
          })
        })
        item.$tables = getTables(item)
      }
    })
    this.setState({ config }, () => {
      this.submitConfig()
    })
  }
  closePop = () => {
    const { config } = this.state
    sessionStorage.setItem('editMenuType', 'menu')
    window.GLOB.urlFields = config.urlFields || []
    window.GLOB.customMenu = config
    this.setState({view: '', popConfig: null})
  }
  closeView = () => {
@@ -392,8 +480,8 @@
    return buttons
  }
  submitConfig = () => {
    let config = fromJS(this.state.config).toJS()
  checkBase = () => {
    const { config } = this.state
    if (!config.MenuName || !config.MenuNo || !config.fstMenuId || !config.parentId) {
      notification.warning({
@@ -401,6 +489,15 @@
        message: '请完善菜单基本信息!',
        duration: 5
      })
      return false
    }
    return true
  }
  submitConfig = () => {
    let config = fromJS(this.state.config).toJS()
    if (!this.checkBase()) {
      return
    }
@@ -495,6 +592,7 @@
          localStorage.setItem('menuUpdate', new Date().getTime())
        }
        config.open_edition = res.open_edition || ''
        this.setState({
          config,
          oriConfig: fromJS(config).toJS(),
@@ -650,13 +748,13 @@
  }
  render () {
    const { activeKey, comloading, MenuId, config, settingshow, ParentId, menuloading } = this.state
    const { view, activeKey, comloading, MenuId, config, settingshow, ParentId, menuloading } = this.state
    return (
      <ConfigProvider locale={_locale}>
        <div className="pc-table-view">
          <Header />
          <DndProvider backend={HTML5Backend}>
        <Header />
        <DndProvider backend={HTML5Backend}>
        {view !== 'popview' ? <div className="pc-table-view">
            <div className="menu-body">
              <div className={'menu-setting ' + (!settingshow ? 'hidden' : '')}>
                <div className="draw">
@@ -718,10 +816,10 @@
                </Card>
              </div>
            </div>
          </DndProvider>
          <StyleController />
          <ModalController />
        </div>
          </div> : <PopView btn={this.state.popConfig} save={this.submitPopConfig} cancel={this.closePop}/>}
        </DndProvider>
        <StyleController />
        <ModalController />
      </ConfigProvider>
    )
  }