From 8f46526cc0943206f8f42359d2937d6db98b3085 Mon Sep 17 00:00:00 2001 From: valarchie <343928303@qq.com> Date: Sun, 2 Jul 2023 20:57:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BD=BF=E7=94=A8getConfig=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=9D=A5=E8=8E=B7=E5=8F=96=E7=B3=BB=E7=BB=9F=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/common.ts | 12 ++++++++++-- src/views/login/index.vue | 15 ++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/api/common.ts b/src/api/common.ts index 1e1e1d9..2e5541c 100644 --- a/src/api/common.ts +++ b/src/api/common.ts @@ -1,14 +1,17 @@ import { http } from "@/utils/http"; export type CaptchaDTO = { - /** 验证码开关 */ - isCaptchaOn: boolean; /** 验证码的base64图片 */ captchaCodeImg: string; /** 验证码对应的缓存key */ captchaCodeKey: string; }; +export type ConfigDTO = { + /** 验证码开关 */ + isCaptchaOn: boolean; +}; + export type LoginByPasswordDTO = { /** 用户名 */ username: string; @@ -32,6 +35,11 @@ export type RefreshTokenResult = { }; }; +/** 获取系统配置接口 */ +export const getConfig = () => { + return http.request>("get", "/getConfig"); +}; + /** 验证码接口 */ export const getCaptchaCode = () => { return http.request>("get", "/captchaImage"); diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 25be3eb..ef17561 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -48,6 +48,7 @@ defineOptions({ // TODO 当请求验证码过于频繁的话 服务器会报错 但是前端没有反应 这块需要处理一下, 通过axios处理一下 const captchaCodeBase64 = ref(""); + const isCaptchaOn = ref(false); const router = useRouter(); @@ -116,10 +117,8 @@ function onkeypress({ code }: KeyboardEvent) { async function getCaptchaCode() { await CommonAPI.getCaptchaCode().then(res => { - isCaptchaOn.value = res.data.isCaptchaOn; captchaCodeBase64.value = `data:image/gif;base64,${res.data.captchaCodeImg}`; ruleForm.captchaCodeKey = res.data.captchaCodeKey; - console.log(ruleForm); }); } @@ -130,8 +129,15 @@ watch(isRememberMe, newVal => { } }); -onBeforeMount(() => { - getCaptchaCode(); +onBeforeMount(async () => { + await CommonAPI.getConfig().then(res => { + isCaptchaOn.value = res.data.isCaptchaOn; + }); + + if (isCaptchaOn.value) { + getCaptchaCode(); + } + isRememberMe.value = getIsRememberMe(); if (isRememberMe.value) { ruleForm.password = getPassword(); @@ -140,7 +146,6 @@ onBeforeMount(() => { onMounted(() => { window.document.addEventListener("keypress", onkeypress); - getCaptchaCode(); }); onBeforeUnmount(() => {