App.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. '/oli-connection/monitoring-board'
  20. ]
  21. watch(
  22. () => route.path,
  23. (newPath) => {
  24. if (whiteList.includes(newPath)) {
  25. console.log('进入白名单页面,移除超时检测')
  26. removeListeners()
  27. } else {
  28. console.log('进入受控页面,开启超时检测')
  29. addListeners()
  30. }
  31. },
  32. { immediate: true } // 初始化时立即执行一次
  33. )
  34. defineOptions({ name: 'APP' })
  35. const { getPrefixCls } = useDesign()
  36. const prefixCls = getPrefixCls('app')
  37. const appStore = useAppStore()
  38. const currentSize = computed(() => appStore.getCurrentSize)
  39. const greyMode = computed(() => appStore.getGreyMode)
  40. const { wsCache } = useCache()
  41. // 根据浏览器当前主题设置系统主题色
  42. const setDefaultTheme = () => {
  43. let isDarkTheme = wsCache.get(CACHE_KEY.IS_DARK)
  44. if (isDarkTheme === null) {
  45. isDarkTheme = isDark()
  46. }
  47. appStore.setIsDark(isDarkTheme)
  48. }
  49. setDefaultTheme()
  50. </script>
  51. <template>
  52. <ConfigGlobal :size="currentSize">
  53. <RouterView :class="greyMode ? `${prefixCls}-grey-mode` : ''" />
  54. <routerSearch />
  55. </ConfigGlobal>
  56. </template>
  57. <style lang="scss">
  58. $prefix-cls: #{$namespace}-app;
  59. .size {
  60. width: 100%;
  61. height: 100%;
  62. }
  63. html,
  64. body {
  65. @extend .size;
  66. padding: 0 !important;
  67. margin: 0;
  68. overflow: hidden;
  69. #app {
  70. @extend .size;
  71. }
  72. }
  73. .#{$prefix-cls}-grey-mode {
  74. filter: grayscale(100%);
  75. }
  76. </style>