From 569ccb3c1ff82f30ffefa7d3700571448d742662 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 03 十二月 2020 11:46:28 +0800 Subject: [PATCH] 2020-12-03 --- src/menu/components/table/normal-table/columns/editColumn/index.jsx | 78 ++++++++++++++++++++++----------------- 1 files changed, 44 insertions(+), 34 deletions(-) diff --git a/src/menu/components/table/normal-table/columns/editColumn/index.jsx b/src/menu/components/table/normal-table/columns/editColumn/index.jsx index 5ab0873..2c86c2c 100644 --- a/src/menu/components/table/normal-table/columns/editColumn/index.jsx +++ b/src/menu/components/table/normal-table/columns/editColumn/index.jsx @@ -1,6 +1,6 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' -import { fromJS } from 'immutable' +import { is, fromJS } from 'immutable' import { Form, Row, Col, Input, Select, InputNumber, Radio, Tooltip, Icon, Cascader, Modal } from 'antd' import { getColumnForm } from './formconfig' @@ -8,20 +8,24 @@ import './index.scss' const columnTypeOptions = { - text: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'prefix', 'postfix', 'textFormat', 'fieldlength', 'blacklist', 'perspective', 'rowspan'], + text: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'prefix', 'postfix', 'textFormat', 'blacklist', 'perspective', 'rowspan'], number: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'decimal', 'format', 'prefix', 'postfix', 'blacklist', 'perspective', 'sum'], - link: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'joint', 'Width', 'fieldlength', 'blacklist'], - textarea: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'prefix', 'postfix', 'fieldlength', 'blacklist'], - picture: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'fieldlength', 'blacklist', 'scale', 'maxHeight'] + link: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'joint', 'Width', 'blacklist'], + textarea: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'prefix', 'postfix', 'blacklist'], + picture: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'blacklist', 'scale', 'lenWidRadio'], + colspan: ['label', 'type', 'Align', 'Hide', 'blacklist'], + custom: ['label', 'type', 'Align', 'Hide', 'Width', 'blacklist'], + action: ['label', 'type', 'Align', 'Width'] } class MainSearch extends Component { static propTpyes = { dict: PropTypes.object, // 瀛楀吀椤� + visible: PropTypes.bool, column: PropTypes.object, fields: PropTypes.array, - updateCol: PropTypes.func, // 鎻愪氦浜嬩欢 - deleteCol: PropTypes.func // 鍙栨秷鏃跺垹闄や簨浠� + submitCol: PropTypes.func, // 鎻愪氦浜嬩欢 + cancelCol: PropTypes.func // 鍙栨秷鏃跺垹闄や簨浠� } state = { @@ -29,16 +33,13 @@ formlist: null } - /** - * @description 鍒濇娣诲姞鐨勬樉绀哄垪鍏冪礌锛岃仛鐒︽彁绀烘枃瀛� - */ - componentDidMount () { - if (this.props.column.focus) { - this.editColumn() + UNSAFE_componentWillReceiveProps (nextProps) { + if (nextProps.column && !is(fromJS(this.props.column), fromJS(nextProps.column))) { + this.editColumn(nextProps.column) } } - editColumn = () => { + editColumn = (column) => { let menulist = sessionStorage.getItem('fstMenuList') if (menulist) { try { @@ -50,14 +51,29 @@ menulist = [] } + let formlist = getColumnForm(column, menulist, this.props.fields) + let _options = fromJS(columnTypeOptions[column.type]).toJS() + if (column.type === 'text' || column.type === 'number') { + if (column.perspective !== 'linkurl') { + _options.push('linkmenu') + } else { + _options.push('linkurl') + } + } + this.setState({ visible: true, - formlist: getColumnForm(this.props.column, menulist, this.props.fields) + type: column.type, + formlist: formlist.map(item => { + item.hidden = !_options.includes(item.key) + + return item + }) }, () => { - if (this.props.column.focus) { + if (column.focus) { try { let _form = document.getElementById('label') - _form.select() + _form && _form.select() } catch { console.warn('琛ㄥ崟focus澶辫触锛�') } @@ -73,12 +89,6 @@ _options.push('linkmenu') } - let fieldlength = 50 - - if (value !== 'text') { - fieldlength = 512 - } - this.setState({ type: value, formlist: this.state.formlist.map(item => { @@ -87,10 +97,12 @@ return item }) }, () => { - if (this.props.form.getFieldValue('fieldlength') !== undefined) { - this.props.form.setFieldsValue({fieldlength: fieldlength}) - } else if (this.props.form.getFieldValue('perspective') !== undefined) { + if (value === 'link' || value === 'textarea' || value === 'picture') { + this.props.form.setFieldsValue({IsSort: 'false'}) + } else if (value === 'text' || value === 'number') { this.props.form.setFieldsValue({perspective: 'linkmenu'}) + } else if (value === 'action' || value === 'colspan') { + this.props.form.setFieldsValue({Align: 'center'}) } }) } else if (key === 'field') { @@ -176,8 +188,8 @@ message: this.props.dict['form.required.input'] + item.label + '!' } ] - })(item.unlimit ? <InputNumber /> : - <InputNumber min={item.min} max={item.max} precision={item.decimal} />)} + })(item.unlimit ? <InputNumber onPressEnter={this.handleSubmit}/> : + <InputNumber min={item.min} max={item.max} precision={item.decimal} onPressEnter={this.handleSubmit}/>)} </Form.Item> </Col> ) @@ -201,7 +213,7 @@ getPopupContainer={() => document.getElementById('columnwinter')} > {item.options.map((option, index) => - <Select.Option key={index} value={option.value || option.field}> + <Select.Option key={`${index}`} value={option.value || option.field}> {option.text || option.label} </Select.Option> )} @@ -287,7 +299,7 @@ this.props.form.validateFieldsAndScroll((err, values) => { if (!err) { this.setState({visible: false, formlist: null}) - this.props.updateCol(values) + this.props.submitCol(values) } }) } @@ -295,9 +307,7 @@ editModalCancel = () => { this.setState({visible: false, formlist: null}) - if (this.props.column.focus) { - this.props.deleteCol() - } + this.props.cancelCol() } render() { @@ -312,9 +322,9 @@ sm: { span: 18 } } } + return ( <div style={{display: 'inline-block'}}> - <Icon className="edit" title="缂栬緫" type="edit" onClick={this.editColumn} /> <Modal title="鏄剧ず鍒楃紪杈�" visible={visible} -- Gitblit v1.8.0