Files
yu-zhi-ran/platform/frontend/login.html
T

194 lines
5.1 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>
<script src="https://cdn.tailwindcss.com"></script>
<script src="/static/vue.global.prod.js?v=20260421-0830"></script>
<link rel="stylesheet" href="/static/element-plus.css?v=20260421-0830" />
<script src="/static/element-plus.full.js?v=20260421-0830"></script>
<style>
.login-container {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.login-card {
width: 100%;
max-width: 400px;
padding: 32px;
background: white;
border-radius: 16px;
box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}
.login-title {
text-align: center;
font-size: 28px;
font-weight: bold;
color: #1f2937;
margin-bottom: 32px;
}
.login-input {
width: 100%;
padding: 12px 16px;
border: 1px solid #d1d5db;
border-radius: 8px;
font-size: 16px;
margin-bottom: 16px;
outline: none;
transition: border-color 0.2s;
}
.login-input:focus {
border-color: #3b82f6;
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}
.login-button {
width: 100%;
padding: 12px;
background: #3b82f6;
color: white;
border: none;
border-radius: 8px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: background 0.2s;
}
.login-button:hover {
background: #2563eb;
}
.login-button:disabled {
opacity: 0.6;
cursor: not-allowed;
}
.login-footer {
text-align: center;
margin-top: 24px;
color: #6b7280;
font-size: 14px;
}
</style>
<!-- Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Vue 3 -->
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<!-- Element Plus CSS -->
<link rel="stylesheet" href="https://unpkg.com/element-plus@2.4.3/dist/index.css">
<!-- Element Plus JS -->
<script src="https://unpkg.com/element-plus@2.4.3/dist/index.full.min.js"></script>
</head>
<body>
<div class="login-container">
<div class="login-card">
<h1 class="login-title">宇之然内容创作平台</h1>
<form @submit.prevent="handleLogin">
<input
v-model="username"
class="login-input"
type="text"
placeholder="请输入用户名"
required
autocomplete="username"
/>
<input
v-model="password"
class="login-input"
type="password"
placeholder="请输入密码"
required
autocomplete="current-password"
/>
<button
class="login-button"
type="submit"
:disabled="loading"
:class="{'opacity-60 cursor-not-allowed': loading}"
>
{{ loading ? '登录中...' : '登录' }}
</button>
</form>
<p class="login-footer">
只有管理员用户可登录访问系统
</p>
</div>
</div>
<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('auth_token', data.token);
localStorage.setItem('user_role', data.role || 'admin');
ElMessage.success('登录成功!正在跳转...');
// 延迟跳转,让用户看到成功消息
setTimeout(() => {
window.location.href = '/';
}, 1000);
} else {
ElMessage.error(data.message || data.error || '登录失败,请检查用户名和密码');
}
} catch (error) {
console.error('登录请求失败:', error);
ElMessage.error('网络连接失败,请检查服务是否正常运行');
} finally {
loading.value = false;
}
};
return {
username,
password,
loading,
handleLogin
};
}
});
app.use(ElementPlus);
app.mount('#app');
</script>
</body>
</html>