Logo.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <div class="sidebar-logo-container" :class="{ 'collapse': collapse }">
  3. <transition name="sidebarLogoFade">
  4. <router-link v-if="collapse" key="collapse" class="sidebar-logo-link" to="/">
  5. <img v-if="logo" :src="logo" class="sidebar-logo" />
  6. <h1 v-else class="sidebar-title">{{ title }}</h1>
  7. </router-link>
  8. <router-link v-else key="expand" class="sidebar-logo-link" to="/">
  9. <img v-if="logo" :src="logo" class="sidebar-logo" />
  10. <h1 class="sidebar-title">{{ title }}</h1>
  11. </router-link>
  12. </transition>
  13. </div>
  14. </template>
  15. <script setup>
  16. import logo from '@/assets/logo/logo.png'
  17. import useSettingsStore from '@/store/modules/settings'
  18. import variables from '@/assets/styles/variables.module.scss'
  19. defineProps({
  20. collapse: {
  21. type: Boolean,
  22. required: true
  23. }
  24. })
  25. const title = import.meta.env.VITE_APP_TITLE
  26. const settingsStore = useSettingsStore()
  27. const sideTheme = computed(() => settingsStore.sideTheme)
  28. // 获取Logo背景色
  29. const getLogoBackground = computed(() => {
  30. if (settingsStore.isDark) {
  31. return 'var(--sidebar-bg)'
  32. }
  33. return sideTheme.value === 'theme-dark' ? variables.menuBg : variables.menuLightBg
  34. })
  35. // 获取Logo文字颜色
  36. const getLogoTextColor = computed(() => {
  37. if (settingsStore.isDark) {
  38. return 'var(--sidebar-text)'
  39. }
  40. return sideTheme.value === 'theme-dark' ? '#fff' : variables.menuLightText
  41. })
  42. </script>
  43. <style lang="scss" scoped>
  44. .sidebarLogoFade-enter-active {
  45. transition: opacity 1.5s;
  46. }
  47. .sidebarLogoFade-enter,
  48. .sidebarLogoFade-leave-to {
  49. opacity: 0;
  50. }
  51. .sidebar-logo-container {
  52. position: relative;
  53. width: 100%;
  54. height: 50px;
  55. line-height: 50px;
  56. background: v-bind(getLogoBackground);
  57. text-align: center;
  58. overflow: hidden;
  59. & .sidebar-logo-link {
  60. height: 100%;
  61. width: 100%;
  62. & .sidebar-logo {
  63. width: 32px;
  64. height: 32px;
  65. vertical-align: middle;
  66. margin-right: 12px;
  67. }
  68. & .sidebar-title {
  69. display: inline-block;
  70. margin: 0;
  71. color: v-bind(getLogoTextColor);
  72. font-weight: 600;
  73. line-height: 50px;
  74. font-size: 14px;
  75. font-family: Avenir, Helvetica Neue, Arial, Helvetica, sans-serif;
  76. vertical-align: middle;
  77. }
  78. }
  79. &.collapse {
  80. .sidebar-logo {
  81. margin-right: 0px;
  82. }
  83. }
  84. }
  85. </style>