App.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 danger_files = import.meta.glob('./assets/images/danger/**', {
  29. eager: true,
  30. query: '?url',
  31. import: 'default'
  32. })
  33. const icon_modules_files = {
  34. ...import.meta.glob('./assets/images/icons/**.svg', {
  35. eager: true,
  36. as: 'raw'
  37. })
  38. }
  39. const normalizeFillSvg = (svg: string) => {
  40. return svg.replace(/\sfill="(?!none\b)[^"]*"/gi, '')
  41. }
  42. const electrical_register_config: any = []
  43. for (const key in electrical_modules_files) {
  44. //根据路径获取svg文件名
  45. const name = key.split('/').pop()!.split('.')[0]
  46. electrical_register_config.push({
  47. id: name,
  48. title: name,
  49. type: 'svg',
  50. thumbnail: 'data:image/svg+xml;utf8,' + encodeURIComponent(electrical_modules_files[key]),
  51. svg: electrical_modules_files[key],
  52. props: {
  53. fill: {
  54. type: 'color',
  55. val: '#FF0000',
  56. title: '填充色'
  57. }
  58. }
  59. })
  60. }
  61. for (const key in electrical_stroke_modules_files) {
  62. //根据路径获取svg文件名
  63. const name = key.split('/').pop()!.split('.')[0]
  64. electrical_register_config.push({
  65. id: name,
  66. title: name,
  67. type: 'svg',
  68. thumbnail:
  69. 'data:image/svg+xml;utf8,' + encodeURIComponent(electrical_stroke_modules_files[key]),
  70. svg: electrical_stroke_modules_files[key],
  71. props: {
  72. stroke: {
  73. type: 'color',
  74. val: '#00ff00',
  75. title: '边框色'
  76. }
  77. }
  78. })
  79. }
  80. leftAsideStore.registerConfig('电气符号', electrical_register_config)
  81. const icon_register_config: any = []
  82. for (const key in icon_modules_files) {
  83. const name = key.split('/').pop()!.split('.')[0]
  84. const svg = normalizeFillSvg(icon_modules_files[key])
  85. icon_register_config.push({
  86. id: `icon-${name}`,
  87. title: name,
  88. type: 'svg',
  89. thumbnail: 'data:image/svg+xml;utf8,' + encodeURIComponent(svg),
  90. svg,
  91. props: {
  92. fill: {
  93. type: 'color',
  94. val: '#FF0000',
  95. title: '填充色'
  96. }
  97. }
  98. })
  99. }
  100. leftAsideStore.registerConfig('图标', icon_register_config)
  101. const process_demo_register_config: any[] = Object.entries(process_demo_image_files).map(
  102. ([key, url]) => {
  103. const name = key.split('/').pop()!.split('.')[0]
  104. return {
  105. id: name,
  106. title: name,
  107. type: 'img',
  108. thumbnail: url,
  109. props: {}
  110. }
  111. }
  112. )
  113. leftAsideStore.registerConfig('工艺流程图', process_demo_register_config)
  114. const materials_register_config: any[] = Object.entries(materials_files).map(([key, url]) => {
  115. const name = key.split('/').pop()!.split('.')[0]
  116. return {
  117. id: name,
  118. title: name,
  119. type: 'img',
  120. thumbnail: url,
  121. props: {}
  122. }
  123. })
  124. leftAsideStore.registerConfig('素材', materials_register_config)
  125. const danger_register_config: any[] = Object.entries(danger_files).map(([key, url]) => {
  126. const name = key.split('/').pop()!.split('.')[0]
  127. return {
  128. id: `danger-${name}`,
  129. title: name,
  130. type: 'img',
  131. thumbnail: url,
  132. props: {}
  133. }
  134. })
  135. leftAsideStore.registerConfig('危险标识', danger_register_config)
  136. const route = useRoute()
  137. const { addListeners, removeListeners } = useAutoLogout()
  138. const whiteList = [
  139. '/login',
  140. '/social-login',
  141. '/auth-redirect',
  142. '/bind',
  143. '/register',
  144. '/oauthLogin/gitee',
  145. '/dingding',
  146. '/deepoil',
  147. '/oli-connection/monitoring-board'
  148. ]
  149. watch(
  150. () => route.path,
  151. (newPath) => {
  152. if (whiteList.includes(newPath)) {
  153. console.log('进入白名单页面,移除超时检测')
  154. removeListeners()
  155. } else {
  156. console.log('进入受控页面,开启超时检测')
  157. addListeners()
  158. }
  159. },
  160. { immediate: true } // 初始化时立即执行一次
  161. )
  162. defineOptions({ name: 'APP' })
  163. const { getPrefixCls } = useDesign()
  164. const prefixCls = getPrefixCls('app')
  165. const appStore = useAppStore()
  166. const currentSize = computed(() => appStore.getCurrentSize)
  167. const greyMode = computed(() => appStore.getGreyMode)
  168. const { wsCache } = useCache()
  169. // 根据浏览器当前主题设置系统主题色
  170. const setDefaultTheme = () => {
  171. let isDarkTheme = wsCache.get(CACHE_KEY.IS_DARK)
  172. if (isDarkTheme === null) {
  173. isDarkTheme = isDark()
  174. }
  175. appStore.setIsDark(isDarkTheme)
  176. }
  177. setDefaultTheme()
  178. </script>
  179. <template>
  180. <ConfigGlobal :size="currentSize">
  181. <RouterView :class="greyMode ? `${prefixCls}-grey-mode` : ''" />
  182. <routerSearch />
  183. </ConfigGlobal>
  184. </template>
  185. <style lang="scss">
  186. $prefix-cls: #{$namespace}-app;
  187. .size {
  188. width: 100%;
  189. height: 100%;
  190. }
  191. html,
  192. body {
  193. @extend .size;
  194. padding: 0 !important;
  195. margin: 0;
  196. overflow: hidden;
  197. #app {
  198. @extend .size;
  199. }
  200. }
  201. .#{$prefix-cls}-grey-mode {
  202. filter: grayscale(100%);
  203. }
  204. </style>