<template>
|
<view class="wxlogin-wrapper wrapperLayer">
|
<titleBar titleText='' :pageForm='"login"' @backIndex="backHome"></titleBar>
|
<view class="pageContent borderBox colCen">
|
<image class="applogo" :src="appInfo.logo" mode="aspectFill"></image>
|
|
<view class="wxlogoBtn rowCenCen" @tap="wxlogin()" v-if="supportWx">
|
<image class="logoIcon" src="../../static/images/mine/wxwhite.png" mode=""></image>
|
<view>微信一键登录</view>
|
</view>
|
<view v-if="isSupportMob" class="goaccount rowCenCen" @tap="mobileLogin()">
|
<view>本机手机号一键登录/注册</view>
|
</view>
|
<view v-else class="goaccount rowCenCen" @tap="goaccount()">
|
<view>手机号登录/注册</view>
|
</view>
|
<view style="margin-top: 20px;" v-if="isother" @tap="goaccount()">
|
手机号登录/注册
|
</view>
|
|
</view>
|
|
<view class="bottom-fixed colCen">
|
<view class="explain-text rowCen">
|
<switch type="checkbox" @change="changeread" :checked='isread' style="transform:scale(0.6)" />
|
登陆代表已详细阅读并同意<text @click="goPage('agreement')">《用户协议》</text>和<text
|
@click="goPage('policy')">《隐私政策》</text>
|
</view>
|
</view>
|
</view>
|
</template>
|
|
<script>
|
import {
|
mapMutations
|
} from 'vuex';
|
import titleBar from '../../components/backTitlebar.vue'
|
const univerifyManager = uni.getUniverifyManager();
|
export default {
|
components: {
|
titleBar
|
},
|
data() {
|
return {
|
appInfo: '',
|
ifPasslogin: false,
|
isread: false,
|
haswxlogin: false,
|
isSupportMob:false,
|
isother:false,
|
supportWx:true
|
}
|
},
|
onLoad() {
|
this.appInfo = uni.getStorageSync('appInfo')
|
this.checkSupportWx();
|
this.isSupportMoblie();
|
},
|
methods: {
|
...mapMutations(['login']),
|
checkSupportWx()
|
{
|
// #ifdef APP-PLUS
|
if (plus.os.name == 'iOS') {
|
if (plus.runtime.isApplicationExist({
|
action: 'weixin://'
|
}) && plus.runtime.isApplicationExist({
|
action: 'taobao://'
|
})) {
|
this.supportWx = true //是否安装微信和淘宝 1代表安装
|
} else {
|
this.supportWx = false
|
}
|
} else {
|
if (plus.runtime.isApplicationExist({pname:'com.tencent.mm',
|
action: 'weixin://'
|
})) {
|
this.supportWx = true //是否安装微信 1代表安装
|
} else {
|
this.supportWx = false
|
}
|
}
|
// #endif
|
},
|
backHome() {
|
var pages = getCurrentPages();
|
console.log(pages.length);
|
if (pages.length == 1) {
|
uni.switchTab({
|
url: '../index/index'
|
})
|
} else {
|
uni.navigateBack({
|
delta: 1
|
})
|
}
|
},
|
isSupportMoblie()
|
{
|
var that=this;
|
uni.preLogin({
|
provider: 'univerify',
|
success(){ //预登录成功
|
// 显示一键登录选项
|
that.isSupportMob=true;
|
},
|
fail(res){ // 预登录失败
|
// 不显示一键登录选项(或置灰)
|
// 根据错误信息判断失败原因,如有需要可将错误提交给统计服务器
|
console.log(res)
|
}
|
})
|
},
|
doMobileLogin(mobRes)
|
{
|
var that=this;
|
uniCloud.callFunction({
|
name: 'getPhoneNumber', // 你的云函数名称
|
data: {
|
'access_token': mobRes.access_token, // 客户端一键登录接口返回的access_token
|
'openid': mobRes.openid // 客户端一键登录接口返回的openid
|
}
|
}).then(res => {
|
console.log(res)
|
that.targetToIndex(res.result.data);
|
// 登录成功,可以关闭一键登录授权界面了
|
univerifyManager.close();
|
}).catch(err=>{
|
// 处理错误
|
console.log(err)
|
that.isother=true;
|
that.$alert('获取手机号码失败,请使用其他方式登录')
|
setTimeout(function(){
|
univerifyManager.close();
|
},2000);
|
|
})
|
},
|
mobileLogin()
|
{
|
var that=this;
|
if (this.isread) {
|
univerifyManager.login({
|
provider: 'univerify',
|
univerifyStyle: { // 自定义登录框样式
|
"fullScreen":false,
|
"authButton":
|
{
|
"normalColor":"#F73314",
|
"highlightColor":"#F73314"
|
},
|
"privacyTerms":{
|
"defaultCheckBoxState":false
|
}
|
|
},
|
success(res){ // 登录成功
|
console.log(res.authResult);
|
that.doMobileLogin(res.authResult);
|
},
|
fail(res){ // 登录失败
|
console.log(res)
|
if(res.errCode==30002)
|
{//切换登录方式
|
that.isother=true;
|
univerifyManager.close();
|
}
|
else
|
{
|
that.$alert('获取手机号码失败,请使用其他方式登录')
|
setTimeout(function(){
|
univerifyManager.close();
|
},2000);
|
}
|
|
that.isother=true;
|
}
|
})
|
|
}
|
else
|
{
|
uni.showToast({
|
title: '请先阅读并同意《用户协议》和《隐私协议》',
|
icon: "none",
|
})
|
}
|
|
},
|
targetToIndex(e)
|
{
|
var that = this;
|
|
that.login(e.data.userinfo);
|
|
that.$alert('登录成功')
|
setTimeout(function(){
|
console.log(e.data.userinfo)
|
if(!e.data.userinfo.invitation_code)
|
{
|
uni.redirectTo({
|
url: './setInviteCode'
|
})
|
}
|
/* else if (e.data.userinfo.isPwd == 'N') {
|
uni.redirectTo({
|
url: './setPass'
|
})
|
} */ else {
|
uni.switchTab({
|
url: '../index/index'
|
})
|
}
|
},1000)
|
},
|
wxlogin() {
|
var that = this;
|
if (this.isread) {
|
uni.getProvider({
|
service: 'oauth',
|
success: othres => {
|
console.log(othres.provider)
|
if (~othres.provider.indexOf('weixin')) {
|
uni.login({
|
provider: 'weixin',
|
success: (loginRes) => {
|
that.$u.api.wxapplogin({
|
openid: loginRes.authResult.openid,
|
access_token: loginRes.authResult.access_token
|
}).then(e => {
|
if (e.code != 0) return that.$alert(e.msg)
|
var res = e.data;
|
if(res.type == 'goUser'){
|
this.targetToIndex(e);
|
}else if(res.type == 'bindMobile'){
|
uni.navigateTo({
|
url: "./bindingPhone?wx="+encodeURIComponent(JSON.stringify(res.info))
|
})
|
}
|
|
|
}).catch(function(err) {
|
console.log(err)
|
})
|
},
|
fail: err => {
|
console.log('111');
|
console.log(err);
|
uni.showToast({
|
title: '微信授权登录失败!',
|
icon: 'none'
|
})
|
}
|
})
|
}
|
}
|
})
|
} else {
|
uni.showToast({
|
title: '请先阅读并同意《用户协议》和《隐私协议》',
|
icon: "none",
|
})
|
}
|
},
|
|
changeread(e) {
|
console.log(e);
|
this.isread = e.target.value
|
},
|
|
goPage(type) {
|
uni.navigateTo({
|
url: './policyAgreement?type=' + type
|
})
|
},
|
|
goaccount() {
|
uni.navigateTo({
|
url: './login'
|
})
|
}
|
}
|
}
|
</script>
|
|
<style lang="scss">
|
.wxlogin-wrapper {
|
width: 100%;
|
min-height: 100vh;
|
background-color: #FFFFFF;
|
|
.pageContent {
|
width: 100%;
|
padding: 0 32rpx;
|
|
.applogo {
|
width: 168rpx;
|
height: 168rpx;
|
margin-top: 80rpx;
|
}
|
|
.wxlogoBtn {
|
width: 100%;
|
height: 100rpx;
|
background: #32BD00;
|
border-radius: 50rpx;
|
font-size: 30rpx;
|
font-weight: 500;
|
color: #FFFFFF;
|
margin-top: 140rpx;
|
|
.logoIcon {
|
width: 47rpx;
|
height: 39rpx;
|
margin-right: 20rpx;
|
}
|
}
|
|
.goaccount {
|
width: 100%;
|
height: 100rpx;
|
background: #FFFFFF;
|
border: 1rpx solid #999999;
|
border-radius: 50rpx;
|
font-size: 30rpx;
|
font-weight: 500;
|
color: #333333;
|
margin-top: 30rpx;
|
}
|
}
|
|
.bottom-fixed {
|
width: 100%;
|
position: fixed;
|
bottom: 100rpx;
|
bottom: calc(100rpx + constant(safe-area-inset-bottom));
|
bottom: env(100rpx + constant(safe-area-inset-bottom));
|
left: 0;
|
z-index: 1;
|
|
.verification-Code {
|
white-space: nowrap;
|
font-size: 28rpx;
|
font-weight: 500;
|
color: #333333;
|
}
|
|
.explain-text {
|
font-size: 22rpx;
|
font-weight: 500;
|
color: #999999;
|
margin-top: 30rpx;
|
white-space: nowrap;
|
}
|
}
|
}
|
</style>
|