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.
143 lines
3.7 KiB
143 lines
3.7 KiB
<template>
|
|
<view>
|
|
<image mode="widthFix" class="width90 mart20" v-if="user && user.infoCompleteStatus == 1" :src="imagewxUrl+imgadres"></image>
|
|
<image mode="widthFix" class="width90 mart20" v-if="!user" :src="imagewxUrl+imgadres1"></image>
|
|
<!-- #ifdef MP -->
|
|
<view class="mart30 width90 height50 fcorfff backcor008 fotct btns font16 fontlet" v-if="user && user.infoCompleteStatus == 1" @click="getuserinfo">
|
|
授权并登录</view>
|
|
<button class="mart30 width90 height50 fcorfff backcor008 fotct btns font16 fontlet" v-if="!user"
|
|
open-type="getPhoneNumber" @getphonenumber="loginByPhone">授权手机号</button>
|
|
<!-- <button class="mart30 width90 height50 fcorfff backcor008 fotct btns font16" v-if="user.phone && user"
|
|
@click="reqmessage">授权获取消息通知</button> -->
|
|
<!-- #endif -->
|
|
<!-- #ifdef H5 -->
|
|
<button class="mart30 width90 height50 fcorfff backcor008 fotct btns font16"
|
|
@click="getH5userinfo">授权并登录</button>
|
|
<!-- #endif -->
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
const app = getApp();
|
|
import {
|
|
getUserInfo,
|
|
loginByPhone
|
|
} from "../../Utils/Api.js"
|
|
export default {
|
|
data() {
|
|
return {
|
|
user: '',
|
|
imagewxUrl: app.globalData.imageWxImg,
|
|
imgadres: 'login.png',
|
|
imgadres1: 'loginphone.png',
|
|
}
|
|
},
|
|
onLoad() {
|
|
this.user = app.globalData.userInfo;
|
|
},
|
|
methods: {
|
|
getuserinfo() {
|
|
let that = this;
|
|
uni.getUserProfile({
|
|
desc: '登录中...',
|
|
success: function(res) {
|
|
let params = {
|
|
openId: app.globalData.openId,
|
|
iv: res.iv,
|
|
encryptedData: res.encryptedData
|
|
}
|
|
getUserInfo(params).then(res => {
|
|
if (res.return_code == '000000') {
|
|
app.globalData.userInfo = res.return_data
|
|
.object
|
|
.highUser;
|
|
that.user = res.return_data.object.highUser;
|
|
app.globalData.token = res.return_data.uniqueCode;
|
|
that.isShowAuth = false
|
|
uni.setStorage({
|
|
key: "user",
|
|
data: res.return_data
|
|
.object
|
|
.highUser
|
|
})
|
|
uni.setStorage({
|
|
key: "token",
|
|
data: res.return_data.uniqueCode
|
|
})
|
|
if (res.return_data.object.highUser.infoCompleteStatus == 0) {
|
|
uni.navigateBack({
|
|
})
|
|
}
|
|
} else {
|
|
uni.showToast({
|
|
title: res.return_msg
|
|
})
|
|
}
|
|
});
|
|
},
|
|
fail: res => {
|
|
uni.showToast({
|
|
title: "微信登录授权失败",
|
|
icon: "none"
|
|
});
|
|
}
|
|
})
|
|
that.isShowAuth = false
|
|
},
|
|
// 微信获取手机号
|
|
loginByPhone(PhoneNumber) {
|
|
if(PhoneNumber.detail.iv == undefined){
|
|
uni.showToast({
|
|
title: "用户取消授权",
|
|
icon: "none"
|
|
});
|
|
return;
|
|
}
|
|
let params = {
|
|
openId: app.globalData.openId,
|
|
iv: PhoneNumber.detail.iv,
|
|
encryptedData: PhoneNumber.detail.encryptedData
|
|
}
|
|
loginByPhone(params).then(res => {
|
|
if (res.return_code == '000000') {
|
|
uni.showToast({
|
|
title: '手机号授权成功',
|
|
icon: 'none',
|
|
duration: 2000
|
|
})
|
|
this.user = res.return_data.object.highUser;
|
|
app.globalData.token = res.return_data.uniqueCode;
|
|
app.globalData.userInfo = res.return_data
|
|
.object
|
|
.highUser;
|
|
uni.setStorage({
|
|
key: "user",
|
|
data: res.return_data
|
|
.object
|
|
.highUser
|
|
})
|
|
uni.setStorage({
|
|
key: "token",
|
|
data: res.return_data.uniqueCode
|
|
})
|
|
if(res.return_data.object.highUser.infoCompleteStatus == 0){
|
|
uni.navigateBack({
|
|
})
|
|
}
|
|
}
|
|
});
|
|
},
|
|
getH5userinfo() {
|
|
uni.navigateTo({
|
|
url: '/pages/login/register'
|
|
})
|
|
},
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
.btns {
|
|
border-radius: 6px;
|
|
}
|
|
</style>
|
|
|