king
2021-06-24 95afd40fc2741ac0ce59c2091f6cfce1f98877d4
src/templates/zshare/editcomponent/index.jsx
@@ -1,8 +1,10 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { fromJS } from 'immutable'
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 TransferForm from '@/templates/zshare/basetransferform'
import zhCN from '@/locales/zh-CN/model.js'
@@ -11,7 +13,7 @@
class editComponent extends Component {
  static propTpyes = {
    type: PropTypes.string,
    options: PropTypes.array,
    MenuID: PropTypes.any,
    config: PropTypes.object,
    thawButtons: PropTypes.any,
@@ -19,10 +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
    pasteVisible: false,
  }
  handleMenuClick = e => {
@@ -37,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) {
@@ -97,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) {
@@ -127,42 +123,122 @@
  }
  pasteSubmit = () => {
    const { config } = this.props
    const { options } = this.props
    let _config = fromJS(this.props.config).toJS()
    this.pasteFormRef.handleConfirm().then(res => {
      if (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 (res.copyType === 'search') {
      } 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)
            }
          })
        }
        this.setState({
          pasteVisible: false
        }, () => {
          this.props.refresh({
            type: 'paste',
            content: res
            config: _config
          })
        })
      } else if (res.copyType === 'columns') {
        let _columns = config.columns.filter(col => !col.origin)
        if (_columns.length > 0) {
      } 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'
        _config.fields.forEach(item => {
          item.field && fields.push(item.field.toLowerCase())
          labels.push(item.label)
        })
        _config.fields.push(res)
        if (res.field && fields.includes(res.field.toLowerCase())) {
          notification.warning({
            top: 92,
            message: '显示列已存在!',
            duration: 5
            message: '字段已存在!',
            duration: 10
          })
          return
        } else if (labels.includes(res.label)) {
          notification.warning({
            top: 92,
            message: '名称已存在!',
            duration: 10
          })
          return
        }
@@ -172,7 +248,8 @@
        }, () => {
          this.props.refresh({
            type: 'paste',
            content: res
            config: _config,
            newform: res
          })
        })
      } else {
@@ -186,12 +263,12 @@
  }
  render() {
    const { MenuID } = this.props
    const { dict } = this.state
    const menu = (
      <Menu onClick={this.handleMenuClick}>
        {this.props.type !== 'TreePage' ? <Menu.Item key="thaw"><Icon type="unlock" />{dict['header.form.thawbutton']}</Menu.Item> : null}
        {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.Item key="replace"><Icon type="retweet" />替换</Menu.Item> */}
      </Menu>
    )
@@ -223,10 +300,7 @@
          onCancel={() => {this.setState({pasteVisible: false})}}
          destroyOnClose
        >
          <PasteForm
            dict={dict}
            wrappedComponentRef={(inst) => this.pasteFormRef = inst}
          />
          <PasteForm wrappedComponentRef={(inst) => this.pasteFormRef = inst}/>
        </Modal>
      </div>
    )