import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { Modal, Button } from 'antd'
|
import { UserOutlined } from '@ant-design/icons'
|
|
import SettingForm from './settingform'
|
import './index.scss'
|
|
class Unattended extends Component {
|
static propTpyes = {
|
config: PropTypes.object,
|
updateConfig: PropTypes.func
|
}
|
|
state = {
|
visible: false,
|
actions: [],
|
autoMatic: null
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
trigger = () => {
|
const { config } = this.props
|
let actions = []
|
|
if (config.components) {
|
config.components[0].action.forEach(item => {
|
if (['pop', 'prompt', 'exec'].includes(item.OpenType) || (item.OpenType === 'funcbutton' && item.funcType === 'print')) {
|
actions.push(item)
|
}
|
})
|
} else {
|
config.action.forEach(item => {
|
if (item.position !== 'toolbar') return
|
if (['pop', 'prompt', 'exec'].includes(item.OpenType) || (item.OpenType === 'funcbutton' && item.funcType === 'print')) {
|
actions.push(item)
|
}
|
})
|
}
|
|
this.setState({
|
actions,
|
autoMatic: config.autoMatic || {enable: 'false', onFail: 'stop', onSuccess: 'stay', action: ''},
|
visible: true
|
})
|
}
|
|
submit = () => {
|
const { config } = this.props
|
|
this.settingRef.handleConfirm().then(res => {
|
this.setState({
|
visible: false
|
})
|
|
this.props.updateConfig({...config, autoMatic: res})
|
})
|
}
|
|
render() {
|
const { visible, actions, autoMatic } = this.state
|
|
return (
|
<>
|
<Button className="mk-border-purple" onClick={this.trigger}><UserOutlined/> 无人值守</Button>
|
<Modal
|
title="无人值守"
|
wrapClassName="unattended-field-modal"
|
visible={visible}
|
width={800}
|
maskClosable={false}
|
onOk={this.submit}
|
onCancel={() => { this.setState({ visible: false })}}
|
destroyOnClose
|
>
|
<SettingForm actions={actions} autoMatic={autoMatic} wrappedComponentRef={(inst) => this.settingRef = inst}/>
|
</Modal>
|
</>
|
)
|
}
|
}
|
|
export default Unattended
|