<template>
  <el-config-provider :locale="zhCn">
    <!-- 全局加载界面（Splash Screen） -->
    <transition name="splash-fade">
      <div v-if="showSplash" class="splash-screen">
        <div class="splash-content">
          <div class="splash-logo">智媒通</div>
          <div class="splash-dots">
            <span></span>
            <span></span>
            <span></span>
          </div>
          <p class="splash-text">正在加载...</p>
        </div>
      </div>
    </transition>
    <router-view />
  </el-config-provider>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import zhCn from 'element-plus/es/locale/lang/zh-cn';

const showSplash = ref(true);
const router = useRouter();

onMounted(() => {
  // 路由首次导航完成后隐藏加载界面
  router.isReady().then(() => {
    setTimeout(() => {
      showSplash.value = false;
    }, 300);
  });
});
</script>

<style>
html, body, #app {
  height: 100%;
  margin: 0;
  padding: 0;
}
</style>

<style scoped>
.splash-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
}

.splash-content {
  text-align: center;
  color: #fff;
}

.splash-logo {
  font-size: 42px;
  font-weight: 700;
  letter-spacing: 4px;
  margin-bottom: 40px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.splash-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 24px;
}

.splash-dots span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.6);
  animation: dot-bounce 1.4s ease-in-out infinite;
}

.splash-dots span:nth-child(1) {
  animation-delay: 0s;
}

.splash-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.splash-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes dot-bounce {
  0%, 80%, 100% {
    transform: scale(0.6);
    opacity: 0.4;
    background: rgba(255, 255, 255, 0.4);
  }
  40% {
    transform: scale(1);
    opacity: 1;
    background: #fff;
  }
}

.splash-text {
  font-size: 16px;
  opacity: 0.8;
  margin: 0;
  animation: text-pulse 2s ease-in-out infinite;
}

@keyframes text-pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

.splash-fade-leave-active {
  transition: opacity 0.4s ease;
}

.splash-fade-leave-to {
  opacity: 0;
}
</style>
