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 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
|
}
|
|
resetconfig = (item, appType) => {
|
if (item.type === 'tabs') {
|
item.uuid = MenuUtils.getuuid()
|
item.setting.name = item.setting.name + MenuUtils.getSignName()
|
item.name = item.setting.name
|
|
item.subtabs.forEach(tab => {
|
tab.uuid = MenuUtils.getuuid()
|
|
tab.components = tab.components.map(cell => {
|
cell = this.resetconfig(cell, appType)
|
return cell
|
})
|
})
|
} else if (item.type === 'group') {
|
item.uuid = MenuUtils.getuuid()
|
item.setting.name = item.setting.name + MenuUtils.getSignName()
|
item.name = item.setting.name
|
|
item.components = item.components.map(cell => {
|
cell = MenuUtils.resetComponentConfig(cell, appType)
|
|
return cell
|
})
|
} else {
|
item = MenuUtils.resetComponentConfig(item, appType)
|
}
|
|
return item
|
}
|
|
pasteSubmit = () => {
|
const { type } = this.props
|
|
let appType = sessionStorage.getItem('appType')
|
// ['calendar', 'balcony', 'datacard', 'doublecard', 'propcard', 'tablecard', 'cardatacard', 'carpropcard', 'line', 'dashboard', 'antvG6', 'pie', 'scatter', 'antvX6', 'chart', 'sandbox', 'editor', 'simpleform', 'stepform', 'tabform', 'group', 'iframe', 'mainsearch', 'basetable', 'editable', 'normaltable', 'tabs', 'timeline', 'tree', 'menubar', 'singleSearch', 'topbar']
|
let options = []
|
let types = {
|
topbar: '导航栏',
|
singleSearch: '搜索',
|
iframe: 'iframe'
|
}
|
|
if (appType === 'mob') {
|
options = ['balcony', 'datacard', 'doublecard', 'propcard', 'tablecard', 'cardatacard', 'carpropcard', 'line', 'pie', 'scatter', 'sandbox', 'editor', 'simpleform', 'stepform', 'tabform', 'basetable', 'normaltable', 'timeline']
|
|
if (type !== 'group') {
|
options.push('tabs', 'group', 'menubar')
|
} else {
|
types.tabs = '标签页'
|
types.group = '分组'
|
types.menubar = '菜单栏'
|
}
|
} else {
|
options = ['calendar', 'balcony', 'datacard', 'doublecard', 'propcard', 'tablecard', 'cardatacard', 'carpropcard', 'line', 'dashboard', 'antvG6', 'pie', 'scatter', 'antvX6', 'chart', 'sandbox', 'editor', 'simpleform', 'stepform', 'tabform', 'basetable', 'editable', 'normaltable', 'timeline', 'tree']
|
|
if (type !== 'group') {
|
options.push('tabs', 'group', 'mainsearch')
|
} else {
|
types.tabs = '标签页'
|
types.group = '分组'
|
types.mainsearch = '搜索'
|
}
|
}
|
|
this.pasteFormRef.handleConfirm().then(res => {
|
if (res.copyType && types[res.copyType]) {
|
notification.warning({
|
top: 92,
|
message: (type === 'group' ? '分组中' : '标签页中') + '不可添加《' + types[res.copyType] + '》组件!',
|
duration: 5
|
})
|
return
|
} else if (!options.includes(res.copyType)) {
|
notification.warning({
|
top: 92,
|
message: '配置信息格式错误!',
|
duration: 5
|
})
|
return
|
}
|
|
if (res.copyType === 'basetable') {
|
res.copyType = 'normaltable'
|
res.subtype = 'normaltable'
|
}
|
|
res = this.resetconfig(res, appType)
|
|
delete res.copyType
|
|
this.props.insert(res)
|
|
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
|