From 1a77522dfbdbb1f9741cc7322d78691038744582 Mon Sep 17 00:00:00 2001 From: cuijiawang Date: Tue, 23 Sep 2025 17:27:12 +0800 Subject: [PATCH] =?UTF-8?q?clientId=E4=B8=BA=E7=A9=BA=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/login/index.vue | 48 ++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 482fd74..21c4aee 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -77,8 +77,14 @@ const ruleForm = reactive({ const onLogin = async (formEl: FormInstance | undefined) => { loading.value = true; if (!formEl) return; - await formEl.validate((valid, fields) => { + await formEl.validate(async (valid, fields) => { if (valid) { + // 确保clientId不为空 + const hasClientId = await ensureClientId(); + if (!hasClientId) { + loading.value = false; + return; + } CommonAPI.loginByPassword({ username: ruleForm.username, password: rsaEncrypt(ruleForm.password), @@ -127,6 +133,38 @@ async function getCaptchaCode() { } } +/** 获取系统配置 */ +async function fetchConfig() { + try { + const res = await CommonAPI.getConfig(); + isCaptchaOn.value = res.data.isCaptchaOn; + isPhoneRegisterOn.value = res.data.isPhoneRegisterOn; + clientId.value = res.data.clientId; + useUserStoreHook().SET_DICTIONARY(res.data.dictionary); + return true; + } catch (error) { + console.error("获取系统配置失败:", error); + return false; + } +} + +/** 确保clientId不为空 */ +async function ensureClientId(): Promise { + if (!clientId.value) { + message("正在获取系统配置...", { type: "info" }); + const success = await fetchConfig(); + if (!success) { + message("获取系统配置失败,请刷新页面重试", { type: "error" }); + return false; + } + if (!clientId.value) { + message("系统配置异常,请联系管理员", { type: "error" }); + return false; + } + } + return true; +} + watch(isRememberMe, newVal => { saveIsRememberMe(newVal); if (newVal === false) { @@ -135,13 +173,7 @@ watch(isRememberMe, newVal => { }); onBeforeMount(async () => { - await CommonAPI.getConfig().then(res => { - isCaptchaOn.value = res.data.isCaptchaOn; - isPhoneRegisterOn.value = res.data.isPhoneRegisterOn; - clientId.value = res.data.clientId; - useUserStoreHook().SET_DICTIONARY(res.data.dictionary); - }); - + await fetchConfig(); await getCaptchaCode(); isRememberMe.value = getIsRememberMe();