import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { fromJS } from 'immutable'
|
import { Modal, Spin, notification, Button } from 'antd'
|
|
import Api from '@/api'
|
import Utils from '@/utils/utils.js'
|
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 MKEmitter from '@/utils/events.js'
|
import './index.scss'
|
|
class editComponent extends Component {
|
static propTpyes = {
|
options: PropTypes.array,
|
MenuID: PropTypes.any,
|
config: PropTypes.object,
|
thawButtons: PropTypes.any,
|
refresh: PropTypes.func
|
}
|
|
state = {
|
dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
|
thawVisible: false,
|
thawbtnlist: null,
|
pasteVisible: false,
|
targetKeys: []
|
}
|
|
/**
|
* @description 解冻按钮
|
*/
|
handleThaw = () => {
|
const { MenuID } = this.props
|
|
this.setState({
|
thawVisible: true,
|
targetKeys: []
|
})
|
|
Api.getSystemConfig({
|
func: 'sPC_Get_FrozenMenu',
|
ParentID: MenuID,
|
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, targetKeys } = this.state
|
let config = fromJS(this.props.config).toJS()
|
|
if (targetKeys.length === 0) {
|
notification.warning({
|
top: 92,
|
message: dict['form.required.select'] + '解冻按钮',
|
duration: 5
|
})
|
} else {
|
thawbtnlist.forEach(item => {
|
if (targetKeys.includes(item.key)) {
|
config.action.push(item.btnParam)
|
}
|
})
|
|
this.props.refresh({
|
type: 'thaw',
|
thawButtons: [...thawButtons, ...targetKeys],
|
config: config
|
})
|
|
this.setState({
|
thawVisible: false,
|
targetKeys: []
|
})
|
}
|
}
|
|
pasteSubmit = () => {
|
const { options, config, type } = this.props
|
let _config = fromJS(this.props.config).toJS()
|
|
this.pasteFormRef.handleConfirm().then(res => {
|
if (!options.includes(res.copyType)) {
|
notification.warning({
|
top: 92,
|
message: '配置信息格式错误!',
|
duration: 5
|
})
|
return
|
} else if (res.copyType === 'action') {
|
res.uuid = Utils.getuuid()
|
MKEmitter.emit('pasteButton', config.uuid, res)
|
} else if (res.copyType === 'search' || (type === 'table' && res.copyType === 'form')) {
|
res.uuid = Utils.getuuid()
|
let keys = _config.search.map(item => item.field ? item.field.toLowerCase() : '')
|
|
if (type === 'table') {
|
if (['number', 'switch', 'textarea', 'fileupload', 'hint', 'color', 'funcvar'].includes(res.type)) {
|
res.type = 'text'
|
} else if (res.type === 'radio') {
|
res.type = 'select'
|
} else if (res.type === 'checkbox') {
|
res.type = 'multiselect'
|
} else if (res.type === 'datetime') {
|
res.type = 'date'
|
}
|
}
|
|
if (res.field && keys.includes(res.field.toLowerCase())) {
|
notification.warning({
|
top: 92,
|
message: '搜索字段已存在!',
|
duration: 5
|
})
|
return
|
}
|
MKEmitter.emit('plusSearch', config.uuid, res, 'simple')
|
} else if (res.copyType === 'columns') {
|
let keys = _config.columns.map(item => item.field ? item.field.toLowerCase() : '')
|
let items = res.columns.filter(col => col.field && !keys.includes(col.field.toLowerCase()))
|
|
MKEmitter.emit('plusColumns', config.uuid, items)
|
} else if (res.copyType === 'form') {
|
let keys = _config.fields.map(item => item.field ? item.field.toLowerCase() : '')
|
res.uuid = Utils.getuuid()
|
|
if (res.field && keys.includes(res.field.toLowerCase())) {
|
notification.warning({
|
top: 92,
|
message: '字段已存在!',
|
duration: 10
|
})
|
return
|
}
|
|
this.props.plusFields([res])
|
} else {
|
notification.warning({
|
top: 92,
|
message: '配置信息格式错误!',
|
duration: 5
|
})
|
return
|
}
|
this.setState({
|
pasteVisible: false
|
})
|
})
|
}
|
|
handleMenuClick = e => {
|
if (e.key === 'thaw') {
|
this.handleThaw()
|
} else if (e.key === 'paste') {
|
this.setState({pasteVisible: true})
|
}
|
}
|
|
render() {
|
const { MenuID } = this.props
|
const { dict } = this.state
|
|
return (
|
<div style={{display: 'inline-block'}}>
|
{MenuID ? <Button className="mk-border-green" onClick={this.handleThaw} icon="unlock">解冻按钮</Button> : null}
|
<Button style={{borderColor: '#40a9ff', color: '#40a9ff'}} onClick={() => this.setState({pasteVisible: true})} icon="snippets">{dict['header.form.paste']}</Button>
|
{/* 解冻按钮模态框 */}
|
<Modal
|
title="解冻按钮"
|
visible={this.state.thawVisible}
|
onOk={this.thawBtnSubmit}
|
onCancel={() => {this.setState({thawVisible: false, thawbtnlist: null, targetKeys: []})}}
|
destroyOnClose
|
>
|
{!this.state.thawbtnlist && <Spin style={{marginLeft: 'calc(50% - 22px)', marginTop: '70px', marginBottom: '70px'}} size="large" />}
|
{this.state.thawbtnlist && <TransferForm onChange={(vals) => this.setState({targetKeys: vals})} 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 wrappedComponentRef={(inst) => this.pasteFormRef = inst}/>
|
</Modal>
|
</div>
|
)
|
}
|
}
|
|
export default editComponent
|