萤火科技 2 роки тому
батько
коміт
0aaf66a522
2 змінених файлів з 24 додано та 22 видалено
  1. 22 19
      pages/login/components/mp-weixin.vue
  2. 2 3
      pages/login/index.vue

+ 22 - 19
pages/login/components/mp-weixin.vue

@@ -10,10 +10,10 @@
     <view class="auth-subtitle">获得你的公开信息(昵称、头像等)</view>
     <view class="login-btn">
       <!-- 获取微信用户信息 -->
-      <button class="button btn-normal" @click.stop="getUserProfile">授权登录</button>
+      <button class="button btn-normal" @click="getUserProfile()">授权登录</button>
     </view>
     <view class="no-login-btn">
-      <button class="button btn-normal" @click="handleCancel">暂不登录</button>
+      <button class="button btn-normal" @click="handleCancel()">暂不登录</button>
     </view>
   </view>
 </template>
@@ -45,8 +45,6 @@
       // 获取商城基本信息
       getStoreInfo() {
         SettingModel.item('store').then(store => this.storeInfo = store)
-
-        // SettingModel.h5Url(true)
       },
 
       // 获取code
@@ -64,22 +62,27 @@
         })
       },
 
-      // 获取微信用户信息(新版)
+      // // 获取微信用户信息 (已废弃)
+      // getUserProfile() {
+      //   const app = this
+      //   wx.canIUse('getUserProfile') && wx.getUserProfile({
+      //     lang: 'zh_CN',
+      //     desc: '获取用户相关信息',
+      //     success({ userInfo }) {
+      //       console.log('用户同意了授权')
+      //       console.log('userInfo:', userInfo)
+      //       // 授权成功事件
+      //       app.onAuthSuccess(userInfo)
+      //     },
+      //     fail() {
+      //       console.log('用户拒绝了授权')
+      //     }
+      //   })
+      // },
+
+      // 获取微信用户信息 (弃用getUserProfile)
       getUserProfile() {
-        const app = this
-        wx.canIUse('getUserProfile') && wx.getUserProfile({
-          lang: 'zh_CN',
-          desc: '获取用户相关信息',
-          success({ userInfo }) {
-            console.log('用户同意了授权')
-            console.log('userInfo:', userInfo)
-            // 授权成功事件
-            app.onAuthSuccess(userInfo)
-          },
-          fail() {
-            console.log('用户拒绝了授权')
-          }
-        })
+        this.onAuthSuccess({ nickName: '微信用户', avatarUrl: '' })
       },
 
       // 授权成功事件

+ 2 - 3
pages/login/index.vue

@@ -52,9 +52,8 @@
       async setShowUserInfo() {
         console.log('setShowUserInfo start')
         const app = this
-        // 判断当前客户端是微信小程序, 并且支持getUserProfile接口
-        const isMpWeixin = app.platform === 'MP-WEIXIN' && wx.canIUse('getUserProfile')
-
+        // 判断当前客户端是微信小程序
+        const isMpWeixin = app.platform === 'MP-WEIXIN'
         // 获取后台设置
         await SettingModel.item(SettingKeyEnum.REGISTER.value, false)
           .then(setting => {