张延森 5 年 前
コミット
a33813975e
共有4 個のファイルを変更した29 個の追加7 個の削除を含む
  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 ファイルの表示

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

+ 3
- 5
src/layouts/BasicLayout.jsx ファイルの表示

@@ -71,9 +71,7 @@ const BasicLayout = props => {
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 77
    * use Authorized check all menu item
@@ -86,9 +84,9 @@ const BasicLayout = props => {
86 84
       return Authorized.check(authority, localItem, null);
87 85
     });
88 86
 
89
-  const checkRights = (children) => {
87
+  const checkRights = children => {
90 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 92
   return (

+ 19
- 0
src/pages/403.jsx ファイルの表示

@@ -0,0 +1,19 @@
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 ファイルの表示

@@ -38,7 +38,7 @@ const AuthComponent = ({
38 38
   return (
39 39
     <Authorized
40 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 43
       {children}
44 44
     </Authorized>