App.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <script setup lang="ts">
  2. import { computed } from 'vue'
  3. import { useAppStore } from '@/store/modules/app'
  4. import { ConfigGlobal } from '@/components/ConfigGlobal'
  5. import { isDark } from '@/utils/is'
  6. import { useDesign } from '@/hooks/web/useDesign'
  7. import Cookies from 'js-cookie'
  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. // 根据浏览器当前主题设置系统主题色
  14. const setDefaultTheme = () => {
  15. if (Cookies.get('isDark')) {
  16. if (Cookies.get('isDark') === 'true') {
  17. appStore.setIsDark(true)
  18. } else {
  19. appStore.setIsDark(false)
  20. }
  21. return
  22. }
  23. const isDarkTheme = isDark()
  24. appStore.setIsDark(isDarkTheme)
  25. }
  26. setDefaultTheme()
  27. </script>
  28. <template>
  29. <ConfigGlobal :size="currentSize">
  30. <RouterView :class="greyMode ? `${prefixCls}-grey-mode` : ''" />
  31. </ConfigGlobal>
  32. </template>
  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>