import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { fromJS } from 'immutable'
|
import { Form, Row, Col, Input, Select, Radio, notification, InputNumber, Tooltip, Checkbox, AutoComplete, Modal } from 'antd'
|
import { QuestionCircleOutlined } from '@ant-design/icons'
|
|
import Api from '@/api'
|
import { formRule } from '@/utils/option.js'
|
import { dateOptions } from '@/utils/option.js'
|
import Utils from '@/utils/utils.js'
|
import EditTable from './modaleditable'
|
import { checkSQL } from '@/utils/utils-custom.js'
|
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('@/templates/zshare/editTable'))
|
const MkEditIcon = asyncComponent(() => import('@/components/mkIcon'))
|
|
const modalTypeOptions = {
|
text: ['initval', 'readonly', 'required', 'hidden', 'readin', 'fieldlength', 'regular', 'interception', 'span', 'labelwidth', 'encryption', 'tooltip', 'extra', 'enter', 'cursor', 'scan', 'splitline', 'placeholder', 'place', 'marginTop', 'marginBottom', 'lenControl', 'inputType', 'constant', 'mkfocus'],
|
number: ['initval', 'readonly', 'hidden', 'decimal', 'min', 'max', 'readin', 'span', 'labelwidth', 'tooltip', 'extra', 'enter', 'cursor', 'splitline', 'place', 'marginTop', 'marginBottom', 'mkfocus'],
|
select: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'declare', 'linkSubField', 'span', 'labelwidth', 'tooltip', 'extra', 'place', 'enter', 'splitline', 'dropdown', 'marginTop', 'marginBottom', 'pickerMode'],
|
checkbox: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'fieldlength', 'span', 'labelwidth', 'tooltip', 'extra', 'place', 'splitline', 'arrange', 'marginTop', 'marginBottom'],
|
radio: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'declare', 'linkSubField', 'span', 'labelwidth', 'tooltip', 'extra', 'place', 'splitline', 'arrange', 'marginTop', 'marginBottom'],
|
checkcard: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'span', 'labelwidth', 'display', 'tooltip', 'extra', 'place', 'width', 'multiple', 'splitline', 'marginTop', 'marginBottom'],
|
multiselect: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'fieldlength', 'span', 'labelwidth', 'tooltip', 'extra', 'marginTop', 'marginBottom', 'dropdown'],
|
link: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'declare', 'linkField', 'linkSubField', 'span', 'place', 'labelwidth', 'tooltip', 'extra', 'enter', 'splitline', 'dropdown', 'marginTop', 'marginBottom', 'pickerMode'],
|
fileupload: ['readonly', 'required', 'hidden', 'readin', 'fieldlength', 'maxfile', 'fileType', 'span', 'labelwidth', 'linkSubField', 'tooltip', 'extra', 'compress', 'miniSet', 'splitline', 'marginTop', 'marginBottom', 'maxSize'],
|
switch: ['initval', 'openVal', 'closeVal', 'openText', 'closeText', 'readonly', 'hidden', 'readin', 'span', 'labelwidth', 'linkSubField', 'tooltip', 'extra', 'enter', 'splitline', 'marginTop', 'marginBottom'],
|
check: ['initval', 'openVal', 'closeVal', 'readonly', 'hidden', 'readin', 'span', 'labelwidth', 'tooltip', 'extra', 'enter', 'splitline', 'marginTop', 'marginBottom', 'checkTip'],
|
date: ['initval', 'readonly', 'required', 'hidden', 'readin', 'span', 'labelwidth', 'tooltip', 'extra', 'declareType', 'mode', 'splitline', 'place', 'marginTop', 'marginBottom', 'minDate', 'maxDate', 'precision'],
|
datemonth: ['initval', 'readonly', 'required', 'hidden', 'readin', 'span', 'labelwidth', 'tooltip', 'extra', 'splitline', 'place', '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', 'place', 'count', 'placeholder', 'marginTop', 'marginBottom'],
|
cascader: ['readonly', 'required', 'hidden', 'readin', 'resourceType', 'fieldlength', 'span', 'labelwidth', 'tooltip', 'extra', 'place', 'splitline', 'marginTop', 'marginBottom', 'separator'],
|
color: ['initval', 'readonly', 'required', 'hidden', 'readin', 'span', 'labelwidth', 'tooltip', 'colorType', 'extra', 'marginTop', 'marginBottom'],
|
rate: ['initval', 'readonly', 'required', 'hidden', 'readin', 'span', 'labelwidth', 'splitline', 'tooltip', 'extra', 'marginTop', 'marginBottom', 'allowHalf', 'color', 'rateCount', 'character', 'place'],
|
hint: ['label', 'field', 'type', 'blacklist', 'supField', 'message', 'span', 'labelwidth', 'splitline', 'marginTop', 'marginBottom'],
|
split: ['label', 'type', 'marginTop', 'marginBottom', 'splitline', 'splitctrl', 'supField'],
|
formula: ['label', 'type', 'marginTop', 'marginBottom', 'splitline', 'supField', 'span', 'labelwidth', 'formula', 'eval', 'postfix'],
|
brafteditor: ['required', 'hidelabel', 'hidden', 'readin', 'fieldlength', 'readonly', 'span', 'labelwidth', 'tooltip', 'extra', 'encryption', 'marginTop', 'marginBottom'],
|
funcvar: ['span', 'labelwidth', 'splitline', 'marginTop', 'marginBottom'],
|
linkMain: ['readonly', 'required', 'hidden','declare', 'span', 'labelwidth', 'tooltip', 'interception', 'extra', 'place', 'marginTop', 'marginBottom'],
|
popSelect: ['initval', 'readonly', 'required', 'hidden', 'readin', 'linkSubField', 'span', 'labelwidth', 'tooltip', 'extra', 'place', 'enter', 'dataSource', 'columns', 'primaryKey', 'order', 'controlField', 'laypage', 'onload', 'searchKey', 'showField', 'popWidth'],
|
vercode: ['label', 'field', 'type', 'blacklist', 'supField', 'readonly', 'required', 'hidden', 'span', 'labelwidth', 'tooltip', 'marginTop', 'marginBottom', 'placeholder', 'enter', 'smsId', 'phoneField', 'sendType']
|
}
|
|
class MainSearch extends Component {
|
static propTpyes = {
|
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.replace(/^\d+、/, '')
|
})
|
}
|
})
|
|
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 = {}
|
|
reRequired.field = true
|
|
if (['hint', 'split', 'formula', 'vercode'].includes(type)) {
|
reRequired.field = false
|
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')
|
}
|
if (this.record.regular !== '') {
|
shows.push('regularText')
|
if (this.record.regular !== 'phone' && this.record.regular !== 'email') {
|
shows.push('regularExtra')
|
}
|
}
|
if (this.record.interception === 'func') {
|
shows.push('func')
|
}
|
} else if (type === 'number') {
|
reTypes.initval = 'number'
|
reRequired.initval = true
|
if (this.record.enter === 'tab' || this.record.enter === 'sub') {
|
shows.push('tabField')
|
}
|
if (sessionStorage.getItem('appType') === 'mob') { // 移动端右侧扩展信息
|
shows.push('placeholder')
|
}
|
} else if (type === 'vercode') {
|
if (this.record.enter === 'tab' || this.record.enter === 'sub') {
|
shows.push('tabField')
|
}
|
} else if (type === 'linkMain') {
|
if (this.record.declare === 'nvarchar') {
|
shows.push('fieldlength')
|
} else if (this.record.declare === 'decimal') {
|
shows.push('decimal')
|
}
|
if (this.record.interception === 'func') {
|
shows.push('func')
|
}
|
} 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
|
}
|
if (['select', 'link', 'radio'].includes(type)) {
|
if (this.record.declare === 'nvarchar') {
|
shows.push('fieldlength')
|
} else if (this.record.declare === 'decimal') {
|
shows.push('decimal')
|
}
|
}
|
} else if (type === 'checkcard') {
|
reRequired.fields = false
|
if (this.record.display === 'picture') {
|
if (this.record.resourceType === '0') { // 自定义资源
|
shows.push('options', 'fields', 'picratio')
|
} else if (this.record.resourceType === '1') { // 数据源
|
shows.push('dataSource', 'cardValField', 'fields', 'urlField', 'orderBy', 'orderType', 'disableField', 'database', 'picratio')
|
}
|
} else if (this.record.display === 'color') {
|
if (this.record.resourceType === '0') { // 自定义资源
|
shows.push('options', 'fields')
|
} else if (this.record.resourceType === '1') { // 数据源
|
shows.push('dataSource', 'cardValField', 'colorField', 'fields', 'orderBy', 'orderType', 'database')
|
}
|
} else {
|
reRequired.fields = true
|
if (this.record.resourceType === '0') { // 自定义资源
|
shows.push('options', 'fields', 'selectStyle', 'border')
|
} else if (this.record.resourceType === '1') { // 数据源
|
shows.push('dataSource', 'cardValField', 'fields', 'orderBy', 'orderType', 'disableField', 'database', 'selectStyle', 'border')
|
}
|
if (this.record.selectStyle === 'custom') {
|
shows.push('backgroundColor')
|
}
|
}
|
|
if (this.record.multiple === 'false') {
|
shows.push('linkSubField', 'declare')
|
if (this.record.declare === 'nvarchar') {
|
shows.push('fieldlength')
|
} else if (this.record.declare === 'decimal') {
|
shows.push('decimal')
|
}
|
} else {
|
shows.push('fieldlength', 'checkAll')
|
reTooltip.initval = '添加多个初始值请使用逗号分隔。'
|
}
|
|
shows.push('linkField')
|
reRequired.linkField = false
|
|
if (sessionStorage.getItem('appType') === 'mob') {
|
shows.push('hidelabel')
|
}
|
if (this.record.readonly === 'true' && this.record.hidden !== 'true') {
|
shows.push('unchecked')
|
}
|
} else if (['date', 'datemonth'].includes(type)) {
|
reOptions.initval = dateOptions[type]
|
reTypes.initval = 'select'
|
if (type === 'date') {
|
if (this.record.minDate === 'custom') {
|
shows.push('minDateField')
|
}
|
if (this.record.maxDate === 'custom') {
|
shows.push('maxDateField')
|
}
|
}
|
} else if (type === 'switch' || type === 'check') {
|
if (this.record.enter === 'tab' || this.record.enter === 'sub') {
|
shows.push('tabField')
|
}
|
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 if (this.record.compress !== 'base64') {
|
shows.push('suffix')
|
}
|
if (this.record.miniSet === 'custom') {
|
shows.push('mediaType', 'sourceType')
|
|
if (this.record.sourceType.includes('camera') && this.record.mediaType.includes('video')) {
|
shows.push('maxDuration')
|
}
|
if (this.record.mediaType.includes('image')) {
|
shows.push('sizeType')
|
}
|
if (this.record.sourceType.includes('camera')) {
|
shows.push('camera')
|
}
|
}
|
} else if (type === 'textarea') {
|
if (this.record.encryption === 'false') {
|
shows.push('enterReplace')
|
}
|
if (this.record.interception === 'func') {
|
shows.push('func')
|
}
|
} else if (type === 'popSelect') {
|
if (this.record.enter === 'tab' || this.record.enter === 'sub') {
|
shows.push('tabField')
|
}
|
}
|
|
if (['multiselect', 'select', 'link', 'radio', 'checkbox', 'checkcard', 'cascader'].includes(type)) {
|
if (this.record.hidden !== 'true') {
|
shows.push('empty')
|
}
|
}
|
|
if (type === 'cascader') {
|
if (this.record.resourceType === '0') { // 自定义资源
|
shows.push('options', 'topmark', 'linkSubField')
|
} else if (this.record.resourceType === '1') { // 数据源
|
shows.push('dataSource', 'valueField', 'valueText', 'orderBy', 'orderType', 'disableField', 'database', 'topmark', 'linkField', 'linkSubField')
|
}
|
reTypes.linkField = 'text'
|
reTooltip.linkField = '用于构建数据结构。'
|
reOptions.resourceType = [{
|
value: '0',
|
text: '自定义'
|
}, {
|
value: '1',
|
text: '数据源'
|
}, {
|
value: '2',
|
text: '省市区'
|
}]
|
} else {
|
reTooltip.linkField = ''
|
reTypes.linkField = 'select'
|
reOptions.resourceType = [{
|
value: '0',
|
text: '自定义'
|
}, {
|
value: '1',
|
text: '数据源'
|
}]
|
}
|
|
if (type === 'brafteditor') {
|
reOptions.encryption = [{
|
value: 'false',
|
text: '无'
|
}, {
|
value: 'true',
|
text: 'base64加密'
|
}]
|
} else {
|
reOptions.encryption = [{
|
value: 'false',
|
text: '无'
|
}, {
|
value: 'true',
|
text: 'base64加密'
|
}, {
|
value: 'md5',
|
text: 'md5加密'
|
}]
|
}
|
|
if (['multiselect', 'checkbox'].includes(type)) {
|
reTooltip.initval = '添加多个初始值请使用逗号分隔。'
|
} else if (['select', 'link', 'radio'].includes(type)) {
|
reTooltip.initval = '使用$first表示默认选择第一项。'
|
}
|
|
if (this.record.supField) {
|
shows.push('supvalue')
|
}
|
|
if (this.record.hidden === 'true') {
|
shows = shows.filter(s => !['supField', 'supvalue', 'tooltip', 'extra', 'enter', 'tabField'].includes(s))
|
}
|
|
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 (['select', 'link', 'popSelect', 'vercode'].includes(value)) {
|
_fieldval.enter = 'false'
|
}
|
|
if (value === 'number' || value === 'rate') {
|
this.record.initval = 0
|
_fieldval.initval = 0
|
} else if (value === 'switch' || value === 'check') {
|
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.type === 'cascader' && value !== 'cascader') {
|
this.record.linkField = ''
|
_fieldval.linkField = ''
|
|
if (this.record.resourceType === '2') {
|
this.record.resourceType = '0'
|
_fieldval.resourceType = '0'
|
}
|
} else if (this.record.type === 'funcvar' && value !== 'funcvar') {
|
this.record.readonly = 'false'
|
}
|
|
if (value === 'checkcard') {
|
if (this.record.options.length > 0) {
|
this.record.options = this.record.options.map(cell => {
|
cell.$value = cell.Value || ''
|
delete cell.Value
|
return cell
|
})
|
}
|
|
if (this.record.options[0] && 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 {
|
this.record.fields = []
|
}
|
} else if (['multiselect', 'select', 'link', 'radio', 'checkbox'].includes(value)) {
|
if (this.record.options.length > 0) {
|
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] || ''
|
delete cell.$value
|
return cell
|
})
|
} else {
|
this.record.options = this.record.options.map(cell => {
|
cell.Value = cell.Value || cell.$value || ''
|
delete 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
|
}
|
|
changeOptions = (data, key) => {
|
this.record[key] = 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') || ''
|
|
if (field === text) {
|
resource = `select '' as ${field} union all \n${resource}`
|
} else {
|
resource = `select '' as ${field},'全部' as ${text} union all \n${resource}`
|
}
|
|
this.props.form.setFieldsValue({dataSource: resource})
|
}
|
|
complete = (option) => {
|
let label = option.props.label
|
|
this.props.form.setFieldsValue({label: label})
|
}
|
|
getFields() {
|
const { getFieldDecorator } = this.props.form
|
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: '请输入' + item.label + '!' },
|
{
|
pattern: /^[^']*$/ig,
|
message: '不可使用英文状态的单引号!'
|
}
|
]
|
if (item.rules) {
|
rules.push(...item.rules)
|
} else 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
|
})
|
}
|
|
if (['field', 'minDateField', 'maxDateField'].includes(item.key) && item.options && item.options.length > 0) {
|
content = <AutoComplete
|
dataSource={item.options.map((cell) => <AutoComplete.Option label={cell.label} value={cell.field} key={cell.uuid}>
|
{cell.field}
|
</AutoComplete.Option>)}
|
filterOption={(input, option) => option.props.children.indexOf(input) > -1}
|
onSelect={(val, option) => item.key === 'field' && this.complete(option)}
|
placeholder=""
|
>
|
<Input placeholder="" autoComplete="off" onPressEnter={this.handleSubmit} />
|
</AutoComplete>
|
} else {
|
content = <Input placeholder={item.placeholder || ''} autoComplete="off" onPressEnter={this.handleSubmit} />
|
}
|
} else if (item.type === 'number') {
|
rules = [
|
{ required: item.required, message: '请输入' + 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: '请选择' + item.label + '!' }
|
]
|
|
let options = item.options
|
if (typeof(item.options) === 'string') {
|
options = this.record[item.options] || []
|
}
|
|
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')}
|
>
|
{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: '请选择' + item.label + '!' }
|
]
|
initVal = item.initVal
|
|
content = <Radio.Group style={{whiteSpace: 'nowrap'}} 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 === 'checkbox') {
|
rules = [
|
{ required: item.required, message: '请选择' + item.label + '!' }
|
]
|
initVal = item.initVal
|
|
content = <Checkbox.Group onChange={(values) => {this.optionChange(item.key, values)}}>
|
{item.options.map(option => <Checkbox key={option.value} value={option.value}>{option.text}</Checkbox>)}
|
</Checkbox.Group>
|
} else if (item.type === 'codemirror') {
|
rules = [
|
{ required: item.required, message: '请输入' + item.label + '!' }
|
]
|
span = 24
|
|
if (this.record.type === 'select' || this.record.type === 'link') {
|
extra = <span className="add-resource-empty" onClick={this.handleEmpty}>空</span>
|
}
|
if (item.placeholder) {
|
extra = <><span className="resource-public-var">{item.placeholder}</span>{extra}</>
|
}
|
|
content = <CodeMirror />
|
} else if (item.type === 'textarea') {
|
span = 24
|
rules = [
|
{ required: item.required, message: '请输入' + item.label + '!' }
|
]
|
|
content = <TextArea rows={item.rows || 4}/>
|
} else if (item.type === 'options') {
|
span = 24
|
|
let type = this.record.type
|
let linkSubFields = this.record.linkSubField || []
|
|
if (type !== 'checkcard') {
|
if (!['select', 'radio', 'link', 'cascader'].includes(type)) {
|
linkSubFields = []
|
}
|
if (type === 'radio' && this.record.linkField) {
|
type = 'link'
|
} else if (type === 'cascader') {
|
type = 'link'
|
if (this.record.resourceType === '2') { // 自定义资源
|
linkSubFields = []
|
}
|
}
|
|
let columns = []
|
if (type === 'link') {
|
columns.push({ title: 'ParentID', key: 'ParentID', strict: true })
|
}
|
columns.push({ title: 'Value', key: 'Value', strict: true })
|
columns.push({ title: 'Text', key: 'Text' })
|
|
linkSubFields.forEach(field => {
|
if (field === 'Value' || field === 'Text') return
|
|
columns.push({ title: transfield[field] || field, key: field })
|
})
|
|
content = <EditTable columns={columns} module="form" onChange={(data) => this.changeOptions(data, item.key)}/>
|
} else {
|
if (this.record.multiple === 'true') {
|
linkSubFields = []
|
}
|
if (this.record.linkField) {
|
type = 'link'
|
}
|
|
let columns = []
|
let fields = this.record.fields || []
|
let keys = ['ParentID', 'pid']
|
|
if (type === 'link') {
|
columns.push({ title: 'ParentID', key: 'ParentID', strict: true })
|
}
|
columns.push({ title: 'Value', key: '$value', strict: true })
|
|
if (this.record.display === 'picture') {
|
columns.push({ title: 'url', key: '$url', type: 'file' })
|
} else if (this.record.display === 'color') {
|
columns.push({ title: 'Color', key: '$color' })
|
extra = <span>使用十六进制色彩代码(HEX)时,请在色值前添加 #</span>
|
}
|
|
fields.forEach(item => {
|
keys.push(item.field)
|
columns.push({ title: item.field, key: item.field })
|
})
|
|
linkSubFields.forEach(m => {
|
if (keys.includes(m)) return
|
|
columns.push({ title: transfield[m] || m, key: m })
|
})
|
|
content = <EditTable columns={columns} onChange={(data) => this.changeOptions(data, item.key)}/>
|
}
|
} else if (item.type === 'fields') {
|
span = 24
|
rules = [
|
{ required: item.required, message: '请添加' + item.label + '!' }
|
]
|
|
content = <FieldsTable indexShow={false} actions={['edit', 'move', 'del', 'add']} columns={item.columns} data={this.record[item.key] || []} onChange={(data) => this.changeOptions(data, item.key)}/>
|
} else if (item.type === 'color') {
|
className = 'color-form-item'
|
rules = [
|
{ required: item.required, message: '请选择' + item.label + '!' }
|
]
|
|
content = <ColorSketch allowClear={true}/>
|
} else if (item.type === 'icon') {
|
rules = [
|
{ required: item.required, message: '请选择' + 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
|
}
|
|
transfer = (options) => {
|
if (options.length === 0) return options
|
|
let isNumber = true
|
options.forEach(item => {
|
if (!item.Value || isNaN(item.Value)) {
|
isNumber = false
|
}
|
})
|
|
if (isNumber) {
|
return options.map(item => {
|
item.Value = +item.Value
|
return item
|
})
|
} else {
|
return options.map(item => {
|
item.Value = item.Value + ''
|
return item
|
})
|
}
|
}
|
|
transferCard = (options) => {
|
if (options.length === 0) return options
|
|
let isNumber = true
|
options.forEach(item => {
|
if (!/^([0-9]|[1-9]\d{0,2})$/.test(item.$value)) {
|
isNumber = false
|
}
|
})
|
|
if (isNumber) {
|
return options.map(item => {
|
item.$value = +item.$value
|
return item
|
})
|
} else {
|
return options.map(item => {
|
item.$value = item.$value + ''
|
return item
|
})
|
}
|
}
|
|
handleConfirm = (fields) => {
|
const { card } = this.props
|
// 表单提交时检查输入值是否正确
|
return new Promise((resolve, reject) => {
|
this.props.form.validateFieldsAndScroll((err, values) => {
|
if (!err) {
|
values.uuid = card.uuid
|
|
if (card.style) {
|
values.style = card.style
|
}
|
|
let fieldrepet = false // 字段重复
|
|
fields.forEach(item => {
|
if (item.uuid === card.uuid || !values.field || !item.field) return
|
if (item.field.toLowerCase() === values.field.toLowerCase()) {
|
fieldrepet = true
|
}
|
})
|
|
if (fieldrepet) {
|
notification.warning({
|
top: 92,
|
message: '字段已存在!',
|
duration: 10
|
})
|
return
|
}
|
|
// 下拉菜单或联动菜单
|
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'
|
}
|
|
values.options = this.transfer(values.options)
|
|
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
|
})
|
|
values.options = this.transferCard(values.options)
|
|
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
|
} else if (values.type === 'text') {
|
if (values.regularExtra) {
|
values.regularExtra = Array.from(new Set(values.regularExtra.split(''))).join('')
|
}
|
}
|
|
['linkField', 'valueField', 'valueText', 'orderBy'].forEach(item => {
|
if (values[item]) {
|
values[item] = values[item].replace(/\s+|\t+|\v+|\r+/ig, '')
|
}
|
})
|
|
let pass = checkSQL(values.dataSource)
|
|
if (!pass) return
|
|
window.GLOB.formId = card.uuid
|
|
if (['select', 'multiselect', 'link', 'checkbox', 'radio', 'checkcard'].includes(values.type) && values.resourceType === '1' && values.dataSource) {
|
let _option = Utils.getSelectQueryOptions(values)
|
|
let sql = `declare @mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20)
|
${_option.sql}`
|
|
// LoginUID|SessionUid|UserID|Appkey 已替换
|
sql = sql.replace(/@\$|\$@/ig, '')
|
|
let rduri = ''
|
if (window.GLOB.mainSystemApi && values.database === 'sso') {
|
rduri = window.GLOB.mainSystemApi
|
}
|
|
resolve({values, loading: true, promise: () => new Promise((resolve, reject) => {
|
Api.sDebug(sql, rduri).then(result => {
|
if (result.status || result.ErrCode === '-2') {
|
resolve()
|
} else {
|
Modal.error({
|
title: result.message
|
})
|
reject()
|
}
|
})
|
})})
|
} else if (values.type === 'popSelect') {
|
let arrfield = values.columns.map(f => f.field)
|
|
if (values.linkSubField && values.linkSubField.length > 0) {
|
values.linkSubField.forEach(n => {
|
if (!arrfield.includes(n)) {
|
arrfield.push(n)
|
}
|
})
|
}
|
|
let _datasource = values.dataSource
|
let sql = ''
|
|
if (/\s/.test(_datasource)) { // 拼接别名
|
_datasource = '(' + _datasource + ') tb'
|
}
|
|
arrfield = arrfield.join(',')
|
|
let _search = ''
|
|
if (values.searchKey) {
|
let fields = values.searchKey.split(',').map(field => field + ' like \'%mk%\'')
|
_search = 'where ' + fields.join(' OR ')
|
}
|
|
if (values.laypage === 'true') {
|
sql = `/*system_query*/select top 10 ${arrfield} from (select ${arrfield} ,ROW_NUMBER() over(order by ${values.order}) as rows from ${_datasource} ${_search}) tmptable where rows > 0 order by tmptable.rows `
|
} else if (values.order) {
|
sql = `/*system_query*/select ${arrfield} from (select ${arrfield} ,ROW_NUMBER() over(order by ${values.order}) as rows from ${_datasource} ${_search}) tmptable order by tmptable.rows `
|
} else {
|
sql = `/*system_query*/select ${arrfield} from ${_datasource} ${_search} `
|
}
|
|
sql = `declare @mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20)
|
${sql}`
|
|
sql = sql.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, `''`)
|
|
resolve({values, loading: true, promise: () => new Promise((resolve, reject) => {
|
Api.sDebug(sql).then(result => {
|
if (result.status || result.ErrCode === '-2') {
|
resolve()
|
} else {
|
Modal.error({
|
title: result.message
|
})
|
reject()
|
}
|
})
|
})})
|
} else {
|
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)
|