| | |
| | | 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 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' |
| | |
| | | dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, |
| | | thawVisible: false, |
| | | thawbtnlist: null, |
| | | pasteVisible: false |
| | | pasteVisible: false, |
| | | replaceVisible: false |
| | | } |
| | | |
| | | handleMenuClick = e => { |
| | |
| | | this.handleThaw() |
| | | } else if (e.key === 'paste') { |
| | | this.setState({pasteVisible: true}) |
| | | } else if (e.key === 'replace') { |
| | | this.setState({replaceVisible: true}) |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | pasteSubmit = () => { |
| | | const { config } = this.props |
| | | const { config, type } = this.props |
| | | |
| | | this.pasteFormRef.handleConfirm().then(res => { |
| | | if (res.copyType === 'action') { |
| | | if (['maintable', 'subtable'].includes(type) && res.copyType === 'action') { |
| | | if (this.props.type === 'subtable' && !['pop', 'prompt', 'exec', 'excelIn', 'excelOut', 'popview'].includes(res.OpenType)) { |
| | | notification.warning({ |
| | | top: 92, |
| | |
| | | content: res |
| | | }) |
| | | }) |
| | | } else if (res.copyType === 'search') { |
| | | } else if (['maintable', 'subtable'].includes(type) && res.copyType === 'search') { |
| | | this.setState({ |
| | | pasteVisible: false |
| | | }, () => { |
| | |
| | | content: res |
| | | }) |
| | | }) |
| | | } else if (res.copyType === 'columns') { |
| | | } else if (['maintable', 'subtable'].includes(type) && res.copyType === 'columns') { |
| | | let _columns = config.columns.filter(col => !col.origin) |
| | | if (_columns.length > 0) { |
| | | notification.warning({ |
| | |
| | | content: res |
| | | }) |
| | | }) |
| | | } else if (['form'].includes(type) && res.copyType === 'form') { |
| | | if (res.type === 'linkMain') { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '不支持此表单类型!', |
| | | duration: 10 |
| | | }) |
| | | return |
| | | } |
| | | |
| | | let _config = fromJS(config).toJS() |
| | | let fieldrepet = false |
| | | let labelrepet = false |
| | | |
| | | 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) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '字段已存在!', |
| | | duration: 10 |
| | | }) |
| | | return |
| | | } else if (labelrepet) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '名称已存在!', |
| | | duration: 10 |
| | | }) |
| | | 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 |
| | | }) |
| | | }) |
| | | } else { |
| | | notification.warning({ |
| | | top: 92, |
| | |
| | | }) |
| | | } |
| | | |
| | | replaceSubmit = () => { |
| | | this.replaceFormRef.handleConfirm().then(res => { |
| | | this.props.refresh({ |
| | | type: 'replace', |
| | | ...res |
| | | }) |
| | | this.setState({ |
| | | replaceVisible: false |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | render() { |
| | | const { type } = 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} |
| | | <Menu.Item key="paste"><Icon type="snippets" />{dict['header.form.paste']}</Menu.Item> |
| | | {['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> */} |
| | | </Menu> |
| | | ) |
| | |
| | | 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} |
| | | /> |
| | | </Modal> |
| | | </div> |
| | | ) |
| | | } |