king
2020-11-03 37a134bd23ec4b227a0e010b08a1a89c2bbaaa0d
src/tabviews/custom/components/share/tabtransfer/index.jsx
@@ -1,17 +1,20 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
// import { fromJS } from 'immutable'
import { connect } from 'react-redux'
import { is, fromJS } from 'immutable'
import { Row, Col, Empty } from 'antd'
import asyncSpinComponent from '@/utils/asyncSpinComponent'
import Utils from '@/utils/utils.js'
import './index.scss'
// 通用组件
const AntvBarAndLine = asyncSpinComponent(() => import('@/tabviews/custom/components/chart/antv-bar-line'))
const MainSearch = asyncSpinComponent(() => import('@/tabviews/custom/components/search/main-search'))
const AntvPie = asyncSpinComponent(() => import('@/tabviews/custom/components/chart/antv-pie'))
const AntvTabs = asyncSpinComponent(() => import('@/tabviews/custom/components/tabs/antv-tabs'))
class MainSearch extends Component {
class TabTransfer extends Component {
  static propTpyes = {
    BID: PropTypes.any,              // 父级Id
    config: PropTypes.object,        // 组件配置信息
@@ -20,14 +23,57 @@
    dataManager: PropTypes.any,      // 数据权限
  }
  state = {}
  state = {
    mainSearch: [],
    self: false
  }
  UNSAFE_componentWillMount () {
    const { config, mainSearch } = this.props
    // 获取主搜索条件
    let _mainSearch = []
    let self = false
    config.components.forEach(component => {
      if (component.type === 'search') {
        self = true
        component.search = component.search.map(item => {
          item.oriInitval = item.initval
          if (!item.blacklist || item.blacklist.length === 0) return item
          let _black = item.blacklist.filter(v => {
            return this.props.permRoles.indexOf(v) !== -1
          })
          if (_black.length > 0) {
            item.Hide = 'true'
          }
          return item
        })
        _mainSearch = Utils.initMainSearch(component.search)
      }
    })
    this.setState({mainSearch: self ? _mainSearch : fromJS(mainSearch).toJS(), self})
  }
  UNSAFE_componentWillReceiveProps(nextProps) {
    const { self } = this.state
    if (!self && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
      this.setState({mainSearch: fromJS(nextProps.mainSearch).toJS()})
    }
  }
  resetSearch = (search) => {
    this.setState({mainSearch: search})
  }
  getComponents = () => {
    const { menuType, dataManager, BID, mainSearch, config } = this.props
    const { menuType, dataManager, BID, config } = this.props
    const { mainSearch } = this.state
    if (!config || !config.components || config.components.length === 0) return (<Empty description={false} />)
@@ -42,6 +88,12 @@
        return (
          <Col span={item.width} key={item.uuid}>
            <AntvPie config={item} BID={BID} mainSearch={mainSearch} menuType={menuType} dataManager={dataManager} />
          </Col>
        )
      } else if (item.type === 'search') {
        return (
          <Col span={item.width} key={item.uuid}>
            <MainSearch config={item} BID={BID} mainSearch={mainSearch} menuType={menuType} dataManager={dataManager} refreshdata={this.resetSearch} />
          </Col>
        )
      } else if (item.type === 'tabs') {
@@ -63,4 +115,17 @@
  }
}
export default MainSearch
const mapStateToProps = (state) => {
  return {
    menuType: state.editLevel,
    permAction: state.permAction,
    permRoles: state.permRoles,
    dataManager: state.dataManager
  }
}
const mapDispatchToProps = () => {
  return {}
}
export default connect(mapStateToProps, mapDispatchToProps)(TabTransfer)