移动端-首页和我的

This commit is contained in:
yml
2026-05-22 19:51:05 +08:00
parent a7011668ff
commit 5f1a7f46a8
6 changed files with 442 additions and 17 deletions
@@ -0,0 +1,281 @@
<script setup lang="ts">
import { computed, reactive, ref } from "vue";
import { useRouter } from "vue-router";
import { sendSmsCode } from "@/api/auth";
import { useSessionStore } from "@/stores/session";
const router = useRouter();
const session = useSessionStore();
const loading = ref(false);
const sending = ref(false);
const agreed = ref(false);
const form = reactive({
phone: "",
code: "",
});
const maskedPhone = computed(() =>
form.phone.length >= 7
? `${form.phone.slice(0, 3)}****${form.phone.slice(-4)}`
: "手机号"
);
async function handleSendCode() {
sending.value = true;
try {
await sendSmsCode(form.phone);
window.alert("验证码已发送,开发环境请查看后端日志");
} catch {
window.alert("验证码发送失败,请稍后重试");
} finally {
sending.value = false;
}
}
async function handleLogin() {
if (!agreed.value) {
window.alert("请先阅读并同意用户协议和隐私政策");
return;
}
loading.value = true;
try {
await session.login(form.phone, form.code);
await router.push("/m/profile");
} catch {
window.alert("登录失败,请检查手机号和验证码");
} finally {
loading.value = false;
}
}
</script>
<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>
</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>
<button class="primary-login" type="button" :disabled="loading" @click="handleLogin">
{{ loading ? "登录中..." : "登录" }}
</button>
<button class="sms-login" type="button" @click="handleSendCode">
使用手机验证码登录
</button>
</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;
}
.login-brand-card {
display: grid;
place-items: center;
margin-bottom: 42px;
text-align: center;
}
.monster-logo {
display: grid;
width: 72px;
height: 72px;
place-items: center;
border-radius: 22px;
background: linear-gradient(145deg, #1777ff, #5fd4ff);
color: #ffffff;
font-size: 28px;
font-weight: 900;
box-shadow: 0 14px 36px rgba(23, 119, 255, 0.24);
}
.login-brand-card p {
margin: 12px 0 2px;
font-size: 24px;
font-weight: 900;
}
.login-brand-card small,
.login-subtitle {
color: #667386;
}
.login-panel {
border-radius: 22px;
}
.login-eyebrow {
margin: 0 0 8px;
color: #02846e;
font-size: 13px;
font-weight: 900;
letter-spacing: 0.04em;
}
.login-panel h1 {
margin: 0;
font-size: 30px;
line-height: 1.2;
}
.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;
font-size: 13px;
font-weight: 700;
}
.field-card input {
width: 100%;
box-sizing: border-box;
border: 0;
outline: 0;
background: #eaf2ff;
color: #151c28;
padding: 11px 12px;
font-size: 16px;
}
.code-line {
display: grid;
grid-template-columns: 1fr 86px;
gap: 8px;
}
.code-line button,
.sms-login,
.primary-login,
.login-links button {
border: 0;
background: none;
font-weight: 800;
}
.code-line button {
border-radius: 8px;
background: #ffffff;
color: #3f4652;
box-shadow: inset 0 0 0 1px #d6dce6;
}
.login-links,
.agreement-row {
display: flex;
align-items: center;
}
.login-links {
justify-content: space-between;
margin: 18px 0 26px;
color: #566274;
font-size: 13px;
}
.login-links button {
color: #08b86f;
}
.agreement-row {
gap: 10px;
color: #333b48;
font-size: 13px;
line-height: 1.5;
}
.agreement-row input {
width: 16px;
height: 16px;
}
.agreement-row b {
color: #e63145;
font-weight: 500;
}
.primary-login,
.sms-login {
width: 100%;
height: 52px;
margin-top: 22px;
border-radius: 11px;
font-size: 16px;
}
.primary-login {
background: #050505;
color: #ffffff;
}
.primary-login:disabled {
opacity: 0.7;
}
.sms-login {
background: #ffffff;
color: #151c28;
box-shadow: inset 0 0 0 1px #e1e6ee;
}
@media (min-width: 520px) {
.mobile-login-shell {
max-width: 430px;
margin: 0 auto;
box-shadow: 0 0 0 1px rgba(23, 35, 61, 0.08);
}
}
</style>