From fc68f6006949a91fced69951778a7c88859cbb6c Mon Sep 17 00:00:00 2001
From: Mr Ke <kelq@hugeinfo.com.cn>
Date: Wed, 06 May 2020 10:49:07 +0800
Subject: [PATCH] Merge branch 'master' of http://120.79.193.119:9090/r/huge/frontEnd/hugeOA

---
 src/components/common/MenuView/index.jsx |   39 +++++++++++++++++++++++----------------
 1 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/src/components/common/MenuView/index.jsx b/src/components/common/MenuView/index.jsx
index 7b9e76b..77c8892 100644
--- a/src/components/common/MenuView/index.jsx
+++ b/src/components/common/MenuView/index.jsx
@@ -6,7 +6,7 @@
 
 /** 菜单渲染组件 */
 
-import React from 'react';
+import React, { useState } from 'react';
 import { Layout, Menu, Icon, Badge } from 'antd';
 import { RouteComponentProps } from 'react-router-dom';
 import './index.scss';
@@ -20,35 +20,42 @@
 }) {
     if (!menudata.length) return null;
 
-    const { path, name } = find(menudata, pathname);
+    const { path, name, parentKey } = find(menudata, pathname);
 
     if (name) {
         const index = name.indexOf(' - ');
         if (index > -1) {
-            document.title = `${name.substr(index)}`;
+            document.title = `恒巨信息OA-${name.substr(index)}`;
         } else {
-            document.title = `${name}`;
+            document.title = `恒巨信息OA-${name}`;
         }
     } else {
-        document.title = `xx系统`;
+        document.title = `恒巨信息`;
     }
 
-    const defaultOpenKeys = menudata.map(({ name }) => name);
+    const defaultOpenKeys = parentKey ? [parentKey] : [];//默认展开的菜单key
+    const [openKeys, setOpenKeys] = useState(defaultOpenKeys);//设置打开菜单的key
+
+    function onOpenChange(key) {
+        let allKeys = menudata.map((d) => d.key);
+        const latestOpenKey = key.find(key => openKeys.indexOf(key) === -1);
+        if (allKeys.indexOf(latestOpenKey) === -1) {
+            setOpenKeys(key)
+        } else {
+            setOpenKeys(latestOpenKey ? [latestOpenKey] : [])
+        }
+    };
 
     return (
-        // <Layout.Sider
-        //   // width={200}
-        //   theme="light"
-        //   style={{ backgroundColor: 'white' }}>
         <Menu
             key={defaultOpenKeys.join('-')}
             style={{ height: '100%', borderRight: 0 }}
-            defaultOpenKeys={defaultOpenKeys}
+            openKeys={openKeys}
             selectedKeys={path ? [path] : []}
+            onOpenChange={onOpenChange}
             mode="inline">
             {render(menudata, history)}
         </Menu>
-        // </Layout.Sider>
     );
 }
 
@@ -56,7 +63,7 @@
     return data.map(({ name, icon, path, count, children, type }, index) =>
         children && children.length ? (
             <SubMenu
-                key={name}
+                key={path}
                 title={
                     <span>
                         <Icon type={icon || 'setting'} />
@@ -71,7 +78,7 @@
                     title={name.length > 10 ? name : undefined}
                     onClick={() => {
                         if (type == 'open') {
-                            window.open('/#' + path);
+                            window.open(path);
                         } else {
                             history.replace(path);
                         }
@@ -84,7 +91,7 @@
 };
 
 const find = (data, full, pathname = { path: '', name: '' }) =>
-    data.reduce((pn, { path, name, children }) => {
+    data.reduce((pn, { path, name, parentKey, children }) => {
         if (children && children.length) {
             return find(children, full, pn);
         }
@@ -92,7 +99,7 @@
             path.length > pn.path.length &&
             full.replace(/\/\d+/g, '').startsWith(path.replace(/\/\d+/g, ''))
         ) {
-            return { path, name };
+            return { path, name, parentKey };
         }
         return pn;
     }, pathname);

--
Gitblit v1.8.0