登陆注册界面优化了

This commit is contained in:
yml
2026-05-22 20:38:52 +08:00
parent 5f1a7f46a8
commit aa9410b990
9 changed files with 1864 additions and 379 deletions
+327 -159
View File
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { computed, reactive, ref } from "vue";
import { useRouter } from "vue-router";
import { onUnmounted, reactive, ref } from "vue";
import { RouterLink, useRouter } from "vue-router";
import { showToast, showDialog } from "vant";
import { sendSmsCode } from "@/api/auth";
import { useSessionStore } from "@/stores/session";
@@ -15,27 +16,61 @@ const form = reactive({
code: "",
});
const maskedPhone = computed(() =>
form.phone.length >= 7
? `${form.phone.slice(0, 3)}****${form.phone.slice(-4)}`
: "手机号"
);
const countDown = ref(0);
let timer: ReturnType<typeof setInterval> | null = null;
function startCountDown() {
countDown.value = 60;
timer = setInterval(() => {
countDown.value--;
if (countDown.value <= 0) {
clearInterval(timer!);
timer = null;
}
}, 1000);
}
onUnmounted(() => {
if (timer) {
clearInterval(timer);
timer = null;
}
});
/* --------- 业务方法 --------- */
async function handleSendCode() {
if (!form.phone.trim()) {
showToast("请输入手机号");
return;
}
sending.value = true;
try {
await sendSmsCode(form.phone);
window.alert("验证码已发送,开发环境请查看后端日志");
} catch {
window.alert("验证码发送失败,请稍后重试");
showToast("验证码已发送,开发环境请查看后端日志");
startCountDown();
} catch (error) {
showToast(readError(error, "验证码发送失败,请稍后重试"));
} finally {
sending.value = false;
}
}
function readError(error: unknown, fallback: string) {
if (typeof error === "object" && error && "response" in error) {
const response = (error as { response?: { data?: { message?: string } } })
.response;
return response?.data?.message || fallback;
}
return fallback;
}
async function handleLogin() {
if (!agreed.value) {
window.alert("请先阅读并同意用户协议和隐私政策");
showDialog({
title: "提示",
message: "请先阅读并同意用户协议和隐私政策",
});
return;
}
@@ -44,7 +79,7 @@ async function handleLogin() {
await session.login(form.phone, form.code);
await router.push("/m/profile");
} catch {
window.alert("登录失败,请检查手机号和验证码");
showToast("登录失败,请检查手机号和验证码");
} finally {
loading.value = false;
}
@@ -53,222 +88,355 @@ async function handleLogin() {
<template>
<main class="mobile-login-shell">
<section class="login-brand-card">
<div class="monster-logo"></div>
<p>大锤商行</p>
<small>平台担保 · 安全租号</small>
</section>
<section class="login-panel">
<p class="login-eyebrow">SMS LOGIN</p>
<h1>登录</h1>
<p class="login-subtitle">使用手机号验证码登录当前开发环境验证码会打印在后端日志</p>
<label class="field-card">
<span>手机号</span>
<input v-model="form.phone" maxlength="11" inputmode="tel" placeholder="请输入手机号" />
</label>
<label class="field-card">
<span>验证码</span>
<div class="code-line">
<input v-model="form.code" maxlength="6" inputmode="numeric" placeholder="6 位验证码" />
<button type="button" :disabled="sending" @click="handleSendCode">
{{ sending ? "发送中" : "发送" }}
</button>
<section class="login-card">
<!-- 品牌区域 -->
<div class="login-top">
<div class="monster-logo"></div>
<div>
<p>大锤商行</p>
<small>平台担保 · 安全租号</small>
</div>
</label>
<div class="login-links">
<button type="button">忘记密码</button>
<span>当前输入{{ maskedPhone }}</span>
</div>
<label class="agreement-row">
<input v-model="agreed" type="checkbox" />
<span>我已阅读并同意 <b>用户协议</b> <b>隐私政策</b></span>
</label>
<!-- 登录/注册 Tab 切换 -->
<div class="auth-switch" aria-label="登录注册切换">
<RouterLink to="/m/login" class="active">登录</RouterLink>
<RouterLink to="/m/register">注册</RouterLink>
</div>
<button class="primary-login" type="button" :disabled="loading" @click="handleLogin">
{{ loading ? "登录中..." : "登录" }}
</button>
<p class="login-eyebrow">SMS LOGIN</p>
<h1>手机号登录</h1>
<p class="login-subtitle">验证码登录开发环境验证码查看后端日志</p>
<button class="sms-login" type="button" @click="handleSendCode">
使用手机验证码登录
</button>
<!-- 手机号输入 -->
<van-field
v-model="form.phone"
type="tel"
maxlength="11"
placeholder="请输入手机号"
clearable
class="login-field"
>
<template #left-icon>
<span class="field-prefix">+86</span>
</template>
</van-field>
<!-- 验证码输入 -->
<van-field
v-model="form.code"
type="digit"
maxlength="6"
placeholder="6 位验证码"
class="login-field"
:left-icon="'shield-o'"
>
<template #button>
<van-button
size="small"
type="primary"
plain
round
:disabled="sending || countDown > 0"
:loading="sending"
@click="handleSendCode"
>
{{
countDown > 0
? `${countDown}s`
: sending
? "发送中"
: "发送验证码"
}}
</van-button>
</template>
</van-field>
<!-- 底部链接行 -->
<div class="login-links">
<van-button size="mini" plain type="primary">忘记密码</van-button>
</div>
<!-- 用户协议 -->
<div class="agreement-row">
<van-checkbox v-model="agreed" shape="square" icon-size="16px">
我已阅读并同意<b>用户协议</b><b>隐私政策</b>
</van-checkbox>
</div>
<!-- 登录按钮 -->
<van-button
type="primary"
block
round
class="login-button"
:loading="loading"
loading-text="登录中..."
@click="handleLogin"
>
登录
</van-button>
<!-- 底部注册入口 -->
<RouterLink
to="/m/register"
class="register-entry"
custom
v-slot="{ navigate }"
>
<van-button
plain
type="primary"
block
round
size="small"
class="register-button"
@click="navigate"
>
没有账号立即注册
</van-button>
</RouterLink>
</section>
</main>
</template>
<style scoped>
.mobile-login-shell {
min-height: 100vh;
background: radial-gradient(circle at 50% 0, #f0fffb 0, #f7fbff 34%, #ffffff 78%);
color: #151c28;
padding: 48px 26px 32px;
/* ========== Vant 主题变量覆盖 ========== */
:root {
--van-primary-color: #1777ff;
--van-primary-color-light: #5fd4ff;
--van-button-primary-background: linear-gradient(135deg, #1777ff, #5fd4ff);
--van-button-primary-border-color: transparent;
}
.login-brand-card {
display: grid;
place-items: center;
margin-bottom: 42px;
text-align: center;
/* ========== 页面容器 ========== */
.mobile-login-shell {
min-height: 100dvh;
box-sizing: border-box;
overflow: hidden;
background: radial-gradient(
circle at 50% 0,
#eafff9 0,
#f7fbff 38%,
#ffffff 86%
);
color: #151c28;
padding: 40px 24px;
}
.login-card {
display: flex;
min-height: calc(100dvh - 80px);
flex-direction: column;
justify-content: center;
}
/* ========== 品牌区域 ========== */
.login-top {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 14px;
}
.monster-logo {
display: grid;
width: 72px;
height: 72px;
width: 48px;
height: 48px;
flex: 0 0 auto;
place-items: center;
border-radius: 22px;
border-radius: 16px;
background: linear-gradient(145deg, #1777ff, #5fd4ff);
color: #ffffff;
font-size: 28px;
font-size: 21px;
font-weight: 900;
box-shadow: 0 14px 36px rgba(23, 119, 255, 0.24);
box-shadow: 0 10px 22px rgba(23, 119, 255, 0.2);
}
.login-brand-card p {
margin: 12px 0 2px;
font-size: 24px;
.login-top p {
margin: 0 0 2px;
font-size: 20px;
font-weight: 900;
}
.login-brand-card small,
.login-top small,
.login-subtitle {
color: #667386;
}
.login-panel {
border-radius: 22px;
/* ========== Tab 切换 ========== */
.auth-switch {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 8px;
margin-bottom: 16px;
border-radius: 15px;
background: #eef4fb;
padding: 5px;
}
.auth-switch a {
border-radius: 11px;
color: #667386;
padding: 10px 0;
text-align: center;
font-size: 14px;
font-weight: 900;
text-decoration: none;
}
.auth-switch a.active {
background: #ffffff;
color: #111827;
box-shadow: 0 8px 18px rgba(23, 35, 61, 0.08);
}
/* ========== 标题区 ========== */
.login-eyebrow {
margin: 0 0 8px;
margin: 0 0 5px;
color: #02846e;
font-size: 13px;
font-size: 12px;
font-weight: 900;
letter-spacing: 0.04em;
}
.login-panel h1 {
.login-card h1 {
margin: 0;
font-size: 30px;
line-height: 1.2;
font-size: 28px;
line-height: 1.15;
}
.login-subtitle {
margin: 12px 0 28px;
font-size: 14px;
line-height: 1.7;
}
.field-card {
display: block;
margin-top: 14px;
border: 1px solid #e1e6ee;
border-radius: 13px;
background: rgba(255, 255, 255, 0.88);
padding: 14px;
}
.field-card span {
display: block;
margin-bottom: 10px;
color: #5d6674;
margin: 7px 0 14px;
font-size: 13px;
font-weight: 700;
line-height: 1.45;
}
.field-card input {
width: 100%;
box-sizing: border-box;
border: 0;
outline: 0;
background: #eaf2ff;
/* ========== Vant Field 覆盖样式 ========== */
.login-field {
margin-top: 12px;
border-radius: 12px;
background: rgba(255, 255, 255, 0.92);
box-shadow: inset 0 1px 3px rgba(23, 35, 61, 0.04);
overflow: hidden;
}
.login-field :deep(.van-field__control) {
font-size: 15px;
color: #151c28;
padding: 11px 12px;
font-size: 16px;
}
.code-line {
display: grid;
grid-template-columns: 1fr 86px;
gap: 8px;
.login-field :deep(.van-field__label) {
width: auto;
margin-right: 8px;
color: #333b48;
font-weight: 700;
font-size: 13px;
}
.login-field :deep(.van-field__left-icon) {
color: #1777ff;
margin-right: 0;
}
.code-line button,
.sms-login,
.primary-login,
.login-links button {
border: 0;
background: none;
.login-field :deep(.van-field__right-icon) {
color: #999;
}
.field-prefix {
color: #1777ff;
font-weight: 800;
font-size: 14px;
margin-right: 4px;
}
.code-line button {
border-radius: 8px;
background: #ffffff;
color: #3f4652;
box-shadow: inset 0 0 0 1px #d6dce6;
/* ========== 底部链接行 ========== */
.login-links {
display: flex;
align-items: center;
justify-content: space-between;
margin: 10px 0 12px;
color: #566274;
font-size: 12px;
}
.login-links,
/* ========== 协议行 ========== */
.agreement-row {
display: flex;
align-items: center;
margin-bottom: 16px;
}
.login-links {
justify-content: space-between;
margin: 18px 0 26px;
color: #566274;
font-size: 13px;
}
.login-links button {
color: #08b86f;
}
.agreement-row {
gap: 10px;
.agreement-row :deep(.van-checkbox__label) {
margin-left: 6px;
color: #333b48;
font-size: 12px;
line-height: 1.4;
}
.agreement-row :deep(.van-checkbox__label b) {
color: #1777ff;
font-weight: 600;
}
/* ========== 登录按钮 ========== */
.login-button {
margin-top: 6px;
height: 46px;
font-size: 15px;
font-weight: 800;
background: linear-gradient(135deg, #1777ff, #5fd4ff) !important;
border: none !important;
box-shadow: 0 8px 20px rgba(23, 119, 255, 0.25);
}
/* ========== 注册入口按钮 ========== */
.register-button {
margin-top: 12px;
font-size: 13px;
line-height: 1.5;
font-weight: 800;
}
.agreement-row input {
width: 16px;
height: 16px;
.register-entry {
text-decoration: none;
}
.agreement-row b {
color: #e63145;
font-weight: 500;
}
/* ========== 响应式 ========== */
@media (max-height: 620px) {
.mobile-login-shell {
padding-top: 10px;
padding-bottom: 10px;
}
.primary-login,
.sms-login {
width: 100%;
height: 52px;
margin-top: 22px;
border-radius: 11px;
font-size: 16px;
}
.login-card {
min-height: calc(100dvh - 20px);
}
.primary-login {
background: #050505;
color: #ffffff;
}
.login-top {
margin-bottom: 10px;
}
.primary-login:disabled {
opacity: 0.7;
}
.monster-logo {
width: 42px;
height: 42px;
border-radius: 14px;
}
.sms-login {
background: #ffffff;
color: #151c28;
box-shadow: inset 0 0 0 1px #e1e6ee;
.auth-switch {
margin-bottom: 11px;
}
.login-card h1 {
font-size: 24px;
}
.login-field {
margin-top: 8px;
}
.login-button {
height: 42px;
margin-top: 10px;
}
}
@media (min-width: 520px) {