From c3554246cc94e566ae9881193680b9f27e2cbd33 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 21 七月 2023 20:42:49 +0800 Subject: [PATCH] Merge branch 'develop' --- src/tabviews/custom/components/card/prop-card/index.jsx | 150 +++++++++++++++++++++++++++---------------------- 1 files changed, 83 insertions(+), 67 deletions(-) diff --git a/src/tabviews/custom/components/card/prop-card/index.jsx b/src/tabviews/custom/components/card/prop-card/index.jsx index 26f4ea6..fbec582 100644 --- a/src/tabviews/custom/components/card/prop-card/index.jsx +++ b/src/tabviews/custom/components/card/prop-card/index.jsx @@ -15,9 +15,7 @@ class PropCard extends Component { static propTpyes = { - data: PropTypes.array, // 缁熶竴鏌ヨ鏁版嵁 - config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 + config: PropTypes.object } state = { @@ -25,7 +23,6 @@ config: null, // 鍥捐〃閰嶇疆淇℃伅 loading: false, // 鏁版嵁鍔犺浇鐘舵�� activeKey: '', // 閫変腑鏁版嵁 - sync: false, // 鏄惁缁熶竴璇锋眰鏁版嵁 data: {}, // 鏁版嵁 BData: '', selected: 'false', @@ -35,9 +32,9 @@ autoTimer = null UNSAFE_componentWillMount () { - const { data, initdata } = this.props - let _config = fromJS(this.props.config).toJS() + const { config } = this.props + let _config = fromJS(config).toJS() let _data = { $$empty: true } let _sync = false @@ -54,22 +51,20 @@ } if (_config.wrap.datatype === 'dynamic') { - _sync = _config.setting.sync === 'true' + if (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) { + _data = window.GLOB.SyncData.get(_config.dataName) || [] - if (_sync && data) { - _data = data[_config.dataName] || {$$empty: true} - if (Array.isArray(_data)) { - _data = _data[0] || {$$empty: true} + if (_config.$cache) { + Api.writeCacheConfig(_config.uuid, fromJS(_data).toJS()) } - _sync = false + + _config.setting.sync = 'false' + + _data = _data[0] || {$$empty: true} + this.loaded = true - } else if (_sync && initdata) { - _data = initdata - if (Array.isArray(_data)) { - _data = _data[0] || {$$empty: true} - } - _sync = false - this.loaded = true + + window.GLOB.SyncData.delete(_config.dataName) } } else if (_config.wrap.datatype === 'public' && window.GLOB.CacheData.get(_config.wrap.publicId)) { _data = window.GLOB.CacheData.get(_config.wrap.publicId) @@ -120,14 +115,13 @@ this.setState({ selected, - sync: _sync, data: _data, BID: BID || '', BData: BData || '', config: _config, arr_field: _config.columns.map(col => col.field).join(','), }, () => { - if (_config.wrap.datatype === 'dynamic' && _config.setting.sync !== 'true' && _config.setting.onload === 'true') { + if (_config.wrap.datatype === 'dynamic' && config.setting.sync !== 'true' && _config.setting.onload === 'true') { setTimeout(() => { this.loadData() }, _config.setting.delay || 0) @@ -166,10 +160,18 @@ const { config } = this.state MKEmitter.addListener('reloadData', this.reloadData) + MKEmitter.addListener('refreshLineData', this.refreshLineData) MKEmitter.addListener('resetSelectLine', this.resetParentParam) MKEmitter.addListener('queryModuleParam', this.queryModuleParam) - MKEmitter.addListener('refreshLineData', this.refreshLineData) MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult) + + if (config.setting.useMSearch) { + MKEmitter.addListener('searchRefresh', this.searchRefresh) + } + + if (config.setting.sync === 'true') { + MKEmitter.addListener('transferSyncData', this.transferSyncData) + } if (config.wrap.datatype === 'public') { MKEmitter.addListener('mkPublicData', this.mkPublicData) @@ -184,7 +186,7 @@ Api.getLCacheConfig(config.uuid).then(res => { if (!res || this.loaded) return - let _data = res[0] + let _data = res[0] || {$$empty: true} _data.$$uuid = _data[config.setting.primaryKey] || '' this.setState({data: _data}) @@ -202,54 +204,65 @@ } MKEmitter.removeListener('reloadData', this.reloadData) MKEmitter.removeListener('mkPublicData', this.mkPublicData) - MKEmitter.removeListener('resetSelectLine', this.resetParentParam) - MKEmitter.removeListener('queryModuleParam', this.queryModuleParam) + MKEmitter.removeListener('searchRefresh', this.searchRefresh) MKEmitter.removeListener('refreshLineData', this.refreshLineData) + MKEmitter.removeListener('resetSelectLine', this.resetParentParam) + MKEmitter.removeListener('transferSyncData', this.transferSyncData) + MKEmitter.removeListener('queryModuleParam', this.queryModuleParam) MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult) this.timer && this.timer.stop() } - /** - * @description 鏁版嵁鏇存柊锛屽埛鏂板唴瀹� - */ - UNSAFE_componentWillReceiveProps (nextProps) { - const { sync, config, BID, BData, selected } = this.state + transferSyncData = (syncId) => { + const { config } = 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 (Array.isArray(_data)) { - _data = _data[0] || {$$empty: true} - } - } + if (config.$syncId !== syncId) return - _data.$$BID = BID || '' - _data.$$BData = BData || '' - _data.$$uuid = _data[config.setting.primaryKey] || '' + const { BID, BData, selected } = this.state - this.loaded = true + let _data = window.GLOB.SyncData.get(config.dataName) || [] - this.setState({sync: false, data: _data}, () => { - if (config.wrap.goback === 'true' && _data.$$empty) { - this.timer && this.timer.stop() - - MKEmitter.emit('closeTabView', config.$pageId) - } else { - if (selected !== 'false') { - this.checkTopLine() - } else if (_data.$$uuid) { - this.transferLine() - } - this.autoExec() - } - }) - } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - this.setState({}, () => { - this.loadData() - }) + if (config.$cache) { + Api.writeCacheConfig(config.uuid, fromJS(_data).toJS()) } + + _data = _data[0] || {$$empty: true} + + _data.$$BID = BID || '' + _data.$$BData = BData || '' + _data.$$uuid = _data[config.setting.primaryKey] || '' + + this.loaded = true + + this.setState({data: _data}, () => { + if (config.wrap.goback === 'true' && _data.$$empty) { + this.timer && this.timer.stop() + + MKEmitter.emit('closeTabView', config.$pageId) + } else { + if (selected !== 'false') { + this.checkTopLine() + } else if (_data.$$uuid) { + this.transferLine() + } + this.autoExec() + } + }) + + window.GLOB.SyncData.delete(config.dataName) + + MKEmitter.removeListener('transferSyncData', this.transferSyncData) + } + + searchRefresh = (searchId) => { + const { config } = this.state + + if (config.$searchId !== searchId) return + + this.setState({}, () => { + this.loadData() + }) } mkPublicData = (publicId, data) => { @@ -373,12 +386,14 @@ * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁� */ queryModuleParam = (menuId, callback) => { - const { mainSearch } = this.props const { config } = this.state if (config.uuid !== menuId) return - let searches = config.setting.useMSearch && mainSearch ? mainSearch : [] + let searches = [] + if (config.setting.useMSearch) { // 涓昏〃鎼滅储鏉′欢 + searches = window.GLOB.SearchBox.get(config.$searchId) || [] + } callback({ arr_field: '', @@ -397,7 +412,6 @@ } async loadData (hastimer, btn) { - const { mainSearch } = this.props const { config, arr_field, BID, BData, selected } = this.state if (config.wrap.datatype === 'public') { @@ -422,10 +436,12 @@ return } - let searches = config.setting.useMSearch && mainSearch ? mainSearch : [] + let searches = [] + if (config.setting.useMSearch) { // 涓昏〃鎼滅储鏉′欢 + searches = window.GLOB.SearchBox.get(config.$searchId) || [] + } - let requireFields = searches.filter(item => item.required && item.value === '') - if (requireFields.length > 0) { + if (config.$s_req && searches.filter(item => item.required && item.value === '').length > 0) { return } @@ -444,7 +460,7 @@ this.loaded = true if (config.$cache && config.setting.onload !== 'false') { - Api.writeCacheConfig(config.uuid, result.data || '') + Api.writeCacheConfig(config.uuid, result.data || []) } if (!result.data || !result.data[0]) { -- Gitblit v1.8.0