Yansen 2 years ago
parent
commit
f2490332e0

+ 4
- 0
src/index.less View File

@@ -49,6 +49,10 @@ html, body, #root {
49 49
   }
50 50
 }
51 51
 
52
+.ant-menu-horizontal > .ant-menu-item a {
53
+  color: #fff !important;
54
+}
55
+
52 56
 
53 57
 // 兼容 360
54 58
 .ant-pro-sider-collapsed-button {

+ 1
- 1
src/layouts/AuthLayout/components/Header/SplitMenu.jsx View File

@@ -14,7 +14,7 @@ export default (props) => {
14 14
 
15 15
   const onClick = (item) => {
16 16
     onChange(item.key);
17
-    navigate(item.key);
17
+    // navigate(item.key);
18 18
   };
19 19
 
20 20
   React.useEffect(() => {

+ 1
- 1
src/layouts/AuthLayout/components/Menus.jsx View File

@@ -36,6 +36,6 @@ export default (props) => {
36 36
   // }, [location.pathname]);
37 37
 
38 38
   return (
39
-    <Menu style={menuStyle} theme={theme} items={items} onClick={onClick} selectedKeys={[location.pathname]} />
39
+    <Menu style={menuStyle} theme={theme} items={items} selectedKeys={[location.pathname]} />
40 40
   )
41 41
 }

+ 16
- 8
src/layouts/AuthLayout/index.jsx View File

@@ -1,8 +1,9 @@
1 1
 import React, { useEffect, useRef, useMemo, useState } from 'react';
2 2
 import { Layout, Spin } from 'antd';
3
-import { useLocation } from "react-router-dom";
3
+import { useLocation, Outlet } from "react-router-dom";
4 4
 import { useModel } from '@/store';
5 5
 import { getItems } from '@/routes/menus';
6
+import useRoute from '@/utils/hooks/useRoute';
6 7
 import RequireLogin from './components/RequireLogin';
7 8
 import SiderBar from './components/SiderBar';
8 9
 import Header from './components/Header';
@@ -23,6 +24,7 @@ export default (props) => {
23 24
   useReady({ user, setUser });
24 25
 
25 26
   const location = useLocation();
27
+  const currentRoute = useRoute();
26 28
 
27 29
   const onSplitMenuChange = (key) => {
28 30
     const target = allMenus.filter(x => x.key === key)[0];
@@ -35,13 +37,19 @@ export default (props) => {
35 37
     <Spin spinning={!user} size="large">
36 38
       <HtmlTitle />
37 39
       <RequireLogin>
38
-        <Layout style={{ minHeight: '100vh' }}>
39
-          <Header theme={theme} menus={allMenus} location={location} onMenuChange={onSplitMenuChange} />
40
-          <Layout>
41
-            <SiderBar theme={theme} menus={siderMenus} location={location} />
42
-            <Container location={location} />
43
-          </Layout>
44
-        </Layout>
40
+        {
41
+          currentRoute && currentRoute.meta && currentRoute.meta.noLayout
42
+            ? <Outlet />
43
+            : (
44
+              <Layout style={{ minHeight: '100vh' }}>
45
+                <Header theme={theme} menus={allMenus} location={location} onMenuChange={onSplitMenuChange} />
46
+                <Layout>
47
+                  <SiderBar theme={theme} menus={siderMenus} location={location} />
48
+                  <Container location={location} />
49
+                </Layout>
50
+              </Layout>
51
+            )
52
+        }
45 53
       </RequireLogin>
46 54
     </Spin>
47 55
   );

+ 6
- 1
src/layouts/Container.jsx View File

@@ -1,5 +1,6 @@
1 1
 import React from 'react';
2 2
 import { Outlet } from 'react-router-dom';
3
+import useRoute from '@/utils/hooks/useRoute';
3 4
 
4 5
 const containerStyle = {
5 6
   margin: '24px 24px 0 24px',
@@ -7,8 +8,12 @@ const containerStyle = {
7 8
 }
8 9
 
9 10
 export default (props) => {
11
+
12
+  const currentRoute = useRoute();
13
+  const style = currentRoute.meta && currentRoute.meta.noLayout ? { height: '100%' } : containerStyle;
14
+
10 15
   return (
11
-    <div style={containerStyle}>
16
+    <div style={style}>
12 17
       <Outlet />
13 18
     </div>
14 19
   )

+ 1
- 1
src/pages/guaranteeTask/print/index.jsx View File

@@ -4,7 +4,7 @@ import { Button } from 'antd';
4 4
 import { useSearchParams } from 'react-router-dom';
5 5
 import { getGuaranteeTask } from '@/services/guaranteeTask';
6 6
 import { getGuaranteeDetailList } from '@/services/guaranteeTask';
7
-import Styles from './style.less';
7
+import Styles from './style.module.less';
8 8
 
9 9
 export default (props) => {
10 10
   const [dataSource, setDataSource] = useState({});

src/pages/guaranteeTask/print/style.less → src/pages/guaranteeTask/print/style.module.less View File


+ 2
- 0
src/routes/Router.jsx View File

@@ -2,6 +2,8 @@ import { createHashRouter, RouterProvider } from "react-router-dom";
2 2
 import routes from './routes'
3 3
 
4 4
 const router = createHashRouter(routes);
5
+export const hashRouter = true;
6
+
5 7
 export default (props) => {
6 8
   return <RouterProvider router={router} />
7 9
 }

+ 23
- 7
src/routes/menus.jsx View File

@@ -1,4 +1,6 @@
1
+import { Link } from 'react-router-dom';
1 2
 import routes from './routes';
3
+import { hashRouter } from './Router';
2 4
 
3 5
 let routeArr = [];
4 6
 
@@ -22,20 +24,20 @@ const getMenuItems = (dts = [], fullPath = '/') => {
22 24
   return dts.map(item => {
23 25
     const path = getPath(fullPath, item.path);
24 26
 
25
-    routeArr.push({
26
-      ...item,
27
-      path,
28
-    });
29
-
30 27
     //
31 28
     if (!isShow(item)) return false;
32 29
     
33 30
     const children = hasChildren(item.children) ? getMenuItems(item.children, path) : false;
34 31
 
32
+    // 坑爹 react-router v6 不支持 hash 路由的 target 跳转
33
+    const label = hashRouter && item.meta && item.meta.target === '_blank' ?
34
+      <a href={`${window.location.pathname}#${path}`} target={item.meta.target}>{item.meta.title}</a>
35
+      : <Link to={path} target={item.meta.target}>{item.meta.title}</Link>;
36
+
35 37
     return Object.assign(
36 38
       {
37 39
         key: path,
38
-        label: item.meta.title,
40
+        label,
39 41
         title: item.meta.title,
40 42
         icon: item.meta.icon,
41 43
       },
@@ -44,10 +46,24 @@ const getMenuItems = (dts = [], fullPath = '/') => {
44 46
   }).filter(Boolean);
45 47
 }
46 48
 
49
+const flatten = (routes, parent) => {
50
+  (routes || []).forEach((route) => {
51
+    const path = getPath(parent, route.path);
52
+    routeArr.push({
53
+      ...route,
54
+      path
55
+    });
56
+
57
+    if (route.children) {
58
+      flatten(route.children, path);
59
+    }
60
+  });
61
+}
62
+
47 63
 const getItems = () => getMenuItems(routes[0]?.children);
48 64
 const getRouteArr = () => {
49 65
   if (routeArr.length < 1) {
50
-    getItems();
66
+    flatten(routes, '/');
51 67
   }
52 68
   return routeArr;
53 69
 }

+ 4
- 0
src/routes/routes.jsx View File

@@ -35,6 +35,8 @@ import RotationChartEdit from '@/pages/rotationChart/edit';
35 35
  * {
36 36
  *    title: 用于页面或者菜单的标题, 没有此字段, 菜单不会显示
37 37
  *    hideInMenu: 布尔值, 如果为 false, 菜单不会显示
38
+ *    noLayout: 布尔值, 如果为 true, 将不会使用默认布局
39
+ *    target: 字符串, 如果为 _blank, 将在新窗口打开
38 40
  * }
39 41
  */
40 42
 
@@ -86,6 +88,8 @@ export default [
86 88
             element: <GuaranteeTaskPrint />,
87 89
             meta: {
88 90
               hideInMenu: true,
91
+              noLayout: true,
92
+              target: '_blank',
89 93
               title: '任务执行',
90 94
             },
91 95
           }

+ 1
- 5
src/store/models/system.js View File

@@ -11,14 +11,10 @@ export default function useSystem() {
11 11
     company: '云致科技'
12 12
   });
13 13
 
14
-  // 页面标题
15
-  const [title, setTitle] = useState();
16
-
17 14
   return {
18 15
     theme,
19 16
     updateTheme,
20 17
     app,
21
-    title,
22
-    setTitle,
18
+    hashRoute: true,
23 19
   }
24 20
 }