go语言写的人脸本地化程序
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.
 
 
 
 
 

578 lines
15 KiB

  1. <!DOCTYPE html>
  2. <html lang="en">
  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. body{
  9. margin: 0;
  10. }
  11. li {
  12. list-style-type: none;
  13. }
  14. @media screen and (orientation: portrait) {
  15. .login {
  16. width: 100vw;
  17. height: 100vh;
  18. background-image: url("/static/img/phoneBgc.jpg");
  19. background-size: 100% 100%;
  20. background-repeat: no-repeat;
  21. }
  22. .register {
  23. background-image: url("/static/img/registerBgc.jpg") !important;
  24. padding-top: 15vh;
  25. }
  26. .logo {
  27. width: 15vw;
  28. margin: 4vw 0 0 4vw;
  29. }
  30. .login_title {
  31. width: 100vw;
  32. font-size: 8vw;
  33. text-align: center;
  34. margin-top: 15vh;
  35. }
  36. .input_box {
  37. width: 100vw;
  38. height: 25vw;
  39. display: flex;
  40. flex-direction: column;
  41. justify-content: center;
  42. align-items: center;
  43. margin-top: 5vh;
  44. position: relative;
  45. }
  46. .phone_input, .account_input{
  47. width: 50vw;
  48. height: 11vw;
  49. border-radius: 2vw;
  50. background-color: transparent;
  51. font-size: 3vw;
  52. padding-left: 2vw;
  53. border: 1px solid #000;
  54. position: absolute;
  55. top: 0vw;
  56. }
  57. .code_input, .password_input{
  58. width: 50vw;
  59. height: 11vw;
  60. margin-top: 2vh;
  61. border-radius: 2vw;
  62. padding-left: 2vw;
  63. font-size: 3vw;
  64. background-color: transparent;
  65. border: 1px solid #000;
  66. position: absolute;
  67. top: 10vw;
  68. }
  69. .login_button {
  70. width: 40vw;
  71. height: 5vh;
  72. background-color: rgb(101, 161, 255);
  73. border-radius: 10vw;
  74. display: flex;
  75. justify-content: center;
  76. align-items: center;
  77. color:#fff;
  78. font-size: 4vw;
  79. margin: 2vh 0 0 30vw;
  80. }
  81. #sendCodeBtn {
  82. position: absolute;
  83. font-size: 2.5vw;
  84. top: 18.5vw;
  85. right: 30vw;
  86. border-left: 2px solid;
  87. padding-left: 2vw;
  88. border: none;
  89. background: transparent;
  90. }
  91. .employee {
  92. display: flex;
  93. align-items: center;
  94. }
  95. .administrator {
  96. display: flex;
  97. align-items: center;
  98. margin-left: 5vw;
  99. }
  100. .choose_employee {
  101. width: 2vw;
  102. height: 2vw;
  103. border-radius: 50%;
  104. border: 2px solid #000;
  105. margin-right: 1vw;
  106. }
  107. .choose_administrator {
  108. width: 2vw;
  109. height: 2vw;
  110. border-radius: 50%;
  111. border: 2px solid #000;
  112. margin-right: 1vw;
  113. }
  114. .login_style {
  115. display: flex;
  116. justify-content: center;
  117. align-items: center;
  118. font-size: 2.5vw;
  119. margin-top: 2vh;
  120. }
  121. .hidden {
  122. display: none;
  123. }
  124. .active {
  125. display: flex;
  126. }
  127. .background {
  128. background-color: #000;
  129. }
  130. .password-container {
  131. position: relative;
  132. }
  133. .password_toggle {
  134. position: absolute;
  135. width: 5vw;
  136. top: 18vw;
  137. right: 26vw;
  138. }
  139. }
  140. @media screen and (orientation: landscape) {
  141. input:focus {
  142. border: 0.1vw solid #000;
  143. outline: none; /* 可选,用于去除默认的外边框样式 */
  144. }
  145. .login {
  146. width: 100vw;
  147. height: 100vh;
  148. background-image: url("/static/img/phoneBgc_pc.jpg");
  149. background-size: 100% 100%;
  150. background-repeat: no-repeat;
  151. position: relative;
  152. }
  153. .PC_img {
  154. width: 52.6vw;
  155. height: 64.44vh;
  156. background-image: url("/static/img/loginBox.png");
  157. background-size: 100% 100%;
  158. background-repeat: no-repeat;
  159. position: absolute;
  160. top: 18.88vh;
  161. left: 23.7vw;
  162. }
  163. .register {
  164. background-image: url("/static/img/registerBgc_pc.jpg") !important;
  165. }
  166. .logo {
  167. width: 15vh;
  168. margin: 4vh 0 0 4vh;
  169. }
  170. .login_title {
  171. /* width: 100vw; */
  172. font-size: 4vh;
  173. text-align: center;
  174. position: absolute;
  175. z-index: 10;
  176. top: 28vh;
  177. margin-left: 58vw;
  178. /* margin-top: 15vh;*/
  179. }
  180. .input_box {
  181. flex-direction: column;
  182. justify-content: center;
  183. align-items: center;
  184. margin-top: 15vh;
  185. position: relative;
  186. }
  187. .phone_input, .account_input {
  188. width: 15vw;
  189. height: 6.66vh;
  190. border-radius: 2vh;
  191. background-color: transparent;
  192. font-size: 1.5vw;
  193. padding-left: 2vh;
  194. padding-right: 5vw;
  195. border: 0.1vw solid #000;
  196. margin-left: 25vw;
  197. }
  198. .code_input, .password_input {
  199. width: 15vw;
  200. height: 6.66vh;
  201. margin-top: 2vw;
  202. border-radius: 2vh;
  203. padding-left: 2vh;
  204. font-size: 1.5vw;
  205. padding-right: 5vw;
  206. background-color: transparent;
  207. border: 0.1vw solid #000;
  208. margin-left: 25vw;
  209. }
  210. .login_button {
  211. width: 16vw;
  212. height: 3vw;
  213. background-color: rgb(101, 161, 255);
  214. border-radius: 10vh;
  215. display: flex;
  216. justify-content: center;
  217. align-items: center;
  218. color: #fff;
  219. font-size: 2vw;
  220. /* margin: 2vh 0 0 30vh; */
  221. position: absolute;
  222. left: 55vw;
  223. top: 65vh;
  224. }
  225. #sendCodeBtn {
  226. position: absolute;
  227. font-size: 1.5vh;
  228. top: 11.5vh;
  229. right: 27.3vw;
  230. border-left: 0.1vw solid;
  231. padding-left: 1vh;
  232. display: flex;
  233. align-items: center;
  234. height: 3vw;
  235. border: none;
  236. background: transparent;
  237. }
  238. .employee {
  239. display: flex;
  240. align-items: center;
  241. }
  242. .administrator {
  243. display: flex;
  244. align-items: center;
  245. margin-left: 3vw;
  246. }
  247. .hand:hover {
  248. cursor: pointer;
  249. }
  250. .choose_employee {
  251. width: 2vh;
  252. height: 2vh;
  253. border-radius: 50%;
  254. border: 0.1vw solid #000;
  255. margin-right: 1vh;
  256. }
  257. .choose_administrator {
  258. width: 2vh;
  259. height: 2vh;
  260. border-radius: 50%;
  261. border: 0.1vw solid #000;
  262. margin-right: 1vh;
  263. }
  264. .login_style {
  265. display: flex;
  266. justify-content: center;
  267. align-items: center;
  268. font-size: 1vw;
  269. margin-top: 2vw;
  270. position: absolute;
  271. left: 54.8vw;
  272. }
  273. .hidden {
  274. display: none;
  275. }
  276. .active {
  277. display: flex;
  278. }
  279. .background {
  280. background-color: #000;
  281. }
  282. .password-container {
  283. position: relative;
  284. }
  285. .password_toggle {
  286. width: 3vw;
  287. position: absolute;
  288. font-size: 1.5vh;
  289. top: 11.5vh;
  290. right: 28.5vw;
  291. padding-left: 0.5vh;
  292. }
  293. #scroll-to-top-btn {
  294. display: none;
  295. position: fixed;
  296. right: 20px;
  297. bottom: 20px;
  298. width: 7vh;
  299. height: 10vw;
  300. color: #fff;
  301. border: none;
  302. border-radius: 5px;
  303. font-size: 3vh;
  304. cursor: pointer;
  305. }
  306. }
  307. button:disabled {
  308. color: black !important;
  309. }
  310. </style>
  311. </head>
  312. <body>
  313. <!-- 登录页面 -->
  314. <div class="login">
  315. <img class="logo" src="/static/img/logo.png" alt="">
  316. <div class="PC_img"></div>
  317. <div class="login_title">请 登 录</div>
  318. <div id="employeeForm" class="input_box hidden active">
  319. <input class="phone_input" type="text" placeholder="请输入手机号">
  320. <input class="code_input" type="text" placeholder="请输入验证码">
  321. <button id="sendCodeBtn" class="btn">发送验证码</button>
  322. </div>
  323. <div id="adminForm" class="input_box hidden password-container">
  324. <input class="account_input" type="text" placeholder="请输入账号">
  325. <input id="password_input" class="password_input" type="password" placeholder="请输入密码">
  326. <img id="password_toggle" class="password_toggle hand" src="/static/img/close.png" alt="">
  327. </div>
  328. <div class="login_style">
  329. <div id="employeeBtn" class="employee hand">
  330. <div id="choose_employee" class="choose_employee background"></div>
  331. <div>员工登录</div>
  332. </div>
  333. <div id="adminBtn" class="administrator hand">
  334. <div id="choose_administrator" class="choose_administrator"></div>
  335. <div>管理员登录</div>
  336. </div>
  337. </div>
  338. <div class="login_button hand">登 录</div>
  339. </div>
  340. <script src="/static/js/jquery.min.js"></script>
  341. <script src="/static/js/msg-box.js"></script>
  342. <script>
  343. $(function(){
  344. console.log("{{.type}}");
  345. if ("{{.type}}" == "mgr") {
  346. $("#adminBtn").click();
  347. }
  348. $.MsgBox = {
  349. Alert: function(title, msg) {
  350. GenerateHtml("alert", title, msg);
  351. btnOk(); //alert只是弹出消息,因此没必要用到回调函数callback
  352. btnNo();
  353. },
  354. Confirm: function(title, msg, callback) {
  355. GenerateHtml("confirm", title, msg);
  356. btnOk(callback);
  357. btnNo();
  358. }
  359. }
  360. const sendCodeBtn = $('#sendCodeBtn');
  361. let countdown = 30;
  362. let timer;
  363. function startCountdown() {
  364. sendCodeBtn.attr("disabled", "disabled");
  365. sendCodeBtn.html(`${countdown}秒`);
  366. timer = setInterval(() => {
  367. console.log(countdown);
  368. countdown--;
  369. sessionStorage.setItem('countdown',countdown);
  370. sendCodeBtn.html(`${countdown}秒`);
  371. if (countdown <= 0) {
  372. clearInterval(timer);
  373. sendCodeBtn.html('发送验证码');
  374. sendCodeBtn.removeAttr("disabled");
  375. countdown = 30;
  376. }
  377. }, 1000);
  378. }
  379. $("#sendCodeBtn").on("click",function(){
  380. if (!phoneValid()){
  381. $.MsgBox.Alert("提示", "手机号为空或不合法,请检查");
  382. return;
  383. }
  384. countdown = 30;
  385. startCountdown();
  386. sessionStorage.setItem('countdown',countdown);
  387. // ajax发送验证码
  388. $.ajax({
  389. url: '/send_validation_code',
  390. type: 'POST',
  391. dataType: 'json',
  392. data: {
  393. phone: $(".phone_input").val(),
  394. },
  395. success: function (response) {
  396. console.log(response);
  397. response = JSON.parse(response)
  398. if (response.code == 200) {
  399. $.MsgBox.Alert("提示", "验证码发送成功");
  400. } else {
  401. $.MsgBox.Alert("提示", response.msg ? response.msg : "验证码发送失败");
  402. }
  403. },
  404. error: function () {
  405. }
  406. });
  407. })
  408. function initCountdown() {
  409. const storedCountdown = sessionStorage.getItem('countdown');
  410. if (storedCountdown) {
  411. countdown = parseInt(storedCountdown, 10);
  412. if (countdown > 0) {
  413. startCountdown();
  414. }
  415. }
  416. }
  417. initCountdown();
  418. function phoneValid() {
  419. const regex = /^1[3-9]\d{9}$/;
  420. var phone = $(".phone_input").val();
  421. if (phone == "" || !regex.test(phone)){
  422. return false;
  423. }
  424. return true;
  425. }
  426. $(".login_button").on("click",function(){
  427. if ($("#employeeForm").hasClass("active")) {
  428. if (!phoneValid()){
  429. $.MsgBox.Alert("提示", "手机号为空或不合法,请检查");
  430. return;
  431. }
  432. const codeRegex = /^\d{4}$/;
  433. var code = $(".code_input").val();
  434. if (code == "" || !codeRegex.test(code)){
  435. $.MsgBox.Alert("提示", "验证码为4位数字,请检查");
  436. return;
  437. }
  438. $.ajax({
  439. url: '/valid_code',
  440. type: 'POST',
  441. dataType: 'json',
  442. data: {
  443. phone: $(".phone_input").val(),
  444. code: code,
  445. },
  446. success: function (response) {
  447. console.log(response);
  448. response = JSON.parse(response)
  449. if (response.status == 0) {
  450. $.ajax({
  451. url: '/phone_login',
  452. type: 'POST',
  453. dataType: 'json',
  454. data: {
  455. phone: $(".phone_input").val(),
  456. },
  457. success: function (response) {
  458. console.log(response);
  459. console.log(response.data);
  460. console.log(response.data.staffId);
  461. // response = JSON.parse(response)
  462. if (response.code == 200) {
  463. window.location.href = '/info?staffId='+response.data.staffId;
  464. } else {
  465. $.MsgBox.Alert("提示", response.msg);
  466. }
  467. },
  468. error: function () {
  469. }
  470. });
  471. } else {
  472. $.MsgBox.Alert("提示", response.err);
  473. }
  474. },
  475. error: function () {
  476. }
  477. });
  478. } else {
  479. if ($(".account_input").val() == "") {
  480. $.MsgBox.Alert("提示", "请输入账号!");
  481. return;
  482. }
  483. if ($(".password_input").val() == "") {
  484. $.MsgBox.Alert("提示", "请输入密码!");
  485. return;
  486. }
  487. $.ajax({
  488. url: '/mgr_login',
  489. type: 'POST',
  490. dataType: 'json',
  491. data: {
  492. userName: $(".account_input").val(),
  493. password: $(".password_input").val(),
  494. },
  495. success: function (response) {
  496. console.log(response);
  497. response = JSON.parse(response)
  498. if (response.code == 200) {
  499. console.log(response.data.access_token);
  500. console.log(response.type);
  501. sessionStorage.setItem('token',response.type);
  502. window.location.href = '/mgr';
  503. } else {
  504. $.MsgBox.Alert("提示", response.msg);
  505. }
  506. },
  507. error: function () {
  508. }
  509. });
  510. }
  511. })
  512. })
  513. // 切换登陆页面
  514. document.getElementById("employeeBtn").addEventListener("click", function() {
  515. document.getElementById("employeeForm").classList.add("active");
  516. document.getElementById("adminForm").classList.remove("active");
  517. document.getElementById("choose_administrator").classList.remove("background");
  518. document.getElementById("choose_employee").classList.add("background");
  519. });
  520. document.getElementById("adminBtn").addEventListener("click", function() {
  521. document.getElementById("employeeForm").classList.remove("active");
  522. document.getElementById("adminForm").classList.add("active");
  523. document.getElementById("choose_employee").classList.remove("background");
  524. document.getElementById("choose_administrator").classList.add("background");
  525. });
  526. document.getElementById("password_toggle").addEventListener("click", function() {
  527. let passwordInput = document.getElementById("password_input")
  528. if (passwordInput.type === 'password') {
  529. passwordInput.type ='text';
  530. document.getElementById("password_toggle").src = "/static/img/open.png"
  531. } else {
  532. passwordInput.type = "password";
  533. document.getElementById("password_toggle").src = "/static/img/close.png"
  534. }
  535. });
  536. </script>
  537. </body>
  538. </html>