App.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <hc-app-config>
  3. <router-view />
  4. </hc-app-config>
  5. </template>
  6. <script setup>
  7. import { nextTick, ref, watch } from 'vue'
  8. import { useAppStore } from '~src/store'
  9. import { detectionBrowser, getAppVersion, useOsTheme } from 'hc-vue3-ui'
  10. import { getObjValue, setElementMainColor } from 'js-fast-way'
  11. import { addDocumentsJs } from '~uti/tools'
  12. import split from 'split.js'
  13. //初始变量
  14. const appStore = useAppStore()
  15. const UserTheme = ref(appStore.getTheme)
  16. //监听
  17. watch(() => [
  18. appStore.getTheme,
  19. appStore.getThemeVal,
  20. appStore.getColor,
  21. ], ([Theme, ThemeVal, ColorVal]) => {
  22. UserTheme.value = Theme
  23. setUserTheme(ThemeVal, ColorVal)
  24. })
  25. nextTick(() => {
  26. detectionBrowser()
  27. window['$split'] = split
  28. setUserTheme(appStore.getThemeVal, appStore.getColor)
  29. addDocumentsJs()
  30. //生产环境下,检测更新
  31. if (import.meta.env.PROD) {
  32. getAppVersion()
  33. }
  34. })
  35. //设置主题
  36. const setUserTheme = (theme, appColor) => {
  37. const projectInfo = appStore.projectInfo
  38. const id = '1891312830718746625'
  39. let isYunNan = projectInfo?.id === id
  40. if (isYunNan) {
  41. setElementMainColor('#409eff')
  42. let colorName = 'blue'
  43. let theme = 'light'
  44. document.documentElement.setAttribute('class', `${theme} color-${colorName}`)
  45. return
  46. }
  47. const colorVal = getObjValue(appColor)
  48. //设置主色调
  49. setElementMainColor(colorVal?.color)
  50. const colorName = colorVal?.name || 'green'
  51. //设置主题
  52. let val = UserTheme.value
  53. if (val === 'auto') {
  54. theme = useOsTheme()
  55. }
  56. if (theme === '') {
  57. theme = val
  58. }
  59. //挂载相关样式
  60. document.documentElement.setAttribute('class', `${theme} color-${colorName}`)
  61. }
  62. </script>