import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { Modal, notification, Button } from 'antd'
|
import { SnippetsOutlined } from '@ant-design/icons'
|
|
import Utils from '@/utils/utils.js'
|
import asyncComponent from '@/utils/asyncComponent'
|
// import './index.scss'
|
|
const PasteForm = asyncComponent(() => import('@/templates/zshare/pasteform'))
|
|
class PasteBaseTable extends Component {
|
static propTpyes = {
|
type: PropTypes.any,
|
insert: PropTypes.func
|
}
|
|
state = {
|
visible: false
|
}
|
|
handleMenuClick = () => {
|
this.setState({visible: true})
|
}
|
|
pasteSubmit = () => {
|
this.pasteFormRef.handleConfirm().then(res => {
|
if (res.copyType !== 'basetable') {
|
notification.warning({
|
top: 92,
|
message: '配置信息格式错误!',
|
duration: 5
|
})
|
return
|
}
|
|
delete res.copyType
|
|
res.uuid = Utils.getuuid()
|
|
res.search = res.search.map(cell => {
|
cell.uuid = Utils.getuuid()
|
return cell
|
})
|
|
let loopCol = (col) => {
|
col.subcols = col.subcols.map(c => {
|
c.uuid = Utils.getuuid()
|
|
if (c.type === 'colspan' && c.subcols) {
|
c = loopCol(c)
|
} else if (c.type === 'custom' && c.elements) {
|
c.elements = c.elements.map(cell => {
|
cell.uuid = Utils.getuuid()
|
return cell
|
})
|
}
|
return c
|
})
|
|
return col
|
}
|
|
res.cols = res.cols.map(col => {
|
col.uuid = Utils.getuuid()
|
|
if (col.type === 'colspan' && col.subcols) {
|
col = loopCol(col)
|
} else if (col.type === 'custom' && col.elements) {
|
col.elements = col.elements.map(cell => {
|
cell.uuid = Utils.getuuid()
|
return cell
|
})
|
} else if (col.type === 'action' && col.elements) {
|
col.elements = col.elements.map(cell => {
|
cell.uuid = Utils.getuuid()
|
return cell
|
})
|
}
|
return col
|
})
|
|
let oriUids = {}
|
res.action = res.action.map(cell => {
|
let _uuid = Utils.getuuid()
|
|
oriUids[cell.uuid] = _uuid
|
|
cell.uuid = _uuid
|
|
return cell
|
})
|
|
res.setting.supModule = ''
|
|
if (res.wrap && res.wrap.doubleClick) {
|
res.wrap.doubleClick = oriUids[res.wrap.doubleClick] || ''
|
}
|
|
this.props.insert(res)
|
|
this.setState({visible: false})
|
|
notification.success({
|
top: 92,
|
message: '粘贴成功!',
|
duration: 2
|
})
|
})
|
}
|
|
render() {
|
const { type } = this.props
|
const { visible } = this.state
|
|
return (
|
<div style={{display: 'inline-block'}}>
|
{type === 'page' ? <Button icon="snippets" style={{color: '#1890ff', borderColor: '#1890ff'}} onClick={() => {this.setState({visible: true})}} >粘贴</Button> : <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 PasteBaseTable
|