import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { Modal, notification } from 'antd'
|
import { SnippetsOutlined } from '@ant-design/icons'
|
|
import MenuUtils from '@/utils/utils-custom.js'
|
import MKEmitter from '@/utils/events.js'
|
import asyncComponent from '@/utils/asyncComponent'
|
// import './index.scss'
|
|
const PasteForm = asyncComponent(() => import('@/templates/zshare/pasteform'))
|
|
class PasteGroup extends Component {
|
static propTpyes = {
|
insert: PropTypes.func
|
}
|
|
state = {
|
visible: false
|
}
|
|
handleMenuClick = () => {
|
this.setState({visible: true})
|
}
|
|
pasteSubmit = () => {
|
let options = ['datacard', 'propcard', 'balcony', 'timeline', 'stepform', 'tabform', 'normaltable', 'tablecard', 'line', 'bar', 'pie', 'dashboard', 'scatter', 'chart']
|
let types = {
|
login: '登录',
|
navbar: '导航栏',
|
topbar: '导航栏',
|
tabs: '标签页',
|
search: '搜索',
|
mainsearch: '搜索',
|
group: '分组',
|
menubar: '菜单'
|
}
|
|
this.pasteFormRef.handleConfirm().then(res => {
|
if (res.copyType && types[res.copyType]) {
|
notification.warning({
|
top: 92,
|
message: '分组中不可添加《' + types[res.copyType] + '》组件!',
|
duration: 5
|
})
|
return
|
} else if (!options.includes(res.copyType)) {
|
notification.warning({
|
top: 92,
|
message: '配置信息格式错误!',
|
duration: 5
|
})
|
return
|
}
|
|
let copyBtns = new Map()
|
|
res = MenuUtils.resetComponentConfig(res, copyBtns)
|
|
delete res.copyType
|
|
this.props.insert(res)
|
|
copyBtns = [...copyBtns.values()]
|
|
if (copyBtns.length > 0) {
|
MKEmitter.emit('copyButtons', copyBtns)
|
}
|
|
this.setState({visible: false})
|
|
notification.success({
|
top: 92,
|
message: '粘贴成功!',
|
duration: 2
|
})
|
})
|
}
|
|
render() {
|
const { visible } = this.state
|
|
return (
|
<div style={{display: 'inline-block'}}>
|
<SnippetsOutlined 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 PasteGroup
|