From 46f79b491173d284a4900d19e7aecf7509481438 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 21 一月 2022 17:21:25 +0800 Subject: [PATCH] 2022-01-21 --- src/tabviews/custom/components/card/prop-card/index.jsx | 101 +++++++++++++++++++++++++++++++++++--------------- 1 files changed, 71 insertions(+), 30 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..e4dc898 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 () { @@ -42,7 +43,7 @@ let _data = { $$empty: true } let _sync = false - if (_config.setting && _config.wrap.datatype !== 'static') { + if (_config.wrap.datatype !== 'static') { _sync = _config.setting.sync === 'true' if (_sync && data) { @@ -63,6 +64,9 @@ if (_data) { _data.$$BID = BID || '' _data.$$BData = BData || '' + if (_config.setting.primaryKey) { + _data.$$uuid = _data[_config.setting.primaryKey] || '' + } } _config.columns.forEach(item => { @@ -97,7 +101,7 @@ }) let offset = 0 - if (_config.wrap.cardFloat && _config.wrap.cardFloat !== 'left' && _config.subcards[0] && _width < 24) { + if (_config.wrap.cardFloat && _config.wrap.cardFloat !== 'left' && _width < 24) { offset = 24 - _width if (_config.wrap.cardFloat === 'center') { offset = Math.floor(offset / 2) @@ -105,15 +109,16 @@ _config.subcards[0].offset = offset } - if (_config.subcards[0] && (_config.wrap.selected === 'always' || _config.wrap.selected === 'init')) { - setTimeout(() => { - this.checkTopLine() - }, 200) - } + let selected = _config.wrap.selected || 'false' _config.wrap.selStyle = _config.wrap.selStyle || 'active' + _config.wrap.priKeyType = _config.wrap.priKeyType || 'static' + _config.wrap.scale = _config.wrap.scale === 'true' ? 'scale' : '' + + _config.wrap.wrapClass = `${_config.wrap.selStyle} ${_config.wrap.cardType || ''} ${_config.wrap.scale || ''}` this.setState({ + selected, sync: _sync, data: _data, BID: BID || '', @@ -121,8 +126,12 @@ config: _config, arr_field: _config.columns.map(col => col.field).join(','), }, () => { - if (_config.wrap.datatype !== 'static' && _config.setting && _config.setting.sync !== 'true' && _config.setting.onload === 'true') { + if (_config.wrap.datatype !== 'static' && _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 +161,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 +191,21 @@ } checkTopLine = () => { - const { config, data } = this.state + const { config, data, selected } = this.state 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 = () => { @@ -264,7 +286,7 @@ resetParentParam = (MenuID, id, data) => { const { config } = this.state - if (!config.setting || !config.setting.supModule || config.setting.supModule !== MenuID) return + if (!config.setting.supModule || config.setting.supModule !== MenuID) return if (id !== this.state.BID || id !== '') { this.setState({ BID: id, BData: data }, () => { this.loadData() @@ -282,7 +304,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 +346,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 +385,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() { @@ -373,12 +407,19 @@ </div> : null } <NormalHeader config={config}/> - <Row className={`card-row-list ${config.wrap.cardType || ''} ${config.wrap.scale || ''}`}> - {config.subcards.map((item, index) => ( - <Col className={(activeKey === index ? config.wrap.selStyle : '') + (item.setting.click ? ' pointer' : '')} key={index} span={item.setting.width || 6} offset={item.offset || 0} onClick={() => {this.changeCard(index, item)}}> - <CardItem card={item} cards={config} data={data}/> - </Col> - ))} + <Row className={`card-row-list data-zoom ${config.wrap.wrapClass}`}> + {config.subcards.map((item, index) => { + let className = item.setting.click ? 'mk-card pointer ' : 'mk-card ' + if (activeKey === index) { + className += 'active' + } + + return ( + <Col className={className} key={index} span={item.setting.width || 6} offset={item.offset || 0} onClick={() => {this.changeCard(index, item)}}> + <CardItem card={item} cards={config} data={data}/> + </Col> + ) + })} </Row> </div> ) -- Gitblit v1.8.0