89 lines
3.3 KiB
HTML
89 lines
3.3 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="css/style.css">
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<nav class="navbar">
|
|
<a class="navbar-brand" href="index.html">
|
|
<span class="logo-icon">📝</span>
|
|
笔记小站
|
|
</a>
|
|
<div class="navbar-actions" id="navbarActions"></div>
|
|
</nav>
|
|
|
|
<div class="modal-overlay"
|
|
style="position:relative;background:var(--bg);min-height:calc(100vh - 64px);display:flex;align-items:center;justify-content:center;">
|
|
<div class="login-modal anim-scale-in" style="position:relative;">
|
|
<h2>🔑 欢迎登录</h2>
|
|
<p class="subtitle">登录后即可使用完整功能</p>
|
|
<div class="form-group">
|
|
<label>用户名</label>
|
|
<input type="text" id="loginUsername" placeholder="请输入用户名" autofocus>
|
|
</div>
|
|
<div class="form-group">
|
|
<label>密码</label>
|
|
<input type="password" id="loginPassword" placeholder="请输入密码">
|
|
</div>
|
|
<button class="btn btn-primary" onclick="doLogin()">登录</button>
|
|
<div class="login-hint" style="margin-top:0.5rem;">
|
|
没有账号?<a href="register.html" style="color:var(--primary);text-decoration:none;font-weight:600;">立即注册</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="toast-container" id="toastContainer"></div>
|
|
|
|
<script src="js/common.js"></script>
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function () { renderNavbar(); });
|
|
|
|
window.doLogin = function () {
|
|
var username = document.getElementById('loginUsername').value.trim();
|
|
var password = document.getElementById('loginPassword').value.trim();
|
|
if (!username || !password) {
|
|
showToast('请填写用户名和密码', 'error'); return;
|
|
}
|
|
|
|
fetch('/function/user.php', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
action: 'login',
|
|
username: username,
|
|
password: password
|
|
})
|
|
}).then(res => res.json()).then(data => {
|
|
if (data.code == 0) {
|
|
showToast('登录成功', 'success');
|
|
if (username == 'admin') {
|
|
setTimeout(() => {
|
|
window.location.href = '/admin_categories.php';
|
|
}, 1000);
|
|
}else{
|
|
setTimeout(() => {
|
|
history.go(-1);
|
|
}, 1000);
|
|
}
|
|
return
|
|
}
|
|
showToast(data.message, 'error'); return;
|
|
}).catch(err => {
|
|
showToast(err.message, 'error');
|
|
});
|
|
};
|
|
|
|
['loginUsername', 'loginPassword'].forEach(function (id) {
|
|
var el = document.getElementById(id);
|
|
if (el) el.addEventListener('keydown', function (e) { if (e.key === 'Enter') doLogin(); });
|
|
});
|
|
</script>
|
|
</body>
|
|
|
|
</html> |