king
2021-11-12 0c84df247914f893ef5e41d57a422e10a2dc814c
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Modal } from 'antd'
import { EditOutlined, CloseOutlined, PlusOutlined } from '@ant-design/icons'
 
import zhCN from '@/locales/zh-CN/model.js'
import enUS from '@/locales/en-US/model.js'
import { getTabForm } from '@/templates/zshare/formconfig'
import TabForm from './tabform'
import './index.scss'
 
const { confirm } = Modal
 
class SettingComponent extends Component {
  static propTpyes = {
    config: PropTypes.any,         // 标签
    tabviews: PropTypes.array,     // 标签集
    updateConfig: PropTypes.func,
    setSubConfig: PropTypes.func
  }
 
  state = {
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    menu: null,          // 菜单信息
    formlist: null,      // 表单信息
    visible: false       // 模态框控制
  }
 
  /**
   * @description 保存页面配置信息
   */
  tabSave = () => {
    const { config } = this.props
 
    this.tabRef.handleConfirm().then(res => {
      this.setState({
        visible: false
      })
      this.props.updateConfig({...config, tab: res})
    })
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState)) || !is(fromJS(this.props.config.tab), fromJS(nextProps.config.tab))
  }
 
  /**
   * @description 组件销毁,清除state更新
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
  }
 
  /**
   * @description 添加或修改标签
   */
  handleTab = (e) => {
    e.stopPropagation()
    const { config } = this.props
 
    this.setState({
      visible: true,
      formlist: getTabForm(config.tab || {}, '', [], '', [], config.Template)
    })
  }
 
  closeTab = (e) => {
    const { config } = this.props
    const _this = this
    e.stopPropagation()
 
    confirm({
      content: '确定删除标签吗?',
      onOk() {
        _this.props.updateConfig({...config, tab: ''})
      },
      onCancel() {}
    })
  }
 
  render() {
    const { tabviews, config } = this.props
    const { dict, visible } = this.state
 
    return (
      <div className="model-calendar-tab">
        {config.tab ? <div className="tab-control">
          <span onDoubleClick={this.props.setSubConfig}>{config.tab.label}</span>
          <EditOutlined onClick={this.handleTab} />
          <CloseOutlined onClick={this.closeTab} />
        </div> : <PlusOutlined title="添加标签" onClick={this.handleTab} />}
        {/* 设置全局配置及列表数据源 */}
        <Modal
          wrapClassName="model-calendar-tab-modal"
          title={dict['model.edit']}
          visible={visible}
          width={700}
          maskClosable={false}
          onCancel={() => { this.setState({ visible: false })}}
          onOk={this.tabSave}
          destroyOnClose
        >
          <TabForm
            tabs={tabviews}
            dict={dict}
            inputSubmit={this.tabSave}
            formlist={this.state.formlist}
            wrappedComponentRef={(inst) => this.tabRef = inst}
          />
        </Modal>
      </div>
    )
  }
}
 
export default SettingComponent