张延森 5 gadus atpakaļ
vecāks
revīzija
9d1b4b1f8d
3 mainītis faili ar 33 papildinājumiem un 16 dzēšanām
  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 Parādīt failu

@@ -6,24 +6,16 @@
6 6
 import ProLayout from '@ant-design/pro-layout';
7 7
 import React, { useEffect } from 'react';
8 8
 import Link from 'umi/link';
9
+import Redirect from 'umi/redirect';
9 10
 import { connect } from 'dva';
10 11
 import { formatMessage } from 'umi-plugin-react/locale';
11 12
 import Authorized from '@/utils/Authorized';
12 13
 import RightContent from '@/components/GlobalHeader/RightContent';
13 14
 import { isAntDesignPro } from '@/utils/utils';
14 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 17
 const footerRender = () => {
25 18
   return (
26
-
27 19
     <div
28 20
       style={{
29 21
         padding: ' 44px 0',
@@ -32,14 +24,13 @@ const footerRender = () => {
32 24
         fontFamily: 'monospace',
33 25
         fontWeight: '200',
34 26
         color: 'rgba(102, 102, 102, 1)',
35
-    
36
-
37 27
       }}
38 28
     >
39 29
       copy Right @ 知与行
40 30
     </div>
41 31
   )
42 32
 }
33
+
43 34
 const BasicLayout = props => {
44 35
   const { dispatch, children, settings } = props;
45 36
   /**
@@ -69,6 +60,26 @@ const BasicLayout = props => {
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 83
   return (
73 84
     <ProLayout
74 85
       logo={logo}
@@ -106,12 +117,13 @@ const BasicLayout = props => {
106 117
       {...settings}
107 118
     // pageTitleRender={()=><></>}
108 119
     >
109
-      {children}
120
+      {checkRights(children)}
110 121
     </ProLayout>
111 122
   );
112 123
 };
113 124
 
114
-export default connect(({ global, settings }) => ({
125
+export default connect(({ global, settings, user }) => ({
115 126
   collapsed: global.collapsed,
116 127
   settings,
128
+  user
117 129
 }))(BasicLayout);

+ 5
- 2
src/models/user.js Parādīt failu

@@ -26,8 +26,11 @@ const UserModel = {
26 26
     },
27 27
   },
28 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 35
     changeNotifyCount(
33 36
       state = {

+ 2
- 0
src/pages/activity/editActivity.jsx Parādīt failu

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