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
|