feat: 调整优化登录的逻辑

This commit is contained in:
2025-09-15 22:52:44 +08:00
parent 66c256cefd
commit fc63bbc994
15 changed files with 190 additions and 159 deletions

View File

@@ -1,5 +1,12 @@
<template>
<view class="login-wrapper" :style="{ backgroundImage: `url(${loginBg})` }">
<!-- 返回按钮 -->
<view class="back-btn" @click="goBack">
<uni-icons fontFamily="znicons" size="24" color="#333">{{
zniconsMap["zn-nav-arrow-left"]
}}</uni-icons>
</view>
<!-- 头部内容 -->
<view class="login-header">
<!-- 卡通形象 -->
@@ -31,7 +38,7 @@
class="login-btn"
open-type="getPhoneNumber"
type="primary"
@getphonenumber="onLogin"
@getphonenumber="getPhoneNumber"
>
微信一键登录
</button>
@@ -66,15 +73,15 @@
<script setup>
import { ref, computed } from "vue";
import { loginAuth, bindPhone, checkPhone } from "@/manager/LoginManager";
import {
getServiceAgreement,
getPrivacyAgreement,
} from "@/request/api/LoginApi";
import { goHome } from "@/hooks/useGoHome";
import { onLogin, goBack } from "@/hooks/useGoLogin";
import loginBg from "./images/bg.png";
import CheckBox from "@/components/CheckBox/index.vue";
import AgreePopup from "./components/AgreePopup/index.vue";
import { zniconsMap } from "@/static/fonts/znicons.js";
const isAgree = ref(false);
const visible = ref(false);
@@ -94,30 +101,20 @@ const handleAgreeAndGetPhone = () => {
}
};
const onLogin = (e) => {
const { code } = e.detail;
console.info("onLogin code: ", code);
loginAuth()
.then(async () => {
// 检测是否绑定手机号,已绑定则直接跳转首页,未绑定则获取手机号并绑定
const res = await checkPhone();
if (res.data) {
return goHome();
}
const { data } = await bindPhone({
wechatPhoneCode: code,
clientId: "2",
const getPhoneNumber = (e) => {
onLogin(e)
.then(() => {
uni.showToast({
title: "登录成功",
icon: "success",
});
if (data) {
goHome();
}
goBack();
})
.catch((err) => {
console.error("登录失败", err);
.catch(() => {
uni.showToast({
title: "登录失败",
icon: "none",
});
});
};
@@ -155,4 +152,8 @@ getPrivacyAgreementData();
<style lang="scss" scoped>
@import "./styles/index.scss";
@font-face {
font-family: znicons;
src: url("@/static/fonts/znicons.ttf");
}
</style>