支付宝小程序快捷登录

<template>

<view class="authorization">

<view class="loginwrap">

<view class="logo">

<image src="http://www.huaxiukeji.com/uploads/img/login.png"></image>

<text>解决您的生活问题</text>

</view>

<view class="logobtn">

<text class="titletop">登录后即可继续当前操作</text>

<button class='bottom' type='primary' :loading='loading' open-type="getUserInfo" @getuserinfo="wxGetUserInfo">百度快捷登录</button>

<!-- <button @tap="wxGetUserInfo" type="primary" hover-stop-propagation="true">获取用户信息</button> -->

<!-- <block>

<text class="otherlogin">其他方式登录</text>

<view class="other" @tap='gocodelogin'>

<image style="width: 71rpx;height: 71rpx;" src="http://www.huaxiukeji.com/uploads/img/classification.png" mode=""></image>

<text class="otherphone">验证码登录</text>

</view>

</block> -->

<text class="titlebottom">登录后可下单,参加活动还可领优惠券</text>

</view>

<view class="logobottom">

<agreement></agreement>

</view>

</view>

<uni-popup ref="showpopup" type="bottom">

<view class="popupwrap">

<view class="popupcontent">

<button class="loginbtn" type='warn' open-type="getPhoneNumber" hover-class='active' @getphonenumber="getPhoneNumber">获取手机号</button>

<view class="title">

<text>授权您的手机号以便进行登录</text>

</view>

</view>

</view>

</uni-popup>

</view>

</template>

<script>

import uniPopup from '@/components/uni-popup/uni-popup.vue'

import agreement from '../../components/agreement/agreement.vue'

import http from '@/common/http.js';

import mixin from '@/common/mixin.js';

export default {

name: "authorization",

data() {

return {

session_key:null,

loading:false,

userinfo:null,

backurl:''

}

},

components:{

agreement,

uniPopup

},

onLoad() {

// this.togglePopup();

let page = getCurrentPages()

this.backurl=page[0].route.replace("pages","..");

},

onShow() {

swan.setPageInfo({

            title: '华修综合家政,下载华修、新用户优惠券大额发放!-华修APP',

            keywords: '华修,华修科技,华修APP,保洁上门,家电维修,上门安装,手机,家政,维修,杭州家政,线上预约',

            description: '杭州华修科技有限公司,APP上线,新客户注册即送大额优惠券,上门服务,不收上门费',

releaseDate: '2020-06-12 12:00:00',

articleTitle:"快捷登录,一键登录"

})

},

// 混入监听方法

mixins: [mixin],

methods: {

sendlocation(){

uni.getLocation({

    type: 'gcj02',

    success:(res)=>{

  http.httpTokenRequest({

  url: "User/setLocation",

  method: 'POST'

  }, {

  user_id: this.userinfo.id,

latitude:res.latitude,

longitude:res.longitude,

reverse_geo:1

  }).then((res) => {

  })

    }

});

},

// 点击获取手机号按钮

getPhoneNumber(e){

http.httpRequest({url:'User/decodeBdData',method:'post'},{token:this.userinfo.token,user_id:this.userinfo.id, encryptedData:e.detail.encryptedData,iv: e.detail.iv,session_key:this.session_key}).then((res)=>{

if(res.data.code==1){

let user=res.data.data;

user.phone=user.mobile;

this.userinfo=Object.assign(this.userinfo,user);

uni.setStorageSync('userinfo',this.userinfo);

getApp().globalData.userinfo=this.userinfo;

http.httpTokenRequest({url:'User/bindPhone',method:'post'},

{phone:this.userinfo.phone,type:2,user_id:this.userinfo.id}).then((res)=>{

console.log(res,'查看是否绑定成功');

})

uni.reLaunch({

    url: this.backurl

});

}else{

uni.showToast({

    title: '手机号码获取失败',

icon:"none",

    duration: 2000

});

}

})

},

togglePopup(type, open) {

this.$refs.showpopup.open()

},

closepopup(){

this.$refs.showpopup.close()

},

gocodelogin(){

// 前往验证码登录页面

console.log('1235846')

uni.navigateTo({

url:'../codelogin/index'

})

},

wxGetUserInfo() {

this.loading=true;

let that=this;

swan.getUserInfo({

success(info) {

swan.login({

success(res){

let nickname=info.userInfo.nickName

http.httpRequest({url:'User/weChat',method:'post'}, {code:res.code,type:5,nick:nickname}).then((res)=>{

var userinfo=res.data.data

userinfo.cover=info.userInfo.avatarUrl;

that.userinfo=userinfo;

that.session_key=userinfo.session_key;

that.sendlocation();

if(userinfo.phone){

uni.setStorageSync('userinfo',userinfo);

getApp().globalData.userinfo=userinfo;

uni.reLaunch({

    url: that.backurl

});

}else{

that.togglePopup()

}

})

}

})

},

fail() {

that.loading=false;

uni.hideLoading();

}

})

}

}

}

</script>

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容