import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { Menu, Dropdown, Icon, Modal, Spin, notification } from 'antd'
|
|
import Api from '@/api'
|
import PasteForm from '@/templates/zshare/pasteform'
|
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
|
}
|
|
handleMenuClick = e => {
|
if (e.key === 'thaw') {
|
this.handleThaw()
|
} else if (e.key === 'paste') {
|
this.setState({pasteVisible: 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 } = this.props
|
|
this.pasteFormRef.handleConfirm().then(res => {
|
if (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 (res.copyType === 'search') {
|
this.setState({
|
pasteVisible: false
|
}, () => {
|
this.props.refresh({
|
type: 'paste',
|
content: res
|
})
|
})
|
} else if (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 {
|
notification.warning({
|
top: 92,
|
message: '配置信息格式错误!',
|
duration: 5
|
})
|
}
|
})
|
}
|
|
render() {
|
const { dict } = this.state
|
const menu = (
|
<Menu onClick={this.handleMenuClick}>
|
{this.props.type !== 'TreePage' ? <Menu.Item key="thaw"><Icon type="unlock" />{dict['header.form.thawbutton']}</Menu.Item> : null}
|
<Menu.Item key="paste"><Icon type="snippets" />{dict['header.form.paste']}</Menu.Item>
|
{/* <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']}
|
okText={dict['model.confirm']}
|
cancelText={dict['model.cancel']}
|
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" dict={dict} 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>
|
</div>
|
)
|
}
|
}
|
|
export default editComponent
|