From 316877c1d9e5b6d92334f30b03d97d7e833cd934 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 02 二月 2021 16:01:57 +0800 Subject: [PATCH] 2021-02-02 --- src/tabviews/zshare/mutilform/index.jsx | 186 +++++++++++++++++++++++++++------------------- 1 files changed, 108 insertions(+), 78 deletions(-) diff --git a/src/tabviews/zshare/mutilform/index.jsx b/src/tabviews/zshare/mutilform/index.jsx index ce1485e..2c79f04 100644 --- a/src/tabviews/zshare/mutilform/index.jsx +++ b/src/tabviews/zshare/mutilform/index.jsx @@ -9,16 +9,17 @@ 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 = { @@ -39,7 +40,6 @@ writein: null, // 鎵ц鏃舵槸鍚﹀~鍏ラ粯璁ql fieldlen: null, // 瀛楁闀垮害 formlist: [], // 琛ㄥ崟椤� - encrypts: [], // 鍔犲瘑瀛楁 intercepts: [], // 鎴彇瀛楁 record: {} // 璁板綍涓嬫媺琛ㄥ崟鍏宠仈瀛楁锛岀敤浜庢暟鎹啓鍏� } @@ -68,7 +68,6 @@ let writein = {} let fieldlen = {} let formlist = [] - let encrypts = [] let intercepts = [] let _inputfields = [] @@ -99,9 +98,6 @@ _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) @@ -121,7 +117,7 @@ } 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 @@ -200,14 +196,7 @@ } } - // 鍔犲瘑瀛楁锛岃В瀵嗗鐞� - 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) { @@ -239,6 +228,10 @@ 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 @@ -260,14 +253,13 @@ }) 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') @@ -461,6 +453,7 @@ } return item }) + let values = [] this.setState({ formlist: _formlist.map(item => { @@ -469,8 +462,21 @@ } 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) }) }) } @@ -554,6 +560,7 @@ } return item }) + let values = [] this.setState({ formlist: _formlist.map(item => { @@ -562,8 +569,21 @@ } 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) }) }) } @@ -633,30 +653,18 @@ } 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({}, () => { @@ -1182,7 +1190,34 @@ }, ..._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> ) @@ -1194,7 +1229,6 @@ handleConfirm = () => { const { record, intercepts, writein } = this.state - let _encrypts = fromJS(this.state.encrypts).toJS() let _format = { date: 'YYYY-MM-DD', datemonth: 'YYYY-MM', @@ -1225,7 +1259,6 @@ let _val = item.initval if (record.hasOwnProperty(item.field)) { _val = record[item.field] - _encrypts = _encrypts.filter(_field => _field !== item.field) // 闅愯棌瀛楁锛屼笉鍙備笌鍔犲瘑澶勭悊 } _item = { @@ -1251,12 +1284,18 @@ 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) @@ -1279,19 +1318,20 @@ } 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) { @@ -1305,15 +1345,23 @@ } _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({ @@ -1326,23 +1374,6 @@ 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 { @@ -1373,7 +1404,6 @@ 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> ) } -- Gitblit v1.8.0