张涛 1 year ago
parent
commit
c493d51ae9
2 changed files with 35 additions and 33 deletions
  1. 33
    32
      src/layouts/index.jsx
  2. 2
    1
      src/store/user.js

+ 33
- 32
src/layouts/index.jsx View File

@@ -11,7 +11,8 @@ 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, duty } = useModel("user");
14
+  // person,
15
+  const { user, duty } = useModel("user");
15 16
   const containerClass = `${laySty["page-conatiner"]} ${
16 17
     tabBar ? laySty["with-tabbar"] : ""
17 18
   } ${className}`;
@@ -19,40 +20,23 @@ export default (props) => {
19 20
   const userRef = useRef();
20 21
   const personRef = useRef();
21 22
 
22
-  React.useEffect(() => {
23
-    if (!userRef.current && !personRef.current) {
24
-      userRef.current = person;
25
-      personRef.current = user;
26
-    }
27
-    if (!user) {
28
-      userRef.current = null;
29
-    }
30
-    console.log("personRef******************");
31
-    console.log(personRef.current);
32
-    console.log("userRef******************");
33
-    console.log(userRef.current);
34
-    console.log(personRef.current && !userRef.current);
35
-
36
-    if (personRef.current && !userRef.current) {
37
-      const currentPage = Taro.getCurrentPages().slice().pop();
38
-      console.log(currentPage.route);
39
-      if ("pages/login/index" !== currentPage.route) {
40
-        Taro.navigateTo({
41
-          url: "/pages/login/index",
42
-        });
43
-      }
44
-    }
45
-  }, [person, user]);
46
-
47 23
   // React.useEffect(() => {
24
+  //   if (!userRef.current && !personRef.current) {
25
+  //     userRef.current = person;
26
+  //     personRef.current = user;
27
+  //   }
28
+  //   if (!user) {
29
+  //     userRef.current = null;
30
+  //   }
48 31
   //   console.log("personRef******************");
49
-  //   console.log(person);
32
+  //   console.log(personRef.current);
50 33
   //   console.log("userRef******************");
51
-  //   console.log(user);
52
-  //   console.log(person && !user);
34
+  //   console.log(userRef.current);
35
+  //   console.log(personRef.current && !userRef.current);
53 36
 
54
-  //   if (person && !user) {
37
+  //   if (personRef.current && !userRef.current) {
55 38
   //     const currentPage = Taro.getCurrentPages().slice().pop();
39
+  //     console.log(currentPage.route);
56 40
   //     if ("pages/login/index" !== currentPage.route) {
57 41
   //       Taro.navigateTo({
58 42
   //         url: "/pages/login/index",
@@ -61,6 +45,23 @@ export default (props) => {
61 45
   //   }
62 46
   // }, [person, user]);
63 47
 
48
+  React.useEffect(() => {
49
+    console.log("personRef******************");
50
+    // console.log(person);
51
+    console.log("userRef******************");
52
+    console.log(user);
53
+    console.log(!user);
54
+
55
+    if (!user) {
56
+      const currentPage = Taro.getCurrentPages().slice().pop();
57
+      if (!currentPage.route.includes("pages/login/index")) {
58
+        Taro.navigateTo({
59
+          url: "/pages/login/index",
60
+        });
61
+      }
62
+    }
63
+  }, [user]);
64
+
64 65
   Taro.useShareAppMessage(() => {
65 66
     return {
66 67
       title: "文明霍山",
@@ -73,13 +74,13 @@ export default (props) => {
73 74
       <Dialog id="vanDialog" />
74 75
       <NavLoading loading={loading} />
75 76
       <View className={containerClass} style={style}>
76
-        {!person && (
77
+        {/* {!person && (
77 78
           <View className={laySty.loading}>
78 79
             <Loading size="32px" vertical>
79 80
               加载中...
80 81
             </Loading>
81 82
           </View>
82
-        )}
83
+        )} */}
83 84
         <Auth roles={roles}>{props.children}</Auth>
84 85
 
85 86
         {!tabBar && <View className={laySty["pdm-space"]}></View>}

+ 2
- 1
src/store/user.js View File

@@ -19,7 +19,7 @@ export default function useUser() {
19 19
   const maLogin = (code) => {
20 20
     login(code)
21 21
       .then((res) => {
22
-        setPerson(res.person);
22
+        // setPerson(res.person);
23 23
         Taro.setStorage({ key: "personId", data: res.person.personId });
24 24
         Taro.setStorage({ key: "sessionKey", data: res.sessionKey });
25 25
       })
@@ -88,6 +88,7 @@ export default function useUser() {
88 88
   };
89 89
 
90 90
   const signOut = () => {
91
+    console.log(111111)
91 92
     setUser(null);
92 93
     initDuty(null);
93 94
   };