import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { Form, Row, Col, Input, Radio, Tooltip, Icon } from 'antd'
|
|
import './index.scss'
|
|
class SettingForm extends Component {
|
static propTpyes = {
|
dict: PropTypes.object, // 字典项
|
wrap: PropTypes.object, // 数据源配置
|
inputSubmit: PropTypes.func // 回车事件
|
}
|
|
state = {
|
type: this.props.wrap.type || 'navbar'
|
}
|
|
handleConfirm = () => {
|
// 表单提交时检查输入值是否正确
|
return new Promise((resolve, reject) => {
|
this.props.form.validateFieldsAndScroll((err, values) => {
|
if (!err) {
|
resolve(values)
|
} else {
|
reject(err)
|
}
|
})
|
})
|
}
|
|
handleSubmit = (e) => {
|
e.preventDefault()
|
|
if (this.props.inputSubmit) {
|
this.props.inputSubmit()
|
}
|
}
|
|
render() {
|
const { wrap } = this.props
|
const { getFieldDecorator } = this.props.form
|
const { type } = this.state
|
const formItemLayout = {
|
labelCol: {
|
xs: { span: 24 },
|
sm: { span: 8 }
|
},
|
wrapperCol: {
|
xs: { span: 24 },
|
sm: { span: 16 }
|
}
|
}
|
|
return (
|
<div className="model-menu-setting-form">
|
<Form {...formItemLayout}>
|
<Row gutter={24}>
|
<Col span={12}>
|
<Form.Item label="类型">
|
{getFieldDecorator('type', {
|
initialValue: wrap.type || 'navbar'
|
})(
|
<Radio.Group onChange={(e) => this.setState({type: e.target.value})}>
|
<Radio value="navbar">导航栏</Radio>
|
<Radio value="search">搜索栏</Radio>
|
</Radio.Group>
|
)}
|
</Form.Item>
|
</Col>
|
<Col span={12}>
|
<Form.Item label={
|
<Tooltip placement="topLeft" title="使用搜索栏时,标题用于搜索条件隐藏时显示。">
|
<Icon type="question-circle" />
|
标题
|
</Tooltip>
|
}>
|
{getFieldDecorator('title', {
|
initialValue: wrap.title || ''
|
})(<Input placeholder={''} autoComplete="off" onPressEnter={this.handleSubmit} />)}
|
</Form.Item>
|
</Col>
|
<Col span={12}>
|
<Form.Item label="返回">
|
{getFieldDecorator('back', {
|
initialValue: wrap.back || 'true'
|
})(
|
<Radio.Group>
|
<Radio value="true">显示</Radio>
|
<Radio value="false">隐藏</Radio>
|
</Radio.Group>
|
)}
|
</Form.Item>
|
</Col>
|
{type === 'navbar' ? <Col span={12}>
|
<Form.Item label="搜索">
|
{getFieldDecorator('search', {
|
initialValue: wrap.search || 'false'
|
})(
|
<Radio.Group>
|
<Radio value="true">显示</Radio>
|
<Radio value="false">隐藏</Radio>
|
</Radio.Group>
|
)}
|
</Form.Item>
|
</Col> : null}
|
<Col span={12}>
|
<Form.Item label={
|
<Tooltip placement="topLeft" title="点击退出时,返回第一个页面。">
|
<Icon type="question-circle" />
|
退出
|
</Tooltip>
|
}>
|
{getFieldDecorator('logout', {
|
initialValue: wrap.logout || 'false'
|
})(
|
<Radio.Group>
|
<Radio value="true">显示</Radio>
|
<Radio value="false">隐藏</Radio>
|
</Radio.Group>
|
)}
|
</Form.Item>
|
</Col>
|
</Row>
|
</Form>
|
</div>
|
)
|
}
|
}
|
|
export default Form.create()(SettingForm)
|