import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { fromJS } from 'immutable'
|
import { Menu, Dropdown, Icon, Modal, Spin, notification } from 'antd'
|
|
import Api from '@/api'
|
import PasteForm from '@/templates/zshare/pasteform'
|
import ReplaceForm from '@/templates/zshare/replaceform'
|
import TransferForm from '@/templates/zshare/basetransferform'
|
import zhCN from '@/locales/zh-CN/model.js'
|
import enUS from '@/locales/en-US/model.js'
|
import './index.scss'
|
|
class editComponent extends Component {
|
static propTpyes = {
|
type: PropTypes.string,
|
MenuID: PropTypes.any,
|
config: PropTypes.object,
|
thawButtons: PropTypes.any,
|
refresh: PropTypes.func
|
}
|
|
state = {
|
dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
|
thawVisible: false,
|
thawbtnlist: null,
|
pasteVisible: false,
|
replaceVisible: false
|
}
|
|
handleMenuClick = e => {
|
if (e.key === 'thaw') {
|
this.handleThaw()
|
} else if (e.key === 'paste') {
|
this.setState({pasteVisible: true})
|
} else if (e.key === 'replace') {
|
this.setState({replaceVisible: true})
|
}
|
}
|
|
/**
|
* @description 解冻按钮
|
*/
|
handleThaw = () => {
|
const { config } = this.props
|
|
this.setState({
|
thawVisible: true
|
})
|
|
let uuid = config.uuid
|
|
if (this.props.type === 'maintable') {
|
uuid = this.props.MenuID
|
}
|
|
Api.getSystemConfig({
|
func: 'sPC_Get_FrozenMenu',
|
ParentID: uuid,
|
TYPE: 40
|
}).then(res => {
|
if (res.status) {
|
let _list = []
|
|
res.data.forEach(menu => {
|
let _conf = ''
|
|
if (menu.ParentParam) {
|
try {
|
_conf = JSON.parse(window.decodeURIComponent(window.atob(menu.ParentParam)))
|
} catch (e) {
|
console.warn('Parse Failure')
|
_conf = ''
|
}
|
}
|
|
if (_conf) {
|
_list.push({
|
key: menu.MenuID,
|
title: menu.MenuName,
|
btnParam: _conf
|
})
|
}
|
})
|
|
this.setState({
|
thawbtnlist: _list
|
})
|
} else {
|
notification.warning({
|
top: 92,
|
message: res.message,
|
duration: 5
|
})
|
}
|
})
|
}
|
|
/**
|
* @description 解冻按钮提交
|
*/
|
thawBtnSubmit = () => {
|
const { thawButtons } = this.props
|
const { thawbtnlist, dict } = this.state
|
let config = JSON.parse(JSON.stringify(this.props.config))
|
|
// 三级菜单解除冻结
|
if (this.refs.trawmenu.state.targetKeys.length === 0) {
|
notification.warning({
|
top: 92,
|
message: dict['form.required.select'] + dict['header.form.thawbutton'],
|
duration: 5
|
})
|
} else {
|
|
thawbtnlist.forEach(item => {
|
if (this.refs.trawmenu.state.targetKeys.includes(item.key)) {
|
config.action.push(item.btnParam)
|
}
|
})
|
|
this.props.refresh({
|
type: 'thaw',
|
thawButtons: [...thawButtons, ...this.refs.trawmenu.state.targetKeys],
|
config: config
|
})
|
|
this.setState({
|
thawVisible: false
|
})
|
}
|
}
|
|
pasteSubmit = () => {
|
const { config, type } = this.props
|
|
this.pasteFormRef.handleConfirm().then(res => {
|
if (['maintable', 'subtable'].includes(type) && res.copyType === 'action') {
|
if (this.props.type === 'subtable' && !['pop', 'prompt', 'exec', 'excelIn', 'excelOut', 'popview'].includes(res.OpenType)) {
|
notification.warning({
|
top: 92,
|
message: '不支持此打开方式!',
|
duration: 5
|
})
|
return
|
}
|
this.setState({
|
pasteVisible: false
|
}, () => {
|
this.props.refresh({
|
type: 'paste',
|
content: res
|
})
|
})
|
} else if (['maintable', 'subtable'].includes(type) && res.copyType === 'search') {
|
this.setState({
|
pasteVisible: false
|
}, () => {
|
this.props.refresh({
|
type: 'paste',
|
content: res
|
})
|
})
|
} else if (['maintable', 'subtable'].includes(type) && res.copyType === 'columns') {
|
let _columns = config.columns.filter(col => !col.origin)
|
if (_columns.length > 0) {
|
notification.warning({
|
top: 92,
|
message: '显示列已存在!',
|
duration: 5
|
})
|
return
|
}
|
|
this.setState({
|
pasteVisible: false
|
}, () => {
|
this.props.refresh({
|
type: 'paste',
|
content: res
|
})
|
})
|
} else if (['form'].includes(type) && res.copyType === 'form') {
|
if (res.type === 'linkMain') {
|
notification.warning({
|
top: 92,
|
message: '不支持此表单类型!',
|
duration: 10
|
})
|
return
|
}
|
|
let _config = fromJS(config).toJS()
|
let fieldrepet = false
|
let labelrepet = false
|
|
if (_config.groups.length > 0) {
|
_config.groups.forEach(group => {
|
group.sublist.forEach(item => {
|
if (item.uuid === res.uuid) {
|
fieldrepet = true
|
} else if (item.field === res.field) {
|
fieldrepet = true
|
} else if (item.label === res.label) {
|
labelrepet = true
|
}
|
})
|
})
|
} else {
|
_config.fields.forEach(item => {
|
if (item.uuid === res.uuid) {
|
fieldrepet = true
|
} else if (item.field === res.field) {
|
fieldrepet = true
|
} else if (item.label === res.label) {
|
labelrepet = true
|
}
|
})
|
}
|
|
if (fieldrepet) {
|
notification.warning({
|
top: 92,
|
message: '字段已存在!',
|
duration: 10
|
})
|
return
|
} else if (labelrepet) {
|
notification.warning({
|
top: 92,
|
message: '名称已存在!',
|
duration: 10
|
})
|
return
|
}
|
|
if (_config.groups.length > 0) {
|
_config.groups.forEach(group => {
|
if (group.default) {
|
group.sublist.push(res)
|
}
|
})
|
} else {
|
_config.fields.push(res)
|
}
|
|
this.setState({
|
pasteVisible: false
|
}, () => {
|
this.props.refresh({
|
type: 'paste',
|
content: _config
|
})
|
})
|
} else {
|
notification.warning({
|
top: 92,
|
message: '配置信息格式错误!',
|
duration: 5
|
})
|
}
|
})
|
}
|
|
replaceSubmit = () => {
|
this.replaceFormRef.handleConfirm().then(res => {
|
this.props.refresh({
|
type: 'replace',
|
...res
|
})
|
this.setState({
|
replaceVisible: false
|
})
|
})
|
}
|
|
render() {
|
const { type } = this.props
|
const { dict } = this.state
|
const menu = (
|
<Menu onClick={this.handleMenuClick}>
|
{['maintable', 'subtable'].includes(type) ? <Menu.Item key="thaw"><Icon type="unlock" />{dict['header.form.thawbutton']}</Menu.Item> : null}
|
{['maintable', 'subtable', 'form'].includes(type) ? <Menu.Item key="paste"><Icon type="snippets" />{dict['header.form.paste']}</Menu.Item> : null}
|
{/* <Menu.Item key="replace"><Icon type="retweet" />替换</Menu.Item> */}
|
</Menu>
|
)
|
|
return (
|
<div style={{display: 'inline-block'}}>
|
<Dropdown overlay={menu} overlayClassName="edit-component-box">
|
<span style={{color: '#1890ff', display: 'inline-block', height: 25}}>
|
{dict['model.edit']} <Icon type="down" />
|
</span>
|
</Dropdown>
|
{/* 解冻按钮模态框 */}
|
<Modal
|
title={dict['header.form.thawbutton']}
|
visible={this.state.thawVisible}
|
onOk={this.thawBtnSubmit}
|
onCancel={() => {this.setState({thawVisible: false, thawbtnlist: null})}}
|
destroyOnClose
|
>
|
{!this.state.thawbtnlist && <Spin style={{marginLeft: 'calc(50% - 22px)', marginTop: '70px', marginBottom: '70px'}} size="large" />}
|
{this.state.thawbtnlist && <TransferForm ref="trawmenu" menulist={this.state.thawbtnlist}/>}
|
</Modal>
|
{/* 按钮配置信息粘贴复制 */}
|
<Modal
|
title={dict['header.form.paste']}
|
visible={this.state.pasteVisible}
|
width={600}
|
maskClosable={false}
|
onOk={this.pasteSubmit}
|
onCancel={() => {this.setState({pasteVisible: false})}}
|
destroyOnClose
|
>
|
<PasteForm
|
dict={dict}
|
wrappedComponentRef={(inst) => this.pasteFormRef = inst}
|
/>
|
</Modal>
|
{/* 替换 */}
|
<Modal
|
title={'替换'}
|
visible={this.state.replaceVisible}
|
width={600}
|
maskClosable={false}
|
onOk={this.replaceSubmit}
|
onCancel={() => {this.setState({replaceVisible: false})}}
|
destroyOnClose
|
>
|
<ReplaceForm
|
dict={dict}
|
inputSubmit={this.replaceSubmit}
|
wrappedComponentRef={(inst) => this.replaceFormRef = inst}
|
/>
|
</Modal>
|
</div>
|
)
|
}
|
}
|
|
export default editComponent
|