Просмотр исходного кода

!1574 修复首次登录网站时的登录问题
Merge pull request !1574 from samisgod/next

zuohuaijun 1 год назад
Родитель
Сommit
25c78308c1
3 измененных файлов с 25 добавлено и 14 удалено
  1. 2 0
      Web/src/App.vue
  2. 1 0
      Web/src/types/pinia.d.ts
  3. 22 14
      Web/src/views/login/component/account.vue

+ 2 - 0
Web/src/App.vue

@@ -136,6 +136,8 @@ const loadSysInfo = () => {
 			// 登录验证
 			themeConfig.value.secondVer = data.sysSecondVer;
 			themeConfig.value.captcha = data.sysCaptcha;
+			// 更新配置加载状态
+			themeConfig.value.isLoaded = true;
 
 			// 更新 favicon
 			updateFavicon(data.sysLogo);

+ 1 - 0
Web/src/types/pinia.d.ts

@@ -99,5 +99,6 @@ declare interface ThemeConfigState {
 		icpUrl: string; // Icp地址
 		secondVer: boolean; // 是否开启二级验证
 		captcha: boolean; // 是否开启验证码
+		isLoaded: boolean; // 是否加载完成
 	};
 }

+ 22 - 14
Web/src/views/login/component/account.vue

@@ -75,7 +75,7 @@
 </template>
 
 <script lang="ts" setup name="loginAccount">
-import { reactive, computed, ref, onMounted, defineAsyncComponent, onUnmounted } from 'vue';
+import { reactive, computed, ref, onMounted, defineAsyncComponent, onUnmounted, watch } from 'vue';
 import { useRoute, useRouter } from 'vue-router';
 import { ElMessage, InputInstance } from 'element-plus';
 import { useI18n } from 'vue-i18n';
@@ -143,19 +143,27 @@ onMounted(async () => {
 	const accessToken = route.query.token;
 	if (accessToken) await saveTokenAndInitRoutes(accessToken);
 
-	// 获取登录配置
-	state.secondVerEnabled = themeConfig.value.secondVer ?? true;
-	state.captchaEnabled = themeConfig.value.captcha ?? true;
-
-	// 获取验证码
-	getCaptcha();
-
-	// 注册验证码过期计时器
-	if (state.captchaEnabled) {
-		timer = setInterval(() => {
-			if (state.expirySeconds > 0) state.expirySeconds -= 1;
-		}, 1000);
-	}
+	watch(
+		() => themeConfig.value.isLoaded,
+		(isLoaded) => {
+			if (isLoaded) {
+				// 获取登录配置
+				state.secondVerEnabled = themeConfig.value.secondVer ?? true;
+				state.captchaEnabled = themeConfig.value.captcha ?? true;
+
+				// 获取验证码
+				getCaptcha();
+
+				// 注册验证码过期计时器
+				if (state.captchaEnabled) {
+					timer = setInterval(() => {
+						if (state.expirySeconds > 0) state.expirySeconds -= 1;
+					}, 1000);
+				}
+			}
+		},
+		{ immediate: true }
+	);
 
 	// 检测大小写按键/CapsLK
 	document.addEventListener('keyup', handleKeyPress);