From 3ca91a731665962918a026f521c556f4745ebf35 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 16 十一月 2020 19:20:19 +0800 Subject: [PATCH] 2020-11-16 --- src/tabviews/custom/index.jsx | 66 +++++++++++++++++++++++++-------- 1 files changed, 50 insertions(+), 16 deletions(-) diff --git a/src/tabviews/custom/index.jsx b/src/tabviews/custom/index.jsx index 5d699e3..e9aae8a 100644 --- a/src/tabviews/custom/index.jsx +++ b/src/tabviews/custom/index.jsx @@ -4,6 +4,7 @@ import { is, fromJS } from 'immutable' import { notification, Spin, Row, Col, Button, message } from 'antd' import moment from 'moment' +import md5 from 'md5' import Api from '@/api' import options from '@/store/options.js' @@ -11,8 +12,7 @@ import enUS from '@/locales/en-US/main.js' import Utils from '@/utils/utils.js' import asyncComponent from '@/utils/asyncComponent' -import { refreshTabView } from '@/store/action' - +import MKEmitter from '@/utils/events.js' import NotFount from '@/components/404' import './index.scss' @@ -101,6 +101,15 @@ return } + // 鏁版嵁缂撳瓨璁剧疆 + if (config.cacheUseful === 'true') { + config.diffUser = config.diffUser !== 'false' + if (!['day', 'hour'].includes(config.timeUnit)) { + config.timeUnit = 'day' + } + config.cacheTime = config.cacheTime || 1 + } + // 鏉冮檺杩囨护 if (this.props.menuType !== 'HS') { config.components = this.filterComponent(config.components) @@ -141,7 +150,16 @@ let params = [] let BID = param && param.BID ? param.BID : '' - config.components = this.formatSetting(config.components, params, mainSearch, permAction) + let inherit = {} + + if (config.cacheUseful === 'true') { // 缂撳瓨缁ф壙 + inherit.cacheUseful = config.cacheUseful + inherit.timeUnit = config.timeUnit + inherit.cacheTime = config.cacheTime + inherit.diffUser = config.diffUser + } + + config.components = this.formatSetting(config.components, params, mainSearch, permAction, inherit) this.setState({ BID: BID, @@ -209,11 +227,12 @@ } // 鏍煎紡鍖栭粯璁よ缃� - formatSetting = (components, params, mainSearch, permAction) => { + formatSetting = (components, params, mainSearch, permAction, inherit) => { return components.map(component => { if (component.type === 'tabs') { component.subtabs = component.subtabs.map(tab => { - tab.components = this.formatSetting(tab.components, [], [], permAction) + tab.components = this.formatSetting(tab.components, [], [], permAction, inherit) + tab = {...tab, ...inherit} return tab }) } @@ -354,6 +373,7 @@ * @description 涓昏〃鏁版嵁鍔犺浇 */ loadmaindata = (params) => { + const { config } = this.state let LText_field = [] let LText = params.map((item, index) => { let _sql = item.sql @@ -380,6 +400,16 @@ param.LText = Utils.formatOptions(param.LText) param.LText_field = Utils.formatOptions(param.LText_field) + + if (config.cacheUseful === 'true') { + param.time_type = config.timeUnit + param.time_limit = config.cacheTime + if (config.diffUser) { + param.userid = sessionStorage.getItem('UserID') + } + param.data_md5 = md5(JSON.stringify(param)) + } + param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') param.secretkey = Utils.encrypt(param.LText, param.timestamp) @@ -431,20 +461,25 @@ } } + reloadMenuView = (menuId) => { + const { MenuID } = this.props + + if (MenuID !== menuId) return + + this.reloadview() + } + UNSAFE_componentWillMount () { // 缁勪欢鍔犺浇鏃讹紝鑾峰彇鑿滃崟鏁版嵁 this.loadconfig() } - UNSAFE_componentWillReceiveProps(nextProps) { - if (nextProps.refreshTab && nextProps.refreshTab.MenuID === this.props.MenuID) { - this.reloadview() - this.props.refreshTabView('') - } - } - shouldComponentUpdate (nextProps, nextState) { return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) + } + + componentDidMount () { + MKEmitter.addListener('reloadMenuView', this.reloadMenuView) } /** @@ -454,6 +489,7 @@ this.setState = () => { return } + MKEmitter.removeListener('reloadMenuView', this.reloadMenuView) } reloadview = () => { @@ -557,10 +593,8 @@ } } -const mapDispatchToProps = (dispatch) => { - return { - refreshTabView: (refreshTab) => dispatch(refreshTabView(refreshTab)) - } +const mapDispatchToProps = () => { + return {} } export default connect(mapStateToProps, mapDispatchToProps)(CustomPage) \ No newline at end of file -- Gitblit v1.8.0