Files
hfb_sys/frontend/src/features/admin/views/AdminLoginView.vue
T

465 lines
11 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 { readError } from '@/shared/utils/error'
import { ElMessage } from 'element-plus'
import { Lock, User } from '@element-plus/icons-vue'
import { onMounted, reactive, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { fetchAdminCaptcha, type AdminCaptcha } from '@/features/admin'
import { useAdminSessionStore } from '@/stores/adminSession'
import { useDistributionSiteStore } from '@/stores/distributionSite'
import { ADMIN_DASHBOARD_PATH, PLATFORM_OPS_PATH, isAdminPath } from '@/shared/utils/adminPath'
const router = useRouter()
const route = useRoute()
const adminSession = useAdminSessionStore()
const siteStore = useDistributionSiteStore()
const loading = ref(false)
const captchaLoading = ref(false)
const captcha = ref<AdminCaptcha | null>(null)
const form = reactive({
username: '',
password: '',
captchaCode: '',
})
onMounted(loadCaptcha)
async function loadCaptcha() {
captchaLoading.value = true
try {
captcha.value = await fetchAdminCaptcha()
form.captchaCode = ''
} catch (error) {
ElMessage.error(readError(error, '验证码加载失败'))
} finally {
captchaLoading.value = false
}
}
async function handleLogin() {
loading.value = true
try {
await adminSession.login(
form.username,
form.password,
captcha.value?.captcha_id || '',
form.captchaCode
)
ElMessage.success('后台登录成功')
const redirect = typeof route.query.redirect === 'string' ? route.query.redirect : ''
const destination = siteStore.isPlatformOps
? PLATFORM_OPS_PATH
: isAdminPath(redirect)
? redirect
: ADMIN_DASHBOARD_PATH
await router.push(destination)
} catch (error) {
ElMessage.error(readError(error, '后台登录失败'))
await loadCaptcha()
} finally {
loading.value = false
}
}
</script>
<template>
<section class="admin-login-shell">
<div class="admin-login-glow" aria-hidden="true" />
<div class="admin-login-glow secondary" aria-hidden="true" />
<div class="admin-login-card">
<div class="admin-login-left">
<div class="brand-lockup">
<div class="brand-logo">{{ siteStore.brandMark }}</div>
<strong
>{{ siteStore.siteName }}{{ siteStore.isPlatformOps ? '' : ' · 后台管理' }}</strong
>
</div>
<div class="admin-login-hero">
<h2>高效管理<br />从容掌控</h2>
<p>统一的后台管理系统,助您轻松处理订单、用户与运营数据。</p>
<div class="login-site-scope">
<span>当前登录站点</span>
<strong>{{ siteStore.siteName }}</strong>
<em>{{
siteStore.isPlatformOps ? '只读统计' : siteStore.isTenant ? '经营站点' : '站点后台'
}}</em>
</div>
</div>
<div class="admin-login-footer">
<span>© 哈夫币租号平台</span>
</div>
</div>
<div class="admin-login-right">
<div class="admin-login-header">
<p class="eyebrow">Admin Login</p>
<h1>管理员登录</h1>
</div>
<el-form class="admin-form" label-position="top" @submit.prevent>
<el-form-item label="用户名">
<el-input
v-model="form.username"
placeholder="请输入管理员用户名"
size="large"
:prefix-icon="User"
/>
</el-form-item>
<el-form-item label="密码">
<el-input
v-model="form.password"
type="password"
show-password
placeholder="请输入管理员密码"
size="large"
:prefix-icon="Lock"
@keyup.enter="handleLogin"
/>
</el-form-item>
<el-form-item label="验证码">
<div class="admin-captcha-row">
<el-input
v-model="form.captchaCode"
maxlength="4"
placeholder="请输入验证码"
size="large"
@keyup.enter="handleLogin"
/>
<button
class="captcha-image-button"
type="button"
:disabled="captchaLoading"
@click="loadCaptcha"
>
<img v-if="captcha" :src="captcha.image" alt="验证码" />
<span v-else>刷新</span>
</button>
</div>
</el-form-item>
<el-button
class="admin-login-btn"
type="primary"
size="large"
:loading="loading"
@click="handleLogin"
>
登录后台
</el-button>
</el-form>
<RouterLink class="back-home" to="/">← 返回首页</RouterLink>
</div>
</div>
</section>
</template>
<style scoped>
.admin-login-shell {
position: relative;
display: grid;
min-height: 100vh;
place-items: center;
overflow: hidden;
background:
radial-gradient(circle at 18% 20%, rgba(20, 119, 255, 0.14), transparent 42%),
radial-gradient(circle at 82% 80%, rgba(109, 40, 217, 0.12), transparent 42%),
linear-gradient(180deg, #0b1120 0%, #0f172a 60%, #111827 100%);
padding: 24px;
}
.admin-login-glow {
position: absolute;
top: -10%;
left: -10%;
width: 50vw;
height: 50vw;
border-radius: 50%;
background: radial-gradient(circle, rgba(20, 119, 255, 0.22), transparent 65%);
filter: blur(80px);
pointer-events: none;
}
.admin-login-glow.secondary {
top: auto;
left: auto;
right: -10%;
bottom: -10%;
background: radial-gradient(circle, rgba(109, 40, 217, 0.18), transparent 65%);
}
.admin-login-card {
position: relative;
z-index: 1;
display: grid;
grid-template-columns: 1fr 420px;
width: min(960px, 100%);
min-height: 560px;
border: 1px solid rgba(255, 255, 255, 0.06);
border-radius: 20px;
background: rgba(15, 23, 42, 0.55);
backdrop-filter: blur(24px);
box-shadow:
0 24px 80px rgba(0, 0, 0, 0.35),
inset 0 1px 0 rgba(255, 255, 255, 0.06);
overflow: hidden;
}
/* ========== 左侧品牌区 ========== */
.admin-login-left {
display: flex;
flex-direction: column;
justify-content: space-between;
padding: 40px 36px;
background:
radial-gradient(circle at 30% 20%, rgba(20, 119, 255, 0.12), transparent 50%),
radial-gradient(circle at 80% 90%, rgba(109, 40, 217, 0.1), transparent 50%),
linear-gradient(160deg, rgba(20, 119, 255, 0.1), rgba(109, 40, 217, 0.06));
}
.brand-lockup {
display: flex;
align-items: center;
gap: 10px;
}
.brand-logo {
display: grid;
width: 36px;
height: 36px;
place-items: center;
border-radius: 10px;
background: linear-gradient(135deg, #1477ff, #2f8dff);
box-shadow: 0 8px 24px rgba(20, 119, 255, 0.25);
color: #fff;
font-size: 15px;
font-weight: 900;
}
.brand-lockup strong {
color: #f8fafc;
font-size: 15px;
font-weight: 800;
letter-spacing: 0.5px;
}
.admin-login-hero h2 {
margin: 0 0 14px;
color: #f1f5f9;
font-size: 28px;
font-weight: 800;
line-height: 1.25;
}
.admin-login-hero p {
margin: 0;
color: #94a3b8;
font-size: 14px;
line-height: 1.7;
max-width: 320px;
}
.login-site-scope {
display: flex;
align-items: center;
gap: 8px;
width: fit-content;
max-width: 100%;
margin-top: 20px;
padding: 8px 11px;
border: 1px solid rgba(148, 163, 184, 0.24);
border-radius: 8px;
background: rgba(15, 23, 42, 0.38);
}
.login-site-scope span {
color: #94a3b8;
font-size: 11px;
white-space: nowrap;
}
.login-site-scope strong {
min-width: 0;
overflow: hidden;
color: #f8fafc;
font-size: 12px;
text-overflow: ellipsis;
white-space: nowrap;
}
.login-site-scope em {
flex: none;
padding: 1px 6px;
border-radius: 999px;
background: rgba(37, 99, 235, 0.2);
color: #93c5fd;
font-size: 10px;
font-style: normal;
font-weight: 700;
}
.admin-login-footer span {
color: #475569;
font-size: 12px;
}
/* ========== 右侧表单区 ========== */
.admin-login-right {
display: flex;
flex-direction: column;
justify-content: center;
padding: 36px 32px;
background: rgba(255, 255, 255, 0.03);
}
.admin-login-header {
margin-bottom: 24px;
}
.admin-login-header .eyebrow {
margin: 0 0 8px;
color: #1477ff;
font-size: 12px;
font-weight: 700;
letter-spacing: 1px;
text-transform: uppercase;
}
.admin-login-header h1 {
margin: 0;
color: #f8fafc;
font-size: 24px;
font-weight: 800;
line-height: 1.2;
}
.admin-form :deep(.el-form-item__label) {
color: #cbd5e1;
font-size: 13px;
font-weight: 600;
padding-bottom: 6px;
}
/* 注意:styles/admin.css 里的全局增强规则带 !important,把输入框底色固定成白色
(.el-input__wrapper { background-color: #ffffff !important }),本页原设计的深色输入框
无法生效;若仍把文字设成浅色就是"白底浅字",输入内容与光标都看不见
(验证码框不会被浏览器自动填充,因此最先暴露该问题)。
这里统一按浅色输入框配色:深色文字 + 中灰占位符;白底、边框与蓝色焦点环由该全局规则提供。 */
.admin-form :deep(.el-input__wrapper) {
padding: 0 12px;
}
.admin-form :deep(.el-input__inner) {
color: #0f172a;
font-size: 14px;
height: 44px;
}
.admin-form :deep(.el-input__inner::placeholder) {
color: #64748b;
}
.admin-form :deep(.el-input__prefix-inner) {
color: #64748b;
}
.admin-captcha-row {
display: grid;
grid-template-columns: 1fr 132px;
gap: 10px;
width: 100%;
}
.captcha-image-button {
display: flex;
align-items: center;
justify-content: center;
height: 44px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 10px;
background: rgba(255, 255, 255, 0.04);
padding: 0;
cursor: pointer;
overflow: hidden;
transition:
background 0.2s,
border-color 0.2s;
}
.captcha-image-button:hover {
background: rgba(255, 255, 255, 0.07);
border-color: rgba(255, 255, 255, 0.14);
}
.captcha-image-button:disabled {
cursor: wait;
opacity: 0.6;
}
.captcha-image-button img {
display: block;
width: 132px;
height: 44px;
}
.captcha-image-button span {
color: #94a3b8;
font-size: 13px;
}
.admin-login-btn {
width: 100%;
height: 46px;
border-radius: 10px;
font-size: 15px;
font-weight: 700;
margin-top: 8px;
letter-spacing: 0.5px;
background: linear-gradient(135deg, #1477ff, #2f8dff);
border: none;
box-shadow: 0 10px 28px rgba(20, 119, 255, 0.25);
transition:
transform 0.15s,
box-shadow 0.2s;
}
.admin-login-btn:hover {
transform: translateY(-1px);
box-shadow: 0 14px 36px rgba(20, 119, 255, 0.32);
}
.back-home {
display: block;
margin-top: 18px;
text-align: center;
color: #64748b;
font-size: 13px;
text-decoration: none;
transition: color 0.2s;
}
.back-home:hover {
color: #94a3b8;
}
/* ========== 响应式 ========== */
@media (max-width: 860px) {
.admin-login-card {
grid-template-columns: 1fr;
max-width: 420px;
}
.admin-login-left {
display: none;
}
.admin-login-right {
padding: 32px 28px;
}
}
@media (max-width: 480px) {
.admin-login-shell {
padding: 16px;
}
.admin-login-right {
padding: 24px 20px;
}
}
@media (prefers-reduced-motion: reduce) {
.admin-login-btn {
transition: none;
}
}
</style>