1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <template>
- <HcAppConfig>
- <router-view/>
- </HcAppConfig>
- </template>
- <script setup>
- import {nextTick, ref, watch} from "vue";
- import {useAppStore} from "~src/store";
- import {useOsTheme} from '~src/plugins/useOsTheme';
- import {setElementMainColor, ulog, getObjValue} from "js-fast-way"
- import {getStoreValue, setStoreValue} from "~uti/storage";
- import {getVersionJson} from "~api/other";
- import config from '~src/config/index';
- //初始变量
- const appStore = useAppStore()
- const UserTheme = ref(appStore.getTheme)
- //监听
- watch(() => [
- appStore.getTheme,
- appStore.getThemeVal,
- appStore.getColor
- ], ([Theme, ThemeVal, ColorVal]) => {
- UserTheme.value = Theme
- setUserTheme(ThemeVal, ColorVal)
- })
- nextTick(() => {
- setUserTheme(appStore.getThemeVal, appStore.getColor)
- //检测新版本
- setTimeout(() => {
- getVersionJsonApi()
- }, 1000)
- })
- //获取版本更新信息
- const getVersionJsonApi = async () => {
- const cache_version = getStoreValue('version')
- const {res} = await getVersionJson()
- const version = getObjValue(res)?.value
- setStoreValue('version', version)
- if (cache_version && cache_version !== version) {
- window?.$messageBox?.alert('检测到有新版本更新,请点击更新,或手动刷新网页更新,如果不更新,将无法使用相关功能', '更新提醒', {
- showCancelButton: true,
- confirmButtonText: '立即更新',
- cancelButtonText: '暂不更新',
- type: 'warning',
- callback: (action) => {
- if (action === 'confirm') {
- //刷新页面
- window.location.reload()
- }
- }
- })
- }
- }
- //设置主题 #0081ff
- const setUserTheme = (theme, appColor) => {
- const colorVal = getObjValue(appColor)
- //设置主色调
- setElementMainColor(colorVal?.color)
- const colorName = colorVal?.name || 'blue'
- //设置主题
- let val = UserTheme.value
- if (val === 'auto') {
- theme = useOsTheme().value;
- }
- if (theme === '') {
- theme = val;
- }
- //挂载相关样式
- document.documentElement.setAttribute('class', `${theme} color-${colorName}`)
- }
- </script>
|