feat: 新增 首页布局容器组件

This commit is contained in:
pengzhanbo 2024-03-04 03:20:18 +08:00
parent 83bae10344
commit bfa9164037

View File

@ -0,0 +1,73 @@
<script setup lang="ts">
import { withBase } from 'vuepress/client'
import { computed, normalizeClass } from 'vue'
import { isLinkHttp } from 'vuepress/shared'
import type { PlumeHomeConfigBase } from '../../../shared/index.js'
import { useDarkMode } from '../../composables/index.js'
const props = defineProps<PlumeHomeConfigBase & {
containerClass?: any
}>()
const isDark = useDarkMode()
const styles = computed(() => {
if (!props.backgroundImage)
return null
const image = typeof props.backgroundImage === 'string' ? props.backgroundImage : (props.backgroundImage[isDark.value ? 'dark' : 'light'] ?? props.backgroundImage.light)
const link = isLinkHttp(image) ? props.backgroundImage : withBase(image)
return {
'background-image': `url(${link})`,
'background-size': 'cover',
'background-position': 'center',
'background-repeat': 'no-repeat',
'background-attachment': props.backgroundAttachment || '',
}
})
const containerClass = computed(() => normalizeClass(props.containerClass || ''))
</script>
<template>
<div class="home-box" :class="{ full: props.full }" :style="styles">
<slot name="before" />
<div class="container" :class="containerClass">
<slot />
</div>
<slot name="after" />
</div>
</template>
<style>
.home-box {
position: relative;
padding: 24px;
}
@media (min-width: 640px) {
.home-box {
padding: 32px 48px;
}
}
@media (min-width: 960px) {
.home-box {
padding: 48px;
}
}
.home-box .container {
width: 100%;
max-width: 1152px;
margin: 0 auto;
}
.home-box.full {
display: flex;
align-items: center;
justify-content: center;
min-height: calc(100vh - var(--vp-nav-height));
}
</style>