import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { Form, Row, Col, Input, Select, Icon, Radio, notification } from 'antd'
|
import './index.scss'
|
|
const { TextArea } = Input
|
|
const btnIcons = [{
|
MenuID: '',
|
text: 'unset'
|
}, {
|
MenuID: 'plus',
|
text: 'plus'
|
}, {
|
MenuID: 'plus-circle',
|
text: 'plus-circle'
|
}, {
|
MenuID: 'edit',
|
text: 'edit'
|
}, {
|
MenuID: 'form',
|
text: 'form'
|
}, {
|
MenuID: 'close',
|
text: 'close'
|
}, {
|
MenuID: 'close-circle',
|
text: 'close-circle'
|
}, {
|
MenuID: 'delete',
|
text: 'delete'
|
}]
|
|
const btnClasses = [{
|
MenuID: 'default',
|
text: '默认(黑边白底)'
|
}, {
|
MenuID: 'primary',
|
text: '蓝色'
|
}, {
|
MenuID: 'yellow',
|
text: '黄色'
|
}, {
|
MenuID: 'danger',
|
text: '红色'
|
}, {
|
MenuID: 'green',
|
text: '绿色'
|
}, {
|
MenuID: 'dgreen',
|
text: '深绿色'
|
}, {
|
MenuID: 'purple',
|
text: '紫色'
|
}, {
|
MenuID: 'gray',
|
text: '灰色'
|
}]
|
|
class MainSearch extends Component {
|
static propTpyes = {
|
dict: PropTypes.object, // 字典项
|
formlist: PropTypes.any,
|
card: PropTypes.any
|
}
|
|
state = {
|
formlist: null,
|
openType: null,
|
interType: null,
|
reqOptionSgl: [{
|
MenuID: 'requiredSgl',
|
text: this.props.dict['header.form.requiredSgl']
|
}],
|
reqOptions: [{
|
MenuID: 'notRequired',
|
text: this.props.dict['header.form.notRequired']
|
}, {
|
MenuID: 'requiredSgl',
|
text: this.props.dict['header.form.requiredSgl']
|
}],
|
reqOptionsMutil: [{
|
MenuID: 'notRequired',
|
text: this.props.dict['header.form.notRequired']
|
}, {
|
MenuID: 'requiredSgl',
|
text: this.props.dict['header.form.requiredSgl']
|
}, {
|
MenuID: 'required',
|
text: this.props.dict['header.form.required']
|
}, {
|
MenuID: 'requiredOnce',
|
text: this.props.dict['header.form.requiredOnce']
|
}]
|
}
|
|
|
UNSAFE_componentWillMount () {
|
let _opentype = this.props.formlist.filter(form => form.key === 'OpenType')[0].initVal
|
let _intertype = this.props.formlist.filter(form => form.key === 'intertype')[0].initVal
|
let _options = null
|
if (_opentype === 'innerpage') { // 新页面(内部),可选模板
|
_options = ['label', 'Ot', 'OpenType', 'pageTemplate', 'icon', 'class', 'position']
|
} else if (_opentype === 'outerpage') { // 新页面(外部),需要页面地址
|
_options = ['label', 'Ot', 'OpenType', 'url', 'icon', 'class', 'position']
|
} else if (_opentype === 'blank' || _opentype === 'tab' || _opentype === 'popview') {
|
_options = ['label', 'Ot', 'OpenType', 'icon', 'class', 'position']
|
} else {
|
if (_intertype === 'outer') {
|
_options = ['label', 'position', 'OpenType', 'intertype', 'innerFunc', 'interface', 'outerFunc', 'callbackFunc', 'Ot', 'icon', 'class', 'execSuccess', 'execError', 'method']
|
} else {
|
_options = ['label', 'position', 'OpenType', 'intertype', 'innerFunc', 'Ot', 'icon', 'class', 'execSuccess', 'execError', 'sql']
|
}
|
}
|
this.setState({
|
openType: _opentype,
|
interType: _intertype,
|
formlist: this.props.formlist.map(item => {
|
if (item.key === 'class') {
|
item.options = btnClasses
|
} else if (item.key === 'icon') {
|
item.options = btnIcons
|
} else if (item.key === 'Ot') {
|
if (_opentype === 'innerpage') {
|
item.options = this.state.reqOptionSgl
|
} else if (['outerpage', 'blank', 'tab', 'pop', 'popview'].includes(_opentype)) {
|
item.options = this.state.reqOptions
|
} else {
|
item.options = this.state.reqOptionsMutil
|
}
|
}
|
item.hidden = !_options.includes(item.key)
|
return item
|
})
|
})
|
}
|
|
openTypeChange = (key, value) => {
|
if (key === 'OpenType') {
|
let _options = null
|
if (value === 'innerpage') {
|
_options = ['label', 'Ot', 'OpenType', 'pageTemplate', 'icon', 'class', 'position']
|
} else if (value === 'outerpage') {
|
_options = ['label', 'Ot', 'OpenType', 'url', 'icon', 'class', 'position']
|
} else if (value === 'blank' || value === 'tab' || value === 'popview') {
|
_options = ['label', 'Ot', 'OpenType', 'icon', 'class', 'position']
|
} else {
|
if (this.state.interType === 'inner') {
|
_options = ['label', 'position', 'OpenType', 'intertype', 'innerFunc', 'Ot', 'icon', 'class', 'execSuccess', 'execError', 'sql']
|
} else {
|
_options = ['label', 'position', 'OpenType', 'intertype', 'innerFunc', 'Ot', 'icon', 'class', 'execSuccess', 'execError', 'interface', 'outerFunc', 'callbackFunc', 'method']
|
}
|
}
|
this.setState({
|
openType: value,
|
formlist: this.state.formlist.map(item => {
|
if (_options) {
|
item.hidden = !_options.includes(item.key)
|
if (item.key === 'intertype') {
|
item.initVal = this.state.interType
|
}
|
}
|
if (item.key === 'Ot') {
|
if (value === 'innerpage') {
|
item.options = this.state.reqOptionSgl
|
item.initVal = 'requiredSgl'
|
item.hidden = true
|
} else if (['outerpage', 'blank', 'tab', 'pop', 'popview'].includes(value)) {
|
item.options = this.state.reqOptions
|
item.initVal = 'requiredSgl'
|
item.hidden = true
|
} else {
|
item.options = this.state.reqOptionsMutil
|
}
|
}
|
return item
|
})
|
}, () => {
|
if (!['innerpage', 'outerpage', 'blank', 'tab', 'pop', 'popview'].includes(value)) return
|
|
this.setState({
|
formlist: this.state.formlist.map(item => {
|
if (item.key === 'Ot') {
|
item.hidden = false
|
}
|
return item
|
})
|
})
|
})
|
}
|
}
|
|
onChange = (e, key) => {
|
let value = e.target.value
|
if (key === 'intertype') {
|
let _options = null
|
if (value === 'inner') {
|
_options = ['label', 'position', 'OpenType', 'intertype', 'innerFunc', 'Ot', 'icon', 'class', 'execSuccess', 'execError', 'sql']
|
} else {
|
_options = ['label', 'position', 'OpenType', 'intertype', 'innerFunc', 'Ot', 'icon', 'class', 'execSuccess', 'execError', 'interface', 'outerFunc', 'callbackFunc', 'method']
|
}
|
this.setState({
|
interType: value,
|
formlist: this.state.formlist.map(item => {
|
item.hidden = !_options.includes(item.key)
|
return item
|
})
|
})
|
}
|
}
|
|
getFields() {
|
const { getFieldDecorator } = this.props.form
|
const fields = []
|
this.state.formlist.forEach((item, index) => {
|
if (item.hidden) return
|
|
if (item.type === 'text') { // 文本搜索
|
fields.push(
|
<Col span={12} key={index}>
|
<Form.Item label={item.label}>
|
{getFieldDecorator(item.key, {
|
initialValue: item.initVal || '',
|
rules: [
|
{
|
required: item.readonly ? false : !!item.required,
|
message: this.props.dict['form.required.input'] + item.label + '!'
|
}
|
]
|
})(<Input placeholder="" autoComplete="off" disabled={item.readonly} />)}
|
</Form.Item>
|
</Col>
|
)
|
} else if (item.type === 'select') { // 下拉搜索
|
fields.push(
|
<Col span={12} key={index}>
|
<Form.Item label={item.label}>
|
{getFieldDecorator(item.key, {
|
initialValue: item.initVal || '',
|
rules: [
|
{
|
required: !!item.required,
|
message: this.props.dict['form.required.select'] + item.label + '!'
|
}
|
]
|
})(
|
<Select
|
showSearch
|
filterOption={(input, option) => option.props.children[2].toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
onChange={(value) => {this.openTypeChange(item.key, value)}}
|
getPopupContainer={() => document.getElementById('winter')}
|
>
|
{item.options.map(option =>
|
<Select.Option id={option.MenuID} title={option.text} key={option.MenuID} value={option.MenuID}>
|
{item.key === 'icon' && option.MenuID && <Icon type={option.MenuID} />} {option.text}
|
</Select.Option>
|
)}
|
</Select>
|
)}
|
</Form.Item>
|
</Col>
|
)
|
} else if (item.type === 'radio') {
|
fields.push(
|
<Col span={12} key={index}>
|
<Form.Item label={item.label}>
|
{getFieldDecorator(item.key, {
|
initialValue: item.initVal,
|
rules: [
|
{
|
required: !!item.required,
|
message: this.props.dict['form.required.select'] + item.label + '!'
|
}
|
]
|
})(
|
<Radio.Group onChange={(e) => {this.onChange(e, item.key)}}>
|
{
|
item.options.map(option => {
|
return (
|
<Radio key={option.MenuID} value={option.MenuID}>{option.text}</Radio>
|
)
|
})
|
}
|
</Radio.Group>
|
)}
|
</Form.Item>
|
</Col>
|
)
|
} else if (item.type === 'textarea') {
|
fields.push(
|
<Col span={24} key={index}>
|
<Form.Item label={item.label} help={this.props.dict['header.form.datasource.actionhelp']} className="textarea">
|
{getFieldDecorator(item.key, {
|
initialValue: item.initVal
|
})(<TextArea rows={4} />)}
|
</Form.Item>
|
</Col>
|
)
|
}
|
})
|
return fields
|
}
|
|
handleConfirm = () => {
|
// 表单提交时检查输入值是否正确
|
return new Promise((resolve, reject) => {
|
this.props.form.validateFieldsAndScroll((err, values) => {
|
if (!err) {
|
values.id = this.props.card.id
|
values.uuid = this.props.card.uuid
|
|
if (values.innerFunc === '' && values.sql === '') {
|
notification.warning({
|
top: 92,
|
message: this.props.dict['header.form.datasource.actionhelp'],
|
duration: 10
|
})
|
} else {
|
resolve({
|
type: 'action',
|
values
|
})
|
}
|
} else {
|
reject(err)
|
}
|
})
|
})
|
}
|
|
render() {
|
const formItemLayout = {
|
labelCol: {
|
xs: { span: 24 },
|
sm: { span: 7 }
|
},
|
wrapperCol: {
|
xs: { span: 24 },
|
sm: { span: 17 }
|
}
|
}
|
return (
|
<Form {...formItemLayout} className="ant-advanced-search-form commontable-action-form" id="winter">
|
<Row gutter={24}>{this.getFields()}</Row>
|
</Form>
|
)
|
}
|
}
|
|
export default Form.create()(MainSearch)
|