Leon 2 gadi atpakaļ
vecāks
revīzija
18835e47b7

+ 10 - 0
src/features/trackSomething/components/Activity.tsx

@@ -9,6 +9,7 @@ import { activityCards, uploadSteps } from "@/services/trackSomething";
 import { TimeFormatter } from "@/utils/time_format";
 import MetricItem from "./MetricItem";
 import { checkFail, checkStart, checkSuccess, setResult } from "@/store/action_results";
+import { uploadSessionKey } from "@/services/common";
 
 export default function Component(props: any) {
     const user = useSelector((state: any) => state.user);
@@ -124,11 +125,20 @@ export default function Component(props: any) {
                     getCards();
                 }).catch(e => {
                     dispatch(setResult({ isSuccess: false }) as any);
+                    updateSessionKey();
                 });
             }
         })
     }
 
+    function updateSessionKey(){
+        Taro.login().then(res => {
+            // code = res.code;
+            uploadSessionKey({ type: 'WX_MP', code: res.code });
+
+          })
+    }
+
     function refuseAuth() {
         // setTitle('开启');
         setIsChecking(false)

+ 10 - 0
src/pages/Profile.tsx

@@ -21,6 +21,13 @@ export default function Page(){
             url: '/pages/ChooseAuth'
         })
     }
+
+    function reset(){
+        Taro.login({
+            
+        })
+    }
+
     return <View  className="container">
         {
             user.isLogin&&<Text>用户名:{user.nickname}</Text>
@@ -36,6 +43,9 @@ export default function Page(){
             user.isLogin?<Buttons title='注销账号' onClick={clearF} style={{ width: 289, marginBottom: 30 }} />:
             <Text></Text>
         }
+        {
+            user.isLogin&& <Buttons title='重置session' onClick={reset} style={{ width: 289, marginBottom: 30 }} />
+        }
         
     </View>
 }

+ 6 - 3
src/pages/RecordsHistory.tsx

@@ -53,6 +53,7 @@ export default function Page() {
     // })
 
     function refresh() {
+        debugger
         setPageIndex(1)
         getHistory(1)
     }
@@ -64,13 +65,14 @@ export default function Page() {
     }
 
     function getHistory(page = pageIndex) {
+        
         if (router.params.type == 'time') {
             getClockRecords({
                 page: page,
                 limit: pageSize,
                 only_finished: false
             }).then(res => {
-                if (pageIndex == 1) {
+                if (page == 1) {
                     setRecords((res as any).data)
                 } else {
                     setRecords(records.concat((res as any).data))
@@ -85,7 +87,8 @@ export default function Page() {
                     code:'_walk'
                 }
             ).then(res => {
-                if (pageIndex == 1) {
+                debugger
+                if (page == 1) {
                     setRecords((res as any).data)
                 } else {
                     setRecords(records.concat((res as any).data))
@@ -100,7 +103,7 @@ export default function Page() {
                     code:router.params.code
                 }
             ).then(res => {
-                if (pageIndex == 1) {
+                if (page == 1) {
                     setRecords((res as any).data)
                 } else {
                     setRecords(records.concat((res as any).data))

+ 6 - 10
src/pages/clock.tsx

@@ -68,6 +68,11 @@ export default function IndexPage() {
   }, [user.isLogin])
 
   function checkSession() {
+    Taro.login().then(res => {
+      // code = res.code;
+      uploadSessionKey({ type: 'WX_MP', code: res.code });
+    })
+    return
     if (process.env.TARO_ENV === 'weapp') {
       Taro.checkSession({
         success: function () {
@@ -75,21 +80,12 @@ export default function IndexPage() {
           console.log('session_key 未过期,并且在本生命周期一直有效')
         },
         fail: function () {
-          // session_key 已经失效,需要重新执行登录流程
-          console.log('session_key 已经失效,需要重新执行登录流程')
-          //更新session key,发送给服务器
-          // dispatch(logoutSuccess());
-          // wx.login() //重新登录
-
-
+          console.log('session_key 已经失效,需要更新登录code')
           Taro.login().then(res => {
             // code = res.code;
             uploadSessionKey({ type: 'WX_MP', code: res.code });
-
           })
-
         }
-
       })
     }
   }

+ 0 - 2
src/store/user.tsx

@@ -47,7 +47,6 @@ const userSlice = createSlice({
             Taro.setStorage({ key: 'userData', data: JSON.stringify(action.payload) });
         },
         logoutSuccess(state) {
-            debugger
             state.id = null;
             state.nickname = null;
             state.avatar = null;
@@ -58,7 +57,6 @@ const userSlice = createSlice({
             Taro.clearStorage();
         },
         clearSuccess(state) {
-            debugger
             state.id = null;
             state.nickname = null;
             state.avatar = null;