king
2020-08-31 b3547d1c531e479021219fda5df153a11b9b52a3
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
88
89
90
91
92
93
94
95
96
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Icon, Modal } from 'antd'
 
import zhCN from '@/locales/zh-CN/model.js'
import enUS from '@/locales/en-US/model.js'
import CalendarForm from './calendarform'
 
import './index.scss'
 
class SettingComponent extends Component {
  static propTpyes = {
    config: PropTypes.any,         // 标签
    updateConfig: PropTypes.func,
  }
 
  state = {
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    calendar: null,  // 日历设置
    visible: false,  // 模态框控制
  }
 
  /**
   * @description 保存页面配置信息
   */
  calendarSave = () => {
    const { config } = this.props
 
    this.calendarRef.handleConfirm().then(res => {
      this.setState({
        visible: false
      })
      this.props.updateConfig({...config, calendar: res})
    })
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
 
  /**
   * @description 组件销毁,清除state更新
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
  }
 
  /**
   * @description 添加或修改标签
   */
  handleTab = (e) => {
    const { config } = this.props
    e.stopPropagation()
 
    let calendar = fromJS(config.calendar).toJS()
 
    this.setState({
      visible: true,
      calendar
    })
  }
 
  render() {
    const { config } = this.props
    const { dict, visible, calendar } = this.state
 
    return (
      <div className="model-calendar-setting">
        <Icon type="edit" onClick={this.handleTab} />
        {/* 设置全局配置及列表数据源 */}
        <Modal
          wrapClassName="model-calendar-setting-modal"
          title={dict['model.edit']}
          visible={visible}
          width={700}
          maskClosable={false}
          onCancel={() => { this.setState({ visible: false })}}
          onOk={this.calendarSave}
          destroyOnClose
        >
          <CalendarForm
            dict={dict}
            config={config}
            calendar={calendar}
            wrappedComponentRef={(inst) => this.calendarRef = inst}
          />
        </Modal>
      </div>
    )
  }
}
 
export default SettingComponent