| | |
| | | |
| | | import { dateOptions, matchReg, formRule } from '@/utils/option.js' |
| | | import Utils from '@/utils/utils.js' |
| | | import { checkSQL } from '@/utils/utils-custom.js' |
| | | import CodeMirror from '@/templates/zshare/codemirror' |
| | | import asyncComponent from '@/utils/asyncComponent' |
| | | import './index.scss' |
| | |
| | | |
| | | const searchTypeOptions = { |
| | | text: ['label', 'field', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'inputType', 'advanced', 'query', 'labelwidth'], |
| | | select: ['label', 'field', 'resourceType', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced', 'setAll', 'dropdown', 'query', 'labelwidth'], |
| | | radio: ['label', 'field', 'resourceType', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced', 'setAll', 'query', 'labelwidth'], |
| | | select: ['label', 'field', 'resourceType', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced', 'dropdown', 'query', 'labelwidth'], |
| | | radio: ['label', 'field', 'resourceType', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced', 'query', 'labelwidth'], |
| | | multiselect: ['label', 'field', 'resourceType', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced', 'query', 'labelwidth'], |
| | | link: ['label', 'field', 'resourceType', 'initval', 'type', 'linkField', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced', 'setAll', 'dropdown', 'query', 'labelwidth'], |
| | | link: ['label', 'field', 'resourceType', 'initval', 'type', 'linkField', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced', 'dropdown', 'query', 'labelwidth'], |
| | | date: ['label', 'field', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced', 'query', 'precision', 'labelwidth'], |
| | | checkcard: ['label', 'field', 'initval', 'type', 'match', 'ratio', 'blacklist', 'resourceType', 'display', 'width', 'multiple', 'required', 'Hide', 'labelShow', 'advanced', 'query', 'labelwidth'], |
| | | dateweek: ['label', 'field', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced', 'query', 'labelwidth'], |
| | |
| | | group: ['label', 'type', 'field', 'datefield', 'initval', 'blacklist', 'ratio', 'items', 'required', 'labelShow', 'query', 'labelwidth'], |
| | | switch: ['label', 'field', 'initval', 'type', 'match', 'ratio', 'blacklist', 'openVal', 'closeVal', 'openText', 'closeText', 'Hide', 'labelShow', 'advanced', 'query', 'labelwidth'], |
| | | check: ['label', 'field', 'initval', 'type', 'match', 'ratio', 'blacklist', 'openVal', 'closeVal', 'checkTip', 'Hide', 'labelShow', 'advanced', 'query', 'labelwidth'], |
| | | range: ['label', 'type', 'field', 'initval', 'match', 'blacklist', 'Hide', 'required', 'maxValue', 'minValue', 'step', 'labelShow', 'query', 'labelwidth'] |
| | | range: ['label', 'type', 'field', 'initval', 'match', 'ratio', 'blacklist', 'Hide', 'required', 'maxValue', 'minValue', 'step', 'labelShow', 'query', 'labelwidth', 'advanced'] |
| | | } |
| | | |
| | | class MainSearch extends Component { |
| | |
| | | if (this.record.selectStyle === 'custom') { |
| | | shows.push('backgroundColor') |
| | | } |
| | | if (this.record.multiple === 'dropdown' && this.record.resourceType === '1') { |
| | | shows.push('mark', 'parentField') |
| | | if (this.record.multiple === 'dropdown') { |
| | | shows.push('mark') |
| | | if (this.record.resourceType === '1') { |
| | | shows.push('parentField') |
| | | } |
| | | } |
| | | } |
| | | shows.push('linkField') |
| | | reRequired.linkField = false |
| | | } else if (type === 'daterange' || type === 'datemonth') { |
| | | if (this.record.initval) { |
| | | shows.push('dateShift') |
| | | } |
| | | } |
| | | |
| | | if (dateOptions.hasOwnProperty(type)) { // 根据搜索条件类型,选择初始值的类型及数据 |
| | |
| | | reTypes.initval = 'text' |
| | | } |
| | | |
| | | reTooltip.match = '' |
| | | if (type === 'text') { |
| | | reOptions.match = matchReg.class1 |
| | | } else if (type === 'multiselect') { |
| | |
| | | reOptions.match = matchReg.class1 |
| | | } else if (type === 'switch' || type === 'check') { |
| | | reOptions.match = matchReg.class2 |
| | | if (type === 'switch') { |
| | | reLabel.openVal = '开启值' |
| | | reLabel.closeVal = '关闭值' |
| | | } else { |
| | | reLabel.openVal = '勾选值' |
| | | reLabel.closeVal = '不勾选值' |
| | | } |
| | | } else if (type === 'date') { |
| | | reOptions.match = matchReg.class4 |
| | | } else if (type === 'datemonth') { |
| | | reOptions.match = matchReg.class5 |
| | | reTooltip.match = '匹配模式为 between 时,搜索条件为大于月初小于月末,匹配模式为 = 时,搜索条件为等于当前月(YYYY-MM)。' |
| | | reOptions.match = matchReg.class6 |
| | | } else if (type === 'dateweek' || type === 'daterange' || type === 'range') { |
| | | reOptions.match = matchReg.class5 |
| | | } else if (type === 'checkcard') { |
| | | if (this.record.multiple === 'false') { |
| | | if (this.record.multiple === 'false' || this.record.multiple === 'dropdown') { |
| | | reOptions.match = matchReg.class1 |
| | | } else if (this.record.multiple === 'true') { |
| | | reOptions.match = matchReg.class3 |
| | |
| | | } else if (type === 'group') { |
| | | reTooltip.field = '查询数据时(自定义脚本或统计数据源),类型字段将用作替换脚本中的 @字段@ ,类型字段对应值为:日 -> day;周 -> week;月 -> month;季 -> quarter;年 -> year;自定义 -> customized' |
| | | reLabel.field = '类型字段' |
| | | } |
| | | |
| | | reTooltip.initval = '' |
| | | if (type === 'select') { |
| | | if (this.record.resourceType === '0') { |
| | | reTooltip.initval = '初始值应为数据的Value值,可使用@username@、@fullName@' |
| | | } else if (this.record.resourceType === '1') { |
| | | reTooltip.initval = '初始值应为《值·字段》的值,可使用@username@、@fullName@、$first。注:使用$first时,搜索条件应为必填。' |
| | | } |
| | | } else if (type === 'link') { |
| | | if (this.record.resourceType === '0') { |
| | | reTooltip.initval = '初始值应为数据的Value值。' |
| | | } else if (this.record.resourceType === '1') { |
| | | reTooltip.initval = '初始值应为《值·字段》的值,可使用$first。注:使用$first时,搜索条件应为必填。' |
| | | } |
| | | } else if (type === 'text') { |
| | | reTooltip.initval = '可使用@username@、@fullName@。' |
| | | } else if (type === 'range') { |
| | | reTooltip.initval = '使用逗号拼接,例如 3,10' |
| | | } |
| | | |
| | | return { |
| | |
| | | rules = [ |
| | | { required: item.required, message: '请输入' + item.label + '!' } |
| | | ] |
| | | if (item.key === 'field' || item.key === 'datefield') { |
| | | if (item.key === 'field' || item.key === 'datefield' || item.key === 'dateShift') { |
| | | rules.push({ |
| | | pattern: (type === 'text' || type === 'select' || type === 'daterange') ? formRule.field.multipattern : formRule.field.pattern, |
| | | message: formRule.field.message |
| | |
| | | { required: item.required, message: '请输入' + 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> |
| | | } |
| | | if (item.placeholder) { |
| | | className = 'show-public-var' |
| | | extra = <><span className="resource-public-var">{item.placeholder}</span>{extra}</> |
| | | } |
| | | |
| | | content = <CodeMirror /> |
| | | } else if (item.type === 'options') { |
| | | span = 24 |
| | | className = 'text-area' |
| | | |
| | | let type = this.record.type |
| | | |
| | |
| | | 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 => { |
| | |
| | | } |
| | | } else if (item.type === 'fields') { |
| | | span = 24 |
| | | className = 'text-area' |
| | | |
| | | rules = [ |
| | | { required: item.required, message: '请添加' + item.label + '!' } |
| | |
| | | ] |
| | | |
| | | content = <Checkbox.Group style={{width: '105%'}} options={item.options} onChange={(values) => this.optionChange(item.key, values)}/> |
| | | } else if (item.type === 'multiselect') { // 多选 |
| | | } else if (item.type === 'multiselect') { |
| | | content = <Select |
| | | showSearch |
| | | mode="multiple" |
| | |
| | | <Select.Option id={i} key={i} value={option.value}>{option.text}</Select.Option> |
| | | )} |
| | | </Select> |
| | | } else if (item.type === 'cascader') { // 多选 |
| | | content = <Cascader options={item.options} placeholder="" /> |
| | | } else if (item.type === 'cascader') { |
| | | content = <Cascader options={item.options} /> |
| | | } else if (item.type === 'color') { |
| | | className = 'color-form-item' |
| | | rules = [ |
| | |
| | | fields.push( |
| | | <Col span={span} key={index}> |
| | | <Form.Item className={className} extra={extra} label={item.tooltip ? |
| | | <Tooltip placement="topLeft" title={item.tooltip}> |
| | | <Tooltip placement="topLeft" title={<div onClick={(e) => e.stopPropagation()}>{item.tooltip}</div>}> |
| | | <QuestionCircleOutlined className="mk-form-tip" /> |
| | | {item.label} |
| | | </Tooltip> : item.label |
| | |
| | | values.field.length = 2 |
| | | } |
| | | values.field = values.field.join(',') |
| | | } |
| | | |
| | | if (['select', 'link'].includes(values.type)) { |
| | | if (values.resourceType === '1') { |
| | | if (/\$first/.test(values.initval) && values.initval.replace(/\s/g, '') === '$first') { |
| | | values.initval = '$first' |
| | | } |
| | | |
| | | if (values.initval === '$first' && values.required !== 'true') { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '使用$first时,搜索条件应为必填!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 下拉菜单或联动菜单 |
| | |
| | | |
| | | if (values.type === 'range') { |
| | | let error = '' |
| | | if (values.maxValue <= values.minValue) { |
| | | error = '最大值必须大于最小值' |
| | | } else if (values.step <= 0) { |
| | | error = '步长必须大于0' |
| | | } else { |
| | | let s = (values.maxValue - values.minValue) / values.step |
| | | if (s !== parseInt(s)) { |
| | | error = '步长必须被 (max - min) 整除' |
| | | if (sessionStorage.getItem('appType') === 'mob') { |
| | | if (values.maxValue <= values.minValue) { |
| | | error = '最大值必须大于最小值' |
| | | } else if (values.step <= 0) { |
| | | error = '步长必须大于0' |
| | | } else { |
| | | let s = (values.maxValue - values.minValue) / values.step |
| | | if (s !== parseInt(s)) { |
| | | error = '步长必须被 (max - min) 整除' |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (!error && values.initval) { |
| | | if (!error && values.initval) { |
| | | let vals = values.initval.split(',') |
| | | if (vals.length !== 2) { |
| | | error = '初始值设置错误!' |
| | | } else if (isNaN(parseFloat(vals[0])) || isNaN(parseFloat(vals[1]))) { |
| | | error = '初始值设置错误!' |
| | | } else { |
| | | let start = parseFloat(vals[0]) |
| | | let end = parseFloat(vals[1]) |
| | | let s = (values.maxValue - start) / values.step |
| | | let e = (values.maxValue - end) / values.step |
| | | if (start > end || start < values.minValue || end > values.maxValue) { |
| | | error = '初始值设置错误!' |
| | | } else if (s !== parseInt(s) || e !== parseInt(e)) { |
| | | error = '初始值设置错误!' |
| | | } |
| | | } |
| | | } |
| | | } else if (values.initval) { |
| | | let vals = values.initval.split(',') |
| | | if (vals.length !== 2) { |
| | | error = '初始值设置错误!' |
| | | } else if (isNaN(parseFloat(vals[0])) || isNaN(parseFloat(vals[1]))) { |
| | | error = '初始值设置错误!' |
| | | } else { |
| | | let start = parseFloat(vals[0]) |
| | | let end = parseFloat(vals[1]) |
| | | let s = (values.maxValue - start) / values.step |
| | | let e = (values.maxValue - end) / values.step |
| | | if (start > end || start < values.minValue || end > values.maxValue) { |
| | | error = '初始值设置错误!' |
| | | } else if (s !== parseInt(s) || e !== parseInt(e)) { |
| | | error = '初始值设置错误!' |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (error) { |
| | | notification.warning({ |
| | | top: 92, |
| | |
| | | } |
| | | }) |
| | | |
| | | let error = Utils.verifySql(values.dataSource) |
| | | let pass = checkSQL(values.dataSource) |
| | | |
| | | if (error) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '数据源中不可使用' + error, |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } |
| | | if (!pass) return |
| | | |
| | | resolve(values) |
| | | } else { |