张延森 5 vuotta sitten
vanhempi
commit
a33813975e
4 muutettua tiedostoa jossa 29 lisäystä ja 7 poistoa
  1. 6
    1
      config/routes.js
  2. 3
    5
      src/layouts/BasicLayout.jsx
  3. 19
    0
      src/pages/403.jsx
  4. 1
    1
      src/pages/Authorized.jsx

+ 6
- 1
config/routes.js Näytä tiedosto

17
       {
17
       {
18
         path: '/',
18
         path: '/',
19
         component: '../layouts/BasicLayout',
19
         component: '../layouts/BasicLayout',
20
-        authority: ['admin', 'user'],
21
         routes: [
20
         routes: [
22
           {
21
           {
23
             path: '/',
22
             path: '/',
739
           //     },
738
           //     },
740
           //   ],
739
           //   ],
741
           // },
740
           // },
741
+          {
742
+            name: '403',
743
+            path: '/403',
744
+            component: './403',
745
+            hideInMenu: true,
746
+          },
742
           {
747
           {
743
             component: './404',
748
             component: './404',
744
           },
749
           },

+ 3
- 5
src/layouts/BasicLayout.jsx Näytä tiedosto

71
     }
71
     }
72
   };
72
   };
73
 
73
 
74
-  const findAuthority = (path) => {
75
-    return ((props.user.menuList || []).filter(x => x.code === path)[0] || {}).roles
76
-  }
74
+  const findAuthority = path => ((props.user.menuList || []).filter(x => x.code === path)[0] || {}).roles
77
 
75
 
78
   /**
76
   /**
79
    * use Authorized check all menu item
77
    * use Authorized check all menu item
86
       return Authorized.check(authority, localItem, null);
84
       return Authorized.check(authority, localItem, null);
87
     });
85
     });
88
 
86
 
89
-  const checkRights = (children) => {
87
+  const checkRights = children => {
90
     const authority = findAuthority(props.location.pathname);
88
     const authority = findAuthority(props.location.pathname);
91
-    return Authorized.check(authority, children, <Redirect to="/exception/403" />);
89
+    return Authorized.check(authority, children, <Redirect to="/403" />);
92
   }
90
   }
93
 
91
 
94
   return (
92
   return (

+ 19
- 0
src/pages/403.jsx Näytä tiedosto

1
+import { Button, Result } from 'antd';
2
+import React from 'react';
3
+import router from 'umi/router'; // 这里应该使用 antd 的 404 result 组件,
4
+// 但是还没发布,先来个简单的。
5
+
6
+const NoFoundPage = () => (
7
+  <Result
8
+    status="403"
9
+    title="403"
10
+    subTitle="您暂时无权限访问当前页面."
11
+    extra={
12
+      <Button type="primary" onClick={() => router.push('/')}>
13
+        Back Home
14
+      </Button>
15
+    }
16
+  ></Result>
17
+);
18
+
19
+export default NoFoundPage;

+ 1
- 1
src/pages/Authorized.jsx Näytä tiedosto

38
   return (
38
   return (
39
     <Authorized
39
     <Authorized
40
       authority={getRouteAuthority(location.pathname, routes) || ''}
40
       authority={getRouteAuthority(location.pathname, routes) || ''}
41
-      noMatch={isLogin ? <Redirect to="/exception/403" /> : <Redirect to="/user/login" />}
41
+      noMatch={isLogin ? <Redirect to="/403" /> : <Redirect to="/user/login" />}
42
     >
42
     >
43
       {children}
43
       {children}
44
     </Authorized>
44
     </Authorized>