login.html 3.39 KB
<!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>