clientId为空重新加载
This commit is contained in:
parent
63a06c7eca
commit
1a77522dfb
@ -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<boolean> {
|
||||
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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user