<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()
  console.log("用户信息：",resp)
  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 {
  border-radius: 0 !important;
  transition: all 0.2s ease;
  font-weight: 500;
}

/* 主按钮 - 深蓝灰色 */
.el-button--primary {
  background-color: #2c3e50 !important;
  border-color: #2c3e50 !important;
  color: #ffffff !important;
}

.el-button--primary:hover {
  background-color: #34495e !important;
  border-color: #34495e !important;
}

.el-button--primary:active {
  background-color: #1a252f !important;
  border-color: #1a252f !important;
}

/* 成功按钮 - 绿色系 */
.el-button--success {
  background-color: #27ae60 !important;
  border-color: #27ae60 !important;
  color: #ffffff !important;
}

.el-button--success:hover {
  background-color: #2ecc71 !important;
  border-color: #2ecc71 !important;
}

.el-button--success:active {
  background-color: #229954 !important;
  border-color: #229954 !important;
}

/* 危险按钮 - 红色系 */
.el-button--danger {
  background-color: #e74c3c !important;
  border-color: #e74c3c !important;
  color: #ffffff !important;
}

.el-button--danger:hover {
  background-color: #ec7063 !important;
  border-color: #ec7063 !important;
}

.el-button--danger:active {
  background-color: #c0392b !important;
  border-color: #c0392b !important;
}

/* 默认按钮 */
.el-button--default {
  background-color: #ffffff !important;
  border-color: #d5d9e0 !important;
  color: #606266 !important;
}

.el-button--default:hover {
  background-color: #f5f7fa !important;
  border-color: #c0c4cc !important;
  color: #606266 !important;
}

/* Link按钮 */
.el-button.is-link {
  color: #3498db !important;
  border: none !important;
  padding: 0;
  background: transparent !important;
}

.el-button.is-link:hover {
  color: #2980b9 !important;
  background: transparent !important;
}

.el-button--primary.is-link {
  color: #3498db !important;
  background: transparent !important;
}

.el-button--primary.is-link:hover {
  color: #2980b9 !important;
  background: transparent !important;
}

/* 输入框扁平化 */
.el-input__wrapper {
  border-radius: 0 !important;
  box-shadow: 0 0 0 1px #d5d9e0 inset !important;
  background-color: #ffffff !important;
  transition: all 0.2s ease;
}

.el-input__wrapper:hover {
  box-shadow: 0 0 0 1px #b8bcc5 inset !important;
}

.el-input__wrapper.is-focus {
  box-shadow: 0 0 0 1px #2c3e50 inset !important;
}

/* 标签扁平化 */
.el-tag {
  border-radius: 0 !important;
  border: none !important;
  font-weight: 500;
  padding: 2px 10px;
}

/* 成功标签 */
.el-tag--success {
  background-color: #d5f4e6 !important;
  color: #27ae60 !important;
}

/* 危险标签 */
.el-tag--danger {
  background-color: #fadbd8 !important;
  color: #e74c3c !important;
}

/* 信息标签 */
.el-tag--info {
  background-color: #ebf5fb !important;
  color: #3498db !important;
}

/* 卡片扁平化 + 层次感 */
.el-card {
  border-radius: 0 !important;
  border: 1px solid #e1e8ed !important;
  box-shadow: none !important;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.el-card[shadow="hover"]:hover {
  border-color: #c0c4cc !important;
  box-shadow: 0 2px 12px rgba(44, 62, 80, 0.08) !important;
}

/* 表格扁平化 */
.el-table {
  border-radius: 0 !important;
  border: none !important;
  color: #2c3e50 !important;
}

.el-table__header {
  background: #f8f9fa !important;
}

.el-table th {
  background: #f8f9fa !important;
  border-bottom: 2px solid #e1e8ed !important;
  color: #2c3e50 !important;
  font-weight: 600 !important;
  font-size: 13px !important;
}

.el-table td {
  border-bottom: 1px solid #f0f2f5 !important;
  color: #34495e !important;
}

.el-table tr:hover > td {
  background-color: #f8f9fa !important;
}

/* 分页扁平化 */
.el-pagination .el-pager li {
  border-radius: 0 !important;
  color: #606266 !important;
  font-weight: 500;
}

.el-pagination .el-pager li.is-active {
  background-color: #2c3e50 !important;
  color: #ffffff !important;
}

.el-pagination .el-pager li:hover {
  color: #2c3e50 !important;
}

.el-pagination button {
  border-radius: 0 !important;
  color: #606266 !important;
}

.el-pagination button:hover {
  color: #2c3e50 !important;
}

.el-pagination .el-select .el-input__wrapper {
  box-shadow: 0 0 0 1px #d5d9e0 inset !important;
}

.el-pagination .el-input__inner {
  color: #606266 !important;
}

/* 下拉菜单扁平化 */
.el-dropdown-menu {
  border-radius: 0 !important;
  border: 1px solid #e1e8ed !important;
  background-color: #ffffff !important;
  box-shadow: 0 2px 8px rgba(44, 62, 80, 0.1) !important;
  padding: 4px 0;
}

.el-dropdown-menu__item {
  color: #34495e !important;
  transition: all 0.2s ease;
  padding: 8px 16px;
}

.el-dropdown-menu__item:hover {
  background-color: #f8f9fa !important;
  color: #2c3e50 !important;
}

.el-dropdown-menu__item.is-divided {
  border-top: 1px solid #e1e8ed !important;
}

/* 选择框扁平化 */
.el-select .el-input__wrapper {
  border-radius: 0 !important;
}

/* 文本域扁平化 */
.el-textarea__inner {
  border-radius: 0 !important;
  box-shadow: 0 0 0 1px #d5d9e0 inset !important;
  transition: all 0.2s ease;
}

.el-textarea__inner:hover {
  box-shadow: 0 0 0 1px #b8bcc5 inset !important;
}

.el-textarea__inner:focus {
  box-shadow: 0 0 0 1px #2c3e50 inset !important;
}

/* 菜单扁平化 */
.el-menu {
  border-right: none;
}

/* 表单标签 */
.el-form-item__label {
  color: #2c3e50 !important;
  font-weight: 500;
}

/* Dialog 扁平化样式 */
.el-overlay {
  background-color: rgba(0, 0, 0, 0.5);
}

.el-overlay-dialog {
  display: flex;
  align-items: center;
  justify-content: center;
}

.el-dialog {
  border-radius: 0;
  border: none;
  box-shadow: 0 4px 16px rgba(44, 62, 80, 0.15);
  background-color: #ffffff;
  margin: 0;
  padding: 0 !important;
}

.el-dialog__wrapper {
  border: none;
}

.el-dialog__header {
  margin: 0;
  padding: 20px 24px;
  border-bottom: 1px solid #e1e8ed;
  background-color: #fafbfc;
  font-weight: 600;
  font-size: 16px;
  color: #2c3e50;
}

.el-dialog__headerbtn {
  top: 20px;
  right: 24px;
  width: 32px;
  height: 32px;
}

.el-dialog__close {
  color: #7f8c8d;
  font-size: 18px;
  transition: all 0.2s ease;
}

.el-dialog__close:hover {
  color: #2c3e50;
  background-color: #f8f9fa;
}

.el-dialog__body {
  padding: 24px;
  color: #34495e;
  background-color: #ffffff;
}

.el-dialog__footer {
  padding: 16px 24px;
  border-top: 1px solid #e1e8ed;
  background-color: #fafbfc;
}

/* Dialog 内表单组件样式 */
.el-dialog .el-input__wrapper {
  border-radius: 0;
}

.el-dialog .el-select .el-input__wrapper {
  border-radius: 0;
}

.el-dialog .el-textarea__inner {
  border-radius: 0;
}

.el-dialog .el-form-item__label {
  color: #2c3e50;
  font-weight: 500;
}

.el-dialog .el-form-item {
  margin-bottom: 20px;
}

/* Descriptions 描述列表增强 */
.el-descriptions {
  --el-descriptions-item-bordered-label-background: #fafbfc;
}
.el-descriptions__label {
  color: #606266 !important;
  font-weight: 500 !important;
}
.el-descriptions__content {
  color: #1d2129 !important;
}

/* Loading 遮罩增强 */
.el-loading-mask {
  background-color: rgba(255, 255, 255, 0.85) !important;
}
.el-loading-spinner .circular {
  width: 36px;
  height: 36px;
}
.el-loading-spinner .el-loading-text {
  color: #606266 !important;
  font-size: 13px;
  margin-top: 8px;
}

/* Message Box 增强 */
.el-message-box {
  border-radius: 0 !important;
  box-shadow: 0 4px 16px rgba(44, 62, 80, 0.15) !important;
}
.el-message-box__header {
  padding: 16px 20px 12px !important;
}
.el-message-box__title {
  font-weight: 600 !important;
  color: #1d2129 !important;
}
.el-message-box__btns .el-button {
  border-radius: 0 !important;
}

/* Alert 增强 */
.el-alert {
  border-radius: 0 !important;
}

/* Tabs 增强 */
.el-tabs__item {
  transition: color 0.2s ease !important;
}
.el-tabs__item.is-active {
  font-weight: 600 !important;
}

/* Switch 开关增强 */
.el-switch {
  --el-switch-on-color: #2c3e50;
}

/* 全局链接按钮悬浮下划线 */
.el-button.is-link:hover,
.el-button--primary.is-link:hover {
  text-decoration: underline;
}
</style>