Kaynağa Gözat

feat:授权获取手机号

DaMowang 3 yıl önce
ebeveyn
işleme
75d796a47a
1 değiştirilmiş dosya ile 27 ekleme ve 7 silme
  1. 27 7
      src/pages/my/index.vue

+ 27 - 7
src/pages/my/index.vue

@@ -411,6 +411,8 @@ export default {
       agentName: "", // 缘起
       user_id: undefined,
       userinfo: undefined, // 获取用户信息
+
+      unid: '',
     };
   },
   onLoad: function (options) {
@@ -442,10 +444,18 @@ export default {
         success(res) {
           if (res.code) {
             post("appletLogin", { code: res.code }).then(res => {
-              setTimeout(() => {
-                that.showAuth = true
-                that.shopInfo = app.globalData.shopInfo
-              }, 500);
+              if(res.code === 0){
+                if(res.data.token){
+                  uni.setStorageSync('token', res.data.token);
+                  that.getuserInfo();
+                }else{
+                  that.unid = res.data.unid
+                  // setTimeout(() => {
+                    that.showAuth = true
+                    that.shopInfo = app.globalData.shopInfo
+                  // }, 500);
+                }
+              }
             });
           }
         },
@@ -457,11 +467,21 @@ export default {
       // #endif
     },
     onauthGetTelSuccess(da){
-      console.log(da);
-      post("getMobile", da.detail).then(res => {
-        console.log(res);
+      this.showAuth = false;
+      post("getMobile", {unid:this.unid, ...da.detail}).then(res => {
+            if (res.code === 0) {
+                uni.setStorageSync('token', res.data.token);
+                this.getuserInfo();
+            }
       })
     },
+    getuserInfo() {
+        post("/user/userinfo").then((res) => {
+            if (res.code === 0) {
+                uni.setStorageSync('userinfo', res.data.data);
+            }
+        });
+    },
 
     // 获取用户信息
     loadData() {