layout-header.vue
1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<script setup lang="ts">
import type { CSSProperties } from 'vue';
import { computed, useSlots } from 'vue';
interface Props {
/**
* 横屏
*/
fullWidth: boolean;
/**
* 高度
*/
height: number;
/**
* 是否移动端
*/
isMobile: boolean;
/**
* 是否显示
*/
show: boolean;
/**
* 侧边菜单宽度
*/
sidebarWidth: number;
/**
* 主题
*/
theme: string | undefined;
/**
* 宽度
*/
width: string;
/**
* zIndex
*/
zIndex: number;
}
const props = withDefaults(defineProps<Props>(), {});
const slots = useSlots();
const style = computed((): CSSProperties => {
const { fullWidth, height, show } = props;
const right = !show || !fullWidth ? undefined : 0;
return {
height: `${height}px`,
marginTop: show ? 0 : `-${height}px`,
right,
};
});
const logoStyle = computed((): CSSProperties => {
return {
minWidth: `${props.isMobile ? 40 : props.sidebarWidth}px`,
};
});
</script>
<template>
<header
:class="theme"
:style="style"
class="top-0 flex w-full flex-[0_0_auto] items-center border-b border-border bg-header pl-2 transition-[margin-top] duration-200"
>
<div v-if="slots.logo" :style="logoStyle">
<slot name="logo"></slot>
</div>
<slot name="toggle-button"> </slot>
<slot></slot>
</header>
</template>