App.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <HcAppConfig>
  3. <router-view/>
  4. </HcAppConfig>
  5. </template>
  6. <script setup>
  7. import {nextTick, ref, watch} from "vue";
  8. import {useAppStore} from "~src/store";
  9. import {useOsTheme} from 'hc-vue3-ui'
  10. import {setElementMainColor, ulog, getObjValue} from "js-fast-way"
  11. import config from '~src/config/index';
  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. window['$split'] = split;
  27. setUserTheme(appStore.getThemeVal, appStore.getColor)
  28. ulog('档案管理 启动成功', '当前开发版本 v' + config?.version)
  29. //当屏幕分辨率宽度低于1920时,自动折叠菜单
  30. const width = document.body.clientWidth
  31. if (width < 1920) {
  32. appStore.setCollapse(true)
  33. }
  34. })
  35. //设置主题
  36. const setUserTheme = (theme, appColor) => {
  37. const colorVal = getObjValue(appColor)
  38. //设置主色调
  39. setElementMainColor(colorVal?.color)
  40. const colorName = colorVal?.name || 'green'
  41. //设置主题
  42. let val = UserTheme.value
  43. if (val === 'auto') {
  44. theme = useOsTheme();
  45. }
  46. if (theme === '') {
  47. theme = val;
  48. }
  49. //挂载相关样式
  50. document.documentElement.setAttribute('class',`${theme} color-${colorName}`)
  51. }
  52. </script>