App.vue 1.2 KB

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