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/tabviews/custom/components/table/edit-table/normalTable/index.jsx | 60 +++++++++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 47 insertions(+), 13 deletions(-) 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