Files
ss-crm-manage-web/src/components/ConfigGlobal/src/ConfigGlobal.vue

62 lines
1.5 KiB
Vue
Raw Normal View History

2024-04-28 16:20:45 +08:00
<script lang="ts" name="ConfigGlobal" setup>
import { propTypes } from '@/utils/propTypes'
import { useLocaleStore } from '@/store/modules/locale'
import { useAppStore } from '@/store/modules/app'
import { setCssVar } from '@/utils'
import { useDesign } from '@/hooks/web/useDesign'
import { ElementPlusSize } from '@/types/elementPlus'
import { useWindowSize } from '@vueuse/core'
const { variables } = useDesign()
const appStore = useAppStore()
const props = defineProps({
size: propTypes.oneOf<ElementPlusSize>(['default', 'small', 'large']).def('default')
})
provide('configGlobal', props)
// 初始化所有主题色
onMounted(() => {
appStore.setCssVarTheme()
})
2024-09-20 11:21:05 +08:00
const { width, height } = useWindowSize()
2024-04-28 16:20:45 +08:00
// 监听窗口变化
watch(
() => width.value,
(width: number) => {
2024-09-20 11:21:05 +08:00
if (width < 768 || height.value < 450) {
2024-04-28 16:20:45 +08:00
!appStore.getMobile ? appStore.setMobile(true) : undefined
setCssVar('--left-menu-min-width', '0')
appStore.setCollapse(true)
appStore.getLayout !== 'classic' ? appStore.setLayout('classic') : undefined
} else {
appStore.getMobile ? appStore.setMobile(false) : undefined
setCssVar('--left-menu-min-width', '64px')
}
},
{
immediate: true
}
)
// 多语言相关
const localeStore = useLocaleStore()
const currentLocale = computed(() => localeStore.currentLocale)
</script>
<template>
<ElConfigProvider
:locale="currentLocale.elLocale"
:message="{ max: 1 }"
:namespace="variables.elNamespace"
:size="size"
>
<slot></slot>
</ElConfigProvider>
</template>