|
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>页面登录</title>
- <style>
- body{
- margin: 0;
- }
- li {
- list-style-type: none;
- }
- @media screen and (orientation: portrait) {
- .login {
- width: 100vw;
- height: 100vh;
- background-image: url("/static/img/phoneBgc.jpg");
- background-size: 100% 100%;
- background-repeat: no-repeat;
- }
- .register {
- background-image: url("/static/img/registerBgc.jpg") !important;
- padding-top: 15vh;
- }
- .logo {
- width: 15vw;
- margin: 4vw 0 0 4vw;
- }
- .login_title {
- width: 100vw;
- font-size: 8vw;
- text-align: center;
- margin-top: 15vh;
- }
- .input_box {
- width: 100vw;
- height: 25vw;
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- margin-top: 5vh;
- position: relative;
- }
- .phone_input, .account_input{
- width: 50vw;
- height: 11vw;
- border-radius: 2vw;
- background-color: transparent;
- font-size: 3vw;
- padding-left: 2vw;
- border: 1px solid #000;
- position: absolute;
- top: 0vw;
- }
- .code_input, .password_input{
- width: 50vw;
- height: 11vw;
- margin-top: 2vh;
- border-radius: 2vw;
- padding-left: 2vw;
- font-size: 3vw;
- background-color: transparent;
- border: 1px solid #000;
- position: absolute;
- top: 10vw;
- }
- .login_button {
- width: 40vw;
- height: 5vh;
- background-color: rgb(101, 161, 255);
- border-radius: 10vw;
- display: flex;
- justify-content: center;
- align-items: center;
- color:#fff;
- font-size: 4vw;
- margin: 2vh 0 0 30vw;
- }
- #sendCodeBtn {
- position: absolute;
- font-size: 2.5vw;
- top: 18.5vw;
- right: 30vw;
- border-left: 2px solid;
- padding-left: 2vw;
- border: none;
- background: transparent;
- }
- .employee {
- display: flex;
- align-items: center;
- }
- .administrator {
- display: flex;
- align-items: center;
- margin-left: 5vw;
- }
- .choose_employee {
- width: 2vw;
- height: 2vw;
- border-radius: 50%;
- border: 2px solid #000;
- margin-right: 1vw;
- }
- .choose_administrator {
- width: 2vw;
- height: 2vw;
- border-radius: 50%;
- border: 2px solid #000;
- margin-right: 1vw;
- }
- .login_style {
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 2.5vw;
- margin-top: 2vh;
- }
- .hidden {
- display: none;
- }
- .active {
- display: flex;
- }
- .background {
- background-color: #000;
- }
- .password-container {
- position: relative;
- }
- .password_toggle {
- position: absolute;
- width: 5vw;
- top: 18vw;
- right: 26vw;
- }
- }
- @media screen and (orientation: landscape) {
- input:focus {
- border: 0.1vw solid #000;
- outline: none; /* 可选,用于去除默认的外边框样式 */
- }
-
- .login {
- width: 100vw;
- height: 100vh;
- background-image: url("/static/img/phoneBgc_pc.jpg");
- background-size: 100% 100%;
- background-repeat: no-repeat;
- position: relative;
- }
-
- .PC_img {
- width: 52.6vw;
- height: 64.44vh;
- background-image: url("/static/img/loginBox.png");
- background-size: 100% 100%;
- background-repeat: no-repeat;
- position: absolute;
- top: 18.88vh;
- left: 23.7vw;
- }
-
- .register {
- background-image: url("/static/img/registerBgc_pc.jpg") !important;
- }
-
- .logo {
- width: 15vh;
- margin: 4vh 0 0 4vh;
- }
-
- .login_title {
- /* width: 100vw; */
- font-size: 4vh;
- text-align: center;
- position: absolute;
- z-index: 10;
- top: 28vh;
- margin-left: 58vw;
- /* margin-top: 15vh;*/
- }
-
- .input_box {
- flex-direction: column;
- justify-content: center;
- align-items: center;
- margin-top: 15vh;
- position: relative;
- }
-
- .phone_input, .account_input {
- width: 15vw;
- height: 6.66vh;
- border-radius: 2vh;
- background-color: transparent;
- font-size: 1.5vw;
- padding-left: 2vh;
- padding-right: 5vw;
- border: 0.1vw solid #000;
- margin-left: 25vw;
- }
-
-
- .code_input, .password_input {
- width: 15vw;
- height: 6.66vh;
- margin-top: 2vw;
- border-radius: 2vh;
- padding-left: 2vh;
- font-size: 1.5vw;
- padding-right: 5vw;
- background-color: transparent;
- border: 0.1vw solid #000;
- margin-left: 25vw;
- }
-
- .login_button {
- width: 16vw;
- height: 3vw;
- background-color: rgb(101, 161, 255);
- border-radius: 10vh;
- display: flex;
- justify-content: center;
- align-items: center;
- color: #fff;
- font-size: 2vw;
- /* margin: 2vh 0 0 30vh; */
- position: absolute;
- left: 55vw;
- top: 65vh;
- }
-
-
- #sendCodeBtn {
- position: absolute;
- font-size: 1.5vh;
- top: 11.5vh;
- right: 27.3vw;
- border-left: 0.1vw solid;
- padding-left: 1vh;
- display: flex;
- align-items: center;
- height: 3vw;
- border: none;
- background: transparent;
- }
-
- .employee {
- display: flex;
- align-items: center;
- }
-
- .administrator {
- display: flex;
- align-items: center;
- margin-left: 3vw;
- }
-
- .hand:hover {
- cursor: pointer;
- }
-
- .choose_employee {
- width: 2vh;
- height: 2vh;
- border-radius: 50%;
- border: 0.1vw solid #000;
- margin-right: 1vh;
- }
-
- .choose_administrator {
- width: 2vh;
- height: 2vh;
- border-radius: 50%;
- border: 0.1vw solid #000;
- margin-right: 1vh;
- }
-
- .login_style {
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 1vw;
- margin-top: 2vw;
- position: absolute;
- left: 54.8vw;
- }
-
- .hidden {
- display: none;
- }
-
- .active {
- display: flex;
- }
-
- .background {
- background-color: #000;
- }
-
- .password-container {
- position: relative;
- }
-
- .password_toggle {
- width: 3vw;
- position: absolute;
- font-size: 1.5vh;
- top: 11.5vh;
- right: 28.5vw;
- padding-left: 0.5vh;
- }
-
- #scroll-to-top-btn {
- display: none;
- position: fixed;
- right: 20px;
- bottom: 20px;
- width: 7vh;
- height: 10vw;
- color: #fff;
- border: none;
- border-radius: 5px;
- font-size: 3vh;
- cursor: pointer;
- }
-
- }
- button:disabled {
- color: black !important;
- }
- </style>
- </head>
- <body>
- <!-- 登录页面 -->
- <div class="login">
- <img class="logo" src="/static/img/logo.png" alt="">
- <div class="PC_img"></div>
- <div class="login_title">请 登 录</div>
- <div id="employeeForm" class="input_box hidden active">
- <input class="phone_input" type="text" placeholder="请输入手机号">
- <input class="code_input" type="text" placeholder="请输入验证码">
- <button id="sendCodeBtn" class="btn">发送验证码</button>
- </div>
- <div id="adminForm" class="input_box hidden password-container">
- <input class="account_input" type="text" placeholder="请输入账号">
- <input id="password_input" class="password_input" type="password" placeholder="请输入密码">
- <img id="password_toggle" class="password_toggle hand" src="/static/img/close.png" alt="">
- </div>
- <div class="login_style">
- <div id="employeeBtn" class="employee hand">
- <div id="choose_employee" class="choose_employee background"></div>
- <div>员工登录</div>
- </div>
- <div id="adminBtn" class="administrator hand">
- <div id="choose_administrator" class="choose_administrator"></div>
- <div>管理员登录</div>
- </div>
- </div>
- <div class="login_button hand">登 录</div>
- </div>
- <script src="/static/js/jquery.min.js"></script>
- <script src="/static/js/msg-box.js"></script>
- <script>
- $(function(){
- console.log("{{.type}}");
- if ("{{.type}}" == "mgr") {
- $("#adminBtn").click();
- }
- $.MsgBox = {
- Alert: function(title, msg) {
- GenerateHtml("alert", title, msg);
- btnOk(); //alert只是弹出消息,因此没必要用到回调函数callback
- btnNo();
- },
- Confirm: function(title, msg, callback) {
- GenerateHtml("confirm", title, msg);
- btnOk(callback);
- btnNo();
- }
- }
-
-
- const sendCodeBtn = $('#sendCodeBtn');
- let countdown = 30;
- let timer;
-
- function startCountdown() {
- sendCodeBtn.attr("disabled", "disabled");
- sendCodeBtn.html(`${countdown}秒`);
- timer = setInterval(() => {
- console.log(countdown);
- countdown--;
- sessionStorage.setItem('countdown',countdown);
- sendCodeBtn.html(`${countdown}秒`);
- if (countdown <= 0) {
- clearInterval(timer);
- sendCodeBtn.html('发送验证码');
- sendCodeBtn.removeAttr("disabled");
- countdown = 30;
- }
- }, 1000);
- }
- $("#sendCodeBtn").on("click",function(){
- if (!phoneValid()){
- $.MsgBox.Alert("提示", "手机号为空或不合法,请检查");
- return;
- }
- countdown = 30;
- startCountdown();
- sessionStorage.setItem('countdown',countdown);
- // ajax发送验证码
- $.ajax({
- url: '/send_validation_code',
- type: 'POST',
- dataType: 'json',
- data: {
- phone: $(".phone_input").val(),
- },
- success: function (response) {
- console.log(response);
- response = JSON.parse(response)
- if (response.code == 200) {
- $.MsgBox.Alert("提示", "验证码发送成功");
- } else {
- $.MsgBox.Alert("提示", response.msg ? response.msg : "验证码发送失败");
- }
- },
- error: function () {
- }
- });
- })
-
- function initCountdown() {
- const storedCountdown = sessionStorage.getItem('countdown');
- if (storedCountdown) {
- countdown = parseInt(storedCountdown, 10);
- if (countdown > 0) {
- startCountdown();
- }
- }
- }
- initCountdown();
-
- function phoneValid() {
- const regex = /^1[3-9]\d{9}$/;
- var phone = $(".phone_input").val();
- if (phone == "" || !regex.test(phone)){
- return false;
- }
- return true;
- }
-
- $(".login_button").on("click",function(){
- if ($("#employeeForm").hasClass("active")) {
- if (!phoneValid()){
- $.MsgBox.Alert("提示", "手机号为空或不合法,请检查");
- return;
- }
- const codeRegex = /^\d{4}$/;
- var code = $(".code_input").val();
- if (code == "" || !codeRegex.test(code)){
- $.MsgBox.Alert("提示", "验证码为4位数字,请检查");
- return;
- }
- $.ajax({
- url: '/valid_code',
- type: 'POST',
- dataType: 'json',
- data: {
- phone: $(".phone_input").val(),
- code: code,
- },
- success: function (response) {
- console.log(response);
- response = JSON.parse(response)
- if (response.status == 0) {
- $.ajax({
- url: '/phone_login',
- type: 'POST',
- dataType: 'json',
- data: {
- phone: $(".phone_input").val(),
- },
- success: function (response) {
- console.log(response);
- console.log(response.data);
- console.log(response.data.staffId);
- // response = JSON.parse(response)
- if (response.code == 200) {
- window.location.href = '/info?staffId='+response.data.staffId;
-
- } else {
- $.MsgBox.Alert("提示", response.msg);
- }
- },
- error: function () {
- }
- });
-
- } else {
- $.MsgBox.Alert("提示", response.err);
- }
- },
- error: function () {
- }
- });
- } else {
- if ($(".account_input").val() == "") {
- $.MsgBox.Alert("提示", "请输入账号!");
- return;
- }
- if ($(".password_input").val() == "") {
- $.MsgBox.Alert("提示", "请输入密码!");
- return;
- }
-
- $.ajax({
- url: '/mgr_login',
- type: 'POST',
- dataType: 'json',
- data: {
- userName: $(".account_input").val(),
- password: $(".password_input").val(),
- },
- success: function (response) {
- console.log(response);
- response = JSON.parse(response)
- if (response.code == 200) {
- console.log(response.data.access_token);
- console.log(response.type);
- sessionStorage.setItem('token',response.type);
- window.location.href = '/mgr';
-
- } else {
- $.MsgBox.Alert("提示", response.msg);
- }
- },
- error: function () {
- }
- });
- }
- })
-
- })
- // 切换登陆页面
- document.getElementById("employeeBtn").addEventListener("click", function() {
- document.getElementById("employeeForm").classList.add("active");
- document.getElementById("adminForm").classList.remove("active");
- document.getElementById("choose_administrator").classList.remove("background");
- document.getElementById("choose_employee").classList.add("background");
- });
- document.getElementById("adminBtn").addEventListener("click", function() {
- document.getElementById("employeeForm").classList.remove("active");
- document.getElementById("adminForm").classList.add("active");
- document.getElementById("choose_employee").classList.remove("background");
- document.getElementById("choose_administrator").classList.add("background");
- });
- document.getElementById("password_toggle").addEventListener("click", function() {
- let passwordInput = document.getElementById("password_input")
- if (passwordInput.type === 'password') {
- passwordInput.type ='text';
- document.getElementById("password_toggle").src = "/static/img/open.png"
- } else {
- passwordInput.type = "password";
- document.getElementById("password_toggle").src = "/static/img/close.png"
- }
- });
-
-
-
-
- </script>
- </body>
- </html>
|