You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

215 lines
6.2 KiB

<template>
<div class="login-bg flex items-center justify-center px-4">
<div class="login-card">
<div class="text-center">
<div class="logo-icon">
<svg class="h-7 w-7 text-white" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" />
</svg>
</div>
<h1 style="font-size:22px; font-weight:700; color:#0F172A; margin:0 0 4px;">{{ siteTitle }}</h1>
<p style="font-size:13px; color:#94A3B8; margin:0 0 32px;">管理控制台</p>
</div>
<div v-if="error" class="login-error show">
<svg style="width:16px;height:16px;flex-shrink:0;" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
<span>{{ error }}</span>
</div>
<form @submit.prevent="login">
<div style="margin-bottom:16px;">
<label class="login-label">账号</label>
<input
v-model="form.account"
type="text"
class="login-input"
placeholder="请输入管理员账号"
autocomplete="username"
required
/>
</div>
<div style="margin-bottom:24px;">
<label class="login-label">密码</label>
<input
v-model="form.password"
type="password"
class="login-input"
placeholder="请输入密码"
autocomplete="current-password"
required
/>
</div>
<button type="submit" class="login-btn" :class="{ loading }">
{{ loading ? '登录中...' : '登 录' }}
</button>
</form>
<p style="text-align:center; font-size:11px; color:#94A3B8; margin-top:24px;">
&copy; 2025 Admin Console · v1.0.1
</p>
</div>
</div>
</template>
<script setup lang="ts">
import { reactive, ref, onMounted } from 'vue'
import { useAuthStore } from '~/stores/auth'
definePageMeta({ layout: 'auth' })
const auth = useAuthStore()
const router = useRouter()
const form = reactive({ account: '', password: '' })
const loading = ref(false)
const error = ref('')
const siteTitle = ref('Admin')
onMounted(async () => {
auth.restore()
if (auth.token) {
router.push('/dashboard')
return
}
try {
const res = await $fetch<{ code: number; data: { sitename?: string } }>(
'/web/api/api_getsiteinfo',
{ method: 'POST', body: {} }
)
const name = res?.data?.sitename
if (name) {
siteTitle.value = name + ' Admin'
auth.setSiteTitle(name)
}
} catch { /* 站点信息获取失败不影响登录 */ }
})
async function login() {
loading.value = true
error.value = ''
try {
const res = await $fetch<{
code: number; msg: string
data: {
account: string; identity: number; token: string
access: string; apps: string; regions: string; products: string
appbinds: { id: number; name: string; region: string }[]
}
}>('/web/api/api_login', {
method: 'POST',
body: { account: form.account, password: form.password },
})
if (res.code === 0 && res.data) {
auth.setLoginData(res.data)
router.push('/dashboard')
} else {
error.value = res.msg || '登录失败'
}
} catch {
error.value = '网络错误,请检查连接'
} finally {
loading.value = false
}
}
</script>
<style scoped>
.login-bg {
min-height: 100vh;
background: linear-gradient(135deg, #0F172A 0%, #1E293B 50%, #0F172A 100%);
position: relative;
overflow: hidden;
}
.login-bg::before {
content: '';
position: absolute;
top: -50%;
left: -50%;
width: 200%;
height: 200%;
background: radial-gradient(ellipse at 30% 20%, rgba(99,102,241,0.15) 0%, transparent 50%),
radial-gradient(ellipse at 70% 80%, rgba(139,92,246,0.1) 0%, transparent 50%);
animation: bgFloat 20s ease-in-out infinite;
}
@keyframes bgFloat {
0%, 100% { transform: translate(0, 0); }
50% { transform: translate(-2%, 2%); }
}
.login-card {
background: rgba(255,255,255,0.95);
backdrop-filter: blur(20px);
border: 1px solid rgba(255,255,255,0.2);
border-radius: 20px;
box-shadow: 0 25px 80px rgba(0,0,0,0.3), 0 8px 32px rgba(0,0,0,0.15);
padding: 40px;
width: 100%;
max-width: 420px;
animation: cardIn 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes cardIn {
from { opacity: 0; transform: translateY(20px) scale(0.96); }
to { opacity: 1; transform: translateY(0) scale(1); }
}
.logo-icon {
width: 56px;
height: 56px;
background: linear-gradient(135deg, #4F46E5, #7C3AED);
border-radius: 16px;
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto 20px;
box-shadow: 0 8px 24px rgba(79, 70, 229, 0.35);
}
.login-input {
width: 100%;
padding: 12px 16px;
border: 1.5px solid #E2E8F0;
border-radius: 10px;
font-size: 14px;
color: #334155;
background: #F8FAFC;
transition: all 0.2s;
outline: none;
}
.login-input:focus {
border-color: #6366F1;
background: #fff;
box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}
.login-input::placeholder { color: #CBD5E1; }
.login-btn {
width: 100%;
padding: 12px;
border: none;
border-radius: 10px;
background: linear-gradient(135deg, #4F46E5, #6366F1);
color: #fff;
font-size: 15px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s;
box-shadow: 0 4px 16px rgba(79, 70, 229, 0.3);
}
.login-btn:hover {
background: linear-gradient(135deg, #4338CA, #4F46E5);
transform: translateY(-2px);
box-shadow: 0 8px 24px rgba(79, 70, 229, 0.4);
}
.login-btn:active { transform: translateY(0); }
.login-btn.loading { opacity: 0.7; pointer-events: none; }
.login-label { display: block; font-size: 13px; font-weight: 500; color: #64748B; margin-bottom: 6px; }
.login-error {
background: #FEF2F2;
border: 1px solid #FECACA;
color: #DC2626;
padding: 10px 14px;
border-radius: 10px;
font-size: 13px;
margin-bottom: 16px;
display: none;
}
.login-error.show { display: flex; align-items: center; gap: 8px; }
</style>