注册登录支持登录不同账户
This commit is contained in:
parent
a038784d1d
commit
7ce564b1e8
|
|
@ -136,6 +136,28 @@ export default {
|
|||
uni.setStorageSync('userProfile', userInfo);
|
||||
return true;
|
||||
},
|
||||
async getWxUserInfo() {
|
||||
// 获取微信登录凭证
|
||||
const wxLoginRes = await wx.login();
|
||||
// 获取openid
|
||||
const wxAuthRes = await uni.request({
|
||||
url: '/wx/auth',
|
||||
header: {
|
||||
code: wxLoginRes.code
|
||||
}
|
||||
})
|
||||
const openId = wxAuthRes[1].data.data.openid;
|
||||
// 从服务端获取用户信息
|
||||
let wxGetUserRes = await this.qryUserInfo(openId);
|
||||
let userInfo = null;
|
||||
if (wxGetUserRes.data) {
|
||||
userInfo = {
|
||||
...wxGetUserRes.data,
|
||||
wxLoginCode: wxLoginRes.code
|
||||
}
|
||||
}
|
||||
return userInfo;
|
||||
},
|
||||
async storageExistUser() {
|
||||
// 获取微信登录凭证
|
||||
const wxLoginRes = await wx.login();
|
||||
|
|
@ -191,12 +213,13 @@ export default {
|
|||
})
|
||||
return res[1].data;
|
||||
},
|
||||
async qryUserInfo(openId) {
|
||||
async qryUserInfo(openId, phone) {
|
||||
let res = await uni.request({
|
||||
url: '/wx/getWorkerInfo',
|
||||
method: 'POST',
|
||||
data: {
|
||||
openId: openId
|
||||
openId: openId,
|
||||
phone: phone
|
||||
}
|
||||
})
|
||||
return res[1].data;
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@
|
|||
},
|
||||
async login() {
|
||||
// 更新缓存中的userInfo
|
||||
await this.$request.storageExistUser();
|
||||
// await this.$request.storageExistUser();
|
||||
// 返回缓存中的userInfo
|
||||
return this.$request.getCurUserInfo();
|
||||
},
|
||||
|
|
|
|||
|
|
@ -169,20 +169,27 @@
|
|||
methods: {
|
||||
async authLogin() {
|
||||
// 更新缓存中的userInfo
|
||||
let res = await this.$request.storageExistUser();
|
||||
// let res = await this.$request.storageExistUser();
|
||||
// 获取缓存中的userInfo
|
||||
let curUserInfo = this.$request.getCurUserInfo();
|
||||
console.log(curUserInfo)
|
||||
// 校验提示登录
|
||||
if (!curUserInfo || !curUserInfo.openId) {
|
||||
this.$refs.vertifyLogin.showModal();
|
||||
// if (!curUserInfo || !curUserInfo.openId) {
|
||||
// this.$refs.vertifyLogin.showModal();
|
||||
// return false;
|
||||
// } else {
|
||||
// this.$refs.vertifyLogin.hideModal();
|
||||
// }
|
||||
if (!curUserInfo) {
|
||||
uni.reLaunch({
|
||||
url: '/pages/login/login'
|
||||
})
|
||||
return false;
|
||||
} else {
|
||||
this.$refs.vertifyLogin.hideModal();
|
||||
}
|
||||
// 校验是否注册过
|
||||
if (!curUserInfo.phone) {
|
||||
uni.reLaunch({
|
||||
url: '/pages/login/login?operType=1'
|
||||
url: '/pages/login/login'
|
||||
})
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,20 +79,27 @@
|
|||
},
|
||||
async authLogin() {
|
||||
// 更新缓存中的userInfo
|
||||
let res = await this.$request.storageExistUser();
|
||||
// let res = await this.$request.storageExistUser();
|
||||
// 获取缓存中的userInfo
|
||||
let curUserInfo = this.$request.getCurUserInfo();
|
||||
console.log(curUserInfo)
|
||||
// 校验提示登录
|
||||
if (!curUserInfo || !curUserInfo.openId) {
|
||||
this.$refs.vertifyLogin.showModal();
|
||||
// if (!curUserInfo || !curUserInfo.openId) {
|
||||
// this.$refs.vertifyLogin.showModal();
|
||||
// return false;
|
||||
// } else {
|
||||
// this.$refs.vertifyLogin.hideModal();
|
||||
// }
|
||||
if (!curUserInfo) {
|
||||
uni.reLaunch({
|
||||
url: '/pages/login/login'
|
||||
})
|
||||
return false;
|
||||
} else {
|
||||
this.$refs.vertifyLogin.hideModal();
|
||||
}
|
||||
// 校验是否注册过
|
||||
if (!curUserInfo.phone) {
|
||||
uni.reLaunch({
|
||||
url: '/pages/login/login?operType=1'
|
||||
url: '/pages/login/login'
|
||||
})
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +1,26 @@
|
|||
<template>
|
||||
<view class="bg-blue light" style="height: 100vh; width: 100%;">
|
||||
<view class="bg-blue light login-top-bg text-center">
|
||||
<view class="cu-avatar round login-avatar"
|
||||
:style="'background-image:url(' + curUserInfo.workerLogoUrl + ');'">
|
||||
</view>
|
||||
</view>
|
||||
<view>
|
||||
<image class="bg-img-container" src="http://gqz.opsoul.com/sys/login-bg-business.jpg" mode="aspectFill"></image>
|
||||
<view class="bg-white login-container padding-lr-lg padding-tb-xl">
|
||||
<view v-if="operType === 0">
|
||||
<!-- 登录内容 -->
|
||||
<view class="margin-tb-xl">
|
||||
<view class="cu-form-group">
|
||||
<view class="text-xxl margin-right"><text class="cuIcon-people"></text></view>
|
||||
<input class="radius-input" type="number" name="phone" v-model="formData.phone" placeholder="请输入帐号(手机号)"></input>
|
||||
<input class="radius-input" type="number" name="phone" v-model="formData.phone"
|
||||
placeholder="请输入帐号(手机号)"></input>
|
||||
</view>
|
||||
<view class="cu-form-group margin-top-lg">
|
||||
<view class="text-xxl margin-right"><text class="cuIcon-unlock"></text></view>
|
||||
<input class="radius-input" password name="password" v-model="formData.password" placeholder="请输入密码"></input>
|
||||
<input class="radius-input" password name="password" v-model="formData.password"
|
||||
placeholder="请输入密码"></input>
|
||||
</view>
|
||||
</view>
|
||||
<view>
|
||||
<view class="cu-btn bg-blue radius long-btn shadow-blur main-btn text-lg" @click="loginByPwd">登录</view>
|
||||
<view class="cu-btn bg-blue light radius long-btn shadow-blur main-btn margin-top text-lg" @click="changeOperType">前往注册</view>
|
||||
<view class="margin-bottom-xl">
|
||||
<view class="cu-btn bg-blue radius long-btn shadow-blur main-btn text-lg" @click="loginByPwd">登录
|
||||
</view>
|
||||
<view class="cu-btn bg-blue light radius long-btn shadow-blur main-btn margin-top text-lg"
|
||||
@click="changeOperType">前往注册</view>
|
||||
</view>
|
||||
<!-- <view class="margin-top-xl text-center text-lg">
|
||||
<text class="text-grey">手机验证码登录</text>
|
||||
|
|
@ -37,20 +37,27 @@
|
|||
</view>
|
||||
<view class="cu-form-group margin-top">
|
||||
<view class="title">手机号码</view>
|
||||
<input class="radius-input" type="number" name="phone" v-model="formData.phone" placeholder="请输入号码(作为登录帐号)"></input>
|
||||
<input class="radius-input" type="number" name="phone" v-model="formData.phone"
|
||||
placeholder="请输入号码(作为登录帐号)"></input>
|
||||
</view>
|
||||
<view class="cu-form-group margin-top">
|
||||
<view class="title">设置密码</view>
|
||||
<input class="radius-input" password name="password" v-model="formData.password" placeholder="请设置至少6位数的登录密码"></input>
|
||||
<input class="radius-input" password name="password" v-model="formData.password"
|
||||
placeholder="请设置至少6位数的登录密码"></input>
|
||||
</view>
|
||||
<view class="cu-form-group margin-top">
|
||||
<view class="title">确认密码</view>
|
||||
<input class="radius-input" password name="passwordAgain" v-model="formData.passwordAgain" placeholder="请再次输入密码"></input>
|
||||
<input class="radius-input" password name="passwordAgain" v-model="formData.passwordAgain"
|
||||
placeholder="请再次输入密码"></input>
|
||||
</view>
|
||||
<view class="cu-form-group margin-top">
|
||||
<view class="title">验证码</view>
|
||||
<input class="radius-input" type="number" name="registerCode" v-model="formData.registerCode" placeholder="请输入验证码"></input>
|
||||
<view class="cu-btn bg-blue round-btn margin-left-sm shadow-blur" @click="sendVertifyCode">发送验证码</view>
|
||||
<input class="radius-input" type="number" name="registerCode" v-model="formData.registerCode"
|
||||
placeholder="请输入验证码"></input>
|
||||
<view v-if="countDownNum === 0" class="cu-btn bg-blue round-btn margin-left-xs shadow-blur" @click="sendVertifyCode">发送验证码
|
||||
</view>
|
||||
<view v-else class="cu-btn bg-gray round-btn margin-left-sm shadow-blur">已发送({{countDownNum}})
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="margin-bottom-sm text-lg flex justify-center align-center">
|
||||
|
|
@ -62,9 +69,11 @@
|
|||
<text class="text-main-color underline-text">用户注册协议</text>
|
||||
</text>
|
||||
</view>
|
||||
<view>
|
||||
<view class="cu-btn bg-blue radius long-btn shadow-blur main-btn text-lg" @click="registerByPhone">立即注册</view>
|
||||
<view class="cu-btn bg-blue light radius long-btn shadow-blur main-btn margin-top text-lg" @click="changeOperType">已有账户,前往登录</view>
|
||||
<view class="margin-bottom-xl">
|
||||
<view class="cu-btn bg-blue radius long-btn shadow-blur main-btn text-lg" @click="registerByPhone">
|
||||
立即注册</view>
|
||||
<view class="cu-btn bg-blue light radius long-btn shadow-blur main-btn margin-top text-lg"
|
||||
@click="changeOperType">已有账户,前往登录</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
|
@ -80,6 +89,7 @@
|
|||
return {
|
||||
pageContentTop: this.CustomBar,
|
||||
operType: 0, // 0为登录,1为注册
|
||||
countDownNum: 0,
|
||||
agreeContract: false,
|
||||
formData: {}
|
||||
}
|
||||
|
|
@ -105,10 +115,8 @@
|
|||
this.agreeContract = false;
|
||||
},
|
||||
async authLogin() {
|
||||
// 更新缓存中的userInfo
|
||||
let res = await this.$request.storageExistUser();
|
||||
// 获取缓存中的userInfo
|
||||
let curUserInfo = this.$request.getCurUserInfo();
|
||||
// 获取微信用户信息
|
||||
let curUserInfo = await this.$request.getWxUserInfo();
|
||||
// 校验提示登录
|
||||
if (!curUserInfo || !curUserInfo.openId) {
|
||||
this.$refs.vertifyLogin.showModal();
|
||||
|
|
@ -143,6 +151,8 @@
|
|||
|
||||
let res = await this.$request.appLogin(this.formData);
|
||||
if (res && res.code === 0) {
|
||||
let cacheRes = await this.$request.qryUserInfo(null, this.formData.phone);
|
||||
uni.setStorageSync('userProfile', cacheRes.data);
|
||||
uni.showToast({
|
||||
icon: 'none',
|
||||
title: '登录成功'
|
||||
|
|
@ -162,6 +172,15 @@
|
|||
})
|
||||
}
|
||||
},
|
||||
startCountDownNum() {
|
||||
this.countDownNum = 180;
|
||||
let t = setInterval(() => {
|
||||
this.countDownNum -= 1;
|
||||
if (this.countDownNum === 0) {
|
||||
clearInterval(t);
|
||||
}
|
||||
}, 1000);
|
||||
},
|
||||
async sendVertifyCode() {
|
||||
if (this.$validate.validContactNum(this.formData.phone)) {
|
||||
let res = await this.$request.sendVertifyCode({
|
||||
|
|
@ -172,6 +191,7 @@
|
|||
icon: 'none',
|
||||
title: '验证码已发送'
|
||||
})
|
||||
this.startCountDownNum();
|
||||
} else if (res && res.msg) {
|
||||
uni.showToast({
|
||||
icon: 'none',
|
||||
|
|
@ -256,15 +276,12 @@
|
|||
|
||||
<style scoped>
|
||||
.login-container {
|
||||
border-radius: 80rpx 80rpx 0 0;
|
||||
min-height: 70vh;
|
||||
width: 100vw;
|
||||
border-radius: 80rpx;
|
||||
/* min-height: 44vh; */
|
||||
width: 92vw;
|
||||
margin: 0 auto;
|
||||
filter: drop-shadow(1px 2px 8px hsl(220deg 60% 50%));
|
||||
}
|
||||
|
||||
.login-top-bg {
|
||||
height: 30vh;
|
||||
filter: drop-shadow(1px 2px 8px hsl(220deg 38% 50%));
|
||||
margin-top: 20vh;
|
||||
}
|
||||
|
||||
.login-avatar {
|
||||
|
|
@ -296,4 +313,20 @@
|
|||
.underline-text {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.bg-img-container {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
width: 100vw;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.cu-form-group .title {
|
||||
text-align: justify;
|
||||
padding-right: 15rpx;
|
||||
font-size: 30rpx;
|
||||
position: relative;
|
||||
height: 60rpx;
|
||||
line-height: 60rpx;
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
Loading…
Reference in New Issue