zhaojs
2023-05-24 92514beb315f5778df2849341dcffb3bb257160c
uniapp/pages/login/wxlogin.vue
@@ -8,9 +8,16 @@
            <image class="logoIcon" src="../../static/images/mine/wxwhite.png" mode=""></image>
            <view>微信一键登录</view>
         </view>
         <view class="goaccount rowCenCen" @tap="goaccount()">
         <view v-if="isSupportMob" class="goaccount rowCenCen" @tap="mobileLogin()">
            <view>本机手机号一键登录/注册</view>
         </view>
         <view v-else class="goaccount rowCenCen" @tap="goaccount()">
            <view>手机号登录/注册</view>
         </view>
         <view style="margin-top: 20px;" v-if="isother"  @tap="goaccount()">
            手机号登录/注册
         </view>
      </view>
      <view class="bottom-fixed colCen">
@@ -28,6 +35,7 @@
      mapMutations
   } from 'vuex';
   import titleBar from '../../components/backTitlebar.vue'
   const univerifyManager = uni.getUniverifyManager();
   export default {
      components: {
         titleBar
@@ -37,7 +45,9 @@
            appInfo: '',
            ifPasslogin: false,
            isread: false,
            haswxlogin: false
            haswxlogin: false,
            isSupportMob:false,
            isother:false
         }
      },
      onLoad() {
@@ -46,6 +56,7 @@
         console.log(getApp().globalData.ifwt)
         //this.haswxlogin = this.appInfo.iosExamine ? false : (getApp().globalData.ifwt == 1 ? true : false)
         this.haswxlogin = getApp().globalData.ifwt == 1 ? true :false;
         this.isSupportMoblie();
      },
      methods: {
         ...mapMutations(['login']),
@@ -62,6 +73,96 @@
               })
            }
         },
         isSupportMoblie()
         {
            var that=this;
            uni.preLogin({
               provider: 'univerify',
               success(){  //预登录成功
                  // 显示一键登录选项
                  that.isSupportMob=true;
               },
               fail(res){  // 预登录失败
                  // 不显示一键登录选项(或置灰)
                // 根据错误信息判断失败原因,如有需要可将错误提交给统计服务器
                  console.log(res)
                  console.log(res.errMsg)
               }
            })
         },
         doMobileLogin(mobRes)
         {
            var that=this;
            uniCloud.callFunction({
              name: 'getPhoneNumber', // 你的云函数名称
              data: {
                'access_token': mobRes.access_token, // 客户端一键登录接口返回的access_token
                'openid': mobRes.openid // 客户端一键登录接口返回的openid
              }
            }).then(res => {
               console.log(res)
               that.targetToIndex(res.result.data);
              // 登录成功,可以关闭一键登录授权界面了
              univerifyManager.close();
            }).catch(err=>{
               // 处理错误
               console.log(err)
               uni.hideLoading();
               that.$alert('获取手机号码失败,请使用其他方式登录')
               setTimeout(function(){
                  univerifyManager.close();
               },2000);
            })
         },
         mobileLogin()
         {
            var that=this;
            if (this.isread) {
               univerifyManager.login({
                  provider: 'univerify',
                  univerifyStyle: { // 自定义登录框样式
                   "fullScreen":false,
                  "authButton":
                  {
                     "normalColor":"#F73314",
                     "highlightColor":"#F73314"
                  }
                 },
               success(res){ // 登录成功
                  console.log(res.authResult);
                  that.doMobileLogin(res.authResult);
                  },
                  fail(res){  // 登录失败
                  console.log(res)
                     if(res.errCode==30002)
                     {//切换登录方式
                        that.isother=true;
                     }
                     else
                     {
                        that.$alert('获取手机号码失败,请使用其他方式登录')
                        setTimeout(function(){
                           univerifyManager.close();
                        },2000);
                     }
                     that.isother=true;
                  }
               })
               }
               else
               {
                  uni.showToast({
                     title: '请先阅读并同意《用户协议》和《隐私协议》',
                     icon: "none",
                  })
               }
         },
         targetToIndex(e)
         {
            var that = this;