From f895e8af9e6a393f71fec0dc26fdf1b9b6616cb4 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 11 十二月 2020 18:53:04 +0800 Subject: [PATCH] 2020-12-11 --- src/tabviews/zshare/mutilform/index.jsx | 93 ++++++++++++++++++++++++++++++++++------------ 1 files changed, 69 insertions(+), 24 deletions(-) diff --git a/src/tabviews/zshare/mutilform/index.jsx b/src/tabviews/zshare/mutilform/index.jsx index aeaf147..ee8a26d 100644 --- a/src/tabviews/zshare/mutilform/index.jsx +++ b/src/tabviews/zshare/mutilform/index.jsx @@ -130,7 +130,8 @@ item.options.unshift({ key: Utils.getuuid(), Value: '', - Text: item.emptyText || '绌�' + Text: item.emptyText || '绌�', + ParentID: '' }) } @@ -245,7 +246,7 @@ item.supInitVal = data[item.linkField] } - item.options = item.oriOptions.filter(option => option.ParentID === item.supInitVal) + item.options = item.oriOptions.filter(option => option.ParentID === item.supInitVal || option.Value === '') } return item }) @@ -261,17 +262,7 @@ formlist: formlist }, () => { if (action.setting && action.setting.focus) { - try { - let _form = document.getElementById('main-form-box') - let _item = _form.getElementsByTagName('input') - _item = [..._item] - _item.forEach(input => { - if (!input || input.id !== action.setting.focus) return - input.select() - }) - } catch { - console.warn('focus error锛�') - } + this.selectInput(action.setting.focus, 'init') } // 鐢ㄦ潵鏇存柊state锛岄槻姝㈠彈鎺ц〃鍗曞垵濮嬫椂涓嶆樉绀� this.setState({ @@ -279,6 +270,28 @@ }) this.improveActionForm(deForms) }) + } + + selectInput = (selectId, type) => { + try { + let _form = document.getElementById('main-form-box') + let _inputs = _form.getElementsByTagName('input') + _inputs = [..._inputs] + _inputs.forEach(input => { + if (!input || input.id !== selectId) return + + if (input.className === 'ant-select-search__field' && type !== 'init') { + let div = document.getElementById(input.id) + div && div.click && div.click() + } else if (input.select) { + input.select() + } else if (input.focus) { + input.focus() + } + }) + } catch { + console.warn('focus error锛�') + } } /** @@ -438,7 +451,7 @@ this.setState({ formlist: _formlist.map(item => { if (item.type === 'link') { - item.options = item.oriOptions.filter(option => option.ParentID === item.supInitVal) + item.options = item.oriOptions.filter(option => option.ParentID === item.supInitVal || option.Value === '') } else if (['select', 'multiselect', 'radio', 'checkbox', 'checkcard'].includes(item.type)) { item.options = item.oriOptions } @@ -531,7 +544,7 @@ this.setState({ formlist: _formlist.map(item => { if (item.type === 'link') { - item.options = item.oriOptions.filter(option => option.ParentID === item.supInitVal) + item.options = item.oriOptions.filter(option => option.ParentID === item.supInitVal || option.Value === '') } else if (['select', 'multiselect', 'radio', 'checkbox', 'checkcard'].includes(item.type)) { item.options = item.oriOptions } @@ -549,7 +562,7 @@ formlist = formlist.map(item => { if (item.type === 'link' && item.linkField === supfield.field) { - item.options = item.oriOptions.filter(option => option.ParentID === supfield.initval) + item.options = item.oriOptions.filter(option => option.ParentID === supfield.initval || option.Value === '') item.initval = item.options[0] ? item.options[0].Value : '' if (this.props.form.getFieldValue(item.field) !== undefined) { @@ -572,13 +585,13 @@ selectChange = (_field, value) => { const { record } = this.state let formlist = fromJS(this.state.formlist).toJS() - let subfields = [] let fieldsvalue = {} let _record = {} + formlist = formlist.map(item => { if (item.type === 'link' && item.linkField === _field.field) { - item.options = item.oriOptions.filter(option => option.ParentID === value) + item.options = item.oriOptions.filter(option => option.ParentID === value || option.Value === '') item.initval = item.options[0] ? item.options[0].Value : '' if (this.props.form.getFieldValue(item.field) !== undefined) { @@ -631,6 +644,16 @@ this.setState(_param) } + + this.setState({}, () => { + if (!_field.enter || _field.enter === 'false') return + + if (_field.enter === 'tab') { + this.selectInput(_field.tabField) + } else if (_field.enter === 'sub') { + this.handleSubmit() + } + }) } handleConfirmPassword = (rule, value, callback, item) => { @@ -643,8 +666,30 @@ callback(item.label + '鏈�澶у�间负 ' + item.max) } } - callback() + } + + handleChange = (e, item) => { + let val = e.target.value + + if (item.enter === 'false') return + if (!val || !/\n/ig.test(val)) return + if (item.enter === 'tab') { + this.selectInput(item.tabField) + } else { + this.handleSubmit(e) + this.selectInput(item.tabField || item.field) + } + } + + handleInputSubmit = (e, item) => { + if (item.enter === 'false') return + if (item.enter === 'tab') { + this.selectInput(item.tabField) + } else { + this.handleSubmit(e) + this.selectInput(item.tabField || item.field) + } } getFields() { @@ -737,7 +782,7 @@ }, ..._rules ] - })(<Input placeholder="" autoComplete="off" disabled={item.readonly === 'true'} onPressEnter={this.handleSubmit} />)} + })(<Input placeholder="" autoComplete="off" disabled={item.readonly === 'true'} onChange={(e) => this.handleChange(e, item)} onPressEnter={(e) => this.handleInputSubmit(e, item)} />)} </Form.Item> </Col> ) @@ -766,8 +811,8 @@ ] })( precision === null ? - <InputNumber disabled={item.readonly === 'true'} onPressEnter={this.handleSubmit} /> : - <InputNumber precision={precision} disabled={item.readonly === 'true'} onPressEnter={this.handleSubmit} /> + <InputNumber disabled={item.readonly === 'true'} onPressEnter={(e) => this.handleInputSubmit(e, item)} /> : + <InputNumber precision={precision} disabled={item.readonly === 'true'} onPressEnter={(e) => this.handleInputSubmit(e, item)} /> )} </Form.Item> </Col> @@ -915,7 +960,7 @@ showSearch allowClear={true} filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} - onChange={(value) => {this.selectChange(item, value)}} + onSelect={(value) => {this.selectChange(item, value)}} disabled={item.readonly === 'true'} > {item.options.map(option => @@ -1285,7 +1330,7 @@ } handleSubmit = (e) => { - e.preventDefault() + e && e.preventDefault() this.props.inputSubmit() } -- Gitblit v1.8.0