From 1b89aa4493d1c9768447f2f480d594cdb8077fdc Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 26 十月 2020 09:24:19 +0800
Subject: [PATCH] 2020-10-26

---
 src/components/tabview/index.jsx |  264 ++++++++++++++++++++++++++++++----------------------
 1 files changed, 153 insertions(+), 111 deletions(-)

diff --git a/src/components/tabview/index.jsx b/src/components/tabview/index.jsx
index bfe7e6e..83ef4ff 100644
--- a/src/components/tabview/index.jsx
+++ b/src/components/tabview/index.jsx
@@ -2,27 +2,39 @@
 import PropTypes from 'prop-types'
 import {connect} from 'react-redux'
 import { is, fromJS } from 'immutable'
-import {Tabs, Icon, Button, ConfigProvider, message} from 'antd'
-import {modifyTabview, toggleIsiframe} from '@/store/action'
-// import asyncComponent from '@/utils/asyncComponent'
-import asyncComponent from '@/utils/asyncLoadComponent'
-import NotFount from '@/components/404'
-import enUS from 'antd/es/locale/en_US'
-import zhCN from 'antd/es/locale/zh_CN'
-import mzhCN from '@/locales/zh-CN/main.js'
-import menUS from '@/locales/en-US/main.js'
+import {Tabs, Icon, Button, message, BackTop} from 'antd'
 import moment from 'moment'
 import 'moment/locale/zh-cn'
+
+import {modifyTabview, toggleIsiframe, refreshTabView} from '@/store/action'
+import asyncComponent from '@/utils/asyncLoadComponent'
+import NotFount from '@/components/404'
+import options from '@/store/options.js'
+import mzhCN from '@/locales/zh-CN/main.js'
+import menUS from '@/locales/en-US/main.js'
+
 import './index.scss'
 
+const Home = asyncComponent(() => import('@/tabviews/home'))
+const CustomPage = asyncComponent(() => import('@/tabviews/custom'))
+const CommonTable = asyncComponent(() => import('@/tabviews/commontable'))
+const CalendarPage = asyncComponent(() => import('@/tabviews/calendar'))
+const TreePage = asyncComponent(() => import('@/tabviews/treepage'))
+const VerupTable = asyncComponent(() => import('@/tabviews/verupmanage'))
+const ScriptTable = asyncComponent(() => import('@/tabviews/scriptmanage'))
+const TabManage = asyncComponent(() => import('@/tabviews/tabmanage'))
+const Iframe = asyncComponent(() => import('@/tabviews/iframe'))
+const DataManage = asyncComponent(() => import('@/tabviews/datamanage'))
+const RoleManage = asyncComponent(() => import('@/tabviews/rolemanage'))
+const TabForm = asyncComponent(() => import('@/tabviews/tabform'))
+const FormTab = asyncComponent(() => import('@/tabviews/formtab'))
 
-let Comps = {}
-let service = window.GLOB.service ? (/\/$/.test(window.GLOB.service) ? window.GLOB.service : window.GLOB.service + '/') : ''
+let service = ''
 
 if (process.env.NODE_ENV === 'production') {
-  service = document.location.origin + '/' + service + 'zh-CN/'
+  service = document.location.origin + '/' + window.GLOB.service + 'zh-CN/'
 } else {
-  service = 'http://qingqiumarket.cn/' + service + 'zh-CN/'
+  service = window.GLOB.location + window.GLOB.service + 'zh-CN/'
 }
 
 class Header extends Component {
@@ -32,71 +44,92 @@
   }
 
   state = {
-    selectedTabId: '', // 褰撳墠閫変腑tab椤甸潰
+    tabviews: null, // 鏍囩闆�
     iFrameHeight: 0,
-    dict: (!sessionStorage.getItem('lang') || sessionStorage.getItem('lang') === 'zh-CN') ? mzhCN : menUS,
-    locale: (!sessionStorage.getItem('lang') || sessionStorage.getItem('lang') === 'zh-CN') ? zhCN : enUS
+    dict: localStorage.getItem('lang') !== 'en-US' ? mzhCN : menUS
   }
 
-  handleTabview (menu) {
+  handleTabview = (e, menu) => {
+    e.stopPropagation()
     // 鍏抽棴tab椤碉紝閲嶆柊閫夋嫨鏄剧ず椤�
-    let tabs = JSON.parse(JSON.stringify(this.props.tabviews))
+    let tabs = fromJS(this.state.tabviews).toJS()
     tabs = tabs.filter(tab => {
-      if (tab.MenuID === this.state.selectedTabId) {
-        tab.selected = true
-      } else {
-        tab.selected = false
-      }
       return tab.MenuID !== menu.MenuID
     })
     
-    if (menu.MenuID === this.state.selectedTabId) {
+    if (menu.selected) {
       tabs[0] && (tabs[0].selected = true)
     }
 
     this.props.modifyTabview(tabs)
   }
 
-  changeTab (menu) {
-    // 绐楀彛鍒囨崲
-    this.setState({
-      selectedTabId: menu.MenuID
-    })
-    let tabs = JSON.parse(JSON.stringify(this.props.tabviews))
-    tabs = tabs.map(tab => {
-      if (tab.MenuID === menu.MenuID) {
-        tab.selected = true
-      } else {
-        tab.selected = false
-      }
-      return tab
-    })
-    this.props.modifyTabview(tabs)
-    this.resetWindow(menu)
+  refreshTabview = (e, menu) => {
+    e.stopPropagation()
+    window.GLOB.CacheMap = new Map()
+
+    let _menu = {
+      MenuID: menu.MenuID,
+      position: 'view'
+    }
+    this.props.refreshTabView(_menu)
   }
 
-  selectcomponent (view) {
+  changeTab = (e, menu) => {
+    e.stopPropagation()
+    // 绐楀彛鍒囨崲
+    let tabs = fromJS(this.state.tabviews).toJS()
+    tabs = tabs.map(tab => {
+      tab.selected = false
+
+      if (tab.MenuID === menu.MenuID) {
+        tab.selected = true
+      }
+
+      return tab
+    })
+
+    this.setState({
+      tabviews: tabs
+    })
+
+    this.props.modifyTabview(tabs)
+  }
+
+  selectcomponent = (view) => {
     // 鏍规嵁tab椤典腑鑿滃崟淇℃伅锛岄�夋嫨鎵�闇�鐨勭粍浠�
     if (view.type === 'Home') {
-      return (<Comps.Home MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>)
-    } else if (view.type === 'CommonTable') {
-      return (<Comps.CommonTable MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>)
+      return (<Home MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>)
+    } else if (view.type === 'CommonTable' || view.type === 'ManageTable') {
+      return (<CommonTable MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>)
+    } else if (view.type === 'CustomPage') {
+      return (<CustomPage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>)
+    } else if (view.type === 'TreePage') {
+      return (<TreePage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>)
+    } else if (view.type === 'CalendarPage') {
+      return (<CalendarPage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>)
+    } else if (view.type === 'VerupTable') {
+      return (<VerupTable MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>)
+    } else if (view.type === 'ScriptTable') {
+      return (<ScriptTable MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>)
+    } else if (view.type === 'TabManage') {
+      return (<TabManage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>)
     } else if (view.type === 'DataManage') {
-      return (<Comps.DataManage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>)
+      return (<DataManage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>)
     } else if (view.type === 'RolePermission') {
-      return (<Comps.RoleManage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>)
+      return (<RoleManage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>)
     } else if (view.type === 'TabForm') {
-      return (<Comps.TabForm MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>)
+      return (<TabForm MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>)
     } else if (view.type === 'FormTab') {
-      return (<Comps.FormTab MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>)
+      return (<FormTab MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>)
     } else if (view.type === 'iframe') {
-      return (<Comps.Iframe key={view.MenuID} title={view.MenuName} MenuName={view.MenuName} url={service + view.LinkUrl}/>)
+      return (<Iframe key={view.MenuID} title={view.MenuName} MenuName={view.MenuName} url={service + view.LinkUrl}/>)
     } else {
       return (<NotFount key={view.MenuID} />)
     }
   }
 
-  resetWindow (view) {
+  resetWindow = (view) => {
     // 绐楀彛鍦╥frame涓庢櫘閫氶〉闈㈠垏鎹㈡椂锛屼慨鏀瑰乏渚ц彍鍗曟爮鏍峰紡
     if (!view) return
     let _isiframe = this.props.isiframe
@@ -129,90 +162,97 @@
     } else {
       moment.locale('en')
     }
+    this.setState({
+      tabviews: this.props.tabviews
+    })
   }
 
   componentDidMount () {
     let home = {
-      MenuID: '1576117946681plembmkk9akkv8sn0vtdfdsfaf',
+      MenuID: 'home_page_id',
       MenuName: '棣栭〉',
-      MenuNo: 'MESOrderDetailMwe',
-      PageParam: {},
-      id: 1,
       selected: true,
-      src: '',
-      text: '棣栭〉',
       type: 'Home'
     }
     this.props.modifyTabview([home])
   }
 
   UNSAFE_componentWillReceiveProps (nextProps) {
-    if (nextProps.tabviews && !is(fromJS(this.props.tabviews), fromJS(nextProps.tabviews))) {
-      // tab绐楀彛椤靛鍔犳垨鍒犻櫎
-      if (nextProps.tabviews.length > this.props.tabviews.length) {
-        // 鏌ョ湅鏂皌ab椤甸渶瑕佺粍浠舵槸鍚﹀姞杞�
-        let MenuIDs = this.props.tabviews.map(tab => {return tab.MenuID})
-        let newtab = nextProps.tabviews.filter(tab => !MenuIDs.includes(tab.MenuID))[0]
-        if (!Comps.Home && newtab.type === 'Home') {
-          Comps.Home = asyncComponent(() => import('@/tabviews/home'))
-        } else if (!Comps.CommonTable && newtab.type === 'CommonTable') {
-          Comps.CommonTable = asyncComponent(() => import('@/tabviews/commontable'))
-        } else if (!Comps.Iframe && newtab.type === 'iframe') {
-          Comps.Iframe = asyncComponent(() => import('@/tabviews/iframe'))
-        } else if (!Comps.DataManage && newtab.type === 'DataManage') {
-          Comps.DataManage = asyncComponent(() => import('@/tabviews/datamanage'))
-        } else if (!Comps.RoleManage && newtab.type === 'RolePermission') {
-          Comps.RoleManage = asyncComponent(() => import('@/tabviews/rolemanage'))
-        } else if (!Comps.TabForm && newtab.type === 'TabForm') {
-          Comps.TabForm = asyncComponent(() => import('@/tabviews/tabform'))
-        } else if (!Comps.TabForm && newtab.type === 'FormTab') {
-          Comps.FormTab = asyncComponent(() => import('@/tabviews/formtab'))
-        }
-      }
-
-      // 璁剧疆閫変腑绐楀彛
-      let view = nextProps.tabviews.filter(tab => tab.selected)[0]
+    if (nextProps.tabviews && !is(fromJS(this.state.tabviews), fromJS(nextProps.tabviews))) {
+      // 淇濆瓨淇敼鏍囩闆�
       this.setState({
-        selectedTabId: view ? view.MenuID : ''
+        tabviews: nextProps.tabviews
       })
-      this.resetWindow(view)
+
+      let node = document.getElementById('root').parentNode.parentNode
+      if (node) {
+        node.scrollTop = 0
+      }
     }
   }
 
-  shouldComponentUpdate(nextProps, nextState) {
-    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
+  /**
+   * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊
+   */
+  componentWillUnmount () {
+    this.setState = () => {
+      return
+    }
   }
 
   render () {
+    const { menuType } = this.props
+    const { tabviews } = this.state
+    let view = tabviews.filter(tab => tab.selected)[0]
+    this.resetWindow(view)
+    let selectedTabId = view ? view.MenuID : ''
+
     return (
       <section className={'flex-container content-box' + (this.props.collapse ? ' collapsed' : '')}>
-        <ConfigProvider locale={this.state.locale}>
-          <div className="content-header">
-            {this.props.tabviews && this.props.tabviews.length > 0 &&
-              <Tabs activeKey={this.state.selectedTabId}>
-                {this.props.tabviews.map(view => {
-                  return (
-                    <Tabs.TabPane
-                      className="test"
-                      tab={
-                        <span className="tab-control">
-                          <span className="tab-name" onClick={() => {this.changeTab(view)}}>
-                            {view.MenuName}
-                          </span>
-                          {view.type !== 'Home' ? <Icon type="close" onClick={() => {this.handleTabview(view)}}/> : null}
+        <div className="content-header">
+          {tabviews && tabviews.length > 0 &&
+            <Tabs activeKey={selectedTabId}>
+              {tabviews.map(view => {
+                return (
+                  <Tabs.TabPane
+                    tab={
+                      <span className="tab-control">
+                        {['CommonTable', 'FormTab', 'TreePage', 'CalendarPage', 'CustomPage'].includes(view.type) ?
+                          <Icon type="redo" onClick={(e) => {this.refreshTabview(e, view)}}/> : null
+                        }
+                        <span className="tab-name" onClick={(e) => {this.changeTab(e, view)}}>
+                          {view.MenuName}
                         </span>
-                      }
-                      key={view.MenuID}
-                    >
-                      {this.selectcomponent(view)}
-                      <Button className={'main-copy ' + (view.type === 'iframe' ? 'ifr-copy' : '')} icon="copy" data-menuno={view.MenuNo} onClick={this.copyMenuNo} shape="circle" />
-                    </Tabs.TabPane>
-                  )
-                })}
-              </Tabs>
-            }
-          </div>
-        </ConfigProvider>
+                        {view.type !== 'Home' ?
+                          <Icon type="close" onClick={(e) => {this.handleTabview(e, view)}}/> : null
+                        }
+                      </span>
+                    }
+                    key={view.MenuID}
+                  >
+                    {this.selectcomponent(view)}
+                    {options.sysType !== 'cloud' && menuType !== 'HS' && !['CommonTable', 'TreePage', 'ManageTable', 'CalendarPage', 'Home'].includes(view.type) ?
+                      <Button
+                        icon="copy"
+                        shape="circle"
+                        className={'main-copy ' + (view.type === 'iframe' ? 'ifr-copy' : '')}
+                        data-menuno={view.MenuNo}
+                        onClick={this.copyMenuNo}
+                      /> : null
+                    }
+                    <BackTop>
+                      <div className="ant-back-top">
+                        <div className="ant-back-top-content">
+                          <div className="ant-back-top-icon"></div>
+                        </div>
+                      </div>
+                    </BackTop>
+                  </Tabs.TabPane>
+                )
+              })}
+            </Tabs>
+          }
+        </div>
       </section>
     )
   }
@@ -220,6 +260,7 @@
 
 const mapStateToProps = (state) => {
   return {
+    menuType: state.editLevel,
     tabviews: state.tabviews,
     collapse: state.collapse,
     isiframe: state.isiframe
@@ -229,6 +270,7 @@
 const mapDispatchToProps = (dispatch) => {
   return {
     modifyTabview: (tabviews) => dispatch(modifyTabview(tabviews)),
+    refreshTabView: (refreshTab) => dispatch(refreshTabView(refreshTab)),
     toggleIsiframe: (isiframe) => dispatch(toggleIsiframe(isiframe))
   }
 }

--
Gitblit v1.8.0