App.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <script lang="ts" setup>
  2. import { isDark } from '@/utils/is'
  3. import { useAppStore } from '@/store/modules/app'
  4. import { useDesign } from '@/hooks/web/useDesign'
  5. import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
  6. import routerSearch from '@/components/RouterSearch/index.vue'
  7. import { useAutoLogout } from './composable/useAutoLogout'
  8. const route = useRoute()
  9. const { addListeners, removeListeners } = useAutoLogout()
  10. const whiteList = [
  11. '/login',
  12. '/social-login',
  13. '/auth-redirect',
  14. '/bind',
  15. '/register',
  16. '/oauthLogin/gitee',
  17. '/dingding',
  18. '/deepoil'
  19. ]
  20. watch(
  21. () => route.path,
  22. (newPath) => {
  23. if (whiteList.includes(newPath)) {
  24. console.log('进入白名单页面,移除超时检测')
  25. removeListeners()
  26. } else {
  27. console.log('进入受控页面,开启超时检测')
  28. addListeners()
  29. }
  30. },
  31. { immediate: true } // 初始化时立即执行一次
  32. )
  33. defineOptions({ name: 'APP' })
  34. const { getPrefixCls } = useDesign()
  35. const prefixCls = getPrefixCls('app')
  36. const appStore = useAppStore()
  37. const currentSize = computed(() => appStore.getCurrentSize)
  38. const greyMode = computed(() => appStore.getGreyMode)
  39. const { wsCache } = useCache()
  40. // 根据浏览器当前主题设置系统主题色
  41. const setDefaultTheme = () => {
  42. let isDarkTheme = wsCache.get(CACHE_KEY.IS_DARK)
  43. if (isDarkTheme === null) {
  44. isDarkTheme = isDark()
  45. }
  46. appStore.setIsDark(isDarkTheme)
  47. }
  48. setDefaultTheme()
  49. </script>
  50. <template>
  51. <ConfigGlobal :size="currentSize">
  52. <RouterView :class="greyMode ? `${prefixCls}-grey-mode` : ''" />
  53. <routerSearch />
  54. </ConfigGlobal>
  55. </template>
  56. <style lang="scss">
  57. $prefix-cls: #{$namespace}-app;
  58. .size {
  59. width: 100%;
  60. height: 100%;
  61. }
  62. html,
  63. body {
  64. @extend .size;
  65. padding: 0 !important;
  66. margin: 0;
  67. overflow: hidden;
  68. #app {
  69. @extend .size;
  70. }
  71. }
  72. .#{$prefix-cls}-grey-mode {
  73. filter: grayscale(100%);
  74. }
  75. </style>