App.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. import { leftAsideStore } from '@/export'
  9. // import demo from '/svgs/demo.svg?raw'
  10. const electrical_modules_files = import.meta.glob('./assets/svgs/electrical/**.svg', {
  11. eager: true,
  12. as: 'raw'
  13. })
  14. const electrical_stroke_modules_files = import.meta.glob('./assets/svgs/electrical/stroke/**.svg', {
  15. eager: true,
  16. as: 'raw'
  17. })
  18. const process_demo_image_files = import.meta.glob('./assets/images/process-demo/**', {
  19. eager: true,
  20. query: '?url',
  21. import: 'default'
  22. })
  23. const materials_files = import.meta.glob('./assets/images/materials/**', {
  24. eager: true,
  25. query: '?url',
  26. import: 'default'
  27. })
  28. const electrical_register_config: any = []
  29. for (const key in electrical_modules_files) {
  30. //根据路径获取svg文件名
  31. const name = key.split('/').pop()!.split('.')[0]
  32. electrical_register_config.push({
  33. id: name,
  34. title: name,
  35. type: 'svg',
  36. thumbnail: 'data:image/svg+xml;utf8,' + encodeURIComponent(electrical_modules_files[key]),
  37. svg: electrical_modules_files[key],
  38. props: {
  39. fill: {
  40. type: 'color',
  41. val: '#FF0000',
  42. title: '填充色'
  43. }
  44. }
  45. })
  46. }
  47. for (const key in electrical_stroke_modules_files) {
  48. //根据路径获取svg文件名
  49. const name = key.split('/').pop()!.split('.')[0]
  50. electrical_register_config.push({
  51. id: name,
  52. title: name,
  53. type: 'svg',
  54. thumbnail:
  55. 'data:image/svg+xml;utf8,' + encodeURIComponent(electrical_stroke_modules_files[key]),
  56. svg: electrical_stroke_modules_files[key],
  57. props: {
  58. stroke: {
  59. type: 'color',
  60. val: '#00ff00',
  61. title: '边框色'
  62. }
  63. }
  64. })
  65. }
  66. leftAsideStore.registerConfig('电气符号', electrical_register_config)
  67. const process_demo_register_config: any[] = Object.entries(process_demo_image_files).map(
  68. ([key, url]) => {
  69. const name = key.split('/').pop()!.split('.')[0]
  70. return {
  71. id: name,
  72. title: name,
  73. type: 'img',
  74. thumbnail: url,
  75. props: {}
  76. }
  77. }
  78. )
  79. leftAsideStore.registerConfig('工艺流程图', process_demo_register_config)
  80. const materials_register_config: any[] = Object.entries(materials_files).map(([key, url]) => {
  81. const name = key.split('/').pop()!.split('.')[0]
  82. return {
  83. id: name,
  84. title: name,
  85. type: 'img',
  86. thumbnail: url,
  87. props: {}
  88. }
  89. })
  90. leftAsideStore.registerConfig('素材', materials_register_config)
  91. const route = useRoute()
  92. const { addListeners, removeListeners } = useAutoLogout()
  93. const whiteList = [
  94. '/login',
  95. '/social-login',
  96. '/auth-redirect',
  97. '/bind',
  98. '/register',
  99. '/oauthLogin/gitee',
  100. '/dingding',
  101. '/deepoil',
  102. '/oli-connection/monitoring-board'
  103. ]
  104. watch(
  105. () => route.path,
  106. (newPath) => {
  107. if (whiteList.includes(newPath)) {
  108. console.log('进入白名单页面,移除超时检测')
  109. removeListeners()
  110. } else {
  111. console.log('进入受控页面,开启超时检测')
  112. addListeners()
  113. }
  114. },
  115. { immediate: true } // 初始化时立即执行一次
  116. )
  117. defineOptions({ name: 'APP' })
  118. const { getPrefixCls } = useDesign()
  119. const prefixCls = getPrefixCls('app')
  120. const appStore = useAppStore()
  121. const currentSize = computed(() => appStore.getCurrentSize)
  122. const greyMode = computed(() => appStore.getGreyMode)
  123. const { wsCache } = useCache()
  124. // 根据浏览器当前主题设置系统主题色
  125. const setDefaultTheme = () => {
  126. let isDarkTheme = wsCache.get(CACHE_KEY.IS_DARK)
  127. if (isDarkTheme === null) {
  128. isDarkTheme = isDark()
  129. }
  130. appStore.setIsDark(isDarkTheme)
  131. }
  132. setDefaultTheme()
  133. </script>
  134. <template>
  135. <ConfigGlobal :size="currentSize">
  136. <RouterView :class="greyMode ? `${prefixCls}-grey-mode` : ''" />
  137. <routerSearch />
  138. </ConfigGlobal>
  139. </template>
  140. <style lang="scss">
  141. $prefix-cls: #{$namespace}-app;
  142. .size {
  143. width: 100%;
  144. height: 100%;
  145. }
  146. html,
  147. body {
  148. @extend .size;
  149. padding: 0 !important;
  150. margin: 0;
  151. overflow: hidden;
  152. #app {
  153. @extend .size;
  154. }
  155. }
  156. .#{$prefix-cls}-grey-mode {
  157. filter: grayscale(100%);
  158. }
  159. </style>