king
2023-09-18 b58d2d0277eecbae9348d633e7dc805771962024
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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