市场夺宝奇兵
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

350 lines
12 KiB

2 months ago
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>系统登录</title>
  7. <style>
  8. * {
  9. margin: 0;
  10. padding: 0;
  11. box-sizing: border-box;
  12. font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
  13. }
  14. body {
  15. background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
  16. display: flex;
  17. justify-content: center;
  18. align-items: center;
  19. min-height: 100vh;
  20. padding: 20px;
  21. }
  22. .login-container {
  23. background-color: white;
  24. border-radius: 12px;
  25. box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  26. width: 100%;
  27. max-width: 420px;
  28. padding: 40px 30px;
  29. transition: transform 0.3s ease;
  30. }
  31. .login-container:hover {
  32. transform: translateY(-5px);
  33. }
  34. .login-header {
  35. text-align: center;
  36. margin-bottom: 30px;
  37. }
  38. .login-header h1 {
  39. color: #333;
  40. font-size: 28px;
  41. margin-bottom: 8px;
  42. }
  43. .login-header p {
  44. color: #666;
  45. font-size: 16px;
  46. }
  47. .form-group {
  48. margin-bottom: 20px;
  49. }
  50. label {
  51. display: block;
  52. margin-bottom: 8px;
  53. color: #555;
  54. font-weight: 500;
  55. }
  56. input {
  57. width: 100%;
  58. padding: 14px 16px;
  59. border: 1px solid #ddd;
  60. border-radius: 8px;
  61. font-size: 16px;
  62. transition: all 0.3s;
  63. }
  64. input:focus {
  65. border-color: #4a90e2;
  66. box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.2);
  67. outline: none;
  68. }
  69. .error-message {
  70. color: #e74c3c;
  71. font-size: 14px;
  72. margin-top: 5px;
  73. display: none;
  74. }
  75. .login-button {
  76. background: linear-gradient(to right, #6a11cb, #2575fc);
  77. color: white;
  78. border: none;
  79. border-radius: 8px;
  80. padding: 14px;
  81. font-size: 16px;
  82. font-weight: 600;
  83. cursor: pointer;
  84. width: 100%;
  85. transition: all 0.3s;
  86. margin-top: 10px;
  87. }
  88. .login-button:hover {
  89. background: linear-gradient(to right, #5a0db5, #1c68e8);
  90. box-shadow: 0 5px 15px rgba(37, 117, 252, 0.4);
  91. }
  92. .login-button:active {
  93. transform: scale(0.98);
  94. }
  95. .login-footer {
  96. text-align: center;
  97. margin-top: 25px;
  98. color: #777;
  99. font-size: 14px;
  100. }
  101. .alert {
  102. padding: 12px 16px;
  103. border-radius: 8px;
  104. margin-bottom: 20px;
  105. display: none;
  106. }
  107. .alert-error {
  108. background-color: #ffebee;
  109. color: #c62828;
  110. border: 1px solid #ffcdd2;
  111. }
  112. .alert-success {
  113. background-color: #e8f5e9;
  114. color: #2e7d32;
  115. border: 1px solid #c8e6c9;
  116. }
  117. .password-requirements {
  118. font-size: 12px;
  119. color: #777;
  120. margin-top: 5px;
  121. }
  122. .input-error {
  123. border-color: #e74c3c;
  124. box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.2);
  125. }
  126. </style>
  127. </head>
  128. <body>
  129. <div class="login-container">
  130. <div class="login-header">
  131. <h1>系统登录</h1>
  132. <p>请输入您的账号和密码</p>
  133. </div>
  134. <div id="usernameAlert" class="alert alert-error">
  135. 账号不存在,请检查后重试!
  136. </div>
  137. <div id="passwordAlert" class="alert alert-error">
  138. 密码错误,请检查后重试!
  139. </div>
  140. <form id="loginForm">
  141. <div class="form-group">
  142. <label for="username">账号</label>
  143. <input type="text" id="username" name="username" placeholder="请输入账号" required>
  144. <div class="error-message" id="usernameError">账号不能为空</div>
  145. </div>
  146. <div class="form-group">
  147. <label for="password">密码</label>
  148. <input type="password" id="password" name="password" placeholder="请输入密码" required>
  149. <div class="error-message" id="passwordError">密码不能为空</div>
  150. <div class="password-requirements">密码必须为8位数字</div>
  151. </div>
  152. <button type="submit" class="login-button">登录</button>
  153. </form>
  154. </div>
  155. <script>
  156. document.addEventListener('DOMContentLoaded', function () {
  157. const loginForm = document.getElementById('loginForm');
  158. const usernameInput = document.getElementById('username');
  159. const passwordInput = document.getElementById('password');
  160. const usernameError = document.getElementById('usernameError');
  161. const passwordError = document.getElementById('passwordError');
  162. const usernameAlert = document.getElementById('usernameAlert');
  163. const passwordAlert = document.getElementById('passwordAlert');
  164. // 正确的账号和密码
  165. const CORRECT_USERNAME = 'admin';
  166. const CORRECT_PASSWORD = '20251107';
  167. // 表单提交事件
  168. loginForm.addEventListener('submit', function (e) {
  169. e.preventDefault();
  170. // 重置错误状态
  171. resetErrors();
  172. // 获取表单数据
  173. const username = usernameInput.value.trim();
  174. const password = passwordInput.value.trim();
  175. // 表单验证
  176. let isValid = true;
  177. if (!username) {
  178. showError(usernameError, '账号不能为空');
  179. usernameInput.classList.add('input-error');
  180. isValid = false;
  181. }
  182. if (!password) {
  183. showError(passwordError, '密码不能为空');
  184. passwordInput.classList.add('input-error');
  185. isValid = false;
  186. } else if (!/^\d{8}$/.test(password)) {
  187. showError(passwordError, '密码必须为8位数字');
  188. passwordInput.classList.add('input-error');
  189. isValid = false;
  190. }
  191. // 如果验证通过,尝试登录
  192. if (isValid) {
  193. // 验证账号密码
  194. if (username === CORRECT_USERNAME && password === CORRECT_PASSWORD) {
  195. // 登录成功,保存登录状态
  196. localStorage.setItem('isLoggedIn', 'true');
  197. localStorage.setItem('loginTime', new Date().getTime());
  198. // 显示成功消息(短暂显示后跳转)
  199. showSuccessMessage();
  200. // 延迟跳转,让用户看到成功消息
  201. setTimeout(function () {
  202. window.location.href = 'hcdbqb-management.html';
  203. }, 1000);
  204. } else {
  205. // 登录失败,明确提示是账号还是密码错误
  206. if (username !== CORRECT_USERNAME) {
  207. usernameAlert.style.display = 'block';
  208. usernameInput.classList.add('input-error');
  209. usernameInput.focus();
  210. } else {
  211. passwordAlert.style.display = 'block';
  212. passwordInput.classList.add('input-error');
  213. passwordInput.value = '';
  214. passwordInput.focus();
  215. }
  216. }
  217. }
  218. });
  219. // 实时验证
  220. usernameInput.addEventListener('blur', function () {
  221. if (!this.value.trim()) {
  222. showError(usernameError, '账号不能为空');
  223. this.classList.add('input-error');
  224. } else {
  225. hideError(usernameError);
  226. this.classList.remove('input-error');
  227. }
  228. });
  229. passwordInput.addEventListener('blur', function () {
  230. const password = this.value.trim();
  231. if (!password) {
  232. showError(passwordError, '密码不能为空');
  233. this.classList.add('input-error');
  234. } else if (!/^\d{8}$/.test(password)) {
  235. showError(passwordError, '密码必须为8位数字');
  236. this.classList.add('input-error');
  237. } else {
  238. hideError(passwordError);
  239. this.classList.remove('input-error');
  240. }
  241. });
  242. // 输入时隐藏错误提示
  243. usernameInput.addEventListener('input', function () {
  244. hideError(usernameError);
  245. hideAlert(usernameAlert);
  246. this.classList.remove('input-error');
  247. });
  248. passwordInput.addEventListener('input', function () {
  249. hideError(passwordError);
  250. hideAlert(passwordAlert);
  251. this.classList.remove('input-error');
  252. });
  253. // 辅助函数
  254. function showError(element, message) {
  255. element.textContent = message;
  256. element.style.display = 'block';
  257. }
  258. function hideError(element) {
  259. element.style.display = 'none';
  260. }
  261. function hideAlert(alertElement) {
  262. alertElement.style.display = 'none';
  263. }
  264. function resetErrors() {
  265. hideError(usernameError);
  266. hideError(passwordError);
  267. hideAlert(usernameAlert);
  268. hideAlert(passwordAlert);
  269. usernameInput.classList.remove('input-error');
  270. passwordInput.classList.remove('input-error');
  271. }
  272. function showSuccessMessage() {
  273. // 临时创建一个成功提示
  274. const successAlert = document.createElement('div');
  275. successAlert.className = 'alert alert-success';
  276. successAlert.textContent = '登录成功,正在跳转...';
  277. usernameAlert.parentNode.insertBefore(successAlert, usernameAlert);
  278. successAlert.style.display = 'block';
  279. // 移除错误提示(如果有)
  280. hideAlert(usernameAlert);
  281. hideAlert(passwordAlert);
  282. }
  283. // 检查是否已经登录(如果已经登录,直接跳转)
  284. if (localStorage.getItem('isLoggedIn') === 'true') {
  285. // 检查登录时间,如果超过24小时需要重新登录
  286. const loginTime = parseInt(localStorage.getItem('loginTime'));
  287. const currentTime = new Date().getTime();
  288. const hoursDiff = (currentTime - loginTime) / (1000 * 60 * 60);
  289. if (hoursDiff < 24) {
  290. window.location.href = 'hcdbqb-management.html';
  291. } else {
  292. // 超过24小时,清除登录状态
  293. localStorage.removeItem('isLoggedIn');
  294. localStorage.removeItem('loginTime');
  295. }
  296. }
  297. });
  298. </script>
  299. </body>
  300. </html>