import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { fromJS } from 'immutable'
|
import { Modal, notification, Button } from 'antd'
|
import { SnippetsOutlined } from '@ant-design/icons'
|
|
import Utils from '@/utils/utils.js'
|
import PasteForm from '@/templates/zshare/pasteform'
|
import MKEmitter from '@/utils/events.js'
|
import './index.scss'
|
|
class editComponent extends Component {
|
static propTpyes = {
|
options: PropTypes.array,
|
config: PropTypes.object,
|
refresh: PropTypes.func
|
}
|
|
state = {
|
visible: false
|
}
|
|
pasteSubmit = () => {
|
const { options, config, type } = this.props
|
let _config = fromJS(this.props.config).toJS()
|
|
this.pasteFormRef.handleConfirm().then(res => {
|
if (type === 'formboard' && res.copyType === 'search' && ['text', 'select', 'multiselect', 'link', 'checkcard', 'date', 'datemonth'].includes(res.type)) {
|
res.copyType = 'form'
|
}
|
if (!options.includes(res.copyType)) {
|
notification.warning({
|
top: 92,
|
message: '配置信息格式错误!',
|
duration: 5
|
})
|
return
|
} else if (res.copyType === 'action') {
|
res.uuid = Utils.getuuid()
|
MKEmitter.emit('pasteButton', config.uuid, res)
|
} else if (res.copyType === 'search' || (type === 'table' && res.copyType === 'form')) {
|
res.uuid = Utils.getuuid()
|
let keys = _config.search.map(item => item.field ? item.field.toLowerCase() : '')
|
|
if (type === 'table') {
|
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'
|
}
|
}
|
|
if (res.field && keys.includes(res.field.toLowerCase())) {
|
notification.warning({
|
top: 92,
|
message: '搜索字段已存在!',
|
duration: 5
|
})
|
return
|
}
|
MKEmitter.emit('plusSearch', config.uuid, res, 'simple')
|
} else if (res.copyType === 'columns') {
|
let keys = _config.columns.map(item => item.field ? item.field.toLowerCase() : '')
|
let items = res.columns.filter(col => col.field && !keys.includes(col.field.toLowerCase()))
|
|
MKEmitter.emit('plusColumns', config.uuid, items)
|
} else if (res.copyType === 'form') {
|
let keys = _config.fields.map(item => item.field ? item.field.toLowerCase() : '')
|
res.uuid = Utils.getuuid()
|
|
if (res.field && keys.includes(res.field.toLowerCase())) {
|
notification.warning({
|
top: 92,
|
message: '字段已存在!',
|
duration: 10
|
})
|
return
|
}
|
|
this.props.plusFields([res])
|
} else if (res.copyType === 'forms') {
|
this.props.plusFields(res, 'forms')
|
} else {
|
notification.warning({
|
top: 92,
|
message: '配置信息格式错误!',
|
duration: 5
|
})
|
return
|
}
|
this.setState({
|
visible: false
|
})
|
})
|
}
|
|
render() {
|
return (
|
<div style={{display: 'inline-block'}}>
|
<Button style={{borderColor: '#40a9ff', color: '#40a9ff'}} onClick={() => this.setState({visible: true})}><SnippetsOutlined /> 粘贴</Button>
|
{/* 按钮配置信息粘贴复制 */}
|
<Modal
|
title="粘贴"
|
visible={this.state.visible}
|
width={600}
|
maskClosable={false}
|
onOk={this.pasteSubmit}
|
onCancel={() => {this.setState({visible: false})}}
|
destroyOnClose
|
>
|
<PasteForm wrappedComponentRef={(inst) => this.pasteFormRef = inst} inputSubmit={this.pasteSubmit}/>
|
</Modal>
|
</div>
|
)
|
}
|
}
|
|
export default editComponent
|