feat:增加Loading组件

This commit is contained in:
2025-12-19 17:33:40 +08:00
parent 4fc8d4eecc
commit c2516e04b5

View File

@@ -1,8 +1,4 @@
<template>
<div>
<!-- 简化版优雅加载动画 -->
<Transition name="fade">
<div v-if="isLoading" class="simple-elegant-loading">
<div class="loading-content">
<!-- 动态加载动画 -->
<div class="loading-spinner">
@@ -19,77 +15,13 @@
<p>请稍候...</p>
</div>
</div>
</div>
</Transition>
<!-- 主内容 -->
<Transition name="slide-up">
<div v-show="!isLoading">
<DefaultTheme.Layout v-bind="$attrs">
<template #doc-before>
<ArticleMetadat />
</template>
</DefaultTheme.Layout>
</div>
</Transition>
</div>
</template>
<script setup lang="ts">
import DefaultTheme from 'vitepress/theme'
import ArticleMetadat from './ArticleMetadata.vue';
import { ref, onMounted, onBeforeUnmount } from 'vue'
const isLoading = ref(true)
let loadTimer: NodeJS.Timeout
onMounted(() => {
const handleLoad = () => {
// 添加一个最小显示时间,避免闪烁
const minDisplayTime = 800 // 最小显示800ms
if (document.readyState === 'complete') {
setTimeout(() => {
isLoading.value = false
}, minDisplayTime)
} else {
loadTimer = setTimeout(() => {
isLoading.value = false
}, minDisplayTime)
}
}
// 监听load事件
window.addEventListener('load', handleLoad)
// 如果已经从缓存加载
if (document.readyState === 'complete') {
handleLoad()
}
})
onBeforeUnmount(() => {
if (loadTimer) {
clearTimeout(loadTimer)
}
})
</script>
<style scoped>
.simple-elegant-loading {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: var(--vp-c-bg);
display: flex;
justify-content: center;
align-items: center;
z-index: 9999;
backdrop-filter: blur(2px);
}
.loading-content {
display: flex;
flex-direction: column;