import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { Button, Modal, notification } from 'antd'
|
|
import Api from '@/api'
|
import options from '@/store/options.js'
|
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, // 自定义设置模态框加载中
|
}
|
|
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
|
})
|
|
// let deffers = []
|
// config.tabgroups.forEach(group => {
|
// group.sublist.forEach(tab => {
|
// deffers.push(new Promise(resolve => {
|
// let param = {
|
// func: 'sPC_Get_LongParam',
|
// MenuID: tab.linkTab
|
// }
|
// Api.getCacheConfig(param).then(res => {
|
// res.tab = tab
|
// resolve(res)
|
// })
|
// }))
|
// })
|
// })
|
|
// if (deffers.length > 0) {
|
// Promise.all(deffers).then(result => {
|
// let errors = result.filter(res => !res.status)
|
// if (errors.length > 0) {
|
// notification.warning({
|
// top: 92,
|
// message: errors[0].message,
|
// duration: 5
|
// })
|
// this.setState({
|
// loading: false
|
// })
|
// return
|
// }
|
|
// let roleId = sessionStorage.getItem('role_id') || '' // 角色ID
|
// result.forEach(res => {
|
// if (!res.LongParam) return
|
|
// let subconfig = ''
|
// let subUserConfig = userConfig ? userConfig[res.tab.uuid] : ''
|
// }
|
}
|
|
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
|
}
|
|
Api.deleteMenuStorage(this.props.MenuID).then(() => {
|
this.setState({
|
visible: false,
|
confirmLoading: false
|
}, () => {
|
window.GLOB.CacheMap = new Map()
|
this.props.reloadview()
|
})
|
})
|
})
|
}
|
|
render() {
|
|
return (
|
<div className="page-setting-wrap">
|
{options.sysType === 'local' ? <Button
|
icon="setting"
|
shape="circle"
|
className="page-setting"
|
onClick={this.handleviewconfig}
|
/> : null}
|
{/* <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}
|
config={this.props.config}
|
userConfig={this.props.userConfig}
|
columns={this.props.columns}
|
handleParam={this.changeMenuParam}
|
/> : null
|
}
|
</Modal>
|
</div>
|
)
|
}
|
}
|
|
export default CustomSetting
|