| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { fromJS } from 'immutable' |
| | | import { Icon, Modal, Button, notification } from 'antd' |
| | | import { Modal, Button, notification } from 'antd' |
| | | |
| | | import Utils from '@/utils/utils.js' |
| | | import MenuUtils from '@/utils/utils-custom.js' |
| | | import MKEmitter from '@/utils/events.js' |
| | | import asyncComponent from '@/utils/asyncComponent' |
| | | import './index.scss' |
| | |
| | | |
| | | class PasteController extends Component { |
| | | static propTpyes = { |
| | | type: PropTypes.any, // 组件类型 |
| | | Tab: PropTypes.any, // 标签,添加菜单组件时为空 |
| | | insert: PropTypes.func |
| | | } |
| | | |
| | |
| | | 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() |
| | | } |
| | | |
| | | resetconfig = (item, copyBtns) => { |
| | | let appType = sessionStorage.getItem('appType') |
| | | |
| | | if (item.type === 'tabs') { |
| | | item.uuid = MenuUtils.getuuid() |
| | | item.setting.name = item.setting.name + MenuUtils.getdataName().toUpperCase().substr(-4) |
| | | item.name = item.setting.name |
| | | |
| | | item.subtabs.forEach(tab => { |
| | | tab.uuid = Utils.getuuid() |
| | | tab.uuid = MenuUtils.getuuid() |
| | | tab.parentId = item.uuid |
| | | |
| | | if (item.floor >= 3) { |
| | | tab.components = tab.components.filter(cell => cell.type !== 'tabs') |
| | | if (appType !== 'mob') { |
| | | tab.components = tab.components.filter(cell => cell.type !== 'menubar') |
| | | } |
| | | |
| | | tab.components = tab.components.map(cell => { |
| | | cell = this.resetconfig(cell, tab, false, copyBtns) |
| | | cell.floor = tab.floor + 1 |
| | | cell.tabId = tab.uuid |
| | | cell.parentId = tab.parentId |
| | | |
| | | cell = this.resetconfig(cell, copyBtns) |
| | | return cell |
| | | }) |
| | | }) |
| | | } else if (item.type === 'group') { |
| | | item.uuid = MenuUtils.getuuid() |
| | | item.setting.name = item.setting.name + MenuUtils.getdataName().toUpperCase().substr(-4) |
| | | item.name = item.setting.name |
| | | if (appType !== 'mob') { |
| | | item.components = item.components.filter(cell => cell.type !== 'menubar') |
| | | } |
| | | item.components = item.components.map(cell => { |
| | | cell = this.resetconfig(cell, item, true, copyBtns) |
| | | cell.floor = item.floor |
| | | cell.tabId = item.tabId || '' |
| | | cell.parentId = item.parentId || '' |
| | | |
| | | cell = MenuUtils.resetComponentConfig(cell, copyBtns) |
| | | return cell |
| | | }) |
| | | } else if (item.type === 'menubar') { |
| | | item.subMenus = item.subMenus.map(cell => { |
| | | cell.uuid = Utils.getuuid() |
| | | return cell |
| | | }) |
| | | } else if (item.type === 'balcony') { |
| | | item.elements = item.elements.map(cell => { |
| | | cell.uuid = Utils.getuuid() |
| | | return cell |
| | | }) |
| | | } else if (item.type === 'card' || (item.type === 'table' && item.subtype === 'tablecard')) { |
| | | item.subcards && 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 |
| | | }) |
| | | } else if (item.type === 'form') { |
| | | item.subcards = item.subcards.map(cell => { |
| | | cell.uuid = Utils.getuuid() |
| | | |
| | | cell.fields = cell.fields.map(m => { |
| | | m.uuid = Utils.getuuid() |
| | | |
| | | return m |
| | | }) |
| | | return cell |
| | | }) |
| | | } |
| | | |
| | | 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] || '' |
| | | } else { |
| | | item = MenuUtils.resetComponentConfig(item, copyBtns) |
| | | } |
| | | |
| | | return item |
| | | } |
| | | |
| | | pasteSubmit = () => { |
| | | const { Tab } = this.props |
| | | |
| | | let isgroup = Tab && Tab.type === 'group' ? true : false |
| | | let options = ['tabs', 'datacard', 'propcard', 'mainsearch', 'balcony', 'group', 'normaltable', 'tablecard', 'line', 'bar', 'pie', 'dashboard', 'scatter'] |
| | | |
| | | if (sessionStorage.getItem('appType') === 'mob') { |
| | | options.push('menubar') |
| | | } |
| | | |
| | | if (isgroup) { |
| | | options = options.filter(item => !['tabs', 'mainsearch', 'group'].includes(item)) |
| | | } |
| | | let options = ['tabs', 'menubar', 'datacard', 'propcard', 'mainsearch', 'stepform', 'tabform', 'balcony', 'group', 'normaltable', 'tablecard', 'line', 'bar', 'pie', 'dashboard', 'scatter'] |
| | | |
| | | this.pasteFormRef.handleConfirm().then(res => { |
| | | if (!options.includes(res.copyType)) { |
| | | if (res.copyType === 'menubar' && sessionStorage.getItem('appType') !== 'mob') { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '配置信息格式错误!', |
| | | message: '当前系统不支持菜单组件!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } else if (Tab && Tab.floor === 3 && res.type === 'tabs') { |
| | | } else if (!options.includes(res.copyType)) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '标签页最多为三重结构!', |
| | | message: '配置信息格式错误!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | |
| | | |
| | | let copyBtns = new Map() |
| | | |
| | | res = this.resetconfig(res, Tab, isgroup, copyBtns) |
| | | res = this.resetconfig(res, copyBtns) |
| | | |
| | | delete res.copyType |
| | | |
| | | this.props.insert(res, Tab) |
| | | this.props.insert(res) |
| | | |
| | | copyBtns = [...copyBtns.values()] |
| | | |
| | |
| | | } |
| | | |
| | | 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} |
| | | <Button className="menu-config-paste" icon="snippets" onClick={() => {this.setState({visible: true})}}>粘贴</Button> |
| | | <Modal |
| | | title="粘贴" |
| | | visible={visible} |