import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { Icon, Button, Modal, notification } from 'antd'
|
|
import Api from '@/api'
|
import asyncComponent from '@/utils/asyncSpinComponent'
|
import './index.scss'
|
|
const VerifyCard = asyncComponent(() => import('@/tabviews/zshare/verifycard'))
|
|
class CustomSetting extends Component {
|
static propTpyes = {
|
dict: PropTypes.any, // 字典表
|
reloadview: PropTypes.func, // 页面刷新
|
}
|
|
state = {
|
userParam: null, // 保存用户编辑中的配置
|
visible: false, // 模态框控制
|
revertLoading: false, // 恢复默认设置
|
confirmLoading: false, // 自定义设置模态框加载中
|
}
|
|
/**
|
* @description 卡片初始化,设置卡片的配置信息
|
*/
|
UNSAFE_componentWillMount () {
|
|
}
|
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
controlCustomSetting = () => {
|
this.setState({
|
visible: true,
|
confirmLoading: false,
|
revertLoading: false
|
})
|
}
|
|
changeMenuParam = (param) => {
|
this.setState({userParam: param})
|
}
|
|
settingRevert = () => {
|
let param = {
|
func: 's_TrdMenu_UserParam_del',
|
MenuID: this.props.MenuID
|
}
|
this.setState({
|
revertLoading: true
|
})
|
|
Api.getSystemConfig(param).then(result => {
|
if (!result.status) {
|
this.setState({
|
revertLoading: false
|
})
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
return
|
}
|
this.setState({
|
visible: false,
|
revertLoading: false
|
}, () => {
|
window.GLOB.CacheMap = new Map()
|
this.props.reloadview()
|
})
|
})
|
}
|
|
settingSubmit = () => {
|
const { userParam } = this.state
|
let _LongParam = ''
|
|
try {
|
_LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(userParam)))
|
} catch (e) {
|
notification.warning({
|
top: 92,
|
message: '编译错误',
|
duration: 5
|
})
|
return
|
}
|
|
let easyCode = userParam[this.props.MenuID] ? userParam[this.props.MenuID].easyCode : ''
|
|
let param = {
|
func: 'sPC_TrdMenu_UserParam',
|
MenuID: this.props.MenuID,
|
EasyCode: easyCode || '',
|
LongParam: _LongParam
|
}
|
|
this.setState({
|
confirmLoading: true
|
})
|
|
Api.getSystemConfig(param).then(result => {
|
if (!result.status) {
|
this.setState({
|
confirmLoading: false
|
})
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
return
|
}
|
this.setState({
|
visible: false,
|
confirmLoading: false
|
}, () => {
|
window.GLOB.CacheMap = new Map()
|
this.props.reloadview()
|
})
|
})
|
}
|
|
render() {
|
|
return (
|
<div>
|
<Icon className="custom-control" type="setting" onClick={this.controlCustomSetting} />
|
<Modal
|
wrapClassName="common-table-custom-modal"
|
title={'自定义设置'}
|
maskClosable={false}
|
width={950}
|
visible={this.state.visible}
|
onCancel={() => { this.setState({ visible: false }) }}
|
footer={[
|
<Button key="revert" type="danger" loading={this.state.revertLoading} onClick={this.settingRevert}>{this.props.dict['main.revert.default']}</Button>,
|
<Button key="cancel" onClick={() => { this.setState({ visible: false }) }}>{this.props.dict['main.cancel']}</Button>,
|
<Button key="confirm" type="primary" loading={this.state.confirmLoading} onClick={this.settingSubmit}>{this.props.dict['main.submit']}</Button>
|
]}
|
destroyOnClose
|
>
|
{this.state.visible ?
|
<VerifyCard
|
MenuID={this.props.MenuID}
|
MenuName={this.props.MenuName}
|
permAction={this.props.permAction}
|
permRoles={this.props.permRoles}
|
config={this.props.config}
|
userConfig={this.props.userConfig}
|
columns={this.props.columns}
|
handleParam={this.changeMenuParam}
|
/> : null
|
}
|
</Modal>
|
</div>
|
)
|
}
|
}
|
|
export default CustomSetting
|