From 71e3da644eca32a5aa40503e903efb0640748093 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 21 七月 2023 17:00:59 +0800 Subject: [PATCH] 2023-07-21 --- src/tabviews/custom/components/code/sand-box/index.jsx | 108 ++++++++++++++++++++++++++++++----------------------- 1 files changed, 61 insertions(+), 47 deletions(-) diff --git a/src/tabviews/custom/components/code/sand-box/index.jsx b/src/tabviews/custom/components/code/sand-box/index.jsx index 6bdaf07..0a9b6a3 100644 --- a/src/tabviews/custom/components/code/sand-box/index.jsx +++ b/src/tabviews/custom/components/code/sand-box/index.jsx @@ -10,16 +10,13 @@ class SandBoxComponent extends Component { static propTpyes = { - data: PropTypes.array, // 缁熶竴鏌ヨ鏁版嵁 - config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 + config: PropTypes.object } state = { BID: '', // 涓婄骇ID config: null, // 鍥捐〃閰嶇疆淇℃伅 loading: false, // 鏁版嵁鍔犺浇鐘舵�� - sync: false, // 鏄惁缁熶竴璇锋眰鏁版嵁 data: [], // 鏁版嵁 html: '', result: {} @@ -28,12 +25,10 @@ loaded = false 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 = [] - let _sync = false - let BID = '' let BData = '' @@ -47,19 +42,20 @@ } if (_config.wrap.datatype !== 'static') { - _sync = _config.setting.sync === 'true' - - if (_sync && data) { - _data = data[_config.dataName] || [] - _sync = false + if (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) { + _data = window.GLOB.SyncData.get(_config.dataName) || [] + + if (_config.$cache) { + Api.writeCacheConfig(_config.uuid, fromJS(_data).toJS()) + } + + _config.setting.sync = 'false' + this.loaded = true - } else if (_sync && initdata) { - _data = initdata || {} - _sync = false - this.loaded = true + + window.GLOB.SyncData.delete(_config.dataName) } } else { - _data = {} this.loaded = true } @@ -74,13 +70,12 @@ } this.setState({ - sync: _sync, data: _data, BID: BID || '', 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') { setTimeout(() => { this.loadData() }, _config.setting.delay || 0) @@ -93,6 +88,14 @@ const { config } = this.state MKEmitter.addListener('reloadData', this.reloadData) + + if (config.setting.useMSearch) { + MKEmitter.addListener('searchRefresh', this.searchRefresh) + } + + if (config.setting.sync === 'true') { + MKEmitter.addListener('transferSyncData', this.transferSyncData) + } if (config.$cache && !this.loaded) { Api.getLCacheConfig(config.uuid).then(res => { @@ -114,34 +117,44 @@ return } MKEmitter.removeListener('reloadData', this.reloadData) + MKEmitter.removeListener('searchRefresh', this.searchRefresh) + MKEmitter.removeListener('transferSyncData', this.transferSyncData) } - /** - * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹� - */ - UNSAFE_componentWillReceiveProps (nextProps) { - const { sync, config } = this.state + transferSyncData = (syncId) => { + const { config } = this.state - if (sync && !is(fromJS(this.props.data), fromJS(nextProps.data))) { - let _data = [] - if (nextProps.data && nextProps.data[config.dataName]) { - _data = nextProps.data[config.dataName] - } + if (config.$syncId !== syncId) return - this.loaded = true + let _data = window.GLOB.SyncData.get(config.dataName) || [] - if (!is(fromJS(this.state.data), fromJS(_data))) { - setTimeout(() => { - this.renderView() - }, 10) - } - - this.setState({sync: false, data: _data}) - } 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()) } + + if (!is(fromJS(this.state.data), fromJS(_data))) { + setTimeout(() => { + this.renderView() + }, 10) + } + + this.setState({data: _data}) + + this.loaded = true + + 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() + }) } reloadData = (menuId) => { @@ -153,7 +166,6 @@ } async loadData () { - const { mainSearch } = this.props const { config, arr_field, BID } = this.state if (config.wrap.datatype === 'static') { @@ -171,10 +183,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 } @@ -191,7 +205,7 @@ this.loaded = true if (config.$cache && config.setting.onload !== 'false') { - Api.writeCacheConfig(config.uuid, result.data || '') + Api.writeCacheConfig(config.uuid, result.data || []) } if (!is(fromJS(this.state.data), fromJS(_data))) { -- Gitblit v1.8.0