BtnTheme.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <template>
  2. <a-dropdown trigger="hover" @select="handleSelect">
  3. <div class="header-right-theme-item">
  4. <img class="icon-theme-img" src="../../../assets/theme.png" />
  5. </div>
  6. <template #content>
  7. <a-doption value="light">浅色主题</a-doption>
  8. <a-doption value="dark">深色主题</a-doption>
  9. </template>
  10. </a-dropdown>
  11. </template>
  12. <script setup>
  13. import { setThemeDark, setThemeLight } from '../../../base/theme';
  14. const props = defineProps({
  15. label: String
  16. });
  17. /**
  18. * 设置系统主题
  19. * @param {string} theme - 主题 dark/theme
  20. */
  21. const handleThemeChange = (theme) => {
  22. if (theme === 'dark') {
  23. setThemeDark();
  24. }
  25. if (theme === 'light') {
  26. setThemeLight();
  27. }
  28. };
  29. const handleSelect = (value) => {
  30. handleThemeChange(value);
  31. };
  32. </script>
  33. <style lang="css" scoped>
  34. .header-right-theme-item {
  35. color: var(--color-text-2);
  36. width: 30px;
  37. height: 30px;
  38. border-radius: 20px;
  39. border: solid 1px #e5e6eb;
  40. display: flex;
  41. justify-content: center;
  42. align-items: center;
  43. cursor: pointer;
  44. }
  45. .icon-theme-img {
  46. width: 16px;
  47. }
  48. </style>