App.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <script setup lang="ts">
  2. import { computed } from 'vue'
  3. import { isDark } from '@/utils/is'
  4. import { useAppStore } from '@/store/modules/app'
  5. import { useDesign } from '@/hooks/web/useDesign'
  6. import { ConfigGlobal } from '@/components/ConfigGlobal'
  7. import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
  8. const { getPrefixCls } = useDesign()
  9. const prefixCls = getPrefixCls('app')
  10. const appStore = useAppStore()
  11. const currentSize = computed(() => appStore.getCurrentSize)
  12. const greyMode = computed(() => appStore.getGreyMode)
  13. const { wsCache } = useCache()
  14. // 根据浏览器当前主题设置系统主题色
  15. const setDefaultTheme = () => {
  16. if (wsCache.get(CACHE_KEY.IS_DARK)) {
  17. if (wsCache.get(CACHE_KEY.IS_DARK) || wsCache.get(CACHE_KEY.IS_DARK) === 'true') {
  18. appStore.setIsDark(true)
  19. } else {
  20. appStore.setIsDark(false)
  21. }
  22. return
  23. }
  24. const isDarkTheme = isDark()
  25. appStore.setIsDark(isDarkTheme)
  26. }
  27. setDefaultTheme()
  28. </script>
  29. <template>
  30. <ConfigGlobal :size="currentSize">
  31. <RouterView :class="greyMode ? `${prefixCls}-grey-mode` : ''" />
  32. </ConfigGlobal>
  33. </template>
  34. <style lang="scss">
  35. $prefix-cls: #{$namespace}-app;
  36. .size {
  37. width: 100%;
  38. height: 100%;
  39. }
  40. html,
  41. body {
  42. padding: 0 !important;
  43. margin: 0;
  44. overflow: hidden;
  45. @extend .size;
  46. #app {
  47. @extend .size;
  48. }
  49. }
  50. .#{$prefix-cls}-grey-mode {
  51. filter: grayscale(100%);
  52. }
  53. </style>