| | |
| | | import { formRule } from '@/utils/option.js' |
| | | import Utils from '@/utils/utils.js' |
| | | import asyncComponent from '@/utils/asyncComponent' |
| | | import asyncSpinComponent from '@/utils/asyncSpinComponent' |
| | | import './index.scss' |
| | | |
| | | const { MonthPicker } = DatePicker |
| | | const { TextArea } = Input |
| | | |
| | | const CheckCard = asyncComponent(() => import('./checkCard')) |
| | | const CustomSwitch = asyncComponent(() => import('./customSwitch')) |
| | | const CustomTextArea = asyncComponent(() => import('./customTextArea')) |
| | | const FileUpload = asyncComponent(() => import('../fileupload')) |
| | | const ColorSketch = asyncComponent(() => import('@/mob/colorsketch')) |
| | | // const Editor = asyncComponent(() => import('@/components/editor')) |
| | | const Editor = asyncSpinComponent(() => import('@/components/editor')) |
| | | |
| | | class MainSearch extends Component { |
| | | static propTpyes = { |
| | |
| | | writein: null, // 执行时是否填入默认sql |
| | | fieldlen: null, // 字段长度 |
| | | formlist: [], // 表单项 |
| | | encrypts: [], // 加密字段 |
| | | intercepts: [], // 截取字段 |
| | | record: {} // 记录下拉表单关联字段,用于数据写入 |
| | | } |
| | |
| | | let writein = {} |
| | | let fieldlen = {} |
| | | let formlist = [] |
| | | let encrypts = [] |
| | | let intercepts = [] |
| | | let _inputfields = [] |
| | | |
| | |
| | | _inputfields.push(item.field) |
| | | } else if (item.type === 'textarea') { |
| | | _inputfields.push(item.field) |
| | | if (item.encryption === 'true') { // 加密字段 |
| | | encrypts.push(item.field) |
| | | } |
| | | } else if (item.type === 'link') { |
| | | linkFields[item.linkField] = linkFields[item.linkField] || [] |
| | | linkFields[item.linkField].push(item.field) |
| | |
| | | } |
| | | |
| | | let _fieldlen = item.fieldlength || 50 |
| | | if (item.type === 'textarea' || item.type === 'fileupload' || item.type === 'multiselect') { |
| | | if (item.type === 'textarea' || item.type === 'fileupload' || item.type === 'multiselect' || item.type === 'brafteditor') { |
| | | _fieldlen = item.fieldlength || 512 |
| | | } else if (item.type === 'number') { |
| | | _fieldlen = item.decimal ? item.decimal : 0 |
| | |
| | | } |
| | | } |
| | | |
| | | // 加密字段,解密处理 |
| | | if (item.type === 'textarea' && item.encryption === 'true' && newval !== '') { |
| | | try { |
| | | newval = window.decodeURIComponent(window.atob(newval)) |
| | | } catch (e) { |
| | | console.warn(e) |
| | | } |
| | | } else if (item.type === 'switch' && newval !== '') { // 开关只接收固定值 |
| | | if (item.type === 'switch' && newval !== '') { // 开关只接收固定值 |
| | | if (newval !== item.closeVal && newval !== item.openVal) { |
| | | newval = '' |
| | | } else if (newval === item.openVal) { |
| | |
| | | |
| | | if (['select', 'link', 'multiselect', 'radio', 'checkbox', 'checkcard'].includes(item.type) && item.resourceType === '1') { |
| | | deForms.push(item) |
| | | } else if (['select', 'link', 'radio'].includes(item.type) && item.resourceType !== '1') { // 选中第一项 |
| | | if (item.initval && item.initval.indexOf('$first') > -1) { |
| | | item.initval = item.options[0] ? item.options[0].Value : '' |
| | | } |
| | | } |
| | | |
| | | return item |
| | |
| | | }) |
| | | |
| | | this.setState({ |
| | | readtype: readtype, |
| | | datatype: datatype, |
| | | readin: readin, |
| | | writein: writein, |
| | | fieldlen: fieldlen, |
| | | encrypts: encrypts, |
| | | intercepts: intercepts, |
| | | formlist: formlist |
| | | readin, |
| | | writein, |
| | | readtype, |
| | | datatype, |
| | | fieldlen, |
| | | intercepts, |
| | | formlist |
| | | }, () => { |
| | | if (action.setting && action.setting.focus) { |
| | | this.selectInput(action.setting.focus, 'init') |
| | |
| | | } |
| | | return item |
| | | }) |
| | | let values = [] |
| | | |
| | | this.setState({ |
| | | formlist: _formlist.map(item => { |
| | |
| | | } else if (['select', 'multiselect', 'radio', 'checkbox', 'checkcard'].includes(item.type)) { |
| | | item.options = item.oriOptions |
| | | } |
| | | if (['select', 'link', 'radio'].includes(item.type) && item.initval && item.initval.indexOf('$first') > -1) { // 选中第一项 |
| | | item.initval = item.options[0] ? item.options[0].Value : '' |
| | | values.push({field: item.field, value: item.initval}) |
| | | } |
| | | return item |
| | | }) |
| | | }, () => { |
| | | if (values.length === 0) return |
| | | let fieldsvalue = {} |
| | | values.forEach(item => { |
| | | if (this.props.form.getFieldValue(item.field) !== undefined) { |
| | | fieldsvalue[item.field] = item.value |
| | | } |
| | | }) |
| | | this.props.form.setFieldsValue(fieldsvalue) |
| | | }) |
| | | }) |
| | | } |
| | |
| | | } |
| | | return item |
| | | }) |
| | | let values = [] |
| | | |
| | | this.setState({ |
| | | formlist: _formlist.map(item => { |
| | |
| | | } else if (['select', 'multiselect', 'radio', 'checkbox', 'checkcard'].includes(item.type)) { |
| | | item.options = item.oriOptions |
| | | } |
| | | if (['select', 'link', 'radio'].includes(item.type) && item.initval && item.initval.indexOf('$first') > -1) { // 选中第一项 |
| | | item.initval = item.options[0] ? item.options[0].Value : '' |
| | | values.push({field: item.field, value: item.initval}) |
| | | } |
| | | return item |
| | | }) |
| | | }, () => { |
| | | if (values.length === 0) return |
| | | let fieldsvalue = {} |
| | | values.forEach(item => { |
| | | if (this.props.form.getFieldValue(item.field) !== undefined) { |
| | | fieldsvalue[item.field] = item.value |
| | | } |
| | | }) |
| | | this.props.form.setFieldsValue(fieldsvalue) |
| | | }) |
| | | }) |
| | | } |
| | |
| | | } |
| | | |
| | | if (subfields.length === 0) { |
| | | if (Object.keys(fieldsvalue).length > 0) { |
| | | this.props.form.setFieldsValue(fieldsvalue) |
| | | } |
| | | if (Object.keys(_record).length > 0) { |
| | | this.setState({ |
| | | record: {...record, ..._record} |
| | | }) |
| | | } |
| | | this.props.form.setFieldsValue(fieldsvalue) |
| | | this.setState({ |
| | | record: {...record, ..._record} |
| | | }) |
| | | } else { |
| | | let result = this.resetform(formlist, subfields, 0, fieldsvalue) |
| | | |
| | | if (Object.keys(result.fieldsvalue).length > 0) { |
| | | this.props.form.setFieldsValue(fieldsvalue) |
| | | } |
| | | |
| | | let _param = { |
| | | formlist: result.formlist |
| | | } |
| | | |
| | | if (Object.keys(_record).length > 0) { |
| | | _param.record = {...record, ..._record} |
| | | } |
| | | |
| | | this.setState(_param) |
| | | this.props.form.setFieldsValue(fieldsvalue) |
| | | this.setState({ |
| | | formlist: result.formlist, |
| | | record: {...record, ..._record} |
| | | }) |
| | | } |
| | | |
| | | this.setState({}, () => { |
| | |
| | | }, |
| | | ..._rules |
| | | ] |
| | | })(<TextArea autoSize={{ minRows: 2, maxRows: item.maxRows || 6 }} disabled={item.readonly === 'true'} />)} |
| | | })(<CustomTextArea Item={item} />)} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | } else if (item.type === 'brafteditor') { |
| | | let _max = item.fieldlength || 512 |
| | | |
| | | fields.push( |
| | | <Col span={24} key={index}> |
| | | <Form.Item label={item.hidelabel !== 'true' && item.tooltip ? |
| | | <Tooltip placement="topLeft" title={item.tooltip}> |
| | | <Icon type="question-circle" /> |
| | | {item.label} |
| | | </Tooltip> : (item.hidelabel !== 'true' ? item.label : '') |
| | | }> |
| | | {getFieldDecorator(item.field, { |
| | | initialValue: item.initval || '', |
| | | rules: [ |
| | | { |
| | | required: item.required === 'true', |
| | | message: this.props.dict['form.required.input'] + item.label + '!' |
| | | }, |
| | | { |
| | | max: _max, |
| | | message: formRule.input.formMessage.replace('@max', _max) |
| | | } |
| | | ] |
| | | })(<Editor Item={item}/>)} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | |
| | | |
| | | handleConfirm = () => { |
| | | const { record, intercepts, writein } = this.state |
| | | let _encrypts = fromJS(this.state.encrypts).toJS() |
| | | let _format = { |
| | | date: 'YYYY-MM-DD', |
| | | datemonth: 'YYYY-MM', |
| | |
| | | let _val = item.initval |
| | | if (record.hasOwnProperty(item.field)) { |
| | | _val = record[item.field] |
| | | _encrypts = _encrypts.filter(_field => _field !== item.field) // 隐藏字段,不参与加密处理 |
| | | } |
| | | |
| | | _item = { |
| | |
| | | |
| | | if (!_item) return |
| | | |
| | | if (item.type === 'date' || item.type === 'datemonth' || item.type === 'datetime') { |
| | | if (_item.value && _item.value.format) { |
| | | _item.value = _item.value.format(_format[item.type]) |
| | | } else if (!_item.value) { |
| | | if (_item.value === undefined) { |
| | | _item.value = '' |
| | | } else if (item.type === 'date' || item.type === 'datemonth' || item.type === 'datetime') { |
| | | if (!_item.value) { |
| | | _item.value = '' |
| | | } else if (_item.value.format) { |
| | | _item.value = _item.value.format(_format[item.type]) |
| | | } |
| | | } else if (item.type === 'text' && _item.value && typeof(_item.value) === 'string') { // 特殊字段替换 |
| | | _item.value = _item.value.replace(/^(\s*)@appkey@(\s*)$/ig, window.GLOB.appkey) |
| | | _item.value = _item.value.replace(/^(\s*)@SessionUid@(\s*)$/ig, (localStorage.getItem('SessionUid') || '')) |
| | | _item.value = _item.value.replace(/^(\s*)@bid@(\s*)$/ig, (this.props.BID || '')) |
| | | } |
| | | |
| | | search.push(_item) |
| | |
| | | } |
| | | |
| | | let _value = '' |
| | | if (this.state.datatype[key] === 'datetime') { |
| | | let _type = this.state.datatype[key] |
| | | if (_type === 'datetime') { |
| | | _value = values[key] ? moment(values[key]).format('YYYY-MM-DD HH:mm:ss') : '' |
| | | } else if (this.state.datatype[key] === 'datemonth') { |
| | | } else if (_type === 'datemonth') { |
| | | _value = values[key] ? moment(values[key]).format('YYYY-MM') : '' |
| | | } else if (this.state.datatype[key] === 'date') { |
| | | } else if (_type === 'date') { |
| | | _value = values[key] ? moment(values[key]).format('YYYY-MM-DD') : '' |
| | | } else if (this.state.datatype[key] === 'number') { |
| | | } else if (_type === 'number') { |
| | | _value = values[key] |
| | | |
| | | } else if (this.state.datatype[key] === 'multiselect' || this.state.datatype[key] === 'checkbox') { |
| | | } else if (_type === 'multiselect' || _type === 'checkbox') { |
| | | _value = values[key] ? values[key].join(',') : '' |
| | | |
| | | } else if (this.state.datatype[key] === 'fileupload') { |
| | | } else if (_type === 'fileupload') { |
| | | let vals = [] |
| | | |
| | | if (values[key] && values[key].length > 0) { |
| | |
| | | } |
| | | |
| | | _value = vals.join(',') |
| | | } else if (this.state.datatype[key] === 'text' || this.state.datatype[key] === 'textarea') { |
| | | } else if (_type === 'text' || _type === 'textarea') { |
| | | _value = values[key].replace(/\t*|\v*/g, '') // 去除制表符 |
| | | |
| | | if (intercepts.includes(key)) { // 去除首尾空格 |
| | | _value = _value.replace(/(^\s*|\s*$)/g, '') |
| | | } |
| | | if (_type === 'text' && _value) { // 特殊字段替换 |
| | | _value = _value.replace(/^(\s*)@appkey@(\s*)$/ig, window.GLOB.appkey) |
| | | _value = _value.replace(/^(\s*)@SessionUid@(\s*)$/ig, (localStorage.getItem('SessionUid') || '')) |
| | | _value = _value.replace(/^(\s*)@bid@(\s*)$/ig, (this.props.BID || '')) |
| | | } |
| | | } else { |
| | | _value = values[key] |
| | | |
| | | } |
| | | |
| | | if (_value === undefined) { |
| | | _value = '' |
| | | } |
| | | |
| | | search.push({ |
| | |
| | | value: _value |
| | | }) |
| | | }) |
| | | |
| | | // 含有加密字段时,对表单值进行加密 |
| | | if (_encrypts && _encrypts.length > 0) { |
| | | search = search.map(item => { |
| | | let _value = item.value |
| | | if (_encrypts.includes(item.key)) { |
| | | try { |
| | | _value = window.btoa(window.encodeURIComponent(_value)) |
| | | } catch (e) { |
| | | console.warn(e) |
| | | } |
| | | } |
| | | item.value = _value |
| | | |
| | | return item |
| | | }) |
| | | } |
| | | |
| | | resolve(search) |
| | | } else { |
| | |
| | | return ( |
| | | <Form {...formItemLayout} className="ant-advanced-search-form main-form-field" id="main-form-box"> |
| | | <Row className={'cols' + cols} gutter={24}>{this.getFields()}</Row> |
| | | {/* <Editor /> */} |
| | | </Form> |
| | | ) |
| | | } |