From f3d4db769ba9b51b799d981511a710fd443d0e08 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 21 四月 2025 12:18:03 +0800 Subject: [PATCH] Merge branch 'master' into positec --- src/tabviews/custom/components/code/sand-box/index.jsx | 132 +++++++++++++++++++++++++------------------ 1 files changed, 76 insertions(+), 56 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..0116fe3 100644 --- a/src/tabviews/custom/components/code/sand-box/index.jsx +++ b/src/tabviews/custom/components/code/sand-box/index.jsx @@ -1,7 +1,7 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' import { is, fromJS } from 'immutable' -import { Spin, notification, Modal } from 'antd' +import { Spin, notification } from 'antd' import Api from '@/api' import UtilsDM from '@/utils/utils-datamanage.js' @@ -42,11 +42,17 @@ } if (_config.wrap.datatype !== 'static') { + _config.setting.onload = _config.setting.sync === 'true' ? 'false' : _config.setting.onload || 'true' + + if (_config.setting.supModule && !BID) { + _config.setting.onload = '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()) + Api.writeCacheConfig(_config.uuid, fromJS(_data).toJS(), BID) } _config.setting.sync = 'false' @@ -55,8 +61,6 @@ window.GLOB.SyncData.delete(_config.dataName) } - } else { - this.loaded = true } if (_config.css) { @@ -72,15 +76,7 @@ this.setState({ 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() + config: _config }) } @@ -97,15 +93,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) { @@ -121,15 +109,69 @@ MKEmitter.removeListener('transferSyncData', this.transferSyncData) } + initExec = () => { + const { config, BID } = this.state + + if (config.wrap.datatype !== 'static') { + if (config.$cache) { + if (config.$time) { + if (!this.loaded) { + Api.getLCacheConfig(config.uuid, config.$time, BID).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, BID).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) => { - const { config } = this.state + const { config, BID } = this.state if (config.$syncId !== syncId) return let _data = window.GLOB.SyncData.get(config.dataName) || [] if (config.$cache) { - Api.writeCacheConfig(config.uuid, fromJS(_data).toJS()) + Api.writeCacheConfig(config.uuid, fromJS(_data).toJS(), BID) } if (!is(fromJS(this.state.data), fromJS(_data))) { @@ -165,8 +207,8 @@ this.loadData() } - async loadData () { - const { config, arr_field, BID } = this.state + async loadData (type) { + const { config, BID } = this.state if (config.wrap.datatype === 'static') { this.setState({ @@ -197,15 +239,15 @@ }) let _orderBy = config.setting.order || '' - let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, 1, 1, BID) + let param = UtilsDM.getQueryDataParams(config.setting, searches, _orderBy, 1, 1, BID) let result = await Api.genericInterface(param) if (result.status) { let _data = result.data || [] this.loaded = true - if (config.$cache && config.setting.onload !== 'false') { - Api.writeCacheConfig(config.uuid, result.data || []) + if (config.$cache && type === 'init') { + Api.writeCacheConfig(config.uuid, result.data || [], BID) } if (!is(fromJS(this.state.data), fromJS(_data))) { @@ -223,36 +265,14 @@ loading: false }) - if (result.message) { - if (result.ErrCode === 'Y') { - Modal.success({ - title: result.message - }) - } else if (result.ErrCode === 'S') { - notification.success({ - top: 92, - message: result.message, - duration: 2 - }) - } - } + + UtilsDM.querySuccess(result) } else { this.setState({ loading: false }) - if (!result.message) return - if (result.ErrCode === 'N') { - Modal.error({ - title: result.message - }) - } else if (result.ErrCode !== '-2') { - notification.error({ - top: 92, - message: result.message, - duration: 10 - }) - } + UtilsDM.queryFail(result) } } @@ -280,8 +300,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, systemType) {' + js + '})') + evalfunc(data, result, Api, notification, window.GLOB.systemType) } catch (e) { console.warn(e) } -- Gitblit v1.8.0