Files
cz-web/src/views/login/index.vue
2026-09-30 15:55:36 +08:00

248 lines
6.1 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import { ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { useUserStore } from '@/stores/modules/user'
import { isPhone } from '@/utils/validate'
import LoginForm from './cpns/LoginForm.vue'
import SmsLoginForm from './cpns/SmsLoginForm.vue'
type LoginTab = 'account' | 'sms'
const route = useRoute()
const router = useRouter()
const userStore = useUserStore()
const activeTab = ref<LoginTab>('account')
// 演示/联调默认账号:登录页打开即自动预填,可直接点登录(生产环境请清空)
const account = ref('admin')
const password = ref('admin123')
const phone = ref('')
const code = ref('')
const agree = ref(false)
function goAfterLogin(): void {
void router.push(String(route.query.redirect ?? '/'))
}
async function onAccountSubmit(): Promise<void> {
if (!account.value.trim() || !password.value) {
ElMessage.warning('请输入账号和密码')
return
}
if (!agree.value) {
ElMessage.warning('请先阅读并同意《用户协议》和《隐私政策》')
return
}
const ok = await userStore.loginByAccount({ account: account.value.trim(), password: password.value })
if (ok) goAfterLogin()
}
async function onSmsSubmit(): Promise<void> {
if (!isPhone(phone.value)) {
ElMessage.warning('手机号格式不正确')
return
}
if (!code.value) {
ElMessage.warning('请输入验证码')
return
}
if (!agree.value) {
ElMessage.warning('请先阅读并同意《用户协议》和《隐私政策》')
return
}
const ok = await userStore.loginBySms({ phone: phone.value, code: code.value })
if (ok) goAfterLogin()
}
async function onGetCode(target: string): Promise<void> {
if (!isPhone(target)) {
ElMessage.warning('手机号格式不正确')
return
}
try {
await userStore.sendSmsCode(target)
}
catch {
// 失败提示已由 store 统一弹出,此处仅避免未处理的 rejection
}
}
</script>
<template>
<div class="auth-page">
<aside class="auth-page__brand">
<div class="auth-page__brand-inner">
<p class="auth-page__logo">
虫子智造研发一体化平台
</p>
<p class="auth-page__slogan">
安全 · 高效 · 可控
</p>
<RouterLink class="auth-page__guest" to="/">
游客模式 →
</RouterLink>
</div>
</aside>
<main class="auth-page__main">
<div class="auth-page__card">
<div class="auth-page__tabs">
<!-- 设计稿 Tab 顺序:手机验证码登录在前、账号密码登录在后 -->
<button
class="auth-page__tab"
:class="{ 'is-active': activeTab === 'sms' }"
@click="activeTab = 'sms'"
>
手机验证码登录
</button>
<button
class="auth-page__tab"
:class="{ 'is-active': activeTab === 'account' }"
@click="activeTab = 'account'"
>
账号密码登录
</button>
</div>
<LoginForm
v-if="activeTab === 'account'"
v-model:account="account"
v-model:password="password"
v-model:agree="agree"
@submit="onAccountSubmit"
/>
<SmsLoginForm
v-else
v-model:phone="phone"
v-model:code="code"
v-model:agree="agree"
@get-code="onGetCode"
@submit="onSmsSubmit"
/>
<p class="auth-page__switch">
没有账号?<RouterLink class="auth-page__link" to="/register">立即注册</RouterLink>
</p>
</div>
</main>
</div>
</template>
<style lang="less" scoped>
.auth-page {
position: relative;
display: flex;
min-height: 100vh;
// 设计稿:右侧表单区为纯白底,无卡片描边/阴影
background: @white;
&__brand {
// 设计稿:左侧品牌渐变面板约占 786/1920 ≈ 41%
flex: 0 0 41%;
.flex(row, flex-start, stretch);
background: linear-gradient(135deg, @auth-gradient-from 0%, @auth-gradient-to 100%);
color: @white;
}
&__brand-inner {
.flex(column, space-between, flex-start);
width: 100%;
// 设计稿:文字列起点 x=257 ≈ 面板宽 32.7%;主标距顶 ≈ 28%、标语底边距底 ≈ 30%
padding: 26vh 48px 30vh 32%;
}
&__logo {
font-size: 31px;
font-weight: 700;
letter-spacing: 2px;
line-height: 1.45;
// 设计稿文本框 432 设计px:定宽让 11 字在「虫子智造研发 / 一体化平台」处折行
max-width: 200px;
}
&__slogan {
font-size: 17px;
font-weight: 600;
letter-spacing: 8px;
}
// 设计稿:「游客模式」为右上角白底上的深色纯文本,无边框
&__guest {
position: absolute;
top: 18px;
right: 16px;
margin: 0;
padding: 0;
border: none;
border-radius: 0;
color: @heading-color;
font-size: 11px;
text-decoration: none;
transition: color 0.2s;
&:hover {
background: transparent;
color: @primary-strong;
}
}
&__main {
flex: 1;
.flex(row, center, center);
padding: @spacing-xl;
}
&__card {
.flex(column, flex-start);
// 设计稿:表单列宽 688 设计px ≈ 530px,标题/Tab/输入/按钮纵向节奏 ≈ 41px
gap: 41px;
width: 100%;
max-width: 530px;
padding: 0;
border-radius: 0;
background: transparent;
box-shadow: none;
}
&__tabs {
// 设计稿:Tab 左对齐于表单列,仅激活项带 2px 蓝色下划线(无整行分隔线)
.flex(row, flex-start);
gap: @spacing-sm;
border-bottom: none;
}
&__tab {
padding: 0 0 4px;
border: none;
border-bottom: 2px solid transparent;
background: transparent;
font-size: 11px;
color: @text-color;
cursor: pointer;
transition: all 0.2s;
&.is-active {
border-bottom-color: @primary-strong;
color: @primary-strong;
font-weight: 600;
}
}
&__switch {
text-align: center;
font-size: 11px;
color: @text-color-secondary;
}
&__link {
color: @primary-strong;
&:hover {
color: @primary-hover;
}
}
}
</style>