提交 | 用户 | 时间
|
314507
|
1 |
<script setup lang="ts"> |
H |
2 |
import { provide, computed, watch, onMounted } from 'vue' |
|
3 |
import { propTypes } from '@/utils/propTypes' |
|
4 |
import { ComponentSize, ElConfigProvider } from 'element-plus' |
|
5 |
import { useLocaleStore } from '@/store/modules/locale' |
|
6 |
import { useWindowSize } from '@vueuse/core' |
|
7 |
import { useAppStore } from '@/store/modules/app' |
|
8 |
import { setCssVar } from '@/utils' |
|
9 |
import { useDesign } from '@/hooks/web/useDesign' |
|
10 |
|
|
11 |
const { variables } = useDesign() |
|
12 |
|
|
13 |
const appStore = useAppStore() |
|
14 |
|
|
15 |
const props = defineProps({ |
|
16 |
size: propTypes.oneOf<ComponentSize>(['default', 'small', 'large']).def('default') |
|
17 |
}) |
|
18 |
|
|
19 |
provide('configGlobal', props) |
|
20 |
|
|
21 |
// 初始化所有主题色 |
|
22 |
onMounted(() => { |
|
23 |
appStore.setCssVarTheme() |
|
24 |
}) |
|
25 |
|
|
26 |
const { width } = useWindowSize() |
|
27 |
|
|
28 |
// 监听窗口变化 |
|
29 |
watch( |
|
30 |
() => width.value, |
|
31 |
(width: number) => { |
|
32 |
if (width < 768) { |
|
33 |
!appStore.getMobile ? appStore.setMobile(true) : undefined |
|
34 |
setCssVar('--left-menu-min-width', '0') |
|
35 |
appStore.setCollapse(true) |
|
36 |
appStore.getLayout !== 'classic' ? appStore.setLayout('classic') : undefined |
|
37 |
} else { |
|
38 |
appStore.getMobile ? appStore.setMobile(false) : undefined |
|
39 |
setCssVar('--left-menu-min-width', '64px') |
|
40 |
} |
|
41 |
}, |
|
42 |
{ |
|
43 |
immediate: true |
|
44 |
} |
|
45 |
) |
|
46 |
|
|
47 |
// 多语言相关 |
|
48 |
const localeStore = useLocaleStore() |
|
49 |
|
|
50 |
const currentLocale = computed(() => localeStore.currentLocale) |
|
51 |
</script> |
|
52 |
|
|
53 |
<template> |
|
54 |
<ElConfigProvider |
|
55 |
:namespace="variables.elNamespace" |
|
56 |
:locale="currentLocale.elLocale" |
|
57 |
:message="{ max: 5 }" |
|
58 |
:size="size" |
|
59 |
> |
|
60 |
<slot></slot> |
|
61 |
</ElConfigProvider> |
|
62 |
</template> |