张延森 5 年之前
父節點
當前提交
9d1b4b1f8d
共有 3 個文件被更改,包括 33 次插入16 次删除
  1. 26
    14
      src/layouts/BasicLayout.jsx
  2. 5
    2
      src/models/user.js
  3. 2
    0
      src/pages/activity/editActivity.jsx

+ 26
- 14
src/layouts/BasicLayout.jsx 查看文件

6
 import ProLayout from '@ant-design/pro-layout';
6
 import ProLayout from '@ant-design/pro-layout';
7
 import React, { useEffect } from 'react';
7
 import React, { useEffect } from 'react';
8
 import Link from 'umi/link';
8
 import Link from 'umi/link';
9
+import Redirect from 'umi/redirect';
9
 import { connect } from 'dva';
10
 import { connect } from 'dva';
10
 import { formatMessage } from 'umi-plugin-react/locale';
11
 import { formatMessage } from 'umi-plugin-react/locale';
11
 import Authorized from '@/utils/Authorized';
12
 import Authorized from '@/utils/Authorized';
12
 import RightContent from '@/components/GlobalHeader/RightContent';
13
 import RightContent from '@/components/GlobalHeader/RightContent';
13
 import { isAntDesignPro } from '@/utils/utils';
14
 import { isAntDesignPro } from '@/utils/utils';
14
 import logo from '../assets/logo.png';
15
 import logo from '../assets/logo.png';
15
-
16
-/**
17
- * use Authorized check all menu item
18
- */
19
-const menuDataRender = menuList =>
20
-  menuList.map(item => {
21
-    const localItem = { ...item, children: item.children ? menuDataRender(item.children) : [] };
22
-    return Authorized.check(item.authority, localItem, null);
23
-  });
16
+  
24
 const footerRender = () => {
17
 const footerRender = () => {
25
   return (
18
   return (
26
-
27
     <div
19
     <div
28
       style={{
20
       style={{
29
         padding: ' 44px 0',
21
         padding: ' 44px 0',
32
         fontFamily: 'monospace',
24
         fontFamily: 'monospace',
33
         fontWeight: '200',
25
         fontWeight: '200',
34
         color: 'rgba(102, 102, 102, 1)',
26
         color: 'rgba(102, 102, 102, 1)',
35
-    
36
-
37
       }}
27
       }}
38
     >
28
     >
39
       copy Right @ 知与行
29
       copy Right @ 知与行
40
     </div>
30
     </div>
41
   )
31
   )
42
 }
32
 }
33
+
43
 const BasicLayout = props => {
34
 const BasicLayout = props => {
44
   const { dispatch, children, settings } = props;
35
   const { dispatch, children, settings } = props;
45
   /**
36
   /**
69
     }
60
     }
70
   };
61
   };
71
 
62
 
63
+  const findAuthority = (path) => {
64
+    return ((props.user.menuList || []).filter(x => x.code === path)[0] || {}).roles || []
65
+  }
66
+  
67
+  /**
68
+   * use Authorized check all menu item
69
+   */
70
+  const menuDataRender = menuList =>
71
+    menuList.map(item => {
72
+      const localItem = { ...item, children: item.children ? menuDataRender(item.children) : [] };
73
+      const authority = findAuthority(item.path);
74
+      // return Authorized.check(item.authority, localItem, null);
75
+      return Authorized.check(authority, localItem, null);
76
+    });
77
+
78
+  const checkRights = (children) => {
79
+    const authority = findAuthority(props.location.pathname);
80
+    return Authorized.check(authority, children, <Redirect to="/exception/403" />);
81
+  }
82
+
72
   return (
83
   return (
73
     <ProLayout
84
     <ProLayout
74
       logo={logo}
85
       logo={logo}
106
       {...settings}
117
       {...settings}
107
     // pageTitleRender={()=><></>}
118
     // pageTitleRender={()=><></>}
108
     >
119
     >
109
-      {children}
120
+      {checkRights(children)}
110
     </ProLayout>
121
     </ProLayout>
111
   );
122
   );
112
 };
123
 };
113
 
124
 
114
-export default connect(({ global, settings }) => ({
125
+export default connect(({ global, settings, user }) => ({
115
   collapsed: global.collapsed,
126
   collapsed: global.collapsed,
116
   settings,
127
   settings,
128
+  user
117
 }))(BasicLayout);
129
 }))(BasicLayout);

+ 5
- 2
src/models/user.js 查看文件

26
     },
26
     },
27
   },
27
   },
28
   reducers: {
28
   reducers: {
29
-    saveCurrentUser(state, { payload = {} }) {
30
-      return { ...state, currentUser: payload.taUser || {}, menuList: payload.menuList || [] };
29
+    saveCurrentUser(state, { payload }) {
30
+      const { taUser = {} , menuList = [] } = payload || {}
31
+      const currentUser = { ...taUser, roles: (taUser.roles || []).map(x => x.roleId) }
32
+
33
+      return { ...state, currentUser, menuList };
31
     },
34
     },
32
     changeNotifyCount(
35
     changeNotifyCount(
33
       state = {
36
       state = {

+ 2
- 0
src/pages/activity/editActivity.jsx 查看文件

27
  */
27
  */
28
 const Edit = (props) => {
28
 const Edit = (props) => {
29
   const [tab, changeTab] = useState('poster')
29
   const [tab, changeTab] = useState('poster')
30
+
30
   // const [tab, changeTab] = useState('basic')
31
   // const [tab, changeTab] = useState('basic')
31
   const dynamicId = props.location.query.dynamicId
32
   const dynamicId = props.location.query.dynamicId
32
   const [dynamicData, setDynamicData] = useState({})
33
   const [dynamicData, setDynamicData] = useState({})
173
     const [inputValue, changeInput] = useState('')
174
     const [inputValue, changeInput] = useState('')
174
     const [textAreaValue, changeTextArea] = useState('')
175
     const [textAreaValue, changeTextArea] = useState('')
175
     const [imgValue, changeImg] = useState('')
176
     const [imgValue, changeImg] = useState('')
177
+
176
     return <div>
178
     return <div>
177
       <div style={{ display: 'flex' }}>
179
       <div style={{ display: 'flex' }}>
178
         <div style={{ width: '420px', height: '900px', display: 'inline-block', marginTop: '30px' }}>
180
         <div style={{ width: '420px', height: '900px', display: 'inline-block', marginTop: '30px' }}>