king
2020-11-03 37a134bd23ec4b227a0e010b08a1a89c2bbaaa0d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import React, {Component} from 'react'
import PropTypes from 'prop-types'
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 TabTransfer extends Component {
  static propTpyes = {
    BID: PropTypes.any,              // 父级Id
    config: PropTypes.object,        // 组件配置信息
    mainSearch: PropTypes.any,       // 全局搜索条件
    menuType: PropTypes.any,         // 菜单类型
    dataManager: PropTypes.any,      // 数据权限
  }
 
  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, config } = this.props
    const { mainSearch } = this.state
 
    if (!config || !config.components || config.components.length === 0) return (<Empty description={false} />)
 
    return config.components.map(item => {
      if (item.type === 'bar' || item.type === 'line') {
        return (
          <Col span={item.width} key={item.uuid}>
            <AntvBarAndLine config={item} BID={BID} mainSearch={mainSearch} menuType={menuType} dataManager={dataManager} />
          </Col>
        )
      } else if (item.type === 'pie') {
        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') {
        return (
          <Col span={item.width} key={item.uuid}>
            <AntvTabs config={item} BID={BID} mainSearch={mainSearch} menuType={menuType} dataManager={dataManager} />
          </Col>
        )
      } else {
        return null
      }
    })
  }
 
  render() {
    return (
      <Row gutter={8}>{this.getComponents()}</Row>
    )
  }
}
 
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)