import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { fromJS } from 'immutable'
|
import { Form, Row, Col, Input, Select, Radio, notification, InputNumber, Tooltip } from 'antd'
|
import { QuestionCircleOutlined } from '@ant-design/icons'
|
|
import { formRule } from '@/utils/option.js'
|
import { dateOptions } from '@/utils/option.js'
|
import Utils from '@/utils/utils.js'
|
import EditTable from './modaleditable'
|
import asyncComponent from '@/utils/asyncComponent'
|
import CodeMirror from '@/templates/zshare/codemirror'
|
import './index.scss'
|
|
const { TextArea } = Input
|
const ColorSketch = asyncComponent(() => import('@/mob/colorsketch'))
|
const FieldsTable = asyncComponent(() => import('./fieldtable'))
|
const DataTable = asyncComponent(() => import('./datatable'))
|
const MkEditIcon = asyncComponent(() => import('@/components/mkIcon'))
|
|
const modalTypeOptions = {
|
text: ['initval', 'readonly', 'required', 'hidden', 'readin', 'fieldlength', 'regular', 'interception', 'span', 'labelwidth', 'tooltip', 'extra', 'enter', 'cursor', 'scan', 'splitline', 'placeholder', 'place', 'marginTop', 'marginBottom'],
|
number: ['initval', 'readonly', 'hidden', 'decimal', 'min', 'max', 'readin', 'span', 'labelwidth', 'tooltip', 'extra', 'enter', 'cursor', 'splitline', 'place', 'marginTop', 'marginBottom'],
|
select: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'setAll', 'linkSubField', 'span', 'labelwidth', 'tooltip', 'extra', 'emptyText', 'enter', 'splitline', 'dropdown', 'marginTop', 'marginBottom'],
|
checkbox: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'fieldlength', 'span', 'labelwidth', 'tooltip', 'extra', 'splitline', 'arrange', 'marginTop', 'marginBottom'],
|
radio: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'linkSubField', 'span', 'labelwidth', 'tooltip', 'extra', 'setAll', 'emptyText', 'splitline', 'arrange', 'marginTop', 'marginBottom'],
|
checkcard: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'fieldlength', 'span', 'labelwidth', 'display', 'tooltip', 'extra', 'width', 'multiple', 'borderColor', 'splitline', 'marginTop', 'marginBottom'],
|
multiselect: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'fieldlength', 'span', 'labelwidth', 'tooltip', 'extra', 'marginTop', 'marginBottom'],
|
link: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'setAll', 'linkField', 'linkSubField', 'span', 'labelwidth', 'tooltip', 'extra', 'emptyText', 'enter', 'splitline', 'dropdown', 'marginTop', 'marginBottom'],
|
fileupload: ['readonly', 'required', 'readin', 'fieldlength', 'maxfile', 'fileType', 'span', 'labelwidth', 'tooltip', 'extra', 'compress', 'splitline', 'marginTop', 'marginBottom'],
|
switch: ['initval', 'openVal', 'closeVal', 'openText', 'closeText', 'readonly', 'hidden', 'readin', 'span', 'labelwidth', 'tooltip', 'extra', 'splitline', 'marginTop', 'marginBottom'],
|
date: ['initval', 'readonly', 'required', 'hidden', 'readin', 'span', 'labelwidth', 'tooltip', 'extra', 'declareType', 'mode', 'splitline', 'marginTop', 'marginBottom', 'minDate', 'maxDate'],
|
datemonth: ['initval', 'readonly', 'required', 'hidden', 'readin', 'span', 'labelwidth', 'tooltip', 'extra', 'declareType', 'splitline', 'marginTop', 'marginBottom'],
|
datetime: ['initval', 'readonly', 'required', 'hidden', 'readin', 'span', 'labelwidth', 'tooltip', 'extra', 'declareType', 'mode', 'splitline', 'marginTop', 'marginBottom', 'minDate', 'maxDate'],
|
textarea: ['initval', 'readonly', 'required', 'hidden', 'readin', 'fieldlength', 'span', 'labelwidth', 'maxRows', 'encryption', 'interception', 'tooltip', 'extra', 'count', 'placeholder', 'marginTop', 'marginBottom'],
|
color: ['initval', 'readonly', 'required', 'hidden', 'readin', 'span', 'labelwidth', 'tooltip', 'extra', 'marginTop', 'marginBottom'],
|
rate: ['initval', 'readonly', 'required', 'hidden', 'readin', 'span', 'labelwidth', 'splitline', 'tooltip', 'extra', 'marginTop', 'marginBottom', 'allowHalf', 'rateCount', 'character', 'place'],
|
hint: ['label', 'type', 'blacklist', 'message', 'span', 'labelwidth', 'splitline', 'marginTop', 'marginBottom'],
|
split: ['label', 'type', 'marginTop', 'marginBottom'],
|
brafteditor: ['required', 'hidelabel', 'hidden', 'readin', 'fieldlength', 'readonly', 'span', 'labelwidth', 'tooltip', 'extra', 'encryption', 'marginTop', 'marginBottom'],
|
funcvar: ['span', 'labelwidth', 'splitline', 'marginTop', 'marginBottom'],
|
linkMain: ['readonly', 'required', 'hidden', 'fieldlength', 'span', 'labelwidth', 'tooltip', 'extra', 'marginTop', 'marginBottom']
|
}
|
|
class MainSearch extends Component {
|
static propTpyes = {
|
dict: PropTypes.object, // 字典项
|
formlist: PropTypes.any,
|
standardform: PropTypes.any,
|
card: PropTypes.object,
|
inputSubmit: PropTypes.any
|
}
|
|
state = {
|
transfield: {},
|
formlist: null
|
}
|
|
record = {}
|
|
UNSAFE_componentWillMount () {
|
let transfield = {}
|
this.props.formlist.forEach(item => {
|
this.record[item.key] = item.initVal
|
|
if (item.key === 'linkSubField') {
|
item.options.forEach(cell => {
|
transfield[cell.field] = cell.label
|
})
|
}
|
})
|
|
let { shows, reOptions, reTypes, reRequired, reTooltip } = this.getMutilOptions()
|
|
this.setState({
|
transfield,
|
formlist: this.props.formlist.map(item => {
|
item.show = shows.includes(item.key)
|
item.initVal = this.record[item.key]
|
|
if (reOptions[item.key]) {
|
item.options = reOptions[item.key]
|
}
|
if (reTypes[item.key]) {
|
item.type = reTypes[item.key]
|
}
|
if (reRequired[item.key] !== undefined) {
|
item.required = reRequired[item.key]
|
}
|
if (reTooltip[item.key] !== undefined) {
|
item.tooltip = reTooltip[item.key]
|
}
|
|
return item
|
})
|
})
|
}
|
|
componentDidMount () {
|
const { card } = this.props
|
|
if (card.focus) {
|
try {
|
let _form = document.getElementById('label')
|
_form.select()
|
} catch (e) {
|
console.warn('表单focus失败!')
|
}
|
}
|
}
|
|
getMutilOptions = () => {
|
let type = this.record.type
|
let shows = ['label', 'field', 'type', 'blacklist', 'writein', 'supField', ...fromJS(modalTypeOptions[type] || []).toJS()]
|
let reOptions = {}
|
let reTypes = {}
|
let reRequired = {}
|
let reTooltip = {}
|
|
if (type === 'hint' || type === 'split') {
|
shows = fromJS(modalTypeOptions[type]).toJS()
|
}
|
|
// text number select multiselect link switch checkbox radio checkcard fileupload date datemonth datetime textarea
|
// rate color brafteditor funcvar hint split linkMain
|
|
// 通用设置
|
reTypes.initval = 'text'
|
reRequired.initval = false
|
reRequired.label = true
|
reRequired.linkField = true
|
reTooltip.initval = ''
|
|
if (type === 'text') {
|
if (this.record.enter === 'tab' || this.record.enter === 'sub') {
|
shows.push('tabField')
|
}
|
} else if (type === 'number') {
|
reTypes.initval = 'number'
|
reRequired.initval = true
|
if (this.record.enter === 'tab' || this.record.enter === 'sub') {
|
shows.push('tabField')
|
}
|
} else if (['multiselect', 'select', 'link', 'radio', 'checkbox'].includes(type)) {
|
if (this.record.resourceType === '0') { // 自定义资源
|
shows.push('options')
|
} else if (this.record.resourceType === '1') { // 数据源
|
shows.push('dataSource', 'valueField', 'valueText', 'orderBy', 'orderType', 'disableField', 'database')
|
}
|
if (type === 'select' || type === 'link') {
|
if (this.record.enter === 'tab' || this.record.enter === 'sub') {
|
shows.push('tabField')
|
}
|
} else if (type === 'radio') {
|
shows.push('linkField')
|
reRequired.linkField = false
|
}
|
} else if (type === 'checkcard') {
|
if (this.record.display === 'picture') {
|
if (this.record.resourceType === '0') { // 自定义资源
|
shows.push('options', 'ratio')
|
} else if (this.record.resourceType === '1') { // 数据源
|
shows.push('dataSource', 'cardValField', 'urlField', 'orderBy', 'orderType', 'disableField', 'database', 'ratio')
|
}
|
} else {
|
if (this.record.resourceType === '0') { // 自定义资源
|
shows.push('options', 'fields', 'backgroundColor')
|
} else if (this.record.resourceType === '1') { // 数据源
|
shows.push('dataSource', 'cardValField', 'fields', 'orderBy', 'orderType', 'disableField', 'database', 'backgroundColor')
|
}
|
}
|
|
if (this.record.multiple === 'false') {
|
shows.push('linkSubField')
|
} else {
|
reTooltip.initval = '添加多个初始值请使用逗号分隔。'
|
}
|
|
shows.push('linkField')
|
reRequired.linkField = false
|
|
if (sessionStorage.getItem('appType') === 'mob') {
|
shows.push('hidelabel')
|
}
|
} else if (['date', 'datemonth', 'datetime'].includes(type)) {
|
reOptions.initval = dateOptions[type]
|
reTypes.initval = 'select'
|
} else if (type === 'switch') {
|
reOptions.initval = [
|
{value: true, text: '开'},
|
{value: false, text: '关'}
|
]
|
reTypes.initval = 'radio'
|
} else if (type === 'rate') {
|
reTypes.initval = 'number'
|
} else if (type === 'hint') {
|
reRequired.label = false
|
} else if (type === 'fileupload') {
|
if (this.record.compress === 'true') {
|
shows.push('limit', 'rduri', 'proRduri')
|
} else {
|
shows.push('suffix')
|
}
|
}
|
|
if (['multiselect', 'checkbox'].includes(type)) {
|
reTooltip.initval = '添加多个初始值请使用逗号分隔。'
|
} else if (['select', 'link', 'radio'].includes(type)) {
|
reTooltip.initval = '使用$first表示默认选择第一项。'
|
}
|
|
if (this.record.supField) {
|
shows.push('supvalue')
|
}
|
|
return {
|
shows,
|
reOptions,
|
reTypes,
|
reRequired,
|
reTooltip
|
}
|
}
|
|
optionChange = (key, value) => {
|
let _fieldval = {}
|
|
if (key === 'type') {
|
this.record.enter = 'false'
|
this.record.initval = ''
|
this.record.fieldlength = 50
|
_fieldval.initval = ''
|
|
if (value === 'text' || value === 'number') {
|
this.record.enter = 'sub'
|
_fieldval.enter = 'sub'
|
} else if (value === 'select' || value === 'link') {
|
_fieldval.enter = 'false'
|
}
|
|
if (value === 'number' || value === 'rate') {
|
this.record.initval = 0
|
_fieldval.initval = 0
|
} else if (value === 'switch') {
|
this.record.initval = false
|
_fieldval.initval = false
|
}
|
|
if (['hint', 'split', 'brafteditor', 'funcvar', 'linkMain', 'fileupload'].includes(value)) {
|
delete _fieldval.initval
|
}
|
|
if (value === 'text' || value === 'linkMain' || value === 'checkcard') {
|
_fieldval.fieldlength = 50
|
} else if (value === 'textarea' || value === 'brafteditor') {
|
this.record.fieldlength = 8000
|
_fieldval.fieldlength = 8000
|
} else if (value === 'fileupload' || value === 'multiselect' || value === 'checkbox') {
|
this.record.fieldlength = 512
|
_fieldval.fieldlength = 512
|
}
|
|
if (value === 'brafteditor') {
|
this.record.encryption = 'true'
|
_fieldval.encryption = 'true'
|
}
|
|
if (value === 'linkMain') {
|
this.record.hidden = 'true'
|
_fieldval.hidden = 'true'
|
}
|
|
if (this.record.options.length > 0) {
|
if (value === 'checkcard') {
|
this.record.options = this.record.options.map(cell => {
|
cell.$value = cell.Value || ''
|
delete cell.Value
|
return cell
|
})
|
|
if (this.record.options[0].Text) {
|
let key = Utils.getuuid()
|
|
this.record.fields = [{
|
$index: 1,
|
align: 'left',
|
color: 'rgba(0, 0, 0, 0.85)',
|
field: 'Text',
|
fontSize: 14,
|
key: key,
|
uuid: key
|
}]
|
}
|
} else if (['multiselect', 'select', 'link', 'radio', 'checkbox'].includes(value)) {
|
if (!this.record.options[0].Text && this.record.fields.length > 0) {
|
let field = this.record.fields[0].field
|
|
this.record.options = this.record.options.map(cell => {
|
cell.Value = cell.Value || cell.$value || ''
|
cell.Text = cell[field] || ''
|
|
return cell
|
})
|
} else {
|
this.record.options = this.record.options.map(cell => {
|
cell.Value = cell.Value || cell.$value || ''
|
|
return cell
|
})
|
}
|
}
|
}
|
} else if (key === 'multiple') {
|
if (value === 'true') {
|
this.record.fieldlength = 512
|
_fieldval.fieldlength = 512
|
} else {
|
this.record.fieldlength = 50
|
_fieldval.fieldlength = 50
|
}
|
}
|
|
this.record[key] = value
|
|
let { shows, reOptions, reTypes, reRequired, reTooltip } = this.getMutilOptions()
|
|
this.setState({
|
formlist: this.state.formlist.map(item => {
|
item.show = shows.includes(item.key)
|
item.initVal = this.record[item.key]
|
|
if (reOptions[item.key]) {
|
item.options = reOptions[item.key]
|
}
|
if (reTypes[item.key]) {
|
item.type = reTypes[item.key]
|
}
|
if (reRequired[item.key] !== undefined) {
|
item.required = reRequired[item.key]
|
}
|
if (reTooltip[item.key] !== undefined) {
|
item.tooltip = reTooltip[item.key]
|
}
|
|
return item
|
})
|
}, () => {
|
this.props.form.setFieldsValue(_fieldval)
|
})
|
}
|
|
multiselectChange = (key, value) => {
|
if (key !== 'linkSubField') return
|
|
this.record[key] = value
|
}
|
|
changeField = (data) => {
|
this.record.fields = data || []
|
}
|
|
changeOptions = (data) => {
|
this.record.options = data || []
|
}
|
|
changeVal = (val, type) => {
|
if (type !== 'span' || ![24, 12, 8, 6].includes(val)) return
|
|
const { standardform } = this.props
|
|
if (!standardform || ![24, 12, 8, 6].includes(standardform.span) || !standardform.labelwidth) return
|
|
let labelwidth = null
|
|
if (standardform.span === val) {
|
labelwidth = standardform.labelwidth
|
} else if (standardform.span > val) {
|
labelwidth = 33.3
|
} else {
|
switch(standardform.span) {
|
case 12:
|
labelwidth = 16.2
|
break;
|
case 8:
|
if (val === 12) {
|
labelwidth = 21.6
|
} else {
|
labelwidth = 10.5
|
}
|
break;
|
case 6:
|
if (val === 8) {
|
labelwidth = 24.3
|
} else if (val === 12) {
|
labelwidth = 15.8
|
} else {
|
labelwidth = 7.7
|
}
|
break;
|
default:
|
}
|
}
|
|
if (labelwidth) {
|
this.props.form.setFieldsValue({labelwidth})
|
}
|
}
|
|
handleSubmit = (e) => {
|
e.preventDefault()
|
|
if (this.props.inputSubmit) {
|
this.props.inputSubmit()
|
}
|
}
|
|
handleEmpty = () => {
|
let field = this.props.form.getFieldValue('valueField')
|
|
if (!field) {
|
notification.warning({
|
top: 92,
|
message: '请填写值·字段。',
|
duration: 5
|
})
|
return
|
}
|
|
let text = this.props.form.getFieldValue('valueText')
|
|
if (!text) {
|
notification.warning({
|
top: 92,
|
message: '请填写文本·字段。',
|
duration: 5
|
})
|
return
|
}
|
|
let resource = this.props.form.getFieldValue('dataSource') || ''
|
|
resource = `select '' as ${field},'全部' as ${text} union all \n${resource}`
|
|
this.props.form.setFieldsValue({dataSource: resource})
|
}
|
|
getFields() {
|
const { getFieldDecorator } = this.props.form
|
const { dict } = this.props
|
const { transfield } = this.state
|
const fields = []
|
|
this.state.formlist.forEach((item, index) => {
|
if (!item.show || item.forbid) return null
|
|
let span = 12
|
let rules = []
|
let className = ''
|
let content = null
|
let extra = null
|
let initVal = item.initVal || ''
|
|
if (item.type === 'text') {
|
rules = [
|
{ required: item.required, message: dict['form.required.input'] + item.label + '!' }
|
]
|
if (item.key === 'field') {
|
rules.push({
|
pattern: formRule.field.pattern,
|
message: formRule.field.message
|
}, {
|
max: formRule.field.max,
|
message: formRule.field.maxMessage
|
})
|
} else if (item.max) {
|
rules.push({
|
max: item.max,
|
message: `${item.label}最多${item.max}个字符`
|
})
|
} else {
|
rules.push({
|
max: formRule.input.max,
|
message: formRule.input.message
|
})
|
}
|
|
content = <Input placeholder="" autoComplete="off" onPressEnter={this.handleSubmit} />
|
} else if (item.type === 'number') {
|
rules = [
|
{ required: item.required, message: dict['form.required.input'] + item.label + '!' }
|
]
|
initVal = item.initVal
|
|
if (item.max) {
|
content = <InputNumber onChange={(value) => this.changeVal(value, item.key)} min={item.min} max={item.max} precision={item.precision} onPressEnter={this.handleSubmit}/>
|
} else {
|
content = <InputNumber onPressEnter={this.handleSubmit}/>
|
}
|
} else if (item.type === 'select') {
|
rules = [
|
{ required: item.required, message: dict['form.required.select'] + item.label + '!' }
|
]
|
content = <Select
|
showSearch
|
allowClear={item.allowClear === true}
|
filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
onChange={(value) => {this.optionChange(item.key, value)}}
|
getPopupContainer={() => document.getElementById('modal-fields-form-box')}
|
>
|
{item.options.map((option, i) =>
|
<Select.Option key={`${i}`} value={option.value || option.field || ''}>
|
{option.text || option.label}
|
</Select.Option>
|
)}
|
</Select>
|
} else if (item.type === 'multiselect') { // 多选
|
content = <Select
|
showSearch
|
mode="multiple"
|
filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
onChange={(value) => this.multiselectChange(item.key, value)}
|
>
|
{item.options.map((option, i) =>
|
<Select.Option key={i} value={option.field}>{option.label}</Select.Option>
|
)}
|
</Select>
|
} else if (item.type === 'radio') {
|
rules = [
|
{ required: item.required, message: dict['form.required.select'] + item.label + '!' }
|
]
|
initVal = item.initVal
|
|
content = <Radio.Group onChange={(e) => {this.optionChange(item.key, e.target.value)}}>
|
{item.options.map(option => {
|
return (
|
<Radio key={option.value} value={option.value}>{option.text}</Radio>
|
)
|
})}
|
</Radio.Group>
|
} else if (item.type === 'codemirror') {
|
rules = [
|
{ required: item.required, message: dict['form.required.input'] + item.label + '!' }
|
]
|
span = 24
|
className = 'text-area'
|
|
if (this.record.type === 'select' || this.record.type === 'link') {
|
extra = <span className="add-resource-empty" onClick={this.handleEmpty}>空</span>
|
}
|
|
content = <CodeMirror />
|
} else if (item.type === 'textarea') {
|
span = 24
|
className = 'text-msg'
|
rules = [
|
{ required: item.required, message: dict['form.required.input'] + item.label + '!' }
|
]
|
|
content = <TextArea rows={item.rows || 4}/>
|
} else if (item.type === 'options') {
|
span = 24
|
className = 'text-area'
|
|
let type = this.record.type
|
let linkSubFields = this.record.linkSubField || []
|
|
if (type !== 'checkcard') {
|
if (!['select', 'radio', 'link'].includes(type)) {
|
linkSubFields = []
|
}
|
if (type === 'radio' && this.record.linkField) {
|
type = 'link'
|
}
|
content = <EditTable type={type} module="form" transfield={transfield} linkSubFields={linkSubFields} onChange={this.changeOptions}/>
|
} else {
|
if (this.record.multiple === 'true') {
|
linkSubFields = []
|
}
|
if (this.record.linkField) {
|
type = 'link'
|
}
|
content = <DataTable dict={this.props.dict} type={type} display={this.record.display} linkSubFields={linkSubFields} transfield={transfield} fields={this.record.fields || []} onChange={this.changeOptions}/>
|
}
|
} else if (item.type === 'fields') {
|
span = 24
|
className = 'text-area'
|
|
content = <FieldsTable dict={this.props.dict} onChange={this.changeField}/>
|
} else if (item.type === 'color') {
|
className = 'color-form-item'
|
|
content = <ColorSketch allowClear={true}/>
|
} else if (item.type === 'icon') {
|
rules = [
|
{ required: item.required, message: dict['form.required.select'] + item.label + '!' }
|
]
|
|
content = <MkEditIcon allowClear />
|
}
|
|
fields.push(
|
<Col span={span} key={index}>
|
<Form.Item className={className} extra={extra} label={item.tooltip ?
|
<Tooltip placement="topLeft" title={item.tooltip}>
|
<QuestionCircleOutlined className="mk-form-tip" />
|
{item.label}
|
</Tooltip> : item.label
|
}>
|
{getFieldDecorator(item.key, {
|
initialValue: initVal,
|
rules: rules
|
})(content)}
|
</Form.Item>
|
</Col>
|
)
|
})
|
|
return fields
|
}
|
|
handleConfirm = () => {
|
// 表单提交时检查输入值是否正确
|
return new Promise((resolve, reject) => {
|
this.props.form.validateFieldsAndScroll((err, values) => {
|
if (!err) {
|
values.uuid = this.props.card.uuid
|
// 下拉菜单或联动菜单
|
if (['multiselect', 'select', 'link', 'radio', 'checkbox'].includes(values.type)) {
|
if (values.resourceType === '0') {
|
values.options = values.options || []
|
values.dataSource = ''
|
let type = values.type
|
if (values.type === 'radio' && values.linkField) {
|
type = 'link'
|
}
|
|
if (values.options.filter(op => op.Text === '').length > 0) {
|
notification.warning({
|
top: 92,
|
message: '提示文本(Text)不可为空!',
|
duration: 5
|
})
|
return
|
} else if (values.options.filter(op => op.Value === '').length > 1) {
|
notification.warning({
|
top: 92,
|
message: 'Value为空最多只可添加一行(在关联菜单中,Value为空时不区分ParentID)!',
|
duration: 5
|
})
|
return
|
} else if (type === 'link') {
|
let arr = values.options.map(m => m.ParentID + m.Value)
|
let _arr = Array.from(new Set(arr))
|
if (arr.length > _arr.length) {
|
notification.warning({
|
top: 92,
|
message: '同一ParentID中,Value值不可重复!',
|
duration: 5
|
})
|
return
|
}
|
} else {
|
let arr = values.options.map(m => m.Value)
|
let _arr = Array.from(new Set(arr))
|
if (arr.length > _arr.length) {
|
notification.warning({
|
top: 92,
|
message: 'Value值不可重复!',
|
duration: 5
|
})
|
return
|
}
|
}
|
} else {
|
values.options = []
|
}
|
} else if (values.type === 'checkcard') {
|
if (values.resourceType === '0') {
|
values.options = values.options || []
|
let linkSubFields = values.linkSubField || []
|
values.options = values.options.map(m => {
|
m.ParentID = m.ParentID || ''
|
|
linkSubFields.forEach(n => {
|
m[n] = m[n] || ''
|
})
|
return m
|
})
|
|
let type = values.type
|
if (values.linkField) {
|
type = 'link'
|
}
|
|
if (type === 'link') {
|
let arr = values.options.map(m => m.ParentID + m.$value)
|
let _arr = Array.from(new Set(arr))
|
if (arr.length > _arr.length) {
|
notification.warning({
|
top: 92,
|
message: '同一ParentID中,Value值不可重复!',
|
duration: 5
|
})
|
return
|
}
|
} else {
|
let arr = values.options.map(m => m.$value)
|
let _arr = Array.from(new Set(arr))
|
if (arr.length > _arr.length) {
|
notification.warning({
|
top: 92,
|
message: 'Value值不可重复!',
|
duration: 5
|
})
|
return
|
}
|
}
|
} else {
|
values.options = []
|
}
|
} else if (values.type === 'funcvar') { // 函数变量为只读元素
|
values.readonly = 'true'
|
} else if (values.type === 'number') { // 数值型验证最小最大值
|
values.required = 'true'
|
if ((values.min || values.min === 0) && (values.max || values.max === 0) && values.min > values.max) {
|
notification.warning({
|
top: 92,
|
message: '最小值不可大于最大值!',
|
duration: 5
|
})
|
return
|
}
|
} else if (values.type === 'linkMain') {
|
values.initval = ''
|
} else if (values.type === 'split') {
|
values.span = 24
|
}
|
|
['linkField', 'valueField', 'valueText', 'orderBy'].forEach(item => {
|
if (values[item]) {
|
values[item] = values[item].replace(/\s*|\t*|\v*|\r*/ig, '')
|
}
|
})
|
|
let error = Utils.verifySql(values.dataSource)
|
|
if (error) {
|
notification.warning({
|
top: 92,
|
message: '数据源中不可使用' + error,
|
duration: 5
|
})
|
return
|
}
|
|
resolve(values)
|
} else {
|
reject(err)
|
}
|
})
|
})
|
}
|
|
render() {
|
const formItemLayout = {
|
labelCol: {
|
xs: { span: 24 },
|
sm: { span: 8 }
|
},
|
wrapperCol: {
|
xs: { span: 24 },
|
sm: { span: 16 }
|
}
|
}
|
return (
|
<Form {...formItemLayout} className="modal-fields-form" id="modal-fields-form-box">
|
<Row gutter={24}>{this.getFields()}</Row>
|
</Form>
|
)
|
}
|
}
|
|
export default Form.create()(MainSearch)
|