import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { fromJS } from 'immutable'
|
import { Icon, Modal, Button, 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 = {
|
type: PropTypes.any, // 组件类型
|
Tab: PropTypes.any, // 标签,添加菜单组件时为空
|
insert: PropTypes.func
|
}
|
|
state = {
|
visible: false
|
}
|
|
handleMenuClick = () => {
|
this.setState({visible: true})
|
}
|
|
resetconfig = (item, Tab, isgroup, copyBtns) => {
|
item.uuid = Utils.getuuid()
|
item.floor = Tab ? (Tab.floor + 1) : 1
|
|
if (Tab && !isgroup) {
|
item.tabId = Tab.uuid
|
item.parentId = Tab.parentId
|
} else if (Tab) {
|
item.floor = Tab.floor || 1
|
item.parentId = Tab.parentId
|
}
|
|
if (item.dataName) {
|
item.dataName = Utils.getdataName()
|
}
|
|
if (item.type === 'tabs') {
|
item.subtabs.forEach(tab => {
|
tab.uuid = Utils.getuuid()
|
tab.parentId = item.uuid
|
|
if (item.floor >= 3) {
|
tab.components = tab.components.filter(cell => cell.type !== 'tabs')
|
}
|
|
tab.components = tab.components.map(cell => {
|
cell = this.resetconfig(cell, tab, copyBtns)
|
return cell
|
})
|
})
|
} else if (item.type === 'group') {
|
item.components = item.components.map(cell => {
|
cell = this.resetconfig(cell, item, true, copyBtns)
|
return cell
|
})
|
} else if (item.type === 'card' || (item.type === 'table' && item.subtype === 'tablecard')) {
|
item.subcards.forEach(card => {
|
card.uuid = Utils.getuuid()
|
if (card.elements) {
|
if (sessionStorage.getItem('editMenuType') === 'popview') {
|
card.elements = card.elements.filter(b => b.OpenType !== 'popview' && b.OpenType !== 'funcbutton')
|
}
|
card.elements = card.elements.map(cell => {
|
let _uuid = Utils.getuuid()
|
if (cell.OpenType === 'popview') {
|
let _cell = fromJS(cell).toJS()
|
_cell.$originUuid = _cell.uuid
|
_cell.uuid = _uuid
|
copyBtns.set(_uuid, _cell)
|
}
|
cell.uuid = _uuid
|
return cell
|
})
|
}
|
if (card.backElements) {
|
if (sessionStorage.getItem('editMenuType') === 'popview') {
|
card.elements = card.elements.filter(b => b.OpenType !== 'popview' && b.OpenType !== 'funcbutton')
|
}
|
card.backElements = card.backElements.map(cell => {
|
let _uuid = Utils.getuuid()
|
if (cell.OpenType === 'popview') {
|
let _cell = fromJS(cell).toJS()
|
_cell.$originUuid = _cell.uuid
|
_cell.uuid = _uuid
|
copyBtns.set(_uuid, _cell)
|
}
|
cell.uuid = _uuid
|
return cell
|
})
|
}
|
})
|
} else if (item.type === 'table' && item.subtype === 'normaltable' && item.cols) {
|
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
|
}
|
|
item.cols = item.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) {
|
if (sessionStorage.getItem('editMenuType') === 'popview') {
|
col.elements = col.elements.filter(c => c.OpenType !== 'popview' && c.OpenType !== 'funcbutton')
|
}
|
col.elements = col.elements.map(cell => {
|
let _uuid = Utils.getuuid()
|
if (cell.OpenType === 'popview') {
|
let _cell = fromJS(cell).toJS()
|
_cell.$originUuid = _cell.uuid
|
_cell.uuid = _uuid
|
copyBtns.set(_uuid, _cell)
|
}
|
cell.uuid = _uuid
|
return cell
|
})
|
}
|
return col
|
})
|
}
|
|
if (item.btnlog) {
|
item.btnlog = []
|
}
|
|
let oriUids = {}
|
if (item.action) {
|
if (sessionStorage.getItem('editMenuType') === 'popview') {
|
item.action = item.action.filter(c => c.OpenType !== 'popview' && c.OpenType !== 'funcbutton')
|
}
|
item.action = item.action.map(cell => {
|
let _uuid = Utils.getuuid()
|
|
oriUids[cell.uuid] = _uuid
|
|
if (cell.OpenType === 'popview') {
|
let _cell = fromJS(cell).toJS()
|
_cell.$originUuid = _cell.uuid
|
_cell.uuid = _uuid
|
copyBtns.set(_uuid, _cell)
|
}
|
cell.uuid = _uuid
|
return cell
|
})
|
}
|
if (item.search) {
|
item.search = item.search.map(cell => {
|
cell.uuid = Utils.getuuid()
|
return cell
|
})
|
}
|
if (item.columns) {
|
item.columns = item.columns.map(cell => {
|
cell.uuid = Utils.getuuid()
|
return cell
|
})
|
}
|
if (item.setting && item.setting.supModule) {
|
item.setting.supModule = ''
|
}
|
|
if (item.wrap && item.wrap.doubleClick) {
|
item.wrap.doubleClick = oriUids[item.wrap.doubleClick] || ''
|
}
|
|
return item
|
}
|
|
pasteSubmit = () => {
|
const { Tab } = this.props
|
|
let isgroup = Tab && Tab.type === 'group' ? true : false
|
|
this.pasteFormRef.handleConfirm().then(res => {
|
if (!isgroup && !['tabs', 'datacard', 'propcard', 'mainsearch', 'group', 'normaltable', 'tablecard', 'line', 'bar', 'pie', 'dashboard', 'scatter'].includes(res.copyType)) {
|
notification.warning({
|
top: 92,
|
message: '配置信息格式错误!',
|
duration: 5
|
})
|
return
|
} else if (isgroup && !['datacard', 'propcard', 'normaltable', 'tablecard', 'line', 'bar', 'pie', 'dashboard', 'scatter'].includes(res.copyType)) {
|
notification.warning({
|
top: 92,
|
message: '配置信息格式错误!',
|
duration: 5
|
})
|
return
|
} else if (Tab && Tab.floor === 3 && res.type === 'tabs') {
|
notification.warning({
|
top: 92,
|
message: '标签页最多为三重结构!',
|
duration: 5
|
})
|
return
|
}
|
|
let copyBtns = new Map()
|
|
res = this.resetconfig(res, Tab, isgroup, copyBtns)
|
|
delete res.copyType
|
|
this.props.insert(res, Tab)
|
|
copyBtns = [...copyBtns.values()]
|
|
if (copyBtns.length > 0) {
|
MKEmitter.emit('copyButtons', copyBtns)
|
}
|
|
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 !== 'menu' ? <Icon type="snippets" style={{color: 'purple'}} onClick={() => {this.setState({visible: true})}} /> : null}
|
{type === 'menu' ? <Button className="menu-config-paste" icon="snippets" onClick={() => {this.setState({visible: true})}}>粘贴</Button> : null}
|
<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
|