97 lines
3.2 KiB
Vue
97 lines
3.2 KiB
Vue
<template>
|
|
<div class="login-container">
|
|
<div class="login-card">
|
|
<div class="text-center mb-8">
|
|
<h2 class="font-serif text-3xl italic text-white mb-2">后台管理</h2>
|
|
<p class="text-art-muted text-sm">请输入您的管理员账号</p>
|
|
</div>
|
|
<form @submit.prevent="handleLogin" class="space-y-6">
|
|
<div class="form-group">
|
|
<label for="username" class="block text-sm font-medium text-art-muted mb-2">用户名</label>
|
|
<input
|
|
type="text"
|
|
id="username"
|
|
v-model="form.username"
|
|
class="w-full bg-white/5 border border-white/10 rounded-lg px-4 py-3 text-white placeholder-white/30 focus:outline-none focus:border-art-accent focus:ring-1 focus:ring-art-accent transition-all"
|
|
placeholder="Username"
|
|
required
|
|
/>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="password" class="block text-sm font-medium text-art-muted mb-2">密码</label>
|
|
<input
|
|
type="password"
|
|
id="password"
|
|
v-model="form.password"
|
|
class="w-full bg-white/5 border border-white/10 rounded-lg px-4 py-3 text-white placeholder-white/30 focus:outline-none focus:border-art-accent focus:ring-1 focus:ring-art-accent transition-all"
|
|
placeholder="Password"
|
|
required
|
|
/>
|
|
</div>
|
|
<button
|
|
type="submit"
|
|
class="w-full bg-white text-black font-bold py-3 rounded-lg hover:bg-art-accent hover:text-white transition-all transform hover:scale-[1.02] active:scale-[0.98]"
|
|
>
|
|
登 录
|
|
</button>
|
|
<div v-if="error" class="text-red-500 text-sm text-center mt-4 bg-red-500/10 py-2 rounded border border-red-500/20">{{ error }}</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { ref } from 'vue'
|
|
import { useRouter } from 'vue-router'
|
|
import { useToast } from '../composables/useToast'
|
|
import { login } from '../services/api'
|
|
|
|
const router = useRouter()
|
|
const toast = useToast()
|
|
|
|
const form = ref({
|
|
username: '',
|
|
password: ''
|
|
})
|
|
|
|
const error = ref('')
|
|
|
|
const handleLogin = async () => {
|
|
try {
|
|
const response = await login(form.value)
|
|
// 保存token到本地存储
|
|
localStorage.setItem('token', response.token)
|
|
localStorage.setItem('user', JSON.stringify(response.user))
|
|
toast.showToast('登录成功', 'success')
|
|
// 登录成功后重定向到管理后台
|
|
router.push('/admin')
|
|
} catch (err: any) {
|
|
error.value = err.response?.data?.error || '登录失败,请检查用户名和密码'
|
|
toast.showToast('登录失败', 'error')
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style scoped>
|
|
.login-container {
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
min-height: 100vh;
|
|
background-color: #050505;
|
|
background-image: radial-gradient(circle at 50% 50%, rgba(212, 179, 131, 0.05) 0%, transparent 50%);
|
|
}
|
|
|
|
.login-card {
|
|
background: rgba(255, 255, 255, 0.03);
|
|
backdrop-filter: blur(20px);
|
|
-webkit-backdrop-filter: blur(20px);
|
|
padding: 3rem;
|
|
border-radius: 1.5rem;
|
|
border: 1px solid rgba(255, 255, 255, 0.05);
|
|
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
|
|
width: 100%;
|
|
max-width: 420px;
|
|
}
|
|
</style>
|