From f078c137d61270d243cd8e03077fa9cf000e276b Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 14 八月 2023 14:02:40 +0800 Subject: [PATCH] 2023-08-14 --- src/tabviews/custom/components/calendar/index.jsx | 90 +++++++++++++++++++++++++++++++------------- 1 files changed, 63 insertions(+), 27 deletions(-) diff --git a/src/tabviews/custom/components/calendar/index.jsx b/src/tabviews/custom/components/calendar/index.jsx index 43b7021..7b1f9d6 100644 --- a/src/tabviews/custom/components/calendar/index.jsx +++ b/src/tabviews/custom/components/calendar/index.jsx @@ -69,12 +69,6 @@ config: _config, arr_field: _config.columns.map(col => col.field).join(','), search: _config.$searches - }, () => { - if (_config.setting.onload === 'true') { - setTimeout(() => { - this.loadData() - }, _config.setting.delay || 0) - } }) } @@ -89,25 +83,7 @@ MKEmitter.addListener('searchRefresh', this.searchRefresh) } - if (config.$cache && !this.loaded) { - Api.getLCacheConfig(config.uuid).then(res => { - if (!res.data || this.loaded) return - - let data = [] - res.data.forEach((item, index) => { - item.key = index - item.$$uuid = item[config.setting.primaryKey] || '' - - let pass = this.resetLine(item) - - if (pass) { - data.push(item) - } - }) - - this.setState({data: data}) - }) - } + this.initExec() } shouldComponentUpdate (nextProps, nextState) { @@ -122,6 +98,66 @@ MKEmitter.removeListener('searchRefresh', this.searchRefresh) MKEmitter.removeListener('resetSelectLine', this.resetParentParam) MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult) + } + + initExec = () => { + const { config } = this.state + + if (config.$cache) { + if (config.$time) { + 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) return + + let _data = [] + res.data.forEach((item, index) => { + item.key = index + item.$$uuid = item[config.setting.primaryKey] || '' + + let pass = this.resetLine(item) + + if (pass) { + _data.push(item) + } + }) + + this.setState({data: _data}) + }) + } else { + Api.getLCacheConfig(config.uuid, 0).then(res => { + if (!res.data || this.loaded) return + + let _data = [] + res.data.forEach((item, index) => { + item.key = index + item.$$uuid = item[config.setting.primaryKey] || '' + + let pass = this.resetLine(item) + + if (pass) { + _data.push(item) + } + }) + + this.setState({data: _data}) + }) + + if (config.setting.onload === 'true') { + setTimeout(() => { + this.loadData('init') + }, config.setting.delay || 0) + } + } + } else if (config.setting.onload === 'true') { + setTimeout(() => { + this.loadData() + }, config.setting.delay || 0) + } } searchRefresh = (searchId) => { @@ -171,7 +207,7 @@ this.loadData() } - async loadData () { + async loadData (type) { const { config, arr_field, BID, search, year } = this.state if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� @@ -207,7 +243,7 @@ let result = await Api.genericInterface(param) if (result.status) { this.loaded = true - if (config.$cache && config.setting.onload !== 'false') { + if (config.$cache && type === 'init') { Api.writeCacheConfig(config.uuid, result.data || []) } -- Gitblit v1.8.0