From 37a134bd23ec4b227a0e010b08a1a89c2bbaaa0d Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 03 十一月 2020 17:10:14 +0800
Subject: [PATCH] 2020-11-03

---
 src/tabviews/custom/components/share/tabtransfer/index.jsx |   75 +++++++++++++++++++++++++++++++++++--
 1 files changed, 70 insertions(+), 5 deletions(-)

diff --git a/src/tabviews/custom/components/share/tabtransfer/index.jsx b/src/tabviews/custom/components/share/tabtransfer/index.jsx
index 9bddc70..0238c31 100644
--- a/src/tabviews/custom/components/share/tabtransfer/index.jsx
+++ b/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
\ No newline at end of file
+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)
\ No newline at end of file

--
Gitblit v1.8.0