From 2245384d97d69e36d09cd6baa877e50a81d9aff9 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期三, 29 十二月 2021 21:59:09 +0800 Subject: [PATCH] 2021-12-29 --- src/tabviews/custom/components/card/prop-card/index.jsx | 74 ++++++++++++++++++++++++++---------- 1 files changed, 53 insertions(+), 21 deletions(-) diff --git a/src/tabviews/custom/components/card/prop-card/index.jsx b/src/tabviews/custom/components/card/prop-card/index.jsx index bbd7e78..8be4cc6 100644 --- a/src/tabviews/custom/components/card/prop-card/index.jsx +++ b/src/tabviews/custom/components/card/prop-card/index.jsx @@ -31,7 +31,8 @@ sync: false, // 鏄惁缁熶竴璇锋眰鏁版嵁 data: {}, // 鏁版嵁 timer: null, // 瀹氭椂鍣ㄦ椂闂撮棿闅� - BData: '' + BData: '', + selected: 'false', } UNSAFE_componentWillMount () { @@ -63,6 +64,9 @@ if (_data) { _data.$$BID = BID || '' _data.$$BData = BData || '' + if (_config.setting && _config.setting.primaryKey) { + _data.$$uuid = _data[_config.setting.primaryKey] || '' + } } _config.columns.forEach(item => { @@ -105,15 +109,12 @@ _config.subcards[0].offset = offset } - if (_config.subcards[0] && (_config.wrap.selected === 'always' || _config.wrap.selected === 'init')) { - setTimeout(() => { - this.checkTopLine() - }, 200) - } - _config.wrap.selStyle = _config.wrap.selStyle || 'active' + _config.wrap.priKeyType = _config.wrap.priKeyType || 'static' + let selected = _config.wrap.selected || 'false' this.setState({ + selected, sync: _sync, data: _data, BID: BID || '', @@ -123,6 +124,10 @@ }, () => { if (_config.wrap.datatype !== 'static' && _config.setting && _config.setting.sync !== 'true' && _config.setting.onload === 'true') { this.loadData() + } else if ((!_sync || _config.wrap.priKeyType === 'static') && selected !== 'false') { + setTimeout(() => { + this.checkTopLine() + }, 200) } }) } @@ -152,23 +157,28 @@ * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹� */ UNSAFE_componentWillReceiveProps (nextProps) { - const { sync, config, BID, BData } = this.state + const { sync, config, BID, BData, selected } = this.state if (sync && !is(fromJS(this.props.data), fromJS(nextProps.data))) { let _data = { $$empty: true } if (nextProps.data && nextProps.data[config.dataName]) { - _data = nextProps.data[config.dataName] - if (_data && Array.isArray(_data)) { - _data = _data[0] + _data = nextProps.data[config.dataName] || {} + if (Array.isArray(_data)) { + _data = _data[0] || {} } } - if (_data) { - _data.$$BID = BID || '' - _data.$$BData = BData || '' - } + _data.$$BID = BID || '' + _data.$$BData = BData || '' + _data.$$uuid = _data[config.setting.primaryKey] || '' - this.setState({sync: false, data: _data}) + this.setState({sync: false, data: _data}, () => { + if (config.wrap.priKeyType !== 'static' && selected !== 'false') { + setTimeout(() => { + this.checkTopLine() + }, 200) + } + }) } else if ( config.setting.syncRefresh && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { this.setState({}, () => { this.loadData() @@ -177,13 +187,23 @@ } checkTopLine = () => { - const { config, data } = this.state + const { config, data, selected } = this.state + + if (!config.subcards[0]) return this.setState({ - activeKey: 0 + activeKey: 0, + selected: selected === 'init' ? 'false' : selected }) - MKEmitter.emit('resetSelectLine', config.uuid, (config.subcards[0].setting.primaryId || ''), data) + let primaryId = config.subcards[0].setting.primaryId || '' + if (config.wrap.priKeyType === 'dynamic') { + primaryId = data.$$uuid || '' + } else if (config.wrap.priKeyType === 'joint') { + primaryId = (data.$$uuid || '') + ',' + primaryId + } + + MKEmitter.emit('resetSelectLine', config.uuid, primaryId, data) } handleTimer = () => { @@ -282,7 +302,7 @@ async loadData (hastimer) { const { mainSearch, menuType } = this.props - const { config, arr_field, BID, BData } = this.state + const { config, arr_field, BID, BData, selected } = this.state if (config.wrap.datatype === 'static') { this.setState({ @@ -324,10 +344,15 @@ _data.$$BID = BID || '' _data.$$BData = BData + _data.$$uuid = _data[config.setting.primaryKey] || '' this.setState({ data: _data, loading: false + }, () => { + if (config.wrap.priKeyType !== 'static' && selected !== 'false') { + this.checkTopLine() + } }) if (config.timer && config.clearField) { @@ -358,7 +383,14 @@ activeKey: index }) - MKEmitter.emit('resetSelectLine', config.uuid, (item.setting.primaryId || ''), data) + let primaryId = item.setting.primaryId || '' + if (config.wrap.priKeyType === 'dynamic') { + primaryId = data.$$uuid || '' + } else if (config.wrap.priKeyType === 'joint') { + primaryId = (data.$$uuid || '') + ',' + primaryId + } + + MKEmitter.emit('resetSelectLine', config.uuid, primaryId, data) } render() { -- Gitblit v1.8.0