| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { fromJS } from 'immutable' |
| | | import { Modal, Spin, notification, Button } from 'antd' |
| | | import { UnlockOutlined, SnippetsOutlined } from '@ant-design/icons' |
| | | import { Modal, notification, Button } from 'antd' |
| | | import { SnippetsOutlined } from '@ant-design/icons' |
| | | |
| | | import Api from '@/api' |
| | | import Utils from '@/utils/utils.js' |
| | | import PasteForm from '@/templates/zshare/pasteform' |
| | | import TransferForm from '@/templates/zshare/basetransferform' |
| | | 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 = { |
| | | 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, targetKeys } = this.state |
| | | let config = fromJS(this.props.config).toJS() |
| | | |
| | | if (targetKeys.length === 0) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '请选择解冻按钮', |
| | | 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: [] |
| | | }) |
| | | } |
| | | visible: false |
| | | } |
| | | |
| | | pasteSubmit = () => { |
| | |
| | | } |
| | | |
| | | this.props.plusFields([res]) |
| | | } else if (res.copyType === 'forms') { |
| | | this.props.plusFields(res, 'forms') |
| | | } else { |
| | | notification.warning({ |
| | | top: 92, |
| | |
| | | return |
| | | } |
| | | this.setState({ |
| | | pasteVisible: false |
| | | visible: false |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | handleMenuClick = e => { |
| | | if (e.key === 'thaw') { |
| | | this.handleThaw() |
| | | } else if (e.key === 'paste') { |
| | | this.setState({pasteVisible: true}) |
| | | } |
| | | } |
| | | |
| | | render() { |
| | | const { MenuID } = this.props |
| | | |
| | | return ( |
| | | <div style={{display: 'inline-block'}}> |
| | | {MenuID ? <Button className="mk-border-green" onClick={this.handleThaw}><UnlockOutlined /> 解冻按钮</Button> : null} |
| | | <Button style={{borderColor: '#40a9ff', color: '#40a9ff'}} onClick={() => this.setState({pasteVisible: true})}><SnippetsOutlined /> 粘贴</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> |
| | | <Button style={{borderColor: '#40a9ff', color: '#40a9ff'}} onClick={() => this.setState({visible: true})}><SnippetsOutlined /> 粘贴</Button> |
| | | {/* 按钮配置信息粘贴复制 */} |
| | | <Modal |
| | | title="粘贴" |
| | | visible={this.state.pasteVisible} |
| | | visible={this.state.visible} |
| | | width={600} |
| | | maskClosable={false} |
| | | onOk={this.pasteSubmit} |
| | | onCancel={() => {this.setState({pasteVisible: false})}} |
| | | onCancel={() => {this.setState({visible: false})}} |
| | | destroyOnClose |
| | | > |
| | | <PasteForm wrappedComponentRef={(inst) => this.pasteFormRef = inst} inputSubmit={this.pasteSubmit}/> |