import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { Button, Modal, notification } from 'antd'
|
|
import asyncComponent from '@/utils/asyncComponent'
|
// import './index.scss'
|
|
const PasteForm = asyncComponent(() => import('@/templates/zshare/pasteform'))
|
|
class PasteController extends Component {
|
static propTpyes = {
|
config: PropTypes.object, // 组件配置
|
updateConfig: PropTypes.func
|
}
|
|
state = {
|
visible: false
|
}
|
|
pasteSubmit = () => {
|
const { config } = this.props
|
this.pasteFormRef.handleConfirm().then(res => {
|
if (res.copyType === 'forms') {
|
this.props.updateConfig(res, 'forms')
|
this.setState({visible: false})
|
return
|
} else if (res.copyType !== 'form') {
|
notification.warning({ top: 92, message: '配置信息格式错误!', duration: 5 })
|
return
|
}
|
|
let keys = config.fields.map(item => item.field ? item.field.toLowerCase() : '$emp_ty$')
|
|
if (['multiselect', 'color', 'brafteditor'].includes(res.type)) {
|
res.type = 'text'
|
}
|
|
if (res.field && keys.includes(res.field.toLowerCase())) {
|
notification.warning({
|
top: 92,
|
message: '字段已存在!',
|
duration: 5
|
})
|
return
|
}
|
|
this.props.updateConfig({...config, fields: [...config.fields, res]})
|
this.setState({visible: false})
|
|
notification.success({
|
top: 92,
|
message: '粘贴成功!',
|
duration: 2
|
})
|
})
|
}
|
|
render() {
|
const { visible } = this.state
|
|
return (
|
<div style={{display: 'inline-block'}}>
|
<Button icon="snippets" style={{color: 'purple'}} onClick={() => {this.setState({visible: true})}} >粘贴</Button>
|
<Modal
|
title="粘贴"
|
visible={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 PasteController
|