Procházet zdrojové kódy

提交登录逻辑

wangming před 1 měsícem
rodič
revize
79ec0d096d
1 změnil soubory, kde provedl 82 přidání a 40 odebrání
  1. 82 40
      src/pagesA/loginNew/loginNew.vue

+ 82 - 40
src/pagesA/loginNew/loginNew.vue

@@ -78,48 +78,90 @@ export default {
             }
         },
         onGetPhoneNumber(e) {
-            let code = "";
-            // console.log(e.detail.code, 9999);
-            if (e.detail) {
-                code = e.detail.code;
-                this.checked = true;
-            } else {
-                code = e.code;
-                this.checked = true;
-            }
-            this.$http
-                .post(
-                    "wap/user/wx/loginByPhone",
-                    JSON.stringify({
-                        openId: uni.getStorageSync("openid"),
-                        unionId: uni.getStorageSync("unionid"),
-                        code: code,
-                    }),
-                    {
-                        header: {
-                            "Content-Type": "application/json;charset=UTF-8",
-                        },
-                    }
-                )
-                .then((res) => {
-                    if (res.data.data) {
-                        uni.setStorageSync("phone", res.data.data.phone);
-                        uni.setStorageSync(
-                            "tokenValue",
-                            res.data.data.tokenValue
-                        );
-                        uni.setStorageSync("userId", res.data.data.userId);
-
-                        this.$initMqtt();
-                        console.log("✅ 登录成功后 MQTT 开始登录连接");
+            let userId = uni.getStorageSync("userId");
+            if (!userId) {
+                let code = "";
+                // console.log(e.detail.code, 9999);
+                if (e.detail) {
+                    code = e.detail.code;
+                    this.checked = true;
+                } else {
+                    code = e.code;
+                    this.checked = true;
+                }
+                this.$http
+                    .post(
+                        "wap/user/wx/loginByPhone",
+                        JSON.stringify({
+                            openId: uni.getStorageSync("openid"),
+                            unionId: uni.getStorageSync("unionid"),
+                            code: code,
+                        }),
+                        {
+                            header: {
+                                "Content-Type":
+                                    "application/json;charset=UTF-8",
+                            },
+                        }
+                    )
+                    .then((res) => {
+                        if (res.data.data) {
+                            uni.setStorageSync("phone", res.data.data.phone);
+                            uni.setStorageSync(
+                                "tokenValue",
+                                res.data.data.tokenValue
+                            );
+                            uni.setStorageSync("userId", res.data.data.userId);
 
-                        uni.reLaunch({
-                            url: "/pages/home/home",
-                        });
-                    }
-                });
+                            this.$initMqtt();
+                            console.log("✅ 登录成功后 MQTT 开始登录连接");
 
-            this.checked = false;
+                            uni.reLaunch({
+                                url: "/pages/home/home",
+                            });
+                        }
+                    });
+                this.checked = false;
+            } else {
+                let code = "";
+                // console.log(e.detail.code, 9999);
+                if (e.detail) {
+                    code = e.detail.code;
+                    this.checked = true;
+                } else {
+                    code = e.code;
+                    this.checked = true;
+                }
+                this.$http
+                    .post(
+                        "wap/user/wx/loginByPhone",
+                        JSON.stringify({
+                            openId: uni.getStorageSync("openid"),
+                            unionId: uni.getStorageSync("unionid"),
+                            code: code,
+                        }),
+                        {
+                            header: {
+                                "Content-Type":
+                                    "application/json;charset=UTF-8",
+                            },
+                        }
+                    )
+                    .then((res) => {
+                        if (res.data.data) {
+                            uni.setStorageSync("phone", res.data.data.phone);
+                            uni.setStorageSync(
+                                "tokenValue",
+                                res.data.data.tokenValue
+                            );
+                            uni.setStorageSync("userId", res.data.data.userId);
+                            uni.reLaunch({
+                                url: "/pages/home/home",
+                            });
+                        }
+                    });
+                this.checked = false;
+            }
         },
         noLogin() {
             uni.clearStorageSync();