login.html
3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!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">
<style>
.login-wrap {
min-height: 100vh;
display: flex; align-items: center; justify-content: center;
background: #f0f2f5;
padding: 16px;
}
.login-card {
width: 100%; max-width: 380px;
background: #fff; border-radius: 10px;
box-shadow: 0 8px 32px rgba(0,0,0,.12);
padding: 40px 36px 32px;
}
.login-card h1 { font-size: 20px; font-weight: 600; text-align: center; margin-bottom: 6px; }
.login-sub { text-align: center; color: #999; font-size: 13px; margin-bottom: 28px; }
.login-row { margin-bottom: 18px; }
.login-row label { display: block; margin-bottom: 6px; font-size: 13px; color: #555; }
.login-row input {
width: 100%; height: 38px; padding: 0 12px;
border: 1px solid #d0d3da; border-radius: 6px; outline: none; font-size: 14px;
}
.login-row input:focus { border-color: #185fa5; }
.login-btn {
width: 100%; height: 40px; margin-top: 6px;
background: #185fa5; color: #fff; border: none; border-radius: 6px;
font-size: 15px; cursor: pointer;
}
.login-btn:hover { background: #0c447c; }
.login-btn:disabled { opacity: .6; cursor: not-allowed; }
.login-err { color: #a32d2d; font-size: 13px; text-align: center; margin-top: 12px; min-height: 18px; }
</style>
</head>
<body>
<div class="login-wrap">
<div class="login-card">
<h1>数据处理</h1>
<p class="login-sub">D+ 系统 · 系统设置 → 数据处理</p>
<div class="login-row">
<label>账号</label>
<input id="username" autocomplete="username" placeholder="请输入账号">
</div>
<div class="login-row">
<label>密码</label>
<input id="password" type="password" autocomplete="current-password" placeholder="请输入密码">
</div>
<button id="btnLogin" class="login-btn">登 录</button>
<div id="errMsg" class="login-err"></div>
</div>
</div>
<div id="toast" class="toast"></div>
<script>
(function () {
var username = document.getElementById('username');
var password = document.getElementById('password');
var btn = document.getElementById('btnLogin');
var errMsg = document.getElementById('errMsg');
// 已登录则直接进入列表页
fetch('/api/me').then(function (r) { return r.json(); }).then(function (res) {
if (res.code === 0) location.href = '/';
});
function login() {
var u = username.value.trim();
var p = password.value;
if (!u || !p) { errMsg.textContent = '请输入账号和密码'; return; }
errMsg.textContent = '';
btn.disabled = true;
btn.textContent = '登录中...';
fetch('/api/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username: u, password: p })
}).then(function (r) { return r.json(); }).then(function (res) {
if (res.code !== 0) {
errMsg.textContent = res.msg;
btn.disabled = false; btn.textContent = '登 录';
return;
}
location.href = '/';
}).catch(function () {
errMsg.textContent = '网络异常,请重试';
btn.disabled = false; btn.textContent = '登 录';
});
}
btn.onclick = login;
password.addEventListener('keydown', function (e) { if (e.key === 'Enter') login(); });
})();
</script>
</body>
</html>