From d59f518f466274b2caeb2e01c10c92deafe7c93b Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 09 二月 2022 11:48:29 +0800
Subject: [PATCH] 2022-02-09

---
 src/components/header/index.jsx |  153 +++++++++++++++++++++-----------------------------
 1 files changed, 65 insertions(+), 88 deletions(-)

diff --git a/src/components/header/index.jsx b/src/components/header/index.jsx
index 84855e4..dca77b8 100644
--- a/src/components/header/index.jsx
+++ b/src/components/header/index.jsx
@@ -4,17 +4,17 @@
 import {connect} from 'react-redux'
 import { is, fromJS } from 'immutable'
 import moment from 'moment'
-import { Dropdown, Menu, Icon, Modal, Form, notification, Switch, Input } from 'antd'
+import { Dropdown, Menu, Modal, Form, notification, Switch, Input } from 'antd'
+import { SearchOutlined, DownOutlined, MenuFoldOutlined, MenuUnfoldOutlined } from '@ant-design/icons'
 
 import {
   toggleCollapse,
-  modifyMenuTree,
   modifyMainMenu,
-  modifyTabview,
   initActionPermission,
   initMenuPermission,
   logout
 } from '@/store/action'
+import asyncComponent from '@/utils/asyncComponent'
 import Api from '@/api'
 import MKEmitter from '@/utils/events.js'
 import options from '@/store/options.js'
@@ -22,12 +22,12 @@
 import enUS from '@/locales/en-US/main.js'
 import Utils from '@/utils/utils.js'
 import avatar from '@/assets/img/avatar.jpg'
-import Resetpwd from './resetpwd'
-import LoginForm from './loginform'
 import './index.scss'
 
 const { confirm } = Modal
 const { Search } = Input
+const Resetpwd = asyncComponent(() => import('./resetpwd'))
+const LoginForm = asyncComponent(() => import('./loginform'))
 
 class Header extends Component {
   static propTpyes = {
@@ -40,6 +40,7 @@
     confirmLoading: false,
     userName: sessionStorage.getItem('User_Name'),
     logourl: window.GLOB.mainlogo,
+    appVersion: window.GLOB.appVersion,
     loginVisible: false,
     loginLoading: false,
     avatar: Utils.getrealurl(sessionStorage.getItem('avatar')),
@@ -88,9 +89,14 @@
         if (result.status) {
           notification.success({
             top: 92,
-            message: this.state.dict['main.password.resetsuccess'],
+            message: '淇敼鎴愬姛锛岃閲嶆柊鐧诲綍銆�',
             duration: 2
           })
+          setTimeout(() => {
+            sessionStorage.clear()
+            this.props.logout()
+            this.props.history.replace('/login')
+          }, 2000)
         } else {
           notification.warning({
             top: 92,
@@ -137,31 +143,33 @@
     // 鑾峰彇瑙掕壊鏉冮檺
     let roledefer = new Promise(resolve => {
       // edition_type 鎺ュ彛鐗堟湰鎺у埗 ''銆�'Y'銆�'A'
-      Api.getSystemConfig({
-        func: 's_Get_TrdMenu_Role',
-        edition_type: 'A',
-        pro_sys: window.GLOB.systemType === 'production' ? 'Y' : ''
-      }).then(result => {
-        let _permAction = {loaded: true} // 鎸夐挳鏉冮檺
-
-        if (result && result.status) {
-          if (result.UserRoles_Menu) {
-            result.UserRoles_Menu.forEach(menu => {
-              if (!menu.MenuID) return
-              _permAction[menu.MenuID] = true
+      setTimeout(() => {
+        Api.getSystemConfig({
+          func: 's_Get_TrdMenu_Role',
+          edition_type: 'A',
+          pro_sys: window.GLOB.systemType === 'production' ? 'Y' : ''
+        }).then(result => {
+          let _permAction = {loaded: true} // 鎸夐挳鏉冮檺
+  
+          if (result && result.status) {
+            if (result.UserRoles_Menu) {
+              result.UserRoles_Menu.forEach(menu => {
+                if (!menu.MenuID) return
+                _permAction[menu.MenuID] = true
+              })
+            }
+          } else if (result) {
+            notification.error({
+              top: 92,
+              message: result.message,
+              duration: 10
             })
           }
-        } else if (result) {
-          notification.error({
-            top: 92,
-            message: result.message,
-            duration: 10
-          })
-        }
-
-        this.props.initActionPermission(_permAction)
-        resolve()
-      })
+  
+          this.props.initActionPermission(_permAction)
+          resolve()
+        })
+      }, 50)
     })
 
     // 鑾峰彇涓昏彍鍗曞弬鏁�
@@ -211,7 +219,6 @@
           sessionStorage.removeItem('ThirdMenu')
         }
 
-        this.props.modifyMenuTree(menulist)
         this.props.modifyMainMenu(mainMenu)
         this.props.initMenuPermission([...thdMenuList, {MenuID: 'home_page_id', EasyCode: '', MenuName: 'home', type: 'CustomPage'}])
 
@@ -221,21 +228,12 @@
     
     Promise.all([roledefer, menudefer]).then(response => {
       if (response[1]) {
-        let tabs = fromJS(this.props.tabviews).toJS()
         let menu = fromJS(response[1]).toJS()
 
         if (this.state.navBar === 'topmenu' && this.state.menuType !== 'menu_board_navigation') {
-          menu.selected = true
-          this.props.modifyTabview([menu])
+          MKEmitter.emit('modifyTabs', menu, 'replace')
         } else {
-          tabs = tabs.map(tab => {
-            tab.selected = false
-            return tab
-          })
-
-          menu.selected = true
-          tabs.push(menu)
-          this.props.modifyTabview(tabs)
+          MKEmitter.emit('modifyTabs', menu, 'plus')
         }
       }
     })
@@ -384,9 +382,7 @@
       sessionStorage.setItem('dataM', sessionStorage.getItem('cloudDataM'))
       sessionStorage.setItem('isEditState', 'true')
 
-      this.props.modifyMenuTree([])
       this.props.modifyMainMenu(null)
-      this.props.modifyTabview([])
 
       this.props.history.replace('/design')
     }
@@ -411,12 +407,14 @@
           sessionStorage.setItem('dataM', res.dataM ? 'true' : '')
           sessionStorage.setItem('isEditState', 'true')
 
+          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}))))
+          }
+
           this.setSystemFuncs()
-
-          this.props.modifyMenuTree([])
           this.props.modifyMainMenu(null)
-          this.props.modifyTabview([])
-
           this.props.history.replace('/design')
         } else {
           if (res.message.indexOf('瀵嗙爜閿欒') > -1) {
@@ -583,14 +581,6 @@
     this.getRolesMenu()
   }
 
-  UNSAFE_componentWillReceiveProps (nextProps) {
-    if (!is(fromJS(this.props.menuTree), fromJS(nextProps.menuTree)) && !is(fromJS(this.state.menulist), fromJS(nextProps.menuTree))) {
-      this.setState({
-        menulist: nextProps.menuTree
-      })
-    }
-  }
-
   componentDidMount () {
     // 鑾峰彇绯荤粺鐨勭増鏈俊鎭紝寤舵椂鏌ヨ
     setTimeout(() => {
@@ -632,27 +622,11 @@
       if (menu.OpenType === 'newpage' || menu.OpenType === 'NewPage') { // NewPage涓烘墦寮�澶栭儴椤甸潰鍦板潃锛宯ewpage涓烘墦寮�绯荤粺鑿滃崟
         window.open(menu.src)
       } else if (menu.OpenType === 'blank') {
-        menu.selected = true
-        this.props.modifyTabview([menu])
+        MKEmitter.emit('modifyTabs', menu, 'replace')
       } else if (this.state.navBar === 'topmenu' && this.state.menuType !== 'menu_board_navigation') {
-        menu.selected = true
-        this.props.modifyTabview([menu])
+        MKEmitter.emit('modifyTabs', menu, 'replace')
       } else {
-        let tabs = fromJS(this.props.tabviews).toJS()
-        tabs = tabs.filter(tab => {
-          tab.selected = false
-          return tab.MenuID !== menu.MenuID
-        })
-  
-        if (this.props.tabviews.length > tabs.length) {
-          this.props.modifyTabview(fromJS(tabs).toJS())
-        }
-  
-        this.setState({}, () => {
-          menu.selected = true
-          tabs.push(menu)
-          this.props.modifyTabview(tabs)
-        })
+        MKEmitter.emit('modifyTabs', menu, 'plus')
       }
   
       if (window.GLOB.systemType === 'production') {
@@ -663,14 +637,14 @@
 
   verup = () => {
     confirm({
-      title: '鐗堟湰鍗囩骇',
+      title: '椤甸潰鏇存柊',
       content: '閲嶆柊鍔犺浇搴旂敤淇℃伅',
       onOk() {
         return new Promise(resolve => {
           if (!window.GLOB.WebSql && !window.GLOB.IndexDB) {
             notification.warning({
               top: 92,
-              message: '鍗囩骇澶辫触锛岃鍒锋柊椤甸潰閲嶈瘯锛�',
+              message: '鏇存柊澶辫触锛岃鍒锋柊椤甸潰閲嶈瘯锛�',
               duration: 2
             })
             resolve()
@@ -679,7 +653,7 @@
             setTimeout(() => {
               notification.success({
                 top: 92,
-                message: '鍗囩骇鎴愬姛锛�',
+                message: '鏇存柊鎴愬姛锛�',
                 duration: 2
               })
               resolve()
@@ -691,10 +665,15 @@
     })
   }
 
+  about = () => {
+    Modal.success({
+      title: '绯荤粺鐗堟湰v' + this.state.appVersion
+    })
+  }
 
   render () {
     const { mainMenu, collapse } = this.props
-    const { thdMenuList, searchkey, debug, menulist, navBar, menuType } = this.state
+    const { thdMenuList, searchkey, debug, menulist, navBar, menuType, appVersion } = this.state
 
     const menu = (
       <Menu className="header-dropdown">
@@ -710,8 +689,11 @@
         </Menu.SubMenu> : null}
         <Menu.Item key="doc" onClick={this.gotoDoc}>{this.state.dict['main.doc']}</Menu.Item>
         <Menu.Item key="verup" onClick={this.verup}>
-          鐗堟湰鍗囩骇
+          椤甸潰鏇存柊
         </Menu.Item>
+        {appVersion ? <Menu.Item key="version" onClick={this.about}>
+          鍏充簬
+        </Menu.Item> : null}
         <Menu.Item key="logout" onClick={this.logout}>{this.state.dict['main.logout']}</Menu.Item>
       </Menu>
     )
@@ -720,7 +702,7 @@
       <header className="header-container ant-menu-dark" id="main-header-container">
         <div className={'header-logo ' + (collapse && navBar !== 'topmenu' ? 'collapse' : '')}><img src={this.state.logourl} alt=""/></div>
         <div className={'header-collapse ' + (collapse && navBar !== 'topmenu' ? 'collapse' : '')}>
-          {navBar !== 'topmenu' ? <Icon type={collapse ? 'menu-unfold' : 'menu-fold'} onClick={this.handleCollapse}/> : null}
+          {navBar !== 'topmenu' ? (collapse ? <MenuUnfoldOutlined onClick={this.handleCollapse}/> : <MenuFoldOutlined onClick={this.handleCollapse}/>) : null}
         </div>
         {/* 姝e父鑿滃崟 */}
         {navBar !== 'topmenu' && menulist ?
@@ -820,7 +802,7 @@
           <div>
             <img src={this.state.avatar || avatar} alt=""/>
             <span>
-              <span className="username">{this.state.userName}</span> <Icon type="down" />
+              <span className="username">{this.state.userName}</span> <DownOutlined />
             </span>
           </div>
         </Dropdown>
@@ -857,7 +839,7 @@
               </div>
             </div>
           } trigger={['click']} className="search-menu" placement="bottomRight" onVisibleChange={this.dropdownMenuChange}>
-            <Icon className="search-menu" type="search" />
+            <SearchOutlined className="search-menu" />
           </Dropdown> : null
         }
         {/* 淇敼瀵嗙爜 */}
@@ -890,19 +872,14 @@
 
 const mapStateToProps = (state) => {
   return {
-    tabviews: state.tabviews,
     collapse: state.collapse,
-    menuTree: state.menuTree,
-    mainMenu: state.mainMenu,
-    permAction: state.permAction,
+    mainMenu: state.mainMenu
   }
 }
 
 const mapDispatchToProps = (dispatch) => {
   return {
     toggleCollapse: (collapse) => dispatch(toggleCollapse(collapse)),
-    modifyTabview: (tabviews) => dispatch(modifyTabview(tabviews)),
-    modifyMenuTree: (menuTree) => dispatch(modifyMenuTree(menuTree)),
     modifyMainMenu: (mainMenu) => dispatch(modifyMainMenu(mainMenu)),
     initActionPermission: (permAction) => dispatch(initActionPermission(permAction)),
     initMenuPermission: (permMenus) => dispatch(initMenuPermission(permMenus)),

--
Gitblit v1.8.0