Pārlūkot izejas kodu

调整_layout默认显示

code4eat 3 gadi atpakaļ
vecāks
revīzija
06fa929528
3 mainītis faili ar 78 papildinājumiem un 73 dzēšanām
  1. 32 32
      src/components/topBar/index.tsx
  2. 1 3
      src/layouts/index.tsx
  3. 45 38
      src/pages/platform/_layout.tsx

+ 32 - 32
src/components/topBar/index.tsx

@@ -1,7 +1,7 @@
 /*
  * @Author: your name
  * @Date: 2021-11-16 09:12:37
- * @LastEditTime: 2022-09-07 10:24:52
+ * @LastEditTime: 2022-09-07 11:25:51
  * @LastEditors: code4eat awesomedema@gmail.com
  * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  * @FilePath: /KC-MiddlePlatform/src/pages/index/components/topBar/index.tsx
@@ -165,49 +165,49 @@ const TopBar: React.FC<TopBarType> = (props) => {
 
   const reSetNav = (_panelData: TopBar.PanelData[], cur: TopBar.Tab) => {
     
-    // if (!(_panelData.length > 0)) return
+    if (!(_panelData.length > 0)) return
 
-    // if (JSON.stringify(cur) != '{}') {
+    if (JSON.stringify(cur) != '{}') {
 
-    //   let blockIndex = 0;
-    //   let channelIndex = 0;
+      let blockIndex = 0;
+      let channelIndex = 0;
 
 
-    //   const _currentSelectedTabFromLocal = cur;
+      const _currentSelectedTabFromLocal = cur;
 
-    //   one: for (let index = 0; index < _panelData.length; index++) {
-    //     blockIndex = index;
+      one: for (let index = 0; index < _panelData.length; index++) {
+        blockIndex = index;
     
-    //     if (_panelData[index] && _panelData[index].child) {
-    //       two: for (let i = 0; i < _panelData[index].child.length; i++) {
-
-    //         channelIndex = i;
-    //         if (_panelData && _panelData.length > 0) {
-    //           const _systems = _panelData[index].child[i].child;
-    //           if (_systems && _systems.length > 0) {
-    //             for (let k = 0; k < _systems.length; k++) {
-    //               if (_systems[k].menuId == _currentSelectedTabFromLocal.menuId) {
-    //                 set_currentActivedBlockIndex(blockIndex);
-    //                  set_pageTitle(_panelData[blockIndex].child[channelIndex].name); //设置体系标题
+        if (_panelData[index] && _panelData[index].child) {
+          two: for (let i = 0; i < _panelData[index].child.length; i++) {
+
+            channelIndex = i;
+            if (_panelData && _panelData.length > 0) {
+              const _systems = _panelData[index].child[i].child;
+              if (_systems && _systems.length > 0) {
+                for (let k = 0; k < _systems.length; k++) {
+                  if (_systems[k].menuId == _currentSelectedTabFromLocal.menuId) {
+                    set_currentActivedBlockIndex(blockIndex);
+                     set_pageTitle(_panelData[blockIndex].child[channelIndex].name); //设置体系标题
                      
-    //                 break one;
-    //               }
-    //             }
-    //           }
-    //         }
+                    break one;
+                  }
+                }
+              }
+            }
 
-    //       }
-    //     }
-    //   }
+          }
+        }
+      }
 
-    //   if (_panelData && _panelData.length > 0 && _panelData[blockIndex].child) {
-    //     setSystemTabs(_panelData[blockIndex].child[channelIndex].child);  //恢复体系列表
-    //   }
+      // if (_panelData && _panelData.length > 0 && _panelData[blockIndex].child) {
+      //   setSystemTabs(_panelData[blockIndex].child[channelIndex].child);  //恢复体系列表
+      // }
 
-    //   _systemTabClickHandle(_currentSelectedTabFromLocal);  //恢复选中的tab
+      // _systemTabClickHandle(_currentSelectedTabFromLocal);  //恢复选中的tab
   
 
-    // }
+    }
   }
 
   useEffect(() => { 

+ 1 - 3
src/layouts/index.tsx

@@ -1,7 +1,7 @@
 /*
  * @Author: your name
  * @Date: 2021-11-09 13:56:33
- * @LastEditTime: 2022-09-07 09:41:38
+ * @LastEditTime: 2022-09-07 11:21:11
  * @LastEditors: code4eat awesomedema@gmail.com
  * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  * @FilePath: /KC-MiddlePlatform/src/layouts/index.tsx
@@ -29,8 +29,6 @@ const TopHoc = ({ currentSelectedSys, openedSysLists, navData,set_emptyPageConte
   
     if(JSON.stringify(data) != '{}'){
       await setInitialState((s) => ({ ...s, currentSelectedSys: data }));
-
-      console.log({data});
   
       if(data.contentType == '4'){
           //空白页面

+ 45 - 38
src/pages/platform/_layout.tsx

@@ -1,7 +1,7 @@
 /*
  * @Author: your name
  * @Date: 2022-01-06 15:25:39
- * @LastEditTime: 2022-07-19 10:09:28
+ * @LastEditTime: 2022-09-07 14:32:26
  * @LastEditors: code4eat awesomedema@gmail.com
  * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  * @FilePath: /KC-MiddlePlatform/src/pages/platform/_layout.tsx
@@ -23,39 +23,39 @@ export default function Layout({ children, location, route, history, match, ...r
   const [openKeys, set_openKeys] = useState<string[]>([]);
   const [selectedKeys, set_selectedKeys] = useState<string[]>([]);
   const [emptyPageContent, set_emptyPageContent] = useState('');
-  const [isShowPageMenu,set_isShowPageMenu] = useState(true);
-  const [isEmpty,set_isEmpty] = useState(false);
+  const [isShowPageMenu, set_isShowPageMenu] = useState(true);
+  const [isEmpty, set_isEmpty] = useState(false);
 
   //const isShowMenu = localStorage.getItem('isChildShowMenu');
   // console.log({ children, location, route, history, match});
 
 
 
-  const setEmptyPageContent =async (menuId:Key) => {
+  const setEmptyPageContent = async (menuId: Key) => {
     const menuItem = await getSpecifyMenuDetail(menuId);
-    if(menuItem.isSetupMenu){
+    if (menuItem.isSetupMenu) {
       set_isShowPageMenu(false);
     }
     set_emptyPageContent(menuItem.description);
   }
 
-  useEffect(()=>{
+  useEffect(() => {
 
     const isShowMenu = localStorage.getItem('isChildShowMenu');
     set_isShowPageMenu(isShowMenu == 'true')
   });
 
-  useEffect(()=>{
+  useEffect(() => {
 
     // console.log({location});
     // console.log(location.query.isEmpty == 'true');
 
-    if(location.query.menuId){
-      setEmptyPageContent(location.query.menuId as string);   
-    } 
-    
+    if (location.query.menuId) {
+      setEmptyPageContent(location.query.menuId as string);
+    }
+
     set_isEmpty(location.query.isEmpty == 'true');
-  },[location])
+  }, [location])
 
 
   return (
@@ -70,11 +70,11 @@ export default function Layout({ children, location, route, history, match, ...r
       location={{
 
       }}
-      siderWidth={isShowPageMenu? 220 : 0}
+      siderWidth={isShowPageMenu ? 220 : 0}
       pageTitleRender={false}
       disableContentMargin
       menuItemRender={(item, dom) => {
-  
+
         return (
           <a
             onClick={() => {
@@ -101,20 +101,20 @@ export default function Layout({ children, location, route, history, match, ...r
           initialState
         },
         request: async () => {
-        
-          if (initialState&&initialState.currentSelectedSys) {
-            const {systemId,menuId} = initialState.currentSelectedSys;
-            if (systemId||menuId) {
+
+          if (initialState && initialState.currentSelectedSys) {
+            const { systemId, menuId, path } = initialState.currentSelectedSys;
+            if (systemId || menuId) {
               //只有当存在systemId
-              const menuData = await getPlatformMenu(systemId||menuId);
-              let homePage:TreeItemType|undefined;
-      
+              const menuData = await getPlatformMenu(systemId || menuId);
+              let homePage: TreeItemType | undefined;
+
 
               const getVFromTree = (data: TreeItemType[], key: string) => {
                 let result: SpacicalPageParamsType[] = [];
                 function looper(data: TreeItemType[], key: string) {
                   data.forEach((t) => {
-                    if(t.isHomepage){
+                    if (t.isHomepage) {
                       homePage = t;
                     }
                     if (t[key] && t[key] == 1) {
@@ -124,7 +124,7 @@ export default function Layout({ children, location, route, history, match, ...r
                         path: t['path'],
                         reportId: t['reportId'],
                         url: t['youshuUrl'],
-                        
+
                       });
                     }
                     if (t.children && t.children.length > 0) {
@@ -138,36 +138,43 @@ export default function Layout({ children, location, route, history, match, ...r
 
               const _menu = getVFromTree(menuData, 'contentType');
 
-              // console.log({_menu});
 
               setInitialState((t) => ({ ...t, spacicalPageParamsType: _menu }));
-              
-              if(homePage){
+
+              if (homePage) {
                 // console.log({homePage});
                 set_openKeys([homePage.key]);
-                set_selectedKeys([homePage.key]); 
+                set_selectedKeys([homePage.key]);
                 history.push(homePage.path)
-              }else{
-                set_openKeys([menuData[0].key]);
-                set_selectedKeys([menuData[0].key]);
-                history.push(menuData[0].path)
+              } else {
+           
+                if (path == '/platform') {
+                  if(menuData[0].children&&menuData[0].children.length>0){
+
+                    const childs = menuData[0].children;        
+                    set_openKeys([menuData[0].key]);
+                    set_selectedKeys([childs[0].key]);
+                    history.push(`${childs[0].path}`)
+                  }
+                }
+
               }
-              
+
               // console.log({homePage})
               // return [...menuData, {
               //   name: 'SQL编辑器',
               //   path: '/platform/sqlEditer'
               // }];
 
-              const addIcon = (arr:any) => arr.map((item:any) => (item.children?{
+              const addIcon = (arr: any) => arr.map((item: any) => (item.children ? {
                 ...item,
                 icon: <FolderOutlined />,
                 children: addIcon(item.children)
-              }:{
+              } : {
                 ...item,
-                icon:<FileOutlined />,
+                icon: <FileOutlined />,
               }))
-               
+
               const result = addIcon(menuData);
 
               return [...result];
@@ -185,14 +192,14 @@ export default function Layout({ children, location, route, history, match, ...r
       navTheme="light"
     >
       {
-        isEmpty&& (
+        isEmpty && (
           <div className='emptyContainer' style={{ textAlign: 'center', paddingTop: 100 }}>
             <h1>{emptyPageContent}</h1>
           </div>
         )
       }
       {
-        !isEmpty&& (
+        !isEmpty && (
           <PageContainer
             className="kcmpPageContainer"
             header={{