فهرست منبع

feat: randcode

chenlei 1 ماه پیش
والد
کامیت
341ed03927

+ 21 - 15
后台管理/src/pages/Login/index.module.scss

@@ -1,12 +1,12 @@
 .Login {
   width: 100%;
   height: 100%;
-  background-image: url('../../assets/img/bg.jpg');
+  background-image: url("../../assets/img/bg.jpg");
   background-size: 100% 100%;
   position: relative;
 
   &::before {
-    content: '';
+    content: "";
     position: absolute;
     top: 0;
     left: 0;
@@ -15,7 +15,6 @@
   }
 
   :global {
-
     .main {
       border-radius: 6px;
       position: absolute;
@@ -43,35 +42,45 @@
 
         input::-webkit-input-placeholder {
           /* WebKit browsers */
-          color: rgba(255, 255, 255, .6);
+          color: rgba(255, 255, 255, 0.6);
         }
 
         input:-moz-placeholder {
           /* Mozilla Firefox 4 to 18 */
-          color: rgba(255, 255, 255, .6);
+          color: rgba(255, 255, 255, 0.6);
         }
 
         input::-moz-placeholder {
           /* Mozilla Firefox 19+ */
-          color: rgba(255, 255, 255, .6);
+          color: rgba(255, 255, 255, 0.6);
         }
 
         input:-ms-input-placeholder {
           /* Internet Explorer 10+ */
-          color: rgba(255, 255, 255, .6);
+          color: rgba(255, 255, 255, 0.6);
         }
 
         .inputBoxRow {
           width: 100%;
           margin: 0 auto 40px;
 
-
-
           .ant-input-suffix .ant-input-password-icon {
             color: #fff;
             font-size: 22px;
           }
         }
+        .inputBoxRow2 {
+          position: relative;
+
+          .loginCode {
+            z-index: 110;
+            cursor: pointer;
+            position: absolute;
+            top: 50%;
+            right: 0;
+            transform: translateY(-50%);
+          }
+        }
 
         .ant-input-prefix {
           margin-right: 10px;
@@ -95,7 +104,6 @@
           line-height: 60px;
           background-clip: content-box;
           color: #fff;
-
         }
 
         input:-webkit-autofill {
@@ -105,7 +113,6 @@
           -webkit-box-shadow: 0 0 0px 1000px transparent inset !important; //填充阴影,可以用来遮住背景色
           background-color: transparent;
           transition: background-color 50000s ease-in-out 0s; //背景色透明  生效时长  过渡效果  启用时延迟的时间
-
         }
 
         .ant-input-affix-wrapper {
@@ -126,7 +133,7 @@
         }
 
         .ant-input-affix-wrapper-focused {
-          box-shadow: none
+          box-shadow: none;
         }
       }
 
@@ -139,10 +146,9 @@
           width: 100%;
           height: 50px;
           background-color: var(--themeColor2);
-          color: #94844B;
+          color: #94844b;
         }
       }
-
     }
   }
-}
+}

+ 40 - 3
后台管理/src/pages/Login/index.tsx

@@ -1,20 +1,22 @@
 import styles from "./index.module.scss";
 
 import { Input, Button } from "antd";
-import { UserOutlined, LockOutlined } from "@ant-design/icons";
-import { useState } from "react";
+import { UserOutlined, LockOutlined, NumberOutlined } from "@ant-design/icons";
+import { useCallback, useEffect, useState } from "react";
 import { Base64 } from "js-base64";
 import encodeStr from "@/utils/pass";
 import { setTokenInfo } from "@/utils/storage";
 import history from "@/utils/history";
 import { MessageFu } from "@/utils/message";
-import { userLoginAPI } from "@/store/action/layout";
+import { API_LoginGetCode, userLoginAPI } from "@/store/action/layout";
 import loginLogoImg from "@/assets/img/logo.png";
 
 export default function Login() {
   // 账号密码
   const [userName, setUserName] = useState("");
   const [passWord, setPassWord] = useState("");
+  const [code, setCode] = useState<any>("");
+  const [codeImg, setCodeImg] = useState<any>("");
 
   // 键盘按下回车事件
   const keyUpEntFu = (e: React.KeyboardEvent<HTMLInputElement>) => {
@@ -25,9 +27,11 @@ export default function Login() {
     // 非空判断
     if (userName === "") return MessageFu.warning("请输入账号!");
     else if (passWord === "") return MessageFu.warning("请输入密码!");
+    else if (code === "") return MessageFu.warning("请输入验证码!");
     const obj = {
       userName,
       passWord: encodeStr(Base64.encode(passWord)),
+      randCode: code,
     };
     const res: any = await userLoginAPI(obj);
     if (res.code === 0) {
@@ -37,8 +41,23 @@ export default function Login() {
       history.push("/");
     } else if (res.code === 3014)
       MessageFu.warning("账号不存在或密码错误,请联系管理员!");
+    LoginGetCodeFu();
   };
 
+  // 获取验证码
+  const LoginGetCodeFu = useCallback(async () => {
+    const res: any = await API_LoginGetCode();
+    const reader = new FileReader();
+    reader.readAsDataURL(res);
+    reader.onload = () => {
+      setCodeImg(reader.result);
+    };
+  }, []);
+
+  useEffect(() => {
+    LoginGetCodeFu();
+  }, [LoginGetCodeFu]);
+
   return (
     <div className={styles.Login}>
       <div className="main">
@@ -66,6 +85,24 @@ export default function Login() {
               maxLength={15}
             />
           </div>
+          <div className="inputBoxRow inputBoxRow2">
+            <Input
+              onKeyUp={(e) => keyUpEntFu(e)}
+              value={code}
+              onChange={(e) => setCode(e.target.value.trim())}
+              prefix={<NumberOutlined rev={undefined} />}
+              placeholder="请输入验证码"
+              maxLength={5}
+            />
+            {codeImg ? (
+              <img
+                onClick={LoginGetCodeFu}
+                className="loginCode"
+                src={codeImg}
+                alt=""
+              />
+            ) : null}
+          </div>
         </div>
 
         {/* 登录按钮 */}

+ 7 - 0
后台管理/src/store/action/layout.ts

@@ -17,6 +17,13 @@ export const passWordEditAPI = (data: any) => {
   return http.post("sys/user/updatePwd", { ...data });
 };
 
+/**
+ * 获取验证码
+ */
+export const API_LoginGetCode = () => {
+  return http.get("/admin/getRandCode", { responseType: "blob" });
+};
+
 const CancelToken = axios.CancelToken;
 /**
  * 上传封面图和附件

+ 3 - 3
后台管理/src/utils/http.ts

@@ -10,7 +10,7 @@ export const baseURL =
   // process.env.NODE_ENV === "development"
   //   ? "http://192.168.20.61:8052/api/"
   //   : "";
-  process.env.NODE_ENV === "development" ? "https://sit-jswl2.4dage.com" : "";
+  process.env.NODE_ENV === "development" ? "http://192.168.20.61:8052" : "";
 
 // 处理  类型“AxiosResponse<any, any>”上不存在属性“code”
 declare module "axios" {
@@ -46,7 +46,7 @@ http.interceptors.request.use(
   },
   function (err) {
     return Promise.reject(err);
-  }
+  },
 );
 
 let timeId = -1;
@@ -87,7 +87,7 @@ http.interceptors.response.use(
     }, 100);
 
     return Promise.reject(err);
-  }
+  },
 );
 
 // 导出 axios 实例