From 5046d0d13dc6a8563b8e54e31913bc44cfa1072f Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 26 四月 2022 19:23:18 +0800 Subject: [PATCH] 2022-04-26 --- src/menu/components/table/edit-table/columns/editColumn/index.jsx | 405 +++++++++++++++++++++++++++++---------------------------- 1 files changed, 207 insertions(+), 198 deletions(-) diff --git a/src/menu/components/table/edit-table/columns/editColumn/index.jsx b/src/menu/components/table/edit-table/columns/editColumn/index.jsx index d664236..ca299fb 100644 --- a/src/menu/components/table/edit-table/columns/editColumn/index.jsx +++ b/src/menu/components/table/edit-table/columns/editColumn/index.jsx @@ -6,7 +6,10 @@ import { getColumnForm } from './formconfig' import { formRule } from '@/utils/option.js' +import CodeMirror from '@/templates/zshare/codemirror' +import EditTable from '@/templates/zshare/modalform/modaleditable' import './index.scss' + const { TextArea } = Input const columnTypeOptions = { @@ -32,7 +35,19 @@ state = { visible: false, - formlist: null + formlist: null, + transfield: {} + } + + column = null + + UNSAFE_componentWillMount() { + let transfield = {} + this.props.columns.forEach(item => { + transfield[item.field] = item.label + }) + + this.setState({transfield}) } UNSAFE_componentWillReceiveProps (nextProps) { @@ -41,22 +56,45 @@ } } - editColumn = (column) => { - let formlist = getColumnForm(column, this.props.fields, this.props.columns) - let _options = fromJS(columnTypeOptions[column.type]).toJS() + getOptions = () => { + let _options = fromJS(columnTypeOptions[this.column.type]).toJS() - if (column.editable === 'true') { - if (column.type === 'text') { - _options.push('required', 'enter', 'footEnter') - } else if (column.type === 'number') { - _options.push('max', 'min', 'enter', 'footEnter') + if (this.column.editable === 'true') { + if (this.column.type === 'text') { + _options.push('editType') + + if (this.column.editType === 'switch') { + _options.push('enter', 'openVal', 'closeVal', 'openText', 'closeText', 'editField') + } else if (this.column.editType === 'select') { + _options.push('required', 'enter', 'resourceType', 'linkSubField', 'editField', 'dropdown') + + if (this.column.resourceType === '0') { + _options.push('options') + } else { + _options.push('dataSource', 'valueField', 'valueText', 'orderBy', 'orderType', 'disableField', 'database') + } + } else { + _options.push('required', 'enter') + } + } else if (this.column.type === 'number') { + _options.push('max', 'min', 'enter') } } + return _options + } + + editColumn = (column) => { + let formlist = getColumnForm(column, this.props.fields, this.props.columns) + + this.column = fromJS(column).toJS() + this.column.editType = this.column.editType || 'text' + this.column.resourceType = this.column.resourceType || '0' + + let _options = this.getOptions() + this.setState({ visible: true, - editable: column.editable || 'false', - type: column.type, formlist: formlist.map(item => { item.hidden = !_options.includes(item.key) @@ -76,24 +114,14 @@ } typeChange = (key, value, option) => { - const { editable, type } = this.state - if (key === 'type') { - let _options = fromJS(columnTypeOptions[value]).toJS() + this.column[key] = value - if (editable === 'true') { - if (value === 'text') { - _options.push('required', 'enter', 'footEnter') - } else if (value === 'number') { - _options.push('max', 'min', 'enter', 'footEnter') - } - } + if (key === 'type') { + let _options = this.getOptions() this.setState({ - type: value, formlist: this.state.formlist.map(item => { - if (item.key === 'editable') { - item.initVal = editable - } + item.initVal = this.column[item.key] || item.initVal item.hidden = !_options.includes(item.key) return item @@ -116,23 +144,15 @@ values.type = 'text' } - if (values.type !== this.state.type) { - let _options = fromJS(columnTypeOptions[values.type]).toJS() + let _type = this.column.type + this.column.type = values.type - if (editable === 'true') { - if (values.type === 'text') { - _options.push('required', 'enter', 'footEnter') - } else if (values.type === 'number') { - _options.push('max', 'min', 'enter', 'footEnter') - } - } + if (values.type !== _type) { + let _options = this.getOptions() this.setState({ - type: values.type, formlist: this.state.formlist.map(item => { - if (item.key === 'editable') { - item.initVal = editable - } + item.initVal = this.column[item.key] || item.initVal item.hidden = !_options.includes(item.key) return item @@ -145,20 +165,12 @@ } } else if (key === 'format' && value === 'percent') { this.props.form.setFieldsValue({postfix: '%'}) - } else if (key === 'editable') { - let _options = fromJS(columnTypeOptions[type]).toJS() - - if (value === 'true') { - if (type === 'text') { - _options.push('required', 'enter', 'footEnter') - } else if (type === 'number') { - _options.push('max', 'min', 'enter', 'footEnter') - } - } + } else if (key === 'editable' || key === 'editType' || key === 'resourceType') { + let _options = this.getOptions() this.setState({ - editable: value, formlist: this.state.formlist.map(item => { + item.initVal = this.column[item.key] || item.initVal item.hidden = !_options.includes(item.key) return item @@ -167,9 +179,50 @@ } } + multiselectChange = (key, value) => { + if (key !== 'linkSubField') return + + this.column[key] = value + } + + handleEmpty = () => { + let field = this.props.form.getFieldValue('valueField') + + if (!field) { + notification.warning({ + top: 92, + message: '璇峰~鍐欏�悸峰瓧娈点��', + duration: 5 + }) + return + } + + let text = this.props.form.getFieldValue('valueText') + + if (!text) { + notification.warning({ + top: 92, + message: '璇峰~鍐欐枃鏈峰瓧娈点��', + duration: 5 + }) + return + } + + let resource = this.props.form.getFieldValue('dataSource') || '' + + resource = `select '' as ${field},'鍏ㄩ儴' as ${text} union all \n${resource}` + + this.props.form.setFieldsValue({dataSource: resource}) + } + + changeOptions = (data) => { + this.column.options = data || [] + } + getFields() { + const { dict } = this.props const { getFieldDecorator } = this.props.form - const { formlist } = this.state + const { formlist, transfield } = this.state const fields = [] if (!formlist) return null @@ -177,159 +230,113 @@ formlist.forEach((item, index) => { if (item.hidden || item.forbidden) return - if (item.type === 'text') { // 鏂囨湰鎼滅储 - let rules = [] - if (item.key !== 'linkurl') { - rules = [{ + let span = 12 + let rules = [] + let className = '' + let content = null + let extra = null + let initVal = item.initVal || '' + + if (item.type === 'text') { + rules = [ + { required: item.required, message: dict['form.required.input'] + item.label + '!' }, + { max: formRule.input.max, message: formRule.input.message - }] - } - fields.push( - <Col span={12} key={index}> - <Form.Item label={item.tooltip ? - <Tooltip placement="topLeft" title={item.tooltip}> - <QuestionCircleOutlined className="mk-form-tip" /> - {item.label} - </Tooltip> : item.label - }> - {getFieldDecorator(item.key, { - initialValue: item.initVal || '', - rules: [ - { - required: !!item.required, - message: this.props.dict['form.required.input'] + item.label + '!' - }, - ...rules - ] - })(<Input placeholder="" autoComplete="off" disabled={item.readonly} onPressEnter={this.handleSubmit} />)} - </Form.Item> - </Col> - ) + } + ] + + content = <Input placeholder="" autoComplete="off" onPressEnter={this.handleSubmit} /> } else if (item.type === 'number') { - fields.push( - <Col span={12} key={index}> - <Form.Item label={item.tooltip ? - <Tooltip placement="topLeft" title={item.tooltip}> - <QuestionCircleOutlined className="mk-form-tip" /> - {item.label} - </Tooltip> : item.label - }> - {getFieldDecorator(item.key, { - initialValue: item.initVal, - rules: [ - { - required: !!item.required, - message: this.props.dict['form.required.input'] + item.label + '!' - } - ] - })(item.unlimit ? <InputNumber onPressEnter={this.handleSubmit}/> : - <InputNumber min={item.min} max={item.max} precision={item.decimal} onPressEnter={this.handleSubmit}/>)} - </Form.Item> - </Col> - ) + rules = [ + { required: item.required, message: dict['form.required.input'] + item.label + '!' } + ] + initVal = item.initVal + + if (!item.unlimit) { + content = <InputNumber min={item.min} max={item.max} precision={item.precision} onPressEnter={this.handleSubmit}/> + } else { + content = <InputNumber onPressEnter={this.handleSubmit}/> + } } else if (item.type === 'select') { - 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.select'] + item.label + '!' - } - ] - })( - <Select - showSearch - filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} - onChange={(value, option) => {this.typeChange(item.key, value, option)}} - getPopupContainer={() => document.getElementById('columnwinter')} - > - {item.options.map((option, index) => - <Select.Option key={index} datatype={option.datatype || ''} value={(option.value || option.field || option.MenuID)}> - {(option.text || option.label || option.MenuName)} - </Select.Option> - )} - </Select> - )} - </Form.Item> - </Col> - ) + rules = [ + { required: item.required, message: dict['form.required.select'] + item.label + '!' } + ] + content = <Select + showSearch + allowClear={item.allowClear === true} + filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} + onChange={(value, option) => {this.typeChange(item.key, value, option)}} + getPopupContainer={() => document.getElementById('edit-table-column-winter')} + > + {item.options.map((option, i) => + <Select.Option key={i} datatype={option.datatype || ''} value={(option.value || option.field || option.MenuID)}> + {(option.text || option.label || option.MenuName)} + </Select.Option> + )} + </Select> } else if (item.type === 'radio') { - fields.push( - <Col span={12} key={index}> - <Form.Item label={item.tooltip ? - <Tooltip placement="topLeft" title={item.tooltip}> - <QuestionCircleOutlined className="mk-form-tip" /> - {item.label} - </Tooltip> : item.label - }> - {getFieldDecorator(item.key, { - initialValue: item.initVal, - rules: [ - { - required: !!item.required, - message: this.props.dict['form.required.select'] + item.label + '!' - } - ] - })( - <Radio.Group onChange={(e) => {this.typeChange(item.key, e.target.value)}}> - { - item.options.map(option => { - return ( - <Radio key={option.value} value={option.value}>{option.text}</Radio> - ) - }) - } - </Radio.Group> - )} - </Form.Item> - </Col> - ) + rules = [ + { required: item.required, message: dict['form.required.select'] + item.label + '!' } + ] + initVal = item.initVal + + content = <Radio.Group onChange={(e) => {this.typeChange(item.key, e.target.value)}}> + {item.options.map(option => <Radio key={option.value} value={option.value}>{option.text}</Radio>)} + </Radio.Group> } else if (item.type === 'multiselect') { // 澶氶�� - fields.push( - <Col span={12} key={index}> - <Form.Item label={item.label}> - {getFieldDecorator(item.key, { - initialValue: item.initVal || [] - })( - <Select - showSearch - mode="multiple" - filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} - > - {item.options.map((option, i) => - <Select.Option id={i} key={i} value={option.value || option.field}>{option.text || option.label}</Select.Option> - )} - </Select> - )} - </Form.Item> - </Col> - ) - } else if (item.type === 'textarea') { // 鏂囨湰鎼滅储 - fields.push( - <Col span={24} key={index} className="textarea"> - <Form.Item label={item.tooltip ? - <Tooltip placement="topLeft" title={item.tooltip}> - <QuestionCircleOutlined className="mk-form-tip" /> - {item.label} - </Tooltip> : item.label - }> - {getFieldDecorator(item.key, { - initialValue: item.initVal || '', - rules: [ - { - required: !!item.required, - message: this.props.dict['form.required.input'] + item.label + '!' - } - ] - })(<TextArea rows={2} disabled={item.readonly} placeholder={item.placeholder || ''} />)} - </Form.Item> - </Col> - ) + content = <Select + showSearch + mode="multiple" + filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} + onChange={(value) => this.multiselectChange(item.key, value)} + > + {item.options.map((option, i) => + <Select.Option key={i} value={option.value || option.field}>{option.text || option.label}</Select.Option> + )} + </Select> + } else if (item.type === 'textarea') { + span = 24 + className = 'text-area' + rules = [ + { required: item.required, message: dict['form.required.input'] + item.label + '!' } + ] + + content = <TextArea rows={item.rows || 2}/> + } else if (item.type === 'codemirror') { + rules = [ + { required: item.required, message: dict['form.required.input'] + item.label + '!' } + ] + span = 24 + className = 'text-area' + + extra = <span className="add-resource-empty" onClick={this.handleEmpty}>绌�</span> + + content = <CodeMirror /> + } else if (item.type === 'options') { + span = 24 + className = 'text-area' + + let linkSubFields = this.column.linkSubField || [] + + content = <EditTable type={'select'} module="form" transfield={transfield} linkSubFields={linkSubFields} onChange={this.changeOptions}/> } + + fields.push( + <Col span={span} key={index}> + <Form.Item className={className} extra={extra} label={item.tooltip ? + <Tooltip placement="topLeft" title={item.tooltip}> + <QuestionCircleOutlined className="mk-form-tip" /> + {item.label} + </Tooltip> : item.label + }> + {getFieldDecorator(item.key, { + initialValue: initVal, + rules: rules + })(content)} + </Form.Item> + </Col> + ) }) return fields } @@ -352,6 +359,8 @@ } this.setState({visible: false, formlist: null}) this.props.submitCol(values) + + this.column = null } }) } @@ -380,13 +389,13 @@ <Modal title="鏄剧ず鍒楃紪杈�" visible={visible} - width={800} + width={900} maskClosable={false} onOk={this.handleSubmit} onCancel={this.editModalCancel} destroyOnClose > - <Form {...formItemLayout} className="commontable-column-form" id="columnwinter"> + <Form {...formItemLayout} className="commontable-column-form" id="edit-table-column-winter"> <Row gutter={24}>{this.getFields()}</Row> </Form> </Modal> -- Gitblit v1.8.0