From 95afd40fc2741ac0ce59c2091f6cfce1f98877d4 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 24 六月 2021 09:15:45 +0800 Subject: [PATCH] 2021-06-24 --- src/templates/zshare/modalform/index.jsx | 231 +++++++++++++++++++++++++++++++++++---------------------- 1 files changed, 140 insertions(+), 91 deletions(-) diff --git a/src/templates/zshare/modalform/index.jsx b/src/templates/zshare/modalform/index.jsx index 3a241c3..2c30977 100644 --- a/src/templates/zshare/modalform/index.jsx +++ b/src/templates/zshare/modalform/index.jsx @@ -6,39 +6,43 @@ import { dateOptions } from '@/utils/option.js' import Utils from '@/utils/utils.js' import EditTable from './modaleditable' -import DataTable from './datatable' -import FieldsTable from './fieldtable' +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('./fieldtable')) +const DataTable = asyncComponent(() => import('./datatable')) const modalTypeOptions = { - text: ['initval', 'readonly', 'required', 'hidden', 'readin', 'fieldlength', 'regular', 'interception', 'entireLine', 'tooltip', 'enter'], - number: ['initval', 'readonly', 'hidden', 'decimal', 'min', 'max', 'readin', 'entireLine', 'tooltip', 'enter'], - select: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'setAll', 'linkSubField', 'entireLine', 'tooltip', 'emptyText', 'enter'], - checkbox: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'entireLine', 'tooltip'], - radio: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'linkSubField', 'entireLine', 'tooltip', 'setAll', 'emptyText'], - checkcard: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'linkSubField', 'fieldlength', 'display', 'tooltip', 'width', 'multiple'], - multiselect: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'fieldlength', 'entireLine', 'tooltip'], - link: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'setAll', 'linkField', 'entireLine', 'tooltip', 'emptyText', 'enter'], - fileupload: ['readonly', 'required', 'readin', 'fieldlength', 'maxfile', 'fileType', 'entireLine', 'tooltip', 'suffix'], - switch: ['initval', 'openVal', 'closeVal', 'openText', 'closeText', 'readonly', 'hidden', 'readin', 'entireLine', 'tooltip'], - date: ['initval', 'readonly', 'required', 'hidden', 'readin', 'entireLine', 'tooltip'], - datemonth: ['initval', 'readonly', 'required', 'hidden', 'readin', 'entireLine', 'tooltip'], - datetime: ['initval', 'readonly', 'required', 'hidden', 'readin', 'entireLine', 'tooltip'], - textarea: ['initval', 'readonly', 'required', 'hidden', 'readin', 'fieldlength', 'maxRows', 'encryption', 'interception', 'tooltip'], - color: ['initval', 'readonly', 'required', 'hidden', 'readin', 'entireLine', 'tooltip'], - hint: ['label', 'type', 'blacklist', 'message'], - brafteditor: ['required', 'hidelabel', 'hidden', 'readin', 'fieldlength', 'readonly', 'tooltip', 'encryption'], - funcvar: [], - linkMain: ['readonly', 'required', 'hidden', 'fieldlength', 'entireLine', 'tooltip'] + text: ['initval', 'readonly', 'required', 'hidden', 'readin', 'fieldlength', 'regular', 'interception', 'span', 'labelwidth', 'tooltip', 'extra', 'enter', 'cursor', 'scan'], + number: ['initval', 'readonly', 'hidden', 'decimal', 'min', 'max', 'readin', 'span', 'labelwidth', 'tooltip', 'extra', 'enter', 'cursor'], + select: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'setAll', 'linkSubField', 'span', 'labelwidth', 'tooltip', 'extra', 'emptyText', 'enter'], + checkbox: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'span', 'labelwidth', 'tooltip', 'extra'], + radio: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'linkSubField', 'span', 'labelwidth', 'tooltip', 'extra', 'setAll', 'emptyText'], + checkcard: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'linkSubField', 'fieldlength', 'span', 'labelwidth', 'display', 'tooltip', 'extra', 'width', 'multiple', 'borderColor'], + multiselect: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'fieldlength', 'span', 'labelwidth', 'tooltip', 'extra'], + link: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'setAll', 'linkField', 'span', 'labelwidth', 'tooltip', 'extra', 'emptyText', 'enter'], + fileupload: ['readonly', 'required', 'readin', 'fieldlength', 'maxfile', 'fileType', 'span', 'labelwidth', 'tooltip', 'extra', 'compress'], + switch: ['initval', 'openVal', 'closeVal', 'openText', 'closeText', 'readonly', 'hidden', 'readin', 'span', 'labelwidth', 'tooltip', 'extra'], + date: ['initval', 'readonly', 'required', 'hidden', 'readin', 'span', 'labelwidth', 'tooltip', 'extra', 'declareType', 'mode'], + datemonth: ['initval', 'readonly', 'required', 'hidden', 'readin', 'span', 'labelwidth', 'tooltip', 'extra', 'declareType'], + datetime: ['initval', 'readonly', 'required', 'hidden', 'readin', 'span', 'labelwidth', 'tooltip', 'extra', 'declareType', 'mode'], + textarea: ['initval', 'readonly', 'required', 'hidden', 'readin', 'fieldlength', 'span', 'labelwidth', 'maxRows', 'encryption', 'interception', 'tooltip', 'extra', 'count'], + color: ['initval', 'readonly', 'required', 'hidden', 'readin', 'span', 'labelwidth', 'tooltip', 'extra'], + hint: ['label', 'type', 'blacklist', 'message', 'span', 'labelwidth'], + split: ['label', 'type'], + brafteditor: ['required', 'hidelabel', 'hidden', 'readin', 'fieldlength', 'readonly', 'span', 'labelwidth', 'tooltip', 'extra', 'encryption'], + funcvar: ['span', 'labelwidth'], + linkMain: ['readonly', 'required', 'hidden', 'fieldlength', 'span', 'labelwidth', 'tooltip', 'extra'] } class MainSearch extends Component { static propTpyes = { dict: PropTypes.object, // 瀛楀吀椤� formlist: PropTypes.any, + standardform: PropTypes.any, card: PropTypes.object, inputSubmit: PropTypes.any } @@ -47,6 +51,7 @@ openType: null, resourceType: null, supField: '', + compress: 'false', display: 'text', enter: '', cFields: [], @@ -56,11 +61,11 @@ UNSAFE_componentWillMount () { let formlist = fromJS(this.props.formlist).toJS() - let type = '' let resourceType = '' let supField = '' let display = '' + let compress = 'false' let enter = '' let cFields = [] let linkSubFields = [] @@ -68,6 +73,8 @@ formlist.forEach(cell => { if (cell.key === 'type') { type = cell.initVal + } else if (cell.key === 'compress') { + compress = cell.initVal } else if (cell.key === 'display') { display = cell.initVal } else if (cell.key === 'enter') { @@ -91,10 +98,11 @@ } }) - let _options = this.getOptions(type, resourceType, supField, display, enter) + let _options = this.getOptions(type, resourceType, supField, display, enter, compress) this.setState({ enter: enter, + compress: compress, openType: type, supField: supField, display: display, @@ -142,11 +150,13 @@ } } - getOptions = (type, resourceType, supField, display, enter) => { + getOptions = (type, resourceType, supField, display, enter, compress) => { let _options = ['label', 'field', 'type', 'blacklist', 'writein', ...fromJS(modalTypeOptions[type]).toJS()] if (type === 'hint') { _options = fromJS(modalTypeOptions[type]).toJS() + } else if (type === 'split') { + return fromJS(modalTypeOptions[type]).toJS() } else if (['multiselect', 'select', 'link', 'radio', 'checkbox'].includes(type)) { if (resourceType === '0') { // 鑷畾涔夎祫婧� _options.push('options') @@ -162,10 +172,16 @@ } } else { if (resourceType === '0') { // 鑷畾涔夎祫婧� - _options.push('options', 'fields') + _options.push('options', 'fields', 'backgroundColor') } else if (resourceType === '1') { // 鏁版嵁婧� - _options.push('dataSource', 'cardValField', 'fields', 'orderBy', 'orderType', 'database') + _options.push('dataSource', 'cardValField', 'fields', 'orderBy', 'orderType', 'database', 'backgroundColor') } + } + } else if (type === 'fileupload') { + if (compress === 'true') { + _options.push('limit', 'rduri', 'proRduri') + } else { + _options.push('suffix') } } @@ -198,8 +214,7 @@ fieldValue.enter = 'false' } - let _options = this.getOptions(value, this.state.resourceType, this.state.supField, this.state.display, enter) - + let _options = this.getOptions(value, this.state.resourceType, this.state.supField, this.state.display, enter, this.state.compress) this.setState({ openType: value, @@ -232,7 +247,9 @@ } } else if (form.key === 'fieldlength') { form.initVal = 50 - if (value === 'textarea' || value === 'fileupload' || value === 'multiselect' || value === 'checkbox') { + if (value === 'textarea' || value === 'brafteditor') { + form.initVal = 8000 + } else if (value === 'fileupload' || value === 'multiselect' || value === 'checkbox') { form.initVal = 512 } @@ -259,6 +276,10 @@ } else if (form.key === 'encryption') { if (value === 'brafteditor') { fieldValue.encryption = 'true' + } + } else if (form.key === 'hidden') { + if (value === 'linkMain') { + fieldValue.hidden = 'true' } } @@ -306,10 +327,10 @@ } onChange = (e, key) => { - const { openType } = this.state + const { openType, compress } = this.state let value = e.target.value if (key === 'resourceType') { - let _options = this.getOptions(openType, value, this.state.supField, this.state.display, this.state.enter) + let _options = this.getOptions(openType, value, this.state.supField, this.state.display, this.state.enter, compress) this.setState({ resourceType: value, @@ -319,7 +340,7 @@ }) }) } else if (key === 'display') { - let _options = this.getOptions(openType, this.state.resourceType, this.state.supField, value, this.state.enter) + let _options = this.getOptions(openType, this.state.resourceType, this.state.supField, value, this.state.enter, compress) this.setState({ display: value, @@ -328,8 +349,18 @@ return form }) }) + } else if (key === 'compress') { + let _options = this.getOptions(openType, this.state.resourceType, this.state.supField, this.state.display, this.state.enter, value) + + this.setState({ + compress: value, + formlist: this.state.formlist.map(form => { + form.show = _options.includes(form.key) + return form + }) + }) } else if (key === 'enter') { - let _options = this.getOptions(openType, this.state.resourceType, this.state.supField, this.state.display, value) + let _options = this.getOptions(openType, this.state.resourceType, this.state.supField, this.state.display, value, compress) this.setState({ enter: value, @@ -359,6 +390,50 @@ }) } + 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() @@ -373,7 +448,7 @@ const fields = [] this.state.formlist.forEach((item, index) => { - if (!item.show) return + if (!item.show || item.forbid) return null if (item.type === 'text') { // 鏂囨湰鎼滅储 let rules = [] @@ -415,10 +490,15 @@ </Col> ) } else if (item.type === 'number') { - if (item.key === 'decimal') { + if (item.max) { fields.push( <Col span={12} key={index}> - <Form.Item label={item.label}> + <Form.Item label={item.tooltip ? + <Tooltip placement="topLeft" title={item.tooltip}> + <Icon type="question-circle" /> + {item.label} + </Tooltip> : item.label + }> {getFieldDecorator(item.key, { initialValue: item.initVal || 0, rules: [ @@ -427,50 +507,18 @@ message: this.props.dict['form.required.input'] + item.label + '!' } ] - })(<InputNumber min={0} max={18} precision={0} />)} + })(<InputNumber onChange={(value) => this.changeVal(value, item.key)} min={item.min} max={item.max} precision={item.precision} onPressEnter={this.handleSubmit}/>)} </Form.Item> </Col> ) - } else if (item.key === 'fieldlength' || item.key === 'maxfile') { + } else { fields.push( <Col span={12} key={index}> - <Form.Item label={item.label}> - {getFieldDecorator(item.key, { - initialValue: item.initVal, - rules: [ - { - required: !!item.required, - message: this.props.dict['form.required.input'] + item.label + '!' - } - ] - })(<InputNumber min={1} precision={0} />)} - </Form.Item> - </Col> - ) - } else if (item.key === 'maxRows') { - fields.push( - <Col span={12} key={index}> - <Form.Item label={item.label}> - {getFieldDecorator(item.key, { - initialValue: item.initVal, - rules: [ - { - required: !!item.required, - message: this.props.dict['form.required.input'] + item.label + '!' - } - ] - })(<InputNumber min={2} max={100} precision={0} />)} - </Form.Item> - </Col> - ) - } else if (item.key === 'width') { - fields.push( - <Col span={12} key={index}> - <Form.Item label={ + <Form.Item label={item.tooltip ? <Tooltip placement="topLeft" title={item.tooltip}> <Icon type="question-circle" /> {item.label} - </Tooltip> + </Tooltip> : item.label }> {getFieldDecorator(item.key, { initialValue: item.initVal, @@ -480,23 +528,7 @@ message: this.props.dict['form.required.input'] + item.label + '!' } ] - })(<InputNumber min={1} max={24} precision={0} />)} - </Form.Item> - </Col> - ) - } else { - fields.push( - <Col span={12} key={index}> - <Form.Item label={item.label}> - {getFieldDecorator(item.key, { - initialValue: item.initVal, - rules: [ - { - required: !!item.required, - message: this.props.dict['form.required.input'] + item.label + '!' - } - ] - })(<InputNumber />)} + })(<InputNumber onPressEnter={this.handleSubmit}/>)} </Form.Item> </Col> ) @@ -611,7 +643,12 @@ } else if (item.type === 'textarea') { fields.push( <Col span={24} key={index}> - <Form.Item className="text-msg" label={item.label}> + <Form.Item className="text-msg" label={item.tooltip ? + <Tooltip placement="topLeft" overlayClassName={item.tooltipClass} title={item.tooltip}> + <Icon type="question-circle" /> + {item.label} + </Tooltip> : item.label + }> {getFieldDecorator(item.key, { initialValue: item.initVal, rules: [ @@ -620,7 +657,7 @@ message: this.props.dict['form.required.input'] + item.label + '!' } ] - })(<TextArea rows={4} />)} + })(<TextArea rows={item.rows || 4} />)} </Form.Item> </Col> ) @@ -653,6 +690,16 @@ {getFieldDecorator(item.key, { initialValue: item.initVal })(<FieldsTable dict={this.props.dict} onChange={this.changeField}/>)} + </Form.Item> + </Col> + ) + } else if (item.type === 'color') { + fields.push( + <Col span={12} key={index}> + <Form.Item label={item.label} className="color-form-item"> + {getFieldDecorator(item.key, { + initialValue: item.initVal + })(<ColorSketch allowClear={true}/>)} </Form.Item> </Col> ) @@ -708,6 +755,8 @@ } } else if (values.type === 'linkMain') { values.initval = '' + } else if (values.type === 'split') { + values.span = 24 } ['linkField', 'valueField', 'valueText', 'orderBy'].forEach(item => { -- Gitblit v1.8.0