App.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <template>
  2. <AppConfig>
  3. <router-view/>
  4. </AppConfig>
  5. </template>
  6. <script setup>
  7. import {nextTick, ref, watch} from "vue";
  8. import {useAppStore} from "~src/store";
  9. import AppConfig from "~com/AppConfig/index.vue";
  10. import {setMainColor} from "~src/utils/tools";
  11. import {getObjValue, ulog, useOsTheme} from "vue-utils-plus"
  12. import config from '~src/config/index';
  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. setUserTheme(appStore.getThemeVal, appStore.getColor)
  27. ulog('客户端 启动成功', '当前开发版本 v' + config?.version)
  28. })
  29. //设置主题
  30. const setUserTheme = (theme, appColor) => {
  31. const colorVal = getObjValue(appColor)
  32. //设置主色调
  33. setMainColor(colorVal?.color)
  34. const colorName = colorVal?.name || 'green'
  35. //设置主题
  36. let val = UserTheme.value
  37. if (val === 'auto') {
  38. theme = useOsTheme().value;
  39. }
  40. if (theme === '') {
  41. theme = val;
  42. }
  43. //挂载相关样式
  44. document.documentElement.setAttribute('class',`${theme} color-${colorName}`)
  45. }
  46. </script>