From da64ab0923bf8817fc8599a6e37b953ce38f64c8 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期日, 27 八月 2023 18:37:36 +0800
Subject: [PATCH] 2023-08-27

---
 src/components/header/index.jsx |  245 +++++++++++++++++++++++++-----------------------
 1 files changed, 127 insertions(+), 118 deletions(-)

diff --git a/src/components/header/index.jsx b/src/components/header/index.jsx
index def0339..7db59b7 100644
--- a/src/components/header/index.jsx
+++ b/src/components/header/index.jsx
@@ -1,21 +1,13 @@
 import React, {Component} from 'react'
 import { withRouter } from 'react-router-dom'
-import PropTypes from 'prop-types'
-import {connect} from 'react-redux'
 import { is, fromJS } from 'immutable'
 import { Dropdown, Menu, Modal, notification, Switch, Input } from 'antd'
 import { SearchOutlined, DownOutlined, MenuFoldOutlined, MenuUnfoldOutlined } from '@ant-design/icons'
 
-import {
-  toggleCollapse,
-  modifyMainMenu,
-  logout
-} from '@/store/action'
 import asyncSpinComponent from '@/utils/asyncSpinComponent'
 import asyncComponent from '@/utils/asyncComponent'
 import Api from '@/api'
 import MKEmitter from '@/utils/events.js'
-import options from '@/store/options.js'
 import Utils from '@/utils/utils.js'
 import avatar from '@/assets/img/avatar.jpg'
 import './index.scss'
@@ -27,9 +19,6 @@
 const LoginForm = asyncSpinComponent(() => import('./loginform'))
 
 class Header extends Component {
-  static propTpyes = {
-    collapse: PropTypes.bool
-  }
   state = {
     menulist: null, // 涓�绾ц彍鍗�
     userName: '',
@@ -41,13 +30,73 @@
     systems: [],
     searchkey: '',
     thdMenuList: [],
-    debug: sessionStorage.getItem('debug') === 'true'
+    debug: sessionStorage.getItem('debug') === 'true' && window.GLOB.memberLevel > 0,
+    collapse: sessionStorage.getItem('collapse') === 'true'
+  }
+
+  UNSAFE_componentWillMount () {
+    window.GLOB.mainMenu = null
+    // 缁勪欢鍔犺浇鏃讹紝鑾峰彇鑿滃崟鏁版嵁
+    this.getRolesMenu()
+
+    let fullName = sessionStorage.getItem('Full_Name') || ''
+    let userName = sessionStorage.getItem('User_Name') || ''
+
+    if (fullName.toLowerCase() === userName.toLowerCase()) {
+      userName = ''
+    }
+
+    this.setState({fullName, userName})
+  }
+
+  componentDidMount () {
+    // 鑾峰彇绯荤粺鐨勭増鏈俊鎭紝寤舵椂鏌ヨ
+    setTimeout(() => {
+      Api.getAppVersion()
+    }, 1000)
+
+    // sessionStorage 璺ㄩ〉闈㈠叡浜�
+    window.addEventListener('storage', (e) => {
+      if (e.key === 'getSessionStorage' && e.newValue === window.GLOB.appkey) {
+        localStorage.setItem('sessionStorage', JSON.stringify(sessionStorage))
+      } else if (e.key === 'getSysPermission' && e.newValue === window.GLOB.appkey) {
+        localStorage.setItem('sysPermissions', JSON.stringify({mkThdMenus: window.GLOB.mkThdMenus, mkActions: window.GLOB.mkActions}))
+      } else if (e.key === 'menuUpdate') {
+        let vals = e.newValue.split(',')
+        let menuId = vals[1]
+        let position = vals[2] || ''
+        if (position === 'menu') {
+          MKEmitter.emit('reloadMenuView', menuId)
+        } else if (menuId) {
+          Api.getAppVersion(menuId).then(() => {
+            MKEmitter.emit('reloadMenuView', menuId)
+          })
+        }
+      }
+    })
+  }
+
+  shouldComponentUpdate (nextProps, nextState) {
+    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
+  }
+
+  /**
+   * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊
+   */
+  componentWillUnmount () {
+    this.setState = () => {
+      return
+    }
   }
 
   handleCollapse = () => {
-    // 灞曞紑銆佹敹璧峰乏渚ц彍鍗曟爮
-    this.props.toggleCollapse(!this.props.collapse)
-    localStorage.setItem('collapse', !this.props.collapse)
+    const { collapse } = this.state
+
+    sessionStorage.setItem('collapse', !collapse)
+
+    this.setState({collapse: !collapse})
+
+    MKEmitter.emit('toggleCollapse', !collapse)
   }
 
   changePassword = () => {
@@ -55,7 +104,6 @@
     MKEmitter.emit('resetpassword', () => {
       setTimeout(() => {
         sessionStorage.clear()
-        this.props.logout()
         this.props.history.replace('/login')
       }, 2000)
     })
@@ -71,7 +119,6 @@
       cancelText: '鍙栨秷',
       onOk() {
         sessionStorage.clear()
-        _this.props.logout()
         _this.props.history.replace('/login')
       },
       onCancel() {}
@@ -80,16 +127,19 @@
 
   changeMenu (value) {
     // 涓昏彍鍗曞垏鎹�
-    if (value.OpenType === 'outpage') {
-      window.open(value.linkUrl)
+    if (value.OpenType === 'newpage') {
+      window.open(value.src)
+    } else if (value.OpenType === 'newtab') {
+      MKEmitter.emit('modifyTabs', value)
     } else if (value.OpenType === 'menu') {
-      this.props.modifyMainMenu(value)
+      window.GLOB.mainMenu = value
+      MKEmitter.emit('mainMenuChange')
     }
   }
 
   getRolesMenu () {
     // 鑾峰彇涓昏彍鍗曞弬鏁�
-    let _param = {func: 's_get_pc_menus', systemType: options.sysType}
+    let _param = {func: 's_get_pc_menus', systemType: window.GLOB.sysType}
     _param.pro_sys = window.GLOB.systemType === 'production' ? 'Y' : ''
     
     Api.getSystemConfig(_param).then(result => {
@@ -105,10 +155,10 @@
       const { menulist, thdMenuList } = this.getMenulist(result)
 
       let systems = []
-      if ((options.sysType === 'local' || options.sysType === 'SSO') && result.sys_list) {
+      if ((window.GLOB.sysType === 'local' || window.GLOB.sysType === 'SSO') && result.sys_list) {
         systems = result.sys_list
 
-        if (options.sysType === 'local' && window.GLOB.systemType !== 'production' && systems.length > 10) {
+        if (window.GLOB.sysType === 'local' && window.GLOB.systemType !== 'production' && systems.length > 10) {
           systems.length = 10
         }
       }
@@ -129,16 +179,14 @@
         sessionStorage.removeItem('ThirdMenu')
       }
 
-      this.props.modifyMainMenu(mainMenu)
-
+      window.GLOB.mainMenu = mainMenu
       window.GLOB.mkThdMenus = [...thdMenuList, {MenuID: 'home_page_id', EasyCode: '', MenuName: 'home', type: 'CustomPage'}]
 
-      if (_menu) { // 寤舵椂鎵撳紑锛岄槻姝㈡爣绛剧粍鏈畬鎴愬姞杞�
-        setTimeout(() => {
-          MKEmitter.emit('modifyTabs', _menu)
-        }, 200)
+      MKEmitter.emit('mainMenuChange')
+
+      if (_menu) {
+        this.openTab(_menu, 0)
       }
-      MKEmitter.emit('mkMenuLoaded')
     })
     
     // 鑾峰彇瑙掕壊鏉冮檺, edition_type 鎺ュ彛鐗堟湰鎺у埗 ''銆�'Y'銆�'A'
@@ -165,10 +213,24 @@
           })
         }
 
-        MKEmitter.emit('mkActionLoaded')
         window.GLOB.mkActions = _permAction
       })
     }, 50)
+  }
+
+  openTab = (menu, times) => {
+    if (times > 50) return
+    times++
+
+    let tabgroup = document.getElementById('mk-tabgroup-wrap')
+
+    if (window.GLOB.mkActions.loaded && tabgroup) {
+      MKEmitter.emit('modifyTabs', menu)
+    } else {
+      setTimeout(() => {
+        this.openTab(times)
+      }, 200)
+    }
   }
 
   getMenulist = (result) => {
@@ -188,8 +250,13 @@
           let PageParam = JSON.parse(fst.PageParam)
 
           if (PageParam.OpenType === 'outpage' && PageParam.linkUrl) {
-            fstItem.OpenType = 'outpage'
-            fstItem.linkUrl = PageParam.linkUrl
+            fstItem.OpenType = 'newpage'
+            fstItem.src = PageParam.linkUrl
+            if (/#\/iframe\//.test(fstItem.src)) {
+              fstItem.src = fstItem.src.replace(/@loginuid@/ig, sessionStorage.getItem('LoginUID'))
+              fstItem.type = 'iframe'
+              fstItem.OpenType = 'newtab'
+            }
           }
         } catch (e) {}
       }
@@ -237,16 +304,23 @@
                   trdItem.hidden = PageParam.hidden || 'false'
 
                   if (trdItem.type === 'NewPage') {
+                    trdItem.OpenType = 'newpage'
                     trdItem.src = PageParam.url || ''
+                    if (/#\/iframe\//.test(trdItem.src)) {
+                      trdItem.src = trdItem.src.replace(/@loginuid@/ig, sessionStorage.getItem('LoginUID'))
+                      trdItem.type = 'iframe'
+                      trdItem.OpenType = 'newtab'
+                    }
+                  } else if (trdItem.OpenType === 'view') {
+                    trdItem.OpenType = 'newpage'
+                    trdItem.src = '#/view/' + trd.MenuID
+                  } else {
+                    trdItem.src = '#/tab/' + trd.MenuID
                   }
                 } catch (e) {}
-              }
-
-              if (trdItem.type !== 'NewPage') {
+              } else {
                 trdItem.src = '#/tab/' + trd.MenuID
               }
-
-              trdItem.OpenType = trdItem.OpenType.toLowerCase() // NewPage涓烘墦寮�澶栭儴椤甸潰鍦板潃
 
               if (names.has(trdItem.menu_name)) {
                 doublenames.set(trdItem.menu_name, true)
@@ -289,10 +363,7 @@
         loginVisible: true
       })
     } else {
-      sessionStorage.setItem('isEditState', 'true')
-
-      this.props.modifyMainMenu(null)
-
+      window.GLOB.mainMenu = null
       this.props.history.replace('/design')
     }
   }
@@ -331,15 +402,15 @@
           sessionStorage.setItem('cloudDataM', res.dataM ? 'true' : '')
           sessionStorage.setItem('cloudRole_id', res.role_id || '')
 
-          sessionStorage.setItem('isEditState', 'true')
-
+          let _url = window.location.href.split('#')[0] + 'cloud'
           if (param.remember) {
-            let _url = window.location.href.split('#')[0] + 'cloud'
-
             localStorage.setItem(_url, window.btoa(window.encodeURIComponent(JSON.stringify({time: new Date().getTime(), username: param.username, password: param.password}))))
+          } else {
+            localStorage.setItem(_url, window.btoa(window.encodeURIComponent(JSON.stringify({time: new Date().getTime(), username: param.username, password: ''}))))
           }
 
-          this.props.modifyMainMenu(null)
+          window.GLOB.mainMenu = null
+
           this.props.history.replace('/design')
         } else {
           if (res.message.indexOf('瀵嗙爜閿欒') > -1) {
@@ -421,69 +492,23 @@
       }
     })
   }
-  
-  UNSAFE_componentWillMount () {
-    // 缁勪欢鍔犺浇鏃讹紝鑾峰彇鑿滃崟鏁版嵁
-    this.getRolesMenu()
-
-    let fullName = sessionStorage.getItem('Full_Name') || ''
-    let userName = sessionStorage.getItem('User_Name') || ''
-
-    if (fullName.toLowerCase() === userName.toLowerCase()) {
-      userName = ''
-    }
-
-    this.setState({fullName, userName})
-  }
-
-  componentDidMount () {
-    // 鑾峰彇绯荤粺鐨勭増鏈俊鎭紝寤舵椂鏌ヨ
-    setTimeout(() => {
-      Api.getAppVersion()
-    }, 1000)
-
-    // sessionStorage 璺ㄩ〉闈㈠叡浜�
-    window.addEventListener('storage', (e) => {
-      if (e.key === 'getSessionStorage' && e.newValue === window.GLOB.appkey) {
-        localStorage.setItem('sessionStorage', JSON.stringify(sessionStorage))
-      } else if (e.key === 'menuUpdate') {
-        let menuId = e.newValue.split(',')[1]
-        if (menuId) {
-          Api.getAppVersion(menuId).then(() => {
-            MKEmitter.emit('reloadMenuView', menuId)
-          })
-        }
-      }
-    })
-  }
-
-  shouldComponentUpdate (nextProps, nextState) {
-    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
-  }
-
-  /**
-   * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊
-   */
-  componentWillUnmount () {
-    this.setState = () => {
-      return
-    }
-  }
 
   gotoDoc = () => {
-    if (options.sysType === 'local' && window.GLOB.mainSystemApi) {
+    if (window.GLOB.sysType === 'local' && window.GLOB.mainSystemApi) {
       let ssodomain = window.GLOB.mainSystemApi.replace('/webapi/dostars', '')
       let url = `${ssodomain}/doc/index.html#?appkey=${window.GLOB.appkey}&LoginUID=${sessionStorage.getItem('LoginUID')}`
       window.open(url)
-    } else if (options.sysType === 'SSO' || options.sysType === 'cloud') {
+    } else if (window.GLOB.sysType === 'SSO' || window.GLOB.sysType === 'cloud') {
       window.open(`${window.location.href.replace(/\/admin(.*)|\/index.html(.*)|\/#(.*)/ig, '')}/doc/index.html#?appkey=${window.GLOB.appkey}&LoginUID=${sessionStorage.getItem('LoginUID')}`)
     }
   }
 
   changeVerMenu(menu, type) {
     if (type === 'first') {
-      if (menu.OpenType === 'outpage') {
-        window.open(menu.linkUrl)
+      if (menu.OpenType === 'newpage') {
+        window.open(menu.src)
+      } else if (menu.OpenType === 'newtab') {
+        MKEmitter.emit('modifyTabs', menu)
       }
     } else {
       if (menu.OpenType === 'newpage') {
@@ -550,8 +575,7 @@
   }
 
   render () {
-    const { mainMenu, collapse } = this.props
-    const { thdMenuList, searchkey, debug, menulist } = this.state
+    const { thdMenuList, searchkey, debug, menulist, collapse } = this.state
     const navBar = window.GLOB.navBar
 
     const menu = (
@@ -593,7 +617,7 @@
           <ul className="header-menu">{
             menulist.map(item => {
               return (
-                <li key={item.MenuID} onClick={() => {this.changeMenu(item)}} className={mainMenu && mainMenu.MenuID === item.MenuID ? 'active' : ''}>
+                <li key={item.MenuID} onClick={() => {this.changeMenu(item)}} className={window.GLOB.mainMenu && window.GLOB.mainMenu.MenuID === item.MenuID ? 'active' : ''}>
                   <span>{item.MenuName}</span>
                 </li>
               )
@@ -748,19 +772,4 @@
   }
 }
 
-const mapStateToProps = (state) => {
-  return {
-    collapse: state.collapse,
-    mainMenu: state.mainMenu
-  }
-}
-
-const mapDispatchToProps = (dispatch) => {
-  return {
-    toggleCollapse: (collapse) => dispatch(toggleCollapse(collapse)),
-    modifyMainMenu: (mainMenu) => dispatch(modifyMainMenu(mainMenu)),
-    logout: () => dispatch(logout())
-  }
-}
-
-export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Header))
\ No newline at end of file
+export default withRouter(Header)
\ No newline at end of file

--
Gitblit v1.8.0