king
2021-06-24 95afd40fc2741ac0ce59c2091f6cfce1f98877d4
src/templates/zshare/editcomponent/index.jsx
@@ -4,8 +4,8 @@
import { Menu, Dropdown, Icon, Modal, Spin, notification } from 'antd'
import Api from '@/api'
import Utils from '@/utils/utils.js'
import PasteForm from '@/templates/zshare/pasteform'
import ReplaceForm from '@/templates/zshare/replaceform'
import TransferForm from '@/templates/zshare/basetransferform'
import zhCN from '@/locales/zh-CN/model.js'
import enUS from '@/locales/en-US/model.js'
@@ -13,7 +13,7 @@
class editComponent extends Component {
  static propTpyes = {
    type: PropTypes.string,
    options: PropTypes.array,
    MenuID: PropTypes.any,
    config: PropTypes.object,
    thawButtons: PropTypes.any,
@@ -21,11 +21,10 @@
  }
  state = {
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    thawVisible: false,
    thawbtnlist: null,
    pasteVisible: false,
    replaceVisible: false
  }
  handleMenuClick = e => {
@@ -33,8 +32,6 @@
      this.handleThaw()
    } else if (e.key === 'paste') {
      this.setState({pasteVisible: true})
    } else if (e.key === 'replace') {
      this.setState({replaceVisible: true})
    }
  }
@@ -42,21 +39,15 @@
   * @description 解冻按钮
   */
  handleThaw = () => {
    const { config } = this.props
    const { MenuID } = this.props
    this.setState({
      thawVisible: true
    })
    let uuid = config.uuid
    if (this.props.type === 'maintable') {
      uuid = this.props.MenuID
    }
    Api.getSystemConfig({
      func: 'sPC_Get_FrozenMenu',
      ParentID: uuid,
      ParentID: MenuID,
      TYPE: 40
    }).then(res => {
      if (res.status) {
@@ -102,7 +93,7 @@
  thawBtnSubmit = () => {
    const { thawButtons } = this.props
    const { thawbtnlist, dict } = this.state
    let config = JSON.parse(JSON.stringify(this.props.config))
    let config = fromJS(this.props.config).toJS()
    // 三级菜单解除冻结
    if (this.refs.trawmenu.state.targetKeys.length === 0) {
@@ -132,44 +123,79 @@
  }
  pasteSubmit = () => {
    const { config, type } = this.props
    const { options } = this.props
    let _config = fromJS(this.props.config).toJS()
    this.pasteFormRef.handleConfirm().then(res => {
      if (['maintable', 'subtable'].includes(type) && res.copyType === 'action') {
        if (this.props.type === 'subtable' && !['pop', 'prompt', 'exec', 'excelIn', 'excelOut', 'popview'].includes(res.OpenType)) {
      if (res.copyType === 'action' && options.includes('action')) {
        res.uuid = Utils.getuuid()
        _config.action = _config.action.filter(item => !item.origin)
        _config.action.push(res)
        this.setState({
          pasteVisible: false
        }, () => {
          this.props.refresh({
            type: 'paste',
            config: _config
          })
        })
      } else if (options.includes('search') && (res.copyType === 'search' || res.copyType === 'form')) {
        res.uuid = Utils.getuuid()
        _config.search = _config.search.filter(item => !item.origin)
        let keys = _config.search.map(item => item.field.toLowerCase())
        // search: text select multiselect link date dateweek datemonth daterange group
        // form: text number select multiselect link switch checkbox radio checkcard
        //       fileupload date datemonth datetime textarea hint color funcvar
        if (res.copyType === 'form') {
          if (['number', 'switch', 'textarea', 'fileupload', 'hint', 'color', 'funcvar'].includes(res.type)) {
            res.type = 'text'
          } else if (res.type === 'radio') {
            res.type = 'select'
          } else if (res.type === 'checkbox') {
            res.type = 'multiselect'
          } else if (res.type === 'datetime') {
            res.type = 'date'
          }
        }
        res.copyType = 'search'
        _config.search.push(res)
        if (res.field && keys.includes(res.field.toLowerCase())) {
          notification.warning({
            top: 92,
            message: '不支持此打开方式!',
            message: '搜索字段已存在!',
            duration: 5
          })
          return
        }
        this.setState({
          pasteVisible: false
        }, () => {
          this.props.refresh({
            type: 'paste',
            content: res
            config: _config
          })
        })
      } else if (['maintable', 'subtable'].includes(type) && res.copyType === 'search') {
        this.setState({
          pasteVisible: false
        }, () => {
          this.props.refresh({
            type: 'paste',
            content: res
      } else if (options.includes('columns') && res.copyType === 'columns') {
        _config.columns = _config.columns.filter(col => !col.origin)
        let keys = _config.columns.map(item => item.field ? item.field.toLowerCase() : '')
        if (_config.columns.length === 0) {
          _config.columns = res.columns
        } else {
          res.columns.forEach(col => {
            if (!col.field) return
            let _key = col.field.toLowerCase()
            if (!keys.includes(_key)) {
              keys.push(_key)
              _config.columns.push(col)
            }
          })
        })
      } else if (['maintable', 'subtable'].includes(type) && res.copyType === 'columns') {
        let _columns = config.columns.filter(col => !col.origin)
        if (_columns.length > 0) {
          notification.warning({
            top: 92,
            message: '显示列已存在!',
            duration: 5
          })
          return
        }
        
        this.setState({
@@ -177,55 +203,38 @@
        }, () => {
          this.props.refresh({
            type: 'paste',
            content: res
            config: _config
          })
        })
      } else if (['form'].includes(type) && res.copyType === 'form') {
        if (res.type === 'linkMain') {
          notification.warning({
            top: 92,
            message: '不支持此表单类型!',
            duration: 10
          })
          return
      } else if (options.includes('form') && (res.copyType === 'form' || res.copyType === 'search')) {
        let fields = []
        let labels = []
        res.uuid = Utils.getuuid()
        // search: text select multiselect link date dateweek datemonth daterange group
        // form: text number select multiselect link switch checkbox radio checkcard
        //       fileupload date datemonth datetime textarea hint color funcvar
        if (res.copyType === 'search') {
          if (res.type === 'dateweek' || res.type === 'daterange' || res.type === 'group') {
            res.type = 'date'
          }
        }
        res.copyType = 'form'
        let _config = fromJS(config).toJS()
        let fieldrepet = false
        let labelrepet = false
        _config.fields.forEach(item => {
          item.field && fields.push(item.field.toLowerCase())
          labels.push(item.label)
        })
        _config.fields.push(res)
        if (_config.groups.length > 0) {
          _config.groups.forEach(group => {
            group.sublist.forEach(item => {
              if (item.uuid === res.uuid) {
                fieldrepet = true
              } else if (item.field === res.field) {
                fieldrepet = true
              } else if (item.label === res.label) {
                labelrepet = true
              }
            })
          })
        } else {
          _config.fields.forEach(item => {
            if (item.uuid === res.uuid) {
              fieldrepet = true
            } else if (item.field === res.field) {
              fieldrepet = true
            } else if (item.label === res.label) {
              labelrepet = true
            }
          })
        }
        if (fieldrepet) {
        if (res.field && fields.includes(res.field.toLowerCase())) {
          notification.warning({
            top: 92,
            message: '字段已存在!',
            duration: 10
          })
          return
        } else if (labelrepet) {
        } else if (labels.includes(res.label)) {
          notification.warning({
            top: 92,
            message: '名称已存在!',
@@ -233,23 +242,14 @@
          })
          return
        }
        if (_config.groups.length > 0) {
          _config.groups.forEach(group => {
            if (group.default) {
              group.sublist.push(res)
            }
          })
        } else {
          _config.fields.push(res)
        }
        
        this.setState({
          pasteVisible: false
        }, () => {
          this.props.refresh({
            type: 'paste',
            content: _config
            config: _config,
            newform: res
          })
        })
      } else {
@@ -262,26 +262,13 @@
    })
  }
  replaceSubmit = () => {
    this.replaceFormRef.handleConfirm().then(res => {
      this.props.refresh({
        type: 'replace',
        ...res
      })
      this.setState({
        replaceVisible: false
      })
    })
  }
  render() {
    const { type } = this.props
    const { MenuID } = this.props
    const { dict } = this.state
    const menu = (
      <Menu onClick={this.handleMenuClick}>
        {['maintable', 'subtable'].includes(type) ? <Menu.Item key="thaw"><Icon type="unlock" />{dict['header.form.thawbutton']}</Menu.Item> : null}
        {['maintable', 'subtable', 'form'].includes(type) ? <Menu.Item key="paste"><Icon type="snippets" />{dict['header.form.paste']}</Menu.Item> : null}
        {/* <Menu.Item key="replace"><Icon type="retweet" />替换</Menu.Item> */}
        {MenuID ? <Menu.Item key="thaw"><Icon type="unlock" />{dict['header.form.thawbutton']}</Menu.Item> : null}
        <Menu.Item key="paste"><Icon type="snippets" />{dict['header.form.paste']}</Menu.Item>
      </Menu>
    )
@@ -313,26 +300,7 @@
          onCancel={() => {this.setState({pasteVisible: false})}}
          destroyOnClose
        >
          <PasteForm
            dict={dict}
            wrappedComponentRef={(inst) => this.pasteFormRef = inst}
          />
        </Modal>
        {/* 替换 */}
        <Modal
          title={'替换'}
          visible={this.state.replaceVisible}
          width={600}
          maskClosable={false}
          onOk={this.replaceSubmit}
          onCancel={() => {this.setState({replaceVisible: false})}}
          destroyOnClose
        >
          <ReplaceForm
            dict={dict}
            inputSubmit={this.replaceSubmit}
            wrappedComponentRef={(inst) => this.replaceFormRef = inst}
          />
          <PasteForm wrappedComponentRef={(inst) => this.pasteFormRef = inst}/>
        </Modal>
      </div>
    )