<template>
    <router-view v-slot="{ Component }">
      <transition name="fade" mode="out-in">
        <component :is="Component" />
      </transition>
    </router-view>
</template>

<script setup>
// 全局设置ElementPlus主题颜色
import { useCssVar } from '@vueuse/core'
import {useUserStore} from "@/store/userStore.js";
import {onMounted} from "vue";
import {getUserInfo} from "@/api/login.js";

const userStore = useUserStore()
onMounted(async () => {
  let resp = await getUserInfo()
  userStore.setUserInfo(resp.data)
  console.log(userStore.userInfo)
})
// 设置主题颜色
const primaryColor = '#1890ff'
useCssVar('--el-color-primary', document.documentElement).value = primaryColor

// 生成不同深度的主题色
const generateDarkColor = (color, level) => {
  const values = color.replace('#', '').match(/.{2}/g).map(v => parseInt(v, 16))
  const [r, g, b] = values.map(v => Math.max(0, Math.floor(v * (1 - level * 0.1))))
  return `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}`
}

// 设置不同深度的主题色
for (let i = 1; i <= 9; i++) {
  useCssVar(`--el-color-primary-light-${i}`, document.documentElement).value = 
    i <= 5 
      ? `rgba(24, 144, 255, ${1 - i * 0.1})`
      : '#f0f9ff'
  
  if (i <= 2) {
    useCssVar(`--el-color-primary-dark-${i}`, document.documentElement).value = 
      generateDarkColor(primaryColor, i)
  }
}
</script>

<style>
/* 全局样式 */
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '微软雅黑', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background-color: #f5f7fa;
}

/* 过渡动画 */
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.2s ease-in-out;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

/* 滚动条样式 */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* Element Plus样式优化 */
.el-button {
  font-weight: 400;
  border-radius: 4px;
}

.el-card {
  border-radius: 4px;
}

.el-menu {
  border-right: none;
}

.el-table {
  border-radius: 4px;
}

.el-dialog {
  border-radius: 8px;
}

.el-dialog__header {
  margin: 0;
  padding: 20px;
  border-bottom: 1px solid #f0f0f0;
  font-weight: 500;
}

.el-dialog__body {
  padding: 20px;
}

.el-dialog__footer {
  padding: 10px 20px 20px;
}
</style>