From eee991f412fc8250ffe9ba8dd074fc4d0cf6eaa2 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 31 十月 2023 09:09:14 +0800 Subject: [PATCH] 2023-10-31 --- src/menu/components/table/edit-table/columns/editColumn/index.jsx | 2 src/menu/components/table/edit-table/columns/editColumn/formconfig.jsx | 10 +++++ src/tabviews/custom/components/table/edit-table/normalTable/index.jsx | 60 +++++++++++++++++++++++------ 3 files changed, 58 insertions(+), 14 deletions(-) diff --git a/src/menu/components/table/edit-table/columns/editColumn/formconfig.jsx b/src/menu/components/table/edit-table/columns/editColumn/formconfig.jsx index 29ff601..210057a 100644 --- a/src/menu/components/table/edit-table/columns/editColumn/formconfig.jsx +++ b/src/menu/components/table/edit-table/columns/editColumn/formconfig.jsx @@ -593,6 +593,16 @@ options: fields }, { + type: 'select', + key: 'clearField', + label: '娓呯┖瀛楁', + initVal: card.clearField || '', + tooltip: '褰撳墠瀛楁缂栬緫鏃堕渶瑕佹竻绌虹殑瀛楁銆�', + allowClear: true, + required: false, + options: fields + }, + { type: 'text', key: 'ctrlValue', label: '绂佹鍊�', 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 e5f690b..66e7e90 100644 --- a/src/menu/components/table/edit-table/columns/editColumn/index.jsx +++ b/src/menu/components/table/edit-table/columns/editColumn/index.jsx @@ -89,7 +89,7 @@ _options.push('required', 'enter') } } else if (this.record.type === 'number') { - _options.push('max', 'min', 'enter') + _options.push('max', 'min', 'enter', 'clearField') } } if (this.record.type === 'formula' && this.record.eval === 'true') { diff --git a/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx b/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx index cdf3368..eed1528 100644 --- a/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx +++ b/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx @@ -266,25 +266,33 @@ } onChange = (val) => { - const { col } = this.props + const { col, record } = this.props let err = null if (col.type === 'number') { - val = +val - if (isNaN(val)) { + if (col.noValue === 'hide' && val === null) { val = 0 - } - if (typeof(col.max) === 'number' && val > col.max) { - err = col.label + '鏈�澶т负' + col.max - } else if (typeof(col.min) === 'number' && val < col.min) { - err = col.label + '鏈�灏忎负' + col.min + } else { + val = +val + if (isNaN(val)) { + val = 0 + } + if (typeof(col.max) === 'number' && val > col.max) { + err = col.label + '鏈�澶т负' + col.max + } else if (typeof(col.min) === 'number' && val < col.min) { + err = col.label + '鏈�灏忎负' + col.min + } } } else if (col.required === 'true' && !val) { err = '璇峰~鍐�' + col.label } this.setState({value: val, err}) + + if (col.clearField && record[col.clearField]) { + MKEmitter.emit('changeRecord', col.tableId, {...record, [col.clearField]: ''}, 'clear') + } } onSwitchChange = (val, label) => { @@ -680,7 +688,16 @@ class BodyAllCell extends React.Component { state = { err: null, - value: '' + value: '', + resting: false + } + + componentDidMount() { + const { col } = this.props + + if (col && col.type === 'number' && col.clearField) { + MKEmitter.addListener('resetCol', this.resetCol) + } } shouldComponentUpdate (nextProps, nextState) { @@ -711,6 +728,7 @@ this.setState = () => { return } + MKEmitter.removeListener('resetCol', this.resetCol) } enterPress = () => { @@ -736,14 +754,29 @@ } }, 50) } + + resetCol = (tableId, clearField, id) => { + const { col, record } = this.props + + if (col.tableId === tableId && clearField === col.field && record.$$uuid === id) { + this.setState({resting: true}, () => { + this.setState({resting: false}) + }) + } + } onChange = (val) => { - const { col } = this.props + const { col, record } = this.props if (col.noValue === 'hide' && val === null) { this.setState({value: 0}) } else { this.setState({value: val}) + } + + if (col.clearField && record[col.clearField]) { + MKEmitter.emit('changeRecord', col.tableId, {...record, [col.clearField]: ''}, 'clear') + MKEmitter.emit('resetCol', col.tableId, col.clearField, record.$$uuid) } } @@ -878,9 +911,10 @@ render() { let { col, config, record, style, className, ...resProps } = this.props - const { err } = this.state + const { err, resting } = this.state if (!col) return (<td {...resProps} className={className} style={style}/>) + if (resting) return null let disabled = false let editable = false @@ -1824,7 +1858,7 @@ } } - changeRecord = (id, record) => { + changeRecord = (id, record, type) => { const { setting } = this.props const { tableId, signForms } = this.state @@ -1863,7 +1897,7 @@ if (setting.tableType && setting.hasAction && this.state.selectedRowKeys.includes(record.$$uuid)) { this.selectdata(this.state.selectedRowKeys) } - if (setting.commit === 'blur') { + if (setting.commit === 'blur' && type !== 'clear') { this.submit(record) } }) -- Gitblit v1.8.0