Yansen vor 2 Jahren
Ursprung
Commit
822a91f826

+ 1
- 1
config/prod.js Datei anzeigen

@@ -3,7 +3,7 @@ module.exports = {
3 3
     NODE_ENV: '"production"'
4 4
   },
5 5
   defineConstants: {
6
-    HOST: '"http://192.168.89.147:9087"'
6
+    HOST: '"https://t.njyz.tech"'
7 7
   },
8 8
   mini: {},
9 9
   h5: {

+ 2
- 14
src/components/Auth.jsx Datei anzeigen

@@ -4,21 +4,9 @@ import { useModel } from '@/store';
4 4
 
5 5
 export default (props) => {
6 6
   const { roles = [] } = props;
7
-  const { user } = useModel('user');
7
+  const { duty } = useModel('user');
8 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
-  }
9
+  const hasRights = roles.indexOf(duty) > -1;
22 10
 
23 11
   return !roles.length || hasRights ? props.children : (
24 12
     <View style={{width: '100%', height: '100%', display: 'grid', placeItems: 'center'}}>

+ 6
- 6
src/layouts/TabBar.jsx Datei anzeigen

@@ -58,13 +58,13 @@ const mine = {
58 58
 }
59 59
 
60 60
 export default (props) => {
61
-  const { active = -1, className, user } = props;
61
+  const { active = -1, className, duty } = props;
62 62
 
63 63
   const tabItems = React.useMemo(() => {
64
-    if (!user) return [];
64
+    if (!duty) return [];
65 65
 
66
-    if (user.dutyList.indexOf(ROLE_INSPECTOR) > -1 // 督察员
67
-      || user.dutyList.indexOf(ROLE_MANAGER) > -1 // 管理员
66
+    if (duty == ROLE_INSPECTOR // 督察员
67
+      || duty == ROLE_MANAGER // 管理员
68 68
     ) {
69 69
       return [
70 70
         home,
@@ -75,7 +75,7 @@ export default (props) => {
75 75
       ]
76 76
     }
77 77
 
78
-    if (user.dutyList.indexOf(ROLE_ORG_USER) > -1) {
78
+    if (duty == ROLE_ORG_USER) {
79 79
       return [
80 80
         home,
81 81
         notice,
@@ -84,7 +84,7 @@ export default (props) => {
84 84
     }
85 85
 
86 86
     return [];
87
-  }, [user]);
87
+  }, [duty]);
88 88
 
89 89
   const onChange = (e) => {
90 90
     const url = tabItems.filter(x => x.name === e.detail)[0].page;

+ 2
- 2
src/layouts/index.jsx Datei anzeigen

@@ -11,7 +11,7 @@ import laySty from './layout.module.less';
11 11
 export default (props) => {
12 12
   const { className, style, roles, tabBar = false, loading } = props;
13 13
 
14
-  const { person, user } = useModel('user');
14
+  const { person, user, duty } = useModel('user');
15 15
 
16 16
   const containerClass = `${laySty['page-conatiner']} ${tabBar ? laySty['with-tabbar'] : ''} ${className}`;
17 17
 
@@ -51,7 +51,7 @@ export default (props) => {
51 51
         }
52 52
       </View>
53 53
       {
54
-        tabBar && <TabBar className={laySty['page-tabbar']} active={tabBar} user={user} />
54
+        tabBar && <TabBar className={laySty['page-tabbar']} active={tabBar} duty={duty} />
55 55
       }
56 56
     </View>
57 57
   )

+ 27
- 3
src/pages/home/components/Head.jsx Datei anzeigen

@@ -1,20 +1,36 @@
1 1
 import React from 'react';
2 2
 import { View, Image } from '@tarojs/components';
3
+import { ActionSheet, Cell } from '@antmjs/vantui';
3 4
 import { ROLES, ROLE_CITIZEN } from '@/utils/user';
4 5
 import logo from '@/assets/image/logo.png';
5 6
 import avatar from '@/assets/icons/avatar.png';
6 7
 import style from './head.module.less';
7 8
 
8 9
 export default (props) => {
9
-  const { user = {} } = props;
10
+  const { user = {}, duty, onDutyChange } = props;
10 11
   const { dutyList = [] } = user;
11
-  const role = ROLES[dutyList[0] || ROLE_CITIZEN];
12
+  const role = ROLES[duty || ROLE_CITIZEN];
13
+
14
+  const [show, setShow] = React.useState(false);
15
+
16
+  const actions = React.useMemo(() => {
17
+    return dutyList.map(x => ({name: ROLES[x], value: x}));
18
+  }, [dutyList]);
19
+
20
+  const onClick = () => {
21
+    if (dutyList.length < 1) return;
22
+    setShow(true);
23
+  }
24
+
25
+  const onSelect = (e) => {
26
+    onDutyChange(e.detail.value)
27
+  }
12 28
 
13 29
   return (
14 30
     <View className={style.head}>
15 31
       <View className={style.profile}>
16 32
         <View style={{ letterSpacing: '2px' }}>Hi, {user.name}!</View>
17
-        <View className={style.badge}>
33
+        <View className={style.badge} onClick={onClick}>
18 34
           <View className={style.icon}>
19 35
             <Image src={avatar} />
20 36
           </View>
@@ -24,6 +40,14 @@ export default (props) => {
24 40
       <View className={style.avatar}>
25 41
         <Image src={user.avatar || logo}></Image>
26 42
       </View>
43
+      <ActionSheet
44
+        title="请选择身份"
45
+        position="bottom"
46
+        show={show}
47
+        actions={actions}
48
+        onClose={() => setShow(false)}
49
+        onSelect={onSelect}
50
+      />
27 51
     </View>
28 52
   )
29 53
 }

+ 5
- 5
src/pages/home/index.jsx Datei anzeigen

@@ -49,17 +49,17 @@ const menus = {
49 49
 
50 50
 export default (props) => {
51 51
 
52
-  const { user } = useModel('user');
52
+  const { user, duty, updateDuty } = useModel('user');
53 53
 
54 54
   const menuArr = React.useMemo(() => {
55
-    if (!user || !user.dutyList) return [];
55
+    if (!duty) return [];
56 56
 
57
-    return menus[user.dutyList[0]];
58
-  }, [user])
57
+    return menus[duty];
58
+  }, [duty])
59 59
 
60 60
   return (
61 61
     <Page tabBar="home" className='home-page'>
62
-      <Head user={user} />
62
+      <Head user={user} duty={duty} onDutyChange={updateDuty} />
63 63
       <BannerCard />
64 64
 
65 65
       <View className="menu-icons">

+ 10
- 13
src/pages/issue/edit/index.jsx Datei anzeigen

@@ -17,7 +17,7 @@ export default (props) => {
17 17
   const router = Taro.useRouter();
18 18
   const { id, act } = router.params;
19 19
 
20
-  const { user } = useModel('user');
20
+  const { user, duty } = useModel('user');
21 21
 
22 22
   const [loading, setLoading] = React.useState(false);
23 23
   const [issue, setIssue] = React.useState();
@@ -29,11 +29,8 @@ export default (props) => {
29 29
     canAssigned,
30 30
     canCancel,
31 31
   ] = React.useMemo(() => {
32
-    if (!issue) return [];
33
-    if (!user) return [];
34
-
35 32
     // 如果是督察员
36
-    if (user.dutyList.indexOf(ROLE_INSPECTOR) > -1) {
33
+    if (duty == ROLE_INSPECTOR) {
37 34
       return [
38 35
         issue.processNode != 'start' && issue.processStatus != 'reject',
39 36
         issue.processNode == 'start' || issue.processStatus == 'reject',
@@ -43,7 +40,7 @@ export default (props) => {
43 40
     }
44 41
 
45 42
     // 如果是管理员
46
-    if (user?.dutyList.indexOf(ROLE_MANAGER) > -1) {
43
+    if (duty == ROLE_MANAGER) {
47 44
       return [
48 45
         issue.processNode != 'start',
49 46
         false,
@@ -53,14 +50,14 @@ export default (props) => {
53 50
     }
54 51
 
55 52
     return [];
56
-  }, [issue, user]);
53
+  }, [issue, duty]);
57 54
 
58
-  const onIssueChange = (val = {}) => {
59
-    setIssue({
60
-      ...(issue || {}),
61
-      ...val,
62
-    })
63
-  }
55
+  // const onIssueChange = (val = {}) => {
56
+  //   setIssue({
57
+  //     ...(issue || {}),
58
+  //     ...val,
59
+  //   })
60
+  // }
64 61
   
65 62
   React.useEffect(() => {
66 63
     if (id) {

+ 25
- 1
src/store/user.js Datei anzeigen

@@ -6,6 +6,7 @@ import { login, signin, currentUser } from '@/services/wxma';
6 6
 export default function useUser() {
7 7
   const [person, setPerson] = React.useState();
8 8
   const [user, setUser] = React.useState();
9
+  const [duty, setDuty] = React.useState();
9 10
 
10 11
   const maLogin = (code) => {
11 12
     login(code).then(res => {
@@ -15,20 +16,41 @@ export default function useUser() {
15 16
     });
16 17
   }
17 18
 
19
+  const updateDuty = (d) => {
20
+    setDuty(d);
21
+    Taro.setStorageSync('duty', d);
22
+  }
23
+
24
+  const initDuty = (u) => {
25
+    const d = Taro.getStorageSync('duty');
26
+    const dutyList = u?.dutyList || [];
27
+    if (d) {
28
+      if (dutyList.indexOf(d) < 0) {
29
+        updateDuty(dutyList[0]);
30
+      } else {
31
+        updateDuty(d);
32
+      }
33
+    } else {
34
+      updateDuty(dutyList[0]);
35
+    }
36
+  }
37
+
18 38
   const maSignIn = (params) => {
19 39
     const data = {
20 40
       ...params,
21 41
       password: md5(params.password)
22
-    }
42
+    };
23 43
 
24 44
     return signin(data).then(res => {
25 45
       setUser(res.user);
46
+      initDuty(res.user);
26 47
     })
27 48
   }
28 49
 
29 50
   const current = () => {
30 51
     currentUser().then(res => {
31 52
       setUser(res.user);
53
+      initDuty(res.user);
32 54
     })
33 55
   }
34 56
 
@@ -36,7 +58,9 @@ export default function useUser() {
36 58
     user,
37 59
     person,
38 60
     current,
61
+    duty,
39 62
     signin: maSignIn,
40 63
     login: maLogin,
64
+    updateDuty,
41 65
   }
42 66
 }