import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { Button, Modal, notification, Spin, Empty } from 'antd'
|
import { BranchesOutlined } from '@ant-design/icons'
|
|
import Api from '@/api'
|
import MKEmitter from '@/utils/events.js'
|
import './index.scss'
|
|
class CustomSetting extends Component {
|
static propTpyes = {
|
config: PropTypes.object,
|
init: PropTypes.any
|
}
|
|
state = {
|
debug: sessionStorage.getItem('debug') === 'true',
|
visible: false,
|
flows: null,
|
loading: false,
|
activeCode: '',
|
initCode: ''
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
componentDidMount() {
|
const { init } = this.props
|
|
if (init) {
|
this.trigger()
|
}
|
}
|
|
trigger = () => {
|
const { config } = this.props
|
const { debug } = this.state
|
|
if (!debug) return null
|
|
this.setState({
|
visible: true,
|
loading: false,
|
initCode: config.flow_code || '',
|
activeCode: ''
|
})
|
|
let param = {
|
func: 's_get_works_flow_local_param_v6'
|
}
|
|
Api.genericInterface(param).then(result => {
|
if (result.status) {
|
let flows = result.data || []
|
let active = config.flow_code ? flows.filter(item => item.works_flow_code === config.flow_code)[0] : null
|
this.setState({
|
flows: flows,
|
activeCode: active
|
})
|
|
if (config.flow_code && !active) {
|
Modal.error({
|
title: '当前菜单工作流已失效,请重新选择。'
|
})
|
}
|
} else {
|
if (!result.message) return
|
if (result.ErrCode === 'N') {
|
Modal.error({
|
title: result.message,
|
})
|
} else if (result.ErrCode !== '-2') {
|
notification.error({
|
top: 92,
|
message: result.message,
|
duration: 10
|
})
|
}
|
}
|
})
|
}
|
|
settingSubmit = () => {
|
const { config } = this.props
|
const { activeCode } = this.state
|
|
let param = {
|
func: 's_works_flow_param_sso_menu_upt_v6',
|
upt_type: '',
|
works_flow_code: activeCode.works_flow_code,
|
works_flow_name: activeCode.works_flow_name,
|
long_param: activeCode.long_param,
|
flow_id: activeCode.id,
|
menuid: config.MenuID,
|
menuname: config.MenuName,
|
username: sessionStorage.getItem('User_Name') || '',
|
fullName: sessionStorage.getItem('Full_Name') || ''
|
}
|
|
this.setState({
|
loading: true
|
})
|
|
Api.getSystemConfig(param).then(result => {
|
if (!result.status) {
|
this.setState({
|
loading: false
|
})
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
return
|
}
|
|
Api.deleteMenuStorage(config.MenuID)
|
|
setTimeout(() => {
|
this.setState({
|
visible: false,
|
loading: false
|
}, () => {
|
window.GLOB.CacheMap = new Map()
|
MKEmitter.emit('reloadMenuView', config.MenuID)
|
})
|
}, 100)
|
})
|
}
|
|
deleteFlow = () => {
|
const { config } = this.props
|
|
let param = {
|
func: 's_works_flow_param_sso_menu_upt_v6',
|
upt_type: 'del',
|
works_flow_code: '',
|
works_flow_name: '',
|
long_param: '',
|
flow_id: '',
|
menuid: config.MenuID,
|
menuname: config.MenuName,
|
username: sessionStorage.getItem('User_Name') || '',
|
fullName: sessionStorage.getItem('Full_Name') || ''
|
}
|
|
this.setState({
|
deling: true
|
})
|
|
Api.getSystemConfig(param).then(result => {
|
if (!result.status) {
|
this.setState({
|
deling: false
|
})
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
return
|
}
|
|
Api.deleteMenuStorage(config.MenuID)
|
|
setTimeout(() => {
|
this.setState({
|
visible: false,
|
deling: false
|
}, () => {
|
window.GLOB.CacheMap = new Map()
|
MKEmitter.emit('reloadMenuView', config.MenuID)
|
})
|
}, 100)
|
})
|
}
|
|
changeFlow = (item) => {
|
this.setState({
|
activeCode: item
|
})
|
}
|
|
render() {
|
const { flows, visible, initCode, loading, deling, activeCode, debug } = this.state
|
|
if (!debug) return null
|
|
return (
|
<div className="tool-wrap">
|
<Button shape="circle" onClick={this.trigger}><BranchesOutlined /></Button>
|
<Modal
|
wrapClassName="flow-setting-modal"
|
title="工作流"
|
maskClosable={false}
|
width={1000}
|
visible={visible}
|
onCancel={() => { this.setState({ visible: false }) }}
|
footer={[
|
initCode ? <Button key="revert" type="danger" disabled={loading} loading={deling} onClick={this.deleteFlow}>删除</Button> : null,
|
<Button key="cancel" onClick={() => { this.setState({ visible: false }) }}>取消</Button>,
|
<Button key="confirm" type="primary" disabled={deling || !activeCode} loading={loading} onClick={this.settingSubmit}>提交</Button>
|
]}
|
destroyOnClose
|
>
|
{!flows ? <Spin size="large" /> : <>
|
{flows.length === 0 ? <Empty /> : <div>
|
{flows.map(item => (<div className={'flow-item' + (activeCode && activeCode.works_flow_code === item.works_flow_code ? ' active' : '')} key={item.works_flow_code} onClick={() => this.changeFlow(item)}>
|
<div className="header">{item.works_flow_name}({item.works_flow_code})</div>
|
<div className="img" style={{backgroundImage: `url(${item.flow_image})`}}></div>
|
</div>))}
|
</div>}
|
</>}
|
{flows && flows.length === 0 ? <Empty /> : null}
|
{!flows ? <Spin size="large" /> : null}
|
</Modal>
|
</div>
|
)
|
}
|
}
|
|
export default CustomSetting
|