diff --git a/src/api/auth.api.ts b/src/api/auth.api.ts index 64fb97b2..35c28cf9 100644 --- a/src/api/auth.api.ts +++ b/src/api/auth.api.ts @@ -61,6 +61,8 @@ export interface LoginFormData { captchaKey: string; /** 验证码 */ captchaCode: string; + /** 记住我 */ + rememberMe: boolean; } /** 登录响应 */ diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 5b7c90d9..3e5642ed 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -1,132 +1,106 @@ @@ -168,7 +140,7 @@ const loginFormRef = ref(); const isDark = ref(settingsStore.theme === ThemeMode.DARK); // 是否暗黑模式 const loading = ref(false); // 按钮 loading 状态 -const isCapslock = ref(false); // 是否大写锁定 +const isCapsLock = ref(false); // 是否大写锁定 const captchaBase64 = ref(); // 验证码图片Base64字符串 const loginFormData = ref({ @@ -176,6 +148,7 @@ const loginFormData = ref({ password: "123456", captchaKey: "", captchaCode: "", + rememberMe: false, }); const loginRules = computed(() => { @@ -183,14 +156,14 @@ const loginRules = computed(() => { username: [ { required: true, - trigger: "blur", + trigger: "change", message: t("login.message.username.required"), }, ], password: [ { required: true, - trigger: "blur", + trigger: "change", message: t("login.message.password.required"), }, { @@ -202,7 +175,7 @@ const loginRules = computed(() => { captchaCode: [ { required: true, - trigger: "blur", + trigger: "change", message: t("login.message.captchaCode.required"), }, ], @@ -219,12 +192,13 @@ function getCaptcha() { // 登录提交处理 async function handleLoginSubmit() { - // 1. 表单验证 - const valid = await loginFormRef.value?.validate(); - if (!valid) return; - - loading.value = true; try { + // 1. 表单验证 + const valid = await loginFormRef.value?.validate(); + if (!valid) return; + + loading.value = true; + // 2. 执行登录 await userStore.login(loginFormData.value); @@ -275,10 +249,10 @@ const toggleTheme = () => { }; // 检查输入大小写 -function checkCapslock(event: KeyboardEvent) { +function checkCapsLock(event: KeyboardEvent) { // 防止浏览器密码自动填充时报错 if (event instanceof KeyboardEvent) { - isCapslock.value = event.getModifierState("CapsLock"); + isCapsLock.value = event.getModifierState("CapsLock"); } } @@ -288,138 +262,33 @@ const setLoginCredentials = (username: string, password: string) => { loginFormData.value.password = password; }; -onMounted(() => { - getCaptcha(); -}); +// 未实现功能提示 +const unfinished = () => { + ElMessage.warning("该功能尚未完成,敬请期待!"); +}; + +onMounted(() => getCaptcha());