完善用户登录

This commit is contained in:
2025-04-23 11:32:01 +08:00
parent 95b7c69ddb
commit 2ce4777910
80 changed files with 3379 additions and 214 deletions

View File

@ -1,6 +1,6 @@
<template>
<view class="login">
<view class="u-font-xl bold-600 u-margin-top-56">获取你的昵称头像</view>
<view class="u-font-xl bold-600 u-padding-top-56">获取你的昵称头像</view>
<view>
<form @submit="doLogin">
@ -67,12 +67,6 @@
import { mapMutations, mapActions, mapGetters } from 'vuex'
import { uploadFile } from "@/utils/tools";
import {
accountLogin,
codeLogin,
sendSms,
wxpLogin,
smsCodeLogin,
opLogin,
authLogin,
updateUser
} from '@/api/app'
@ -88,9 +82,10 @@
avatar: '',
nickname: '',
isAgree: false
}
},
}
},
methods: {
...mapMutations(['LOGIN', 'LOGOUT']),
...mapActions(['getUser']),
@ -128,7 +123,7 @@
const {
userInfo: { avatarUrl, nickName, gender }
} = await getUserInfo()
console.log(await getUserInfo())
uni.showLoading({
title: '登录中',
mask: true
@ -138,7 +133,8 @@
const {code, data, msg} = await authLogin({
code: wxCode,
nickname: nickName || '', //支付宝小程序没有直接获取昵称
headimgurl: avatarUrl
headimgurl: avatarUrl,
client
})
if (code == 1) {
if (data.is_new_user) {

View File

@ -19,13 +19,51 @@
<u-button @click="mobileLogin" hover-class="none" :customStyle="{color: themeColor, border: '1px solid ' + themeColor, padding: '16rpx 0'}" :plain="true" :hair-line="false" shape="circle">手机号登录/注册</u-button>
</view>
</view>
<view class="u-margin-top-32 u-flex u-row-center">
<view>
<u-checkbox v-model="form.allow" shape="circle" :active-color="themeColor">
<view class="sm row-start">
已阅读并同意
</view>
</u-checkbox>
</view>
<view class="u-flex protocol">
<navigator :style="{color: themeColor}" hover-class="none" url="/pages/server_explan/server_explan?type=0">
服务协议
</navigator>
<navigator :style="{color: themeColor}" hover-class="none" url="/pages/server_explan/server_explan?type=1">
隐私政策
</navigator>
</view>
</view>
<mplogin-popup v-model="loginPopup" @close="loginPopup = false" @update="handleSubmitInfo"/>
</view>
</template>
<script>
import { mapMutations, mapActions, mapGetters } from 'vuex'
import { uploadFile } from "@/utils/tools";
import {
authLogin,
updateUser
} from '@/api/app'
import { getWxCode, getUserInfo } from '@/utils/login'
import { isWeixinClient, currentPage, client } from '@/utils/tools'
import Cache from '@/utils/cache'
import { BACK_URL } from '@/config/cachekey'
export default {
data() {
return {
form: {
allow: false
},
loginData: {},
loginPopup: false
}
},
@ -34,17 +72,90 @@
},
methods: {
fastLogin() {
uni.navigateTo({
url: '/pages/login/fastLogin'
...mapMutations(['LOGIN', 'LOGOUT']),
...mapActions(['getUser']),
// 小程序快捷登录
async fastLogin() {
if (!this.form.allow) {
this.$toast({
title: "请您先阅读并同意服务协议和隐私政策",
})
return false
}
const {
userInfo: { avatarUrl, nickName, gender }
} = await getUserInfo()
uni.showLoading({
title: '登录中',
mask: true
})
const wxCode = await getWxCode()
const {code, data, msg} = await authLogin({
code: wxCode,
nickname: nickName || '', //支付宝小程序没有直接获取昵称
headimgurl: avatarUrl,
client
})
if (code == 1) {
if (data.is_new_user) {
uni.hideLoading()
this.loginPopup = true
this.loginData = data
} else {
this.loginHandle(data)
}
} else {
this.$toast({title: msg})
}
},
// 更新新注册的用户信息
async handleSubmitInfo(e) {
const loginData = this.loginData || {}
const res = await updateUser(e, loginData.token)
if (res.code == 1) {
this.loginHandle(loginData)
}
},
// 登录结果处理
async loginHandle(data) {
this.LOGIN(data)
uni.hideLoading()
const inviteCode = Cache.get('INVITE_CODE')
if (inviteCode) {
inputInviteCode({
code: inviteCode
})
}
// #ifdef H5
location.replace('/mobile' + (Cache.get(BACK_URL) || '/'))
Cache.remove(BACK_URL)
//#endif
// #ifndef H5
uni.navigateBack({
success() {
// 刷新上一页
const { onLoad, options } = currentPage()
onLoad && onLoad(options)
}
})
//#endif
},
mobileLogin() {
uni.navigateTo({
url: '/pages/login/mobileLogin'
})
// uni.navigateTo({
// url: '/pages/login/mobileLogin'
// })
}
},
computed: {
...mapGetters(['appConfig']),
}
}
</script>
@ -58,7 +169,12 @@
margin: 0 64rpx;
.logo {
margin-top: 150rpx;
padding-top: 150rpx;
}
.protocol {
margin-top: -4rpx;
margin-left: -20rpx;
}
}
</style>

View File

@ -111,7 +111,7 @@
.title {
font-size: 56rpx;
margin-top: 190rpx;
padding-top: 190rpx;
}
.mobile {