From 97e18fa9b628357fa43013cfefc96eec078de25e Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 16 一月 2023 15:58:12 +0800 Subject: [PATCH] 2023-01-16 --- src/tabviews/custom/components/tree/antd-tree/index.jsx | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/tabviews/custom/components/tree/antd-tree/index.jsx b/src/tabviews/custom/components/tree/antd-tree/index.jsx index 41794b6..688fe7a 100644 --- a/src/tabviews/custom/components/tree/antd-tree/index.jsx +++ b/src/tabviews/custom/components/tree/antd-tree/index.jsx @@ -1,7 +1,7 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' import { is, fromJS } from 'immutable' -import { Spin, Empty, notification, Input, Tree } from 'antd' +import { Spin, Empty, notification, Input, Tree, Modal } from 'antd' import { FolderOpenOutlined, FolderOutlined, FileOutlined } from '@ant-design/icons' import Api from '@/api' @@ -34,6 +34,8 @@ selected: false // 閫変腑棣栬 } + loaded = false + UNSAFE_componentWillMount () { const { config, data, initdata } = this.props let _config = fromJS(config).toJS() @@ -52,15 +54,17 @@ BID = BData.$BID || '' } - if (config.setting.sync === 'true' && data) { + if (_sync && data) { _data = data[config.dataName] || [] _sync = false - } else if (config.setting.sync === 'true' && initdata) { + } else if (_sync && initdata) { _data = initdata || [] _sync = false } _config.wrap.contentHeight = config.wrap.title || config.wrap.searchable === 'true' ? 'calc(100% - 45px)' : '100%' + + this.loaded = _data !== null this.setState({ selected: _config.wrap.selected === 'true', @@ -92,10 +96,12 @@ _data = nextProps.data[config.dataName] || [] } + this.loaded = true + this.setState({sync: false, data: _data}, () => { this.handleData() }) - } else if (config.setting.syncRefresh && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { + } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { this.setState({}, () => { this.loadData() }) @@ -116,6 +122,16 @@ this.timer = new TimerTask() this.timer.init(config.uuid, config.timer, config.timerRepeats, () => { this.loadData(true) + }) + } + + if (config.$cache && !this.loaded) { + Api.getLCacheConfig(config.uuid).then(res => { + if (!res || this.loaded) return + + this.setState({data: res}, () => { + this.handleData() + }) }) } } @@ -165,6 +181,7 @@ }, () => { this.handleData() }) + this.loaded = true return } @@ -186,6 +203,11 @@ let result = await Api.genericInterface(param) if (result.status) { + this.loaded = true + if (config.$cache) { + Api.writeCacheConfig(config.uuid, result.data || '') + } + this.setState({ data: result.data, loading: false @@ -197,11 +219,18 @@ loading: false }) this.timer && this.timer.stop() - notification.error({ - top: 92, - message: result.message, - duration: 10 - }) + + if (result.ErrCode === 'N') { + Modal.error({ + title: result.message, + }) + } else { + notification.error({ + top: 92, + message: result.message, + duration: 10 + }) + } } } -- Gitblit v1.8.0