微信小程序快捷登录

<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>

<!-- 是否显示其他方式登录

<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" open-type="getPhoneNumber" hover-class='active' @getphonenumber="getPhoneNumber">获取手机号</button>

<view class="title">

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

</view>

</view>

</view>

</uni-popup>

</view>

</template>

<script>

import {qqMapTransBMap} from '../../common/tool.js'

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","..");

},

// 混入监听方法

mixins: [mixin],

methods: {

sendlocation(){

uni.getLocation({

    type: 'gcj02',

    success:(res)=>{

  let mapnum = qqMapTransBMap(res.longitude, res.latitude);

  http.httpTokenRequest({

  url: "User/setLocation",

  method: 'POST'

  }, {

  user_id: this.userinfo.id,

latitude:mapnum.lat,

longitude:mapnum.lng,

reverse_geo:1

  }).then((res) => {

  })

    }

});

},

// 点击获取手机号按钮

getPhoneNumber(e){

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

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

let user=JSON.parse(res.data.data);

user.phone=user.phoneNumber;

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;

uni.showLoading({

    title: '加载中',

mask:true

});

uni.login({

provider: 'weixin',

success(res){

uni.getUserInfo({

provider: 'weixin',

success(info) {

// 用户信息 已经拿到用户信息

let nickname=info.userInfo.nickName

// console.log(res.code,'codecodecodecodecode');

// return false;

http.httpRequest({url:'User/weChat',method:'post'}, {code:res.code,type:3,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{

console.log('弹出框要出来')

that.togglePopup()

}

})

},

complete() {

that.loading=false;

uni.hideLoading();

}

})

}

})

}

}

}

</script>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。