App.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 config from '~src/config/index';
  12. import {useOsTheme} from 'vooks'
  13. //初始变量
  14. const appStore = useAppStore()
  15. const UserTheme = ref(appStore.getTheme)
  16. const appColor = ref(appStore.getColor);
  17. //监听
  18. watch(() => [
  19. appStore.getTheme,
  20. appStore.getThemeVal,
  21. appStore.getColor
  22. ], ([Theme,ThemeVal,ColorVal]) => {
  23. UserTheme.value = Theme
  24. appColor.value = ColorVal
  25. setUserTheme(ThemeVal)
  26. })
  27. nextTick(()=> {
  28. setUserTheme(appStore.getThemeVal)
  29. //设置主色调
  30. setMainColor(appColor.value?.color)
  31. //打印开发版本号
  32. console.log(
  33. `%c 客户端 启动成功 %c 当前开发版本 V` + config.dev_version + `%c`,
  34. 'background:#0081ff; padding: 1px; border-radius: 3px 0 0 3px; color: #fff',
  35. 'background:#354855; padding: 1px 5px; border-radius: 0 3px 3px 0; color: #fff; font-weight: bold;',
  36. 'background:transparent'
  37. )
  38. })
  39. //设置主题
  40. const setUserTheme = (theme) => {
  41. let val = UserTheme.value, colorName = appColor.value?.name || 'green'
  42. if (val === 'auto') {
  43. theme = useOsTheme().value;
  44. }
  45. if (theme === '') {
  46. theme = val;
  47. }
  48. document.documentElement.setAttribute('class',`${theme} color-${colorName}`)
  49. }
  50. </script>