<template>
<view class="container">
<view class='header'>
<open-data type="userAvatarUrl" v-if="platform==1"></open-data>
<image src="../../static/logo.png" v-if="platform==6"></image>
</view>
<view class='content'>
<view>为了提供更好的服务,请点击下方授权登录</view>
<text>获得你的公开信息(昵称,头像等)</text>
</view>
<button class='btns bottoms' lang="zh_CN" @click="redindex" v-if="is_login==0" >授权登录</button>
<button class="btns bottoms" open-type="getPhoneNumber" @getphonenumber="onGetPhoneNumber" v-if="is_login==1" >绑定手机</button>
<button class='btns bottoms no-login' type="default" @click="goBack">返回</button>
</view>
</template>
<script>
export default {
data() {
return {
is_login:0 ,//0:先登录后绑定手机,1:直接绑定手机,2:只需要登录
login_type:0,
logo:'../../static/logo.jpg',
platform:6,
}
},
onShow() {
this.platform = this.gldb.platform;
this.login_type = uni.getStorageSync('showBtnType');console.log('.login_type: '+this.login_type);
if(this.login_type==1){
this.is_login = 1;
}
},
methods: {
goBack(){
uni.switchTab({
url:'/pages/index/index'
})
},
redindex(res){
var that = this;
if(that.gldb.platform==1){
uni.getUserProfile({
desc: '登录账号', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
that.gldb.userInfo = res.userInfo;
let tmp = uni.getStorageSync('device_id');
uni.clearStorageSync();
uni.setStorageSync('device_id', tmp);
uni.setStorageSync('refreshLogin', 1);
uni.setStorageSync('auto_login',1);
if(that.login_type==2){
that.is_login=2;
uni.removeStorageSync('showBtnType');
/* uni.navigateBack({
delta: 1
}); */
uni.switchTab({
url:'/pages/index/index'
})
}else{
that.is_login=1;
}
}
})
}else{
uni.getSetting({
success: (res) => {
that.login( that.storageData );
if (res.authSetting['scope.userInfo'] == true) {
//同意授权
var isIn = true;
}else if(res.authSetting['scope.userInfo'] == false){
//拒绝
console.log('拒绝');
var isIn = false;
}else{
//还有没有授权的操作
var isIn = true;
console.log('还有没有授权的操作');
}
if( isIn == true ){
uni.authorize({
scope: 'scope.userInfo',
success( res ) {
that.login( that.storageData );
},
fail(res){
that.showToast({
title: '请开启用户信息!',
duration: 3000
});
uni.openSetting({
success(res) {
if (res.authSetting['scope.userInfo'] == true) {
that.login( that.storageData );
}
},
fail(res){
console.log('fail-openSetting');
}
});
}
})
}else{
uni.openSetting({
success(res) {
if (res.authSetting['scope.userInfo'] == true) {
that.login( that.storageData );
}
}
});
}
}
})
}
},
storageData(){
var that = this;
let tmp = uni.getStorageSync('device_id');
uni.clearStorageSync();
uni.setStorageSync('device_id', tmp);
uni.setStorageSync('refreshLogin', 1);
uni.setStorageSync('auto_login','1');
if(that.login_type==2){
that.is_login=2;
uni.removeStorageSync('showBtnType');
uni.navigateBack({
delta: 1
});
}else{
that.is_login=1;
}
},
onGetPhoneNumber(e){
console.log(e);
var that = this;
if(e.detail.errMsg=="getPhoneNumber:fail user deny"){ //用户决绝授权
//拒绝授权后弹出一些提示
that.showToast({
title: '绑定手机后才可以获得下单等更多权限哟!',
duration: 3000
});
}else{//允许授权
uni.setStorageSync('refreshLogin', 1);
uni.setStorageSync('ivData', {encryptedData:e.detail.encryptedData,iv:e.detail.iv,type:1});
uni.removeStorageSync('showBtnType');console.log( uni.getStorageSync('ivData') );
uni.navigateBack({
delta: 1
});
}
}
}
}
</script>
<style>
.header {
border-bottom: 1px solid #ccc;
text-align: center;
width: 200upx;
height: 200upx;
margin: 100upx auto;
border-radius: 50%;
overflow: hidden;
}
.header image {
width: 200upx;
height: 200upx;
}
.content {
margin-left: 50upx;
margin-bottom: 90upx;
font-size: 24upx;
}
.content text {
display: block;
color: #9d9d9d;
margin-top: 40upx;
}
.bottoms {
text-align: center;
border-radius: 80upx;
width: 90%;
height: 80rpx;
line-height: 80rpx;
color: #FFFFFF;
margin: auto;
font-size: 35upx;
background: linear-gradient(-90deg, #FF4C11, #FF8225);
}
.no-login{
margin-top: 40upx;
}
open-data{
width: 50upx !important;
height: 50upx;
border-radius: 50%;
}
</style>
0 个回复