Procházet zdrojové kódy

fix(login): 修复登录流程中的 accessToken 存储问题

- 调整了 accessToken 存储的时机,确保用户信息存在时才存储
- 优化了代码结构,减少了重复代码
- 修改了测试用的手机号码和 openId
wzg před 8 měsíci
rodič
revize
91f78e0616

+ 3 - 3
miniprogram/pages/index/index.js

@@ -52,9 +52,8 @@ Page({
         url: "/pages/takePhoto/takePhoto",
       });
     } else {
-      wx.setStorageSync("accessToken", data.result.tokenInfo.tokenValue);
-
       if (data?.result?.userInfo?.userId) {
+        wx.setStorageSync("accessToken", data.result.tokenInfo.tokenValue);
         wx.showModal({
           title: "提示",
           content: "您已注册但尚未绑定船舶,去绑定?",
@@ -100,7 +99,7 @@ Page({
         console.log("data1", data);
         if (data.status === 0) {
           let { phoneNumber: phone } = data.result;
-          // let phone = "19103808211";
+          // let phone = "19103801211";
           wx.setStorageSync("phone", phone);
           let { data } = await postApi("/login", {
             phone,
@@ -118,6 +117,7 @@ Page({
             wx.setStorageSync("accessToken", data.result.tokenInfo.tokenValue);
           } else {
             console.log(data, "data23");
+            wx.setStorageSync("accessToken", data.result.tokenInfo.tokenValue);
             if (data?.result?.userInfo?.userId) {
               wx.showModal({
                 title: "提示",

+ 1 - 1
miniprogram/utils/wxUtils.js

@@ -11,7 +11,7 @@ function wxSetSessionKey() {
           });
           if (data.status === 0) {
             let { openId } = data.result;
-            // let openId = "oiOWR5ch3L_mD2uYwSemzedDdG8I232";
+            // let openId = "oiOWR5ch3L_mD2uYwSemzedDdG8I2322";
             wx.setStorageSync("openId", openId);
             resolve({
               status: 0,