张涛 преди 1 година
родител
ревизия
c493d51ae9
променени са 2 файла, в които са добавени 35 реда и са изтрити 33 реда
  1. 33
    32
      src/layouts/index.jsx
  2. 2
    1
      src/store/user.js

+ 33
- 32
src/layouts/index.jsx Целия файл

11
 export default (props) => {
11
 export default (props) => {
12
   const { className, style, roles, tabBar = false, loading } = props;
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
   const containerClass = `${laySty["page-conatiner"]} ${
16
   const containerClass = `${laySty["page-conatiner"]} ${
16
     tabBar ? laySty["with-tabbar"] : ""
17
     tabBar ? laySty["with-tabbar"] : ""
17
   } ${className}`;
18
   } ${className}`;
19
   const userRef = useRef();
20
   const userRef = useRef();
20
   const personRef = useRef();
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
   // React.useEffect(() => {
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
   //   console.log("personRef******************");
31
   //   console.log("personRef******************");
49
-  //   console.log(person);
32
+  //   console.log(personRef.current);
50
   //   console.log("userRef******************");
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
   //     const currentPage = Taro.getCurrentPages().slice().pop();
38
   //     const currentPage = Taro.getCurrentPages().slice().pop();
39
+  //     console.log(currentPage.route);
56
   //     if ("pages/login/index" !== currentPage.route) {
40
   //     if ("pages/login/index" !== currentPage.route) {
57
   //       Taro.navigateTo({
41
   //       Taro.navigateTo({
58
   //         url: "/pages/login/index",
42
   //         url: "/pages/login/index",
61
   //   }
45
   //   }
62
   // }, [person, user]);
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
   Taro.useShareAppMessage(() => {
65
   Taro.useShareAppMessage(() => {
65
     return {
66
     return {
66
       title: "文明霍山",
67
       title: "文明霍山",
73
       <Dialog id="vanDialog" />
74
       <Dialog id="vanDialog" />
74
       <NavLoading loading={loading} />
75
       <NavLoading loading={loading} />
75
       <View className={containerClass} style={style}>
76
       <View className={containerClass} style={style}>
76
-        {!person && (
77
+        {/* {!person && (
77
           <View className={laySty.loading}>
78
           <View className={laySty.loading}>
78
             <Loading size="32px" vertical>
79
             <Loading size="32px" vertical>
79
               加载中...
80
               加载中...
80
             </Loading>
81
             </Loading>
81
           </View>
82
           </View>
82
-        )}
83
+        )} */}
83
         <Auth roles={roles}>{props.children}</Auth>
84
         <Auth roles={roles}>{props.children}</Auth>
84
 
85
 
85
         {!tabBar && <View className={laySty["pdm-space"]}></View>}
86
         {!tabBar && <View className={laySty["pdm-space"]}></View>}

+ 2
- 1
src/store/user.js Целия файл

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