From 7e46c386be5c2cfc20af3936d26839ad3fce44b0 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期三, 16 八月 2023 17:40:32 +0800 Subject: [PATCH] Merge branch 'master' into positec --- src/tabviews/custom/components/code/sand-box/index.jsx | 85 +++++++++++++++++++++++++++++++----------- 1 files changed, 62 insertions(+), 23 deletions(-) diff --git a/src/tabviews/custom/components/code/sand-box/index.jsx b/src/tabviews/custom/components/code/sand-box/index.jsx index 0a9b6a3..4119dea 100644 --- a/src/tabviews/custom/components/code/sand-box/index.jsx +++ b/src/tabviews/custom/components/code/sand-box/index.jsx @@ -42,6 +42,8 @@ } if (_config.wrap.datatype !== 'static') { + _config.setting.onload = _config.setting.sync === 'true' ? 'false' : 'true' + if (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) { _data = window.GLOB.SyncData.get(_config.dataName) || [] @@ -55,8 +57,6 @@ window.GLOB.SyncData.delete(_config.dataName) } - } else { - this.loaded = true } if (_config.css) { @@ -73,14 +73,7 @@ data: _data, BID: BID || '', config: _config, - arr_field: _config.columns.map(col => col.field).join(','), - }, () => { - if (_config.wrap.datatype !== 'static' && config.setting.sync !== 'true' && _config.setting.onload === 'true') { - setTimeout(() => { - this.loadData() - }, _config.setting.delay || 0) - } - this.renderView() + arr_field: _config.columns.map(col => col.field).join(',') }) } @@ -97,15 +90,7 @@ MKEmitter.addListener('transferSyncData', this.transferSyncData) } - if (config.$cache && !this.loaded) { - Api.getLCacheConfig(config.uuid).then(res => { - if (!res || this.loaded) return - - this.setState({data: res}, () => { - this.renderView() - }) - }) - } + this.initExec() } shouldComponentUpdate (nextProps, nextState) { @@ -119,6 +104,60 @@ MKEmitter.removeListener('reloadData', this.reloadData) MKEmitter.removeListener('searchRefresh', this.searchRefresh) MKEmitter.removeListener('transferSyncData', this.transferSyncData) + } + + initExec = () => { + const { config } = this.state + + if (config.wrap.datatype !== 'static') { + if (config.$cache) { + if (config.$time) { + if (!this.loaded) { + Api.getLCacheConfig(config.uuid, config.$time).then(res => { + if (!res.valid && config.setting.onload === 'true') { + setTimeout(() => { + this.loadData('init') + }, config.setting.delay || 0) + } + + if (!res.data || this.loaded) return + + this.setState({data: res.data}, () => { + this.renderView() + }) + }) + } else { + this.renderView() + } + } else { + if (!this.loaded) { + Api.getLCacheConfig(config.uuid, 0).then(res => { + if (!res.data || this.loaded) return + + this.setState({data: res.data}, () => { + this.renderView() + }) + }) + } + + if (config.setting.onload === 'true') { + setTimeout(() => { + this.loadData('init') + }, config.setting.delay || 0) + } else if (this.loaded) { + this.renderView() + } + } + } else if (config.setting.onload === 'true') { + setTimeout(() => { + this.loadData() + }, config.setting.delay || 0) + } else if (this.loaded) { + this.renderView() + } + } else { + this.renderView() + } } transferSyncData = (syncId) => { @@ -165,7 +204,7 @@ this.loadData() } - async loadData () { + async loadData (type) { const { config, arr_field, BID } = this.state if (config.wrap.datatype === 'static') { @@ -204,7 +243,7 @@ let _data = result.data || [] this.loaded = true - if (config.$cache && config.setting.onload !== 'false') { + if (config.$cache && type === 'init') { Api.writeCacheConfig(config.uuid, result.data || []) } @@ -280,8 +319,8 @@ if (js) { try { // eslint-disable-next-line - let evalfunc = eval('(true && function (data, result) {' + js + '})') - evalfunc(data, result) + let evalfunc = eval('(true && function (data, result, Api, notification) {' + js + '})') + evalfunc(data, result, Api, notification) } catch (e) { console.warn(e) } -- Gitblit v1.8.0