ThemeSwitch.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <template>
  2. <div class="theme-switch">
  3. <el-tooltip effect="dark" :content="isDark ? '切换到浅色模式' : '切换到深色模式'" placement="bottom">
  4. <el-button class="switch-btn" circle text @click="themeStore.toggleDarkMode">
  5. <el-icon :size="18">
  6. <Moon v-if="isDark" />
  7. <Sunny v-else />
  8. </el-icon>
  9. </el-button>
  10. </el-tooltip>
  11. <el-tooltip effect="dark" content="主题设置" placement="bottom">
  12. <el-button class="switch-btn" circle text @click="emit('openSettings')">
  13. <el-icon :size="18"><Setting /></el-icon>
  14. </el-button>
  15. </el-tooltip>
  16. </div>
  17. </template>
  18. <script setup lang="ts">
  19. import { computed } from 'vue'
  20. import { Moon, Sunny, Setting } from '@element-plus/icons-vue'
  21. import { useThemeStore } from '@/store/theme'
  22. const emit = defineEmits<{
  23. openSettings: []
  24. }>()
  25. const themeStore = useThemeStore()
  26. const isDark = computed(() => themeStore.isDark)
  27. </script>
  28. <style lang="scss" scoped>
  29. .theme-switch {
  30. display: flex;
  31. align-items: center;
  32. gap: 4px;
  33. .switch-btn {
  34. width: 36px;
  35. height: 36px;
  36. color: var(--text-secondary);
  37. transition: all var(--transition-base) var(--transition-timing);
  38. &:hover {
  39. color: var(--color-primary);
  40. background-color: var(--bg-hover);
  41. }
  42. }
  43. }
  44. </style>