import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { fromJS } from 'immutable'
|
import { Icon, Modal, notification } from 'antd'
|
|
import Utils from '@/utils/utils.js'
|
import MKEmitter from '@/utils/events.js'
|
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
|
}
|
|
handleMenuClick = () => {
|
this.setState({visible: true})
|
}
|
|
pasteSubmit = () => {
|
const { options, elements } = this.props
|
this.pasteFormRef.handleConfirm().then(res => {
|
if (!options.includes(res.copyType)) {
|
notification.warning({ top: 92, message: '配置信息格式错误!', duration: 5 })
|
return
|
}
|
|
let _uuid = Utils.getuuid()
|
if (res.copyType === 'action' && res.OpenType === 'popview') {
|
let _cell = fromJS(res).toJS()
|
_cell.$originUuid = res.uuid
|
_cell.uuid = _uuid
|
MKEmitter.emit('copyButtons', [_cell])
|
}
|
res.uuid = _uuid
|
|
this.props.updateConfig([...elements, res])
|
this.setState({visible: false})
|
|
notification.success({
|
top: 92,
|
message: '粘贴成功!',
|
duration: 2
|
})
|
})
|
}
|
|
render() {
|
const { visible } = this.state
|
|
return (
|
<div style={{display: 'inline-block'}}>
|
<Icon type="snippets" style={{color: 'purple'}} onClick={() => {this.setState({visible: true})}} />
|
<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
|