<template>
    <HcAppConfig>
        <router-view/>
    </HcAppConfig>
</template>

<script setup>
import {nextTick, ref, watch} from "vue";
import {useAppStore} from "~src/store";
import {useOsTheme} from 'hc-vue3-ui'
import {setElementMainColor, ulog, getObjValue} from "js-fast-way"
import config from '~src/config/index';
import split from "split.js";

//初始变量
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(()=> {
    window['$split'] = split;
    setUserTheme(appStore.getThemeVal, appStore.getColor)
    ulog('档案管理 启动成功', '当前开发版本 v' + config?.version)
    //当屏幕分辨率宽度低于1920时，自动折叠菜单
    const width = document.body.clientWidth
    if (width < 1920) {
        appStore.setCollapse(true)
    }
})

//设置主题
const setUserTheme = (theme, appColor) => {
    const colorVal = getObjValue(appColor)
    //设置主色调
    setElementMainColor(colorVal?.color)
    const colorName = colorVal?.name || 'green'
    //设置主题
    let val = UserTheme.value
    if (val === 'auto') {
        theme = useOsTheme();
    }
    if (theme === '') {
        theme = val;
    }
    //挂载相关样式
    document.documentElement.setAttribute('class',`${theme} color-${colorName}`)
}
</script>
