You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
3.2 KiB
141 lines
3.2 KiB
<!--微信授权登录界面-->
|
|
<template>
|
|
<view>
|
|
<!-- #ifdef MP-WEIXIN -->
|
|
<view v-if="isCanUse" class="back">
|
|
<u-navbar
|
|
title="微信授权登录"
|
|
:safeAreaInsetTop="true"
|
|
:fixed="true"
|
|
bgColor="#FFFFFF00"
|
|
:placeholder="true"
|
|
/>
|
|
<view class="body">
|
|
<view class='header'>
|
|
<image src='../../static/images/wx_icon.png'></image>
|
|
</view>
|
|
<u-gap height="50rpx" />
|
|
<view class='content'>
|
|
<view>申请获取以下权限</view>
|
|
<text>获得你的公开信息(昵称,头像、地区等)</text>
|
|
</view>
|
|
|
|
<button class='bottom' type='primary' open-type="getUserInfo" withCredentials="true" lang="zh_CN" @getuserinfo="login">
|
|
授权登录
|
|
</button>
|
|
</view>
|
|
</view>
|
|
<!-- #endif -->
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
data() {
|
|
return {
|
|
SessionKey: '',
|
|
OpenId: '',
|
|
nickName: null,
|
|
avatarUrl: null,
|
|
isCanUse: uni.getStorageSync('isCanUse')||true//默认为true
|
|
};
|
|
},
|
|
methods: {
|
|
//登录
|
|
login() {
|
|
let _this = this;
|
|
uni.showLoading({
|
|
title: '登录中...'
|
|
});
|
|
|
|
// 1.wx获取登录用户code
|
|
uni.login({
|
|
provider: 'weixin',
|
|
success: function(loginRes) {
|
|
console.log(loginRes);
|
|
let code = loginRes.code;
|
|
/*if (!_this.isCanUse) {
|
|
//非第一次授权获取用户信息
|
|
uni.getUserInfo({
|
|
provider: 'weixin',
|
|
success: function(infoRes) { //获取用户信息后向调用信息更新方法
|
|
let nickName = infoRes.userInfo.nickName; //昵称
|
|
let avatarUrl = infoRes.userInfo.avatarUrl; //头像
|
|
|
|
}
|
|
});
|
|
}*/
|
|
|
|
//2.将用户登录code传递到后台置换用户SessionKey、OpenId等信息
|
|
uni.request({
|
|
url: 'http://192.168.31.11:8888/app/v1/login/wechatlogin',
|
|
data: {
|
|
code: code,
|
|
},
|
|
method: 'POST',
|
|
header: {
|
|
'content-type': 'application/json'
|
|
},
|
|
success: (res) => {
|
|
//openId、或SessionKdy存储//隐藏loading
|
|
console.log("!!!!");
|
|
console.log(res);
|
|
uni.hideLoading();
|
|
},
|
|
fail: (e) => {
|
|
console.log(e);
|
|
uni.hideLoading();
|
|
}
|
|
});
|
|
},
|
|
});
|
|
},
|
|
|
|
onLoad() {//默认加载
|
|
//this.login();
|
|
}
|
|
},
|
|
}
|
|
</script>
|
|
|
|
<style scoped>
|
|
|
|
.body{
|
|
width: 100%;
|
|
//background-color: #0081FF;
|
|
position: relative;
|
|
}
|
|
.header {
|
|
border-bottom: 1px solid #ccc;
|
|
text-align: center;
|
|
width: 750rpx;
|
|
height: 300rpx;
|
|
line-height: 450rpx;
|
|
display: flex;
|
|
flex-direction: row;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
.header image {
|
|
width: 200rpx;
|
|
height: 200rpx;
|
|
}
|
|
|
|
.content {
|
|
margin-left: 50rpx;
|
|
margin-bottom: 90rpx;
|
|
}
|
|
|
|
.content text {
|
|
display: block;
|
|
color: #9d9d9d;
|
|
margin-top: 40rpx;
|
|
}
|
|
|
|
.bottom {
|
|
border-radius: 80rpx;
|
|
margin: 70rpx 50rpx;
|
|
font-size: 35rpx;
|
|
}
|
|
</style>
|
|
|