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
|