Your Name 2 år sedan
förälder
incheckning
50b4608f67
3 ändrade filer med 48 tillägg och 2 borttagningar
  1. 28
    0
      src/components/Auth.jsx
  2. 5
    2
      src/layouts/index.jsx
  3. 15
    0
      src/utils/user.js

+ 28
- 0
src/components/Auth.jsx Visa fil

@@ -0,0 +1,28 @@
1
+import React from 'react';
2
+import { View } from '@tarojs/components';
3
+import { useModel } from '@/store';
4
+
5
+export default (props) => {
6
+  const { roles = [] } = props;
7
+  const { user } = useModel('user');
8
+
9
+  const targets = user?.dutyList || [];
10
+
11
+  let hasRights = false;
12
+  for(let role of roles) {
13
+    if (hasRights) {
14
+      continue;
15
+    }
16
+
17
+    const found = targets.indexOf(role) > -1;
18
+    if (found) {
19
+      hasRights = found;
20
+    }
21
+  }
22
+
23
+  return hasRights ? props.children : (
24
+    <View style={{width: '100%', height: '100%', display: 'grid', placeItems: 'center'}}>
25
+      <View>暂无权限</View>
26
+    </View>
27
+  );
28
+}

+ 5
- 2
src/layouts/index.jsx Visa fil

@@ -2,10 +2,11 @@ import React from 'react';
2 2
 import { View } from '@tarojs/components';
3 3
 import { useModel } from '@/store';
4 4
 import { Loading } from '@antmjs/vantui';
5
+import Auth from '@/components/Auth';
5 6
 import laySty from './layout.module.less';
6 7
 
7 8
 export default (props) => {
8
-  const { className, style } = props;
9
+  const { className, style, roles } = props;
9 10
 
10 11
   const { person } = useModel('user');
11 12
 
@@ -16,13 +17,15 @@ export default (props) => {
16 17
       {
17 18
         !person && (
18 19
           <View className={laySty.loading}>
19
-             <Loading size="32px" vertical>
20
+            <Loading size="32px" vertical>
20 21
               加载中...
21 22
             </Loading>
22 23
           </View>
23 24
         )
24 25
       }
26
+      <Auth roles={roles}>
25 27
       {props.children}
28
+      </Auth>
26 29
     </View>
27 30
   )
28 31
 }

+ 15
- 0
src/utils/user.js Visa fil

@@ -0,0 +1,15 @@
1
+
2
+// 督察员
3
+export const ROLE_INSPECTOR = 'inspector';
4
+
5
+// 管理员
6
+export const ROLE_MANAGER = 'manager';
7
+
8
+// 单位人员
9
+export const ROLE_ORG_USER = 'org_user';
10
+
11
+// 查询员
12
+export const ROLE_QUERY_PERSON = 'query_person';
13
+
14
+// 市民
15
+export const ROLE_CITIZEN = 'citizen';