king
2020-11-16 3ca91a731665962918a026f521c556f4745ebf35
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)