From 0878020d8612da10b5304989fc7cef1687caa579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=A8=9C?= Date: Wed, 12 Feb 2025 15:22:42 +0800 Subject: [PATCH 1/2] =?UTF-8?q?gitignore=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E3=80=81=E6=B7=BB=E5=8A=A0=E9=82=AE=E7=AE=B1=E5=92=8C=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E4=BF=A1=E6=81=AF=E3=80=81=E5=AF=86=E7=A0=81=E5=8A=A0?= =?UTF-8?q?=E5=AF=86=E4=BC=A0=E8=BE=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 42 ++++++++ package.json | 6 +- src/api/auth.ts | 17 ++- src/lang/package/en.ts | 15 +++ src/lang/package/zh-cn.ts | 15 +++ src/store/modules/user.ts | 6 +- src/styles/login.scss | 19 +++- src/views/login/index.vue | 214 ++++++++++++++++++++++++++++++++------ 8 files changed, 291 insertions(+), 43 deletions(-) create mode 100755 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..4b7c870 --- /dev/null +++ b/.gitignore @@ -0,0 +1,42 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +.DS_Store +dist +dist-ssr +coverage +*.local + +/cypress/videos/ +/cypress/screenshots/ + +# Editor directories and files +.vscode +!.vscode/extensions.json +.idea +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? +.env +.env.development +package-lock.json + +*.tsbuildinfo + +.eslintignore +.eslintrc.cjs +.prettierignore +.prettierrc + +.gitee/ +.npmrc +.pnpm-lock.yaml diff --git a/package.json b/package.json index d027adb..48992e7 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "codemirror": "^5.65.17", "codemirror-editor-vue3": "^2.7.0", "color": "^4.2.3", + "crypto-js": "^4.2.0", "echarts": "^5.5.1", "element-plus": "^2.8.0", "exceljs": "^4.4.0", @@ -76,6 +77,7 @@ "@iconify-json/ep": "^1.1.16", "@types/codemirror": "^5.60.15", "@types/color": "^3.0.6", + "@types/crypto-js": "^4.2.2", "@types/lodash": "^4.17.7", "@types/node": "^20.14.15", "@types/nprogress": "^0.2.3", @@ -96,6 +98,7 @@ "eslint-plugin-prettier": "^5.2.1", "eslint-plugin-vue": "^9.27.0", "fast-glob": "^3.3.2", + "husky": "^8.0.3", "lint-staged": "^15.2.9", "postcss": "^8.4.41", "postcss-html": "^1.7.0", @@ -118,8 +121,7 @@ "vite-plugin-mock-dev-server": "^1.7.1", "vite-plugin-svg-icons": "^2.0.1", "vite-plugin-vue-devtools": "^7.3.8", - "vue-tsc": "^2.0.29", - "husky": "^8.0.3" + "vue-tsc": "^2.0.29" }, "license": "MIT", "engines": { diff --git a/src/api/auth.ts b/src/api/auth.ts index 9fd3604..69651dc 100644 --- a/src/api/auth.ts +++ b/src/api/auth.ts @@ -1,12 +1,15 @@ import request from "@/utils/request"; +import CryptoJS from "crypto-js"; // 导入 CryptoJS class AuthAPI { /** 注册 接口*/ - static signin(data: LoginData) { + static signin(data: SigninData) { + const hashPwd = CryptoJS.SHA256(data.passwd).toString(); + const newData = { ...data, passwd: hashPwd }; return request({ url: `/user/add`, method: "post", - params: data, + data: newData, }); } @@ -47,6 +50,16 @@ export interface LoginData { /** 昵称 */ name: string; } +export interface SigninData { + /** 用户名 */ + account: string; + /** 密码 */ + passwd: string; + /** 昵称 */ + name: string; + /** 邮箱 */ + email:string; +} export interface userUpade { account?: string; diff --git a/src/lang/package/en.ts b/src/lang/package/en.ts index 2030cec..c830ffe 100644 --- a/src/lang/package/en.ts +++ b/src/lang/package/en.ts @@ -28,6 +28,21 @@ export default { required: "Enter a password.", notMinThan: "The password cannot be less than 6 characters.", notMaxThan: "The password cannot be longer than 20 characters.", + regxMsg: "The password must contain uppercase letters, lowercase letters, and digits.", + }, + passwd: { + passwordMsg: "The password cannot be empty.", + required: "Enter a password.", + notMinThan: "The password cannot be less than 6 characters.", + notMaxThan: "The password cannot be longer than 20 characters.", + regxMsg: "The password must contain uppercase letters, lowercase letters, and digits.", + }, + email: { + emailMsg: "The email cannot be empty.", + required: "Enter an email.", + notMinThan: "The email cannot be less than 5 characters.", + notMaxThan: "The email cannot be longer than 20 characters.", + regxMsg: "The email format is incorrect.", }, loginTip: "The username or password is not correct.", loginToken: "The session has expired.Please login again.", diff --git a/src/lang/package/zh-cn.ts b/src/lang/package/zh-cn.ts index 92b20c9..2d0eaaf 100644 --- a/src/lang/package/zh-cn.ts +++ b/src/lang/package/zh-cn.ts @@ -28,6 +28,21 @@ export default { required: "请输入密码", notMinThan: "密码长度不能少于6个字符", notMaxThan: "密码长度不能大于20个字符", + regxMsg: "密码必须包含大写字母、小写字母、数字", + }, + passwd: { + passwordMsg: "密码不能为空", + required: "请输入密码", + notMinThan: "密码长度不能少于5个字符", + notMaxThan: "密码长度不能大于20个字符", + regxMsg: "密码必须包含大写字母、小写字母、数字", + }, + email: { + emailMsg: "邮箱不能为空", + required: "请输入邮箱", + notMinThan: "邮箱长度不能少于6个字符", + notMaxThan: "邮箱长度不能大于20个字符", + regxMsg: "邮箱格式不正确", }, loginTip: "用户名或密码错误", loginToken: "您的会话已过期,请重新登录", diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index 19ae887..ea3c931 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -1,4 +1,4 @@ -import AuthAPI, { type LoginData } from "@/api/auth"; +import AuthAPI, { SigninData, type LoginData } from "@/api/auth"; import { type UserInfo } from "@/api/user"; import { resetRouter } from "@/router"; import { store } from "@/store"; @@ -29,10 +29,10 @@ export const useUserStore = defineStore("user", () => { /** * 注册 * - * @param {LoginData} + * @param {signinData} * @returns */ - function signin(signinData: LoginData) { + function signin(signinData: SigninData) { return new Promise((resolve, reject) => { AuthAPI.signin(signinData) .then((data: any) => resolve(data)) diff --git a/src/styles/login.scss b/src/styles/login.scss index 1b91c99..3fd5db4 100644 --- a/src/styles/login.scss +++ b/src/styles/login.scss @@ -39,7 +39,7 @@ .password-from, .username-from { - margin-top: 24px; + margin-top: 15px; margin-bottom: unset !important; .el-input__inner { @@ -83,6 +83,21 @@ font-size: 16px; } } + .backToLogin { + display: flex; + align-items: center; + justify-content: center; + margin: 15px auto; + cursor: pointer; + color: var(--o-color-info); + &:hover { + color: var(--text-color-info-secondary); + transition: 500ms; + } + } + .not-click{ + cursor: not-allowed; + } } .icp-info { @@ -108,4 +123,4 @@ background: var(--el-input-bg-color); border-radius: 5px; } -} \ No newline at end of file +} diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 7c8a262..9ba34bd 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -11,26 +11,14 @@ - + + + +
@@ -126,7 +187,7 @@ import "@/styles/login.scss"; import type { FormInstance } from "element-plus"; import { useRoute } from "vue-router"; import { useUserStore } from "@/store"; -import { type LoginData } from "@/api/auth"; +import { SigninData, type LoginData } from "@/api/auth"; import defaultSettings from "@/settings"; import HeaderBar from "@/components/HeaderBar/index.vue"; import { @@ -147,17 +208,67 @@ const loading = ref(false); const signinLoding = ref(false); // 登录表单ref const loginFormRef = ref(); +const signinFormRef = ref(); const loginData = ref({ name: "", account: "", password: "", }); +const signinData = ref({ + name: "", + account: "", + passwd: "", + email: "", +}); // 是否是注册页面 const isSigIn = ref(false); const loginRules = computed(() => { + return { + account: [ + { + required: true, + trigger: ["blur", "change"], + message: t("login.message.username.usernameMsg"), + }, + { + min: 5, + message: t("login.message.username.notMinThan"), + trigger: "blur", + }, + { + max: 20, + message: t("login.message.username.notMaxThan"), + trigger: "change", + }, + { + pattern: /^[a-z0-9]+$/, + message: t("login.message.username.regxMsg"), + trigger: ["blur", "change"], + }, + ], + password: [ + { + required: true, + trigger: ["blur", "change"], + message: t("login.message.password.passwordMsg"), + }, + { + min: 6, + message: t("login.message.password.notMinThan"), + trigger: "blur", + }, + { + max: 20, + message: t("login.message.password.notMaxThan"), + trigger: "change", + }, + ], + }; +}); +const signinRules = computed(() => { return { name: [ { @@ -193,7 +304,7 @@ const loginRules = computed(() => { trigger: ["blur", "change"], }, ], - password: [ + passwd: [ { required: true, trigger: ["blur", "change"], @@ -209,6 +320,33 @@ const loginRules = computed(() => { message: t("login.message.password.notMaxThan"), trigger: "change", }, + { + pattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).+$/, + message: t("login.message.password.regxMsg"), + trigger: "blur", + }, + ], + email: [ + { + required: true, + trigger: ["blur", "change"], + message: t("login.message.email.emailMsg"), + }, + { + min: 5, + message: t("login.message.email.notMinThan"), + trigger: "blur", + }, + { + max: 20, + message: t("login.message.email.notMaxThan"), + trigger: "change", + }, + { + pattern: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/, + message: t("login.message.email.regxMsg"), + trigger: "blur", + }, ], }; }); @@ -246,7 +384,9 @@ const handleLoginSubmit = () => { }); }; -// 跳转到注册 +/** + * 跳转到注册 + */ const handleSigIn = () => { isSigIn.value = true; loginFormRef.value?.resetFields(); @@ -256,18 +396,23 @@ const handleSigIn = () => { * 返回登录 */ const handleBackLogin = () => { - loginFormRef.value?.resetFields(); + if(signinLoding.value){ + return; + } + signinFormRef.value?.resetFields(); isSigIn.value = false; }; -// 注册请求 +/** + * 注册请求 + */ const handleSigInSubmit = () => { - loginFormRef.value?.validate((valid) => { + signinFormRef.value?.validate((valid) => { if (valid) { signinLoding.value = true; userStore - .signin(loginData.value) - .then((res) => { + .signin(signinData.value) + .then(() => { ElMessage({ showClose: true, message: t("login.signinSuccessful"), @@ -275,6 +420,7 @@ const handleSigInSubmit = () => { customClass: "o-message--success", duration: 3000, }); + handleBackLogin(); }) .finally(() => { signinLoding.value = false; -- Gitee From 406f42eae405e58312481ec5f71713105d9eb6ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=A8=9C?= Date: Wed, 12 Feb 2025 16:09:46 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E5=8A=A0=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/auth.ts | 6 +++--- src/views/login/index.vue | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/api/auth.ts b/src/api/auth.ts index 69651dc..0afbded 100644 --- a/src/api/auth.ts +++ b/src/api/auth.ts @@ -15,10 +15,12 @@ class AuthAPI { /** 登录 接口*/ static login(data: LoginData) { + const hashPwd = CryptoJS.SHA256(data.password).toString(); + const newData = { ...data, password: hashPwd }; return request({ url: `/user/login`, method: "get", - params: data, + params: newData, }); } @@ -47,8 +49,6 @@ export interface LoginData { account: string; /** 密码 */ password: string; - /** 昵称 */ - name: string; } export interface SigninData { /** 用户名 */ diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 9ba34bd..4889435 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -211,7 +211,6 @@ const loginFormRef = ref(); const signinFormRef = ref(); const loginData = ref({ - name: "", account: "", password: "", }); -- Gitee