140 lines
3.8 KiB
HTML
140 lines
3.8 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>宇之然内容创作平台 - 登录</title>
|
|
<link rel="stylesheet" href="element-plus.css">
|
|
<link rel="stylesheet" href="theme-modern.css">
|
|
</head>
|
|
<body class="login-body">
|
|
<!-- 背景装饰 -->
|
|
<div class="bg-circle"></div>
|
|
<div class="bg-circle"></div>
|
|
<div class="bg-circle"></div>
|
|
<div class="bg-circle"></div>
|
|
|
|
<div class="login-card">
|
|
<h1 class="login-title">宇之然内容创作平台</h1>
|
|
<p class="login-subtitle">Yuzhiran Content Creation Platform</p>
|
|
|
|
<form @submit.prevent="handleLogin">
|
|
<div class="form-group">
|
|
<input
|
|
v-model="username"
|
|
class="form-input"
|
|
type="text"
|
|
placeholder=" "
|
|
required
|
|
autocomplete="username"
|
|
/>
|
|
<label class="form-label">用户名</label>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<input
|
|
v-model="password"
|
|
class="form-input"
|
|
type="password"
|
|
placeholder=" "
|
|
required
|
|
autocomplete="current-password"
|
|
/>
|
|
<label class="form-label">密码</label>
|
|
</div>
|
|
|
|
<button
|
|
type="submit"
|
|
class="login-btn"
|
|
:disabled="loading"
|
|
>
|
|
<span v-if="loading" class="btn-loader"></span>
|
|
{{ loading ? '登录中...' : '立即登录' }}
|
|
</button>
|
|
</form>
|
|
|
|
<p class="login-footer">
|
|
管理员用户可访问完整系统功能
|
|
</p>
|
|
</div>
|
|
|
|
<script src="vue.global.prod.js"></script>
|
|
<script src="element-plus.full.js"></script>
|
|
<script>
|
|
const { ref } = Vue;
|
|
const { ElMessage } = ElementPlus;
|
|
|
|
const app = Vue.createApp({
|
|
name: 'LoginPage',
|
|
setup() {
|
|
const username = ref('');
|
|
const password = ref('');
|
|
const loading = ref(false);
|
|
|
|
const handleLogin = async () => {
|
|
if (!username.value.trim() || !password.value) {
|
|
ElMessage.warning('请输入用户名和密码');
|
|
return;
|
|
}
|
|
|
|
loading.value = true;
|
|
|
|
try {
|
|
const response = await fetch('/api/auth/login', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({
|
|
username: username.value.trim(),
|
|
password: password.value
|
|
})
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (response.ok && data.token) {
|
|
localStorage.setItem('authToken', data.token);
|
|
localStorage.setItem('userRole', data.role || 'admin');
|
|
localStorage.setItem('currentUser', JSON.stringify(data.user));
|
|
|
|
ElMessage({
|
|
message: '登录成功!正在跳转...',
|
|
type: 'success',
|
|
duration: 1500,
|
|
onClose: () => {
|
|
window.location.href = '/';
|
|
}
|
|
});
|
|
} else {
|
|
ElMessage.error(data.message || data.error || '登录失败,请检查用户名和密码');
|
|
}
|
|
} catch (error) {
|
|
console.error('登录请求失败:', error);
|
|
ElMessage.error('网络连接失败,请检查服务是否正常运行');
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
};
|
|
|
|
// 检查是否已登录
|
|
const token = localStorage.getItem('authToken');
|
|
if (token) {
|
|
window.location.href = '/';
|
|
}
|
|
|
|
return {
|
|
username,
|
|
password,
|
|
loading,
|
|
handleLogin
|
|
};
|
|
}
|
|
});
|
|
|
|
app.use(ElementPlus);
|
|
app.mount('body');
|
|
</script>
|
|
</body>
|
|
</html>
|