diff --git a/src/pages/login.vue b/src/pages/login.vue index 2b2985ab..3d5aafaa 100644 --- a/src/pages/login.vue +++ b/src/pages/login.vue @@ -32,9 +32,8 @@ const isPasswordVisible = ref(false) const errorMessage = ref('') // 背景图片 URL 和预加载 URL -const backgroundImageUrl = ref('') const backgroundImages = ref([]) -const isImageLoaded = ref(false) +const activeImageIndex = ref(0) // 是否开启双重验证 const isOTP = ref(false) @@ -49,43 +48,11 @@ let intervalTimer: NodeJS.Timeout | null = null async function fetchBackgroundImage() { try { backgroundImages.value = await api.get('/login/wallpapers') - if (backgroundImages.value && backgroundImages.value.length > 0) { - backgroundImages.value.sort(() => Math.random() - 0.5) - backgroundImageUrl.value = backgroundImages.value[0] - } } catch (e) { console.log(e) } } -// 切换背景图片函数 -function startBackgroundImageRotation() { - let currentIndex = 0 - - intervalTimer = setInterval(() => { - if (backgroundImages.value.length > 1) { - // 更新下一张图片索引 - const nextIndex = (currentIndex + 1) % backgroundImages.value.length - const nextImageUrl = backgroundImages.value[nextIndex] - // 使用预加载机制确保下一张图片已加载完成 - const img = new Image() - img.src = nextImageUrl - img.onload = () => { - // 开始淡入过渡 - isImageLoaded.value = false - // 延迟一小段时间触发淡入效果 - setTimeout(() => { - // 更新当前索引并切换背景图片 URL - currentIndex = nextIndex - backgroundImageUrl.value = nextImageUrl - // 切换完成后显示图片 - isImageLoaded.value = true - }, 1000) - } - } - }, 5000) -} - // 查询是否开启双重验证 const fetchOTP = debounce(async () => { const userid = usernameInput.value?.value @@ -216,6 +183,13 @@ function login() { }) } +// 初始化背景图片轮循 +function startBackgroundRotation() { + intervalTimer = setInterval(() => { + activeImageIndex.value = (activeImageIndex.value + 1) % backgroundImages.value.length + }, 5000) // 每5秒切换一次图片 +} + // 自动登录 onMounted(async () => { // 从Vuex Store中获取token和remember状态 @@ -228,8 +202,9 @@ onMounted(async () => { } else { // 获取背景图片 await fetchBackgroundImage() - // 开始背景图片定时切换 - startBackgroundImageRotation() + if (backgroundImages.value.length > 1) { + startBackgroundRotation() + } } }) @@ -240,79 +215,75 @@ onUnmounted(() => { @@ -322,4 +293,8 @@ onUnmounted(() => { .v-card-item__prepend { padding-inline-end: 0 !important; } + +.absolute-top-shift { + inset-block-start: calc(-4rem - env(safe-area-inset-top)); +}