feat(home): 替换首页轮播图实现为广告系统驱动
- 移除原有的硬编码轮播图组件和相关样式 - 新增 getAdByCode 方法用于获取广告数据 - 实现解析广告数据的工具函数 parseSlides 和 parsePx - 集成 useAsyncData 获取 flash 广告数据 - 添加备用图片以确保加载失败时的显示 - 更新页面样式适配新的轮播组件结构
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
<div class="carousel-panel" :style="{ height: heightCss }">
|
<div class="carousel-panel" :style="{ height: heightCss }">
|
||||||
<ClientOnly>
|
<ClientOnly>
|
||||||
<a-carousel
|
<a-carousel
|
||||||
|
ref="carouselRef"
|
||||||
class="carousel"
|
class="carousel"
|
||||||
:autoplay="autoplayEnabled"
|
:autoplay="autoplayEnabled"
|
||||||
:autoplay-speed="autoplaySpeed"
|
:autoplay-speed="autoplaySpeed"
|
||||||
@@ -10,7 +11,12 @@
|
|||||||
:effect="effect"
|
:effect="effect"
|
||||||
:style="{ height: heightCss }"
|
:style="{ height: heightCss }"
|
||||||
>
|
>
|
||||||
<div v-for="it in normalizedItems" :key="it.src" class="carousel-item" :style="{ height: heightCss }">
|
<div
|
||||||
|
v-for="(it, idx) in normalizedItems"
|
||||||
|
:key="`${it.src}::${idx}`"
|
||||||
|
class="carousel-item"
|
||||||
|
:style="{ height: heightCss }"
|
||||||
|
>
|
||||||
<NuxtLink
|
<NuxtLink
|
||||||
v-if="it.href && !isExternal(it.href)"
|
v-if="it.href && !isExternal(it.href)"
|
||||||
:to="it.href"
|
:to="it.href"
|
||||||
@@ -33,6 +39,25 @@
|
|||||||
</div>
|
</div>
|
||||||
</a-carousel>
|
</a-carousel>
|
||||||
|
|
||||||
|
<button
|
||||||
|
v-if="showNav"
|
||||||
|
type="button"
|
||||||
|
class="carousel-nav carousel-nav-left"
|
||||||
|
aria-label="prev"
|
||||||
|
@click.prevent.stop="prev"
|
||||||
|
>
|
||||||
|
<span aria-hidden="true">‹</span>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
v-if="showNav"
|
||||||
|
type="button"
|
||||||
|
class="carousel-nav carousel-nav-right"
|
||||||
|
aria-label="next"
|
||||||
|
@click.prevent.stop="next"
|
||||||
|
>
|
||||||
|
<span aria-hidden="true">›</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
<template #fallback>
|
<template #fallback>
|
||||||
<img class="carousel-img" :style="{ height: heightCss }" :src="fallbackSrc" alt="slide" />
|
<img class="carousel-img" :style="{ height: heightCss }" :src="fallbackSrc" alt="slide" />
|
||||||
</template>
|
</template>
|
||||||
@@ -62,23 +87,41 @@ const props = withDefaults(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type AntdCarouselExpose = {
|
||||||
|
next: () => void
|
||||||
|
prev: () => void
|
||||||
|
goTo: (slide: number, dontAnimate?: boolean) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
const carouselRef = ref<AntdCarouselExpose | null>(null)
|
||||||
|
|
||||||
const heightCss = computed(() => (typeof props.height === 'number' ? `${props.height}px` : props.height))
|
const heightCss = computed(() => (typeof props.height === 'number' ? `${props.height}px` : props.height))
|
||||||
|
|
||||||
const normalizedItems = computed(() => (props.items || []).filter((it) => it && typeof it.src === 'string' && it.src))
|
const normalizedItems = computed(() => (props.items || []).filter((it) => it && typeof it.src === 'string' && it.src))
|
||||||
|
|
||||||
const autoplayEnabled = computed(() => normalizedItems.value.length > 1)
|
const autoplayEnabled = computed(() => normalizedItems.value.length > 1)
|
||||||
const dotsEnabled = computed(() => normalizedItems.value.length > 1)
|
const dotsEnabled = computed(() => normalizedItems.value.length > 1)
|
||||||
|
const showNav = computed(() => normalizedItems.value.length > 1)
|
||||||
|
|
||||||
const fallbackSrc = computed(() => normalizedItems.value[0]?.src || '')
|
const fallbackSrc = computed(() => normalizedItems.value[0]?.src || '')
|
||||||
|
|
||||||
function isExternal(href: string) {
|
function isExternal(href: string) {
|
||||||
return /^https?:\/\//i.test(href)
|
return /^https?:\/\//i.test(href)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function next() {
|
||||||
|
carouselRef.value?.next()
|
||||||
|
}
|
||||||
|
|
||||||
|
function prev() {
|
||||||
|
carouselRef.value?.prev()
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.carousel-panel {
|
.carousel-panel {
|
||||||
background: #fff;
|
background: #fff;
|
||||||
|
position: relative;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.04);
|
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.04);
|
||||||
}
|
}
|
||||||
@@ -109,4 +152,39 @@ function isExternal(href: string) {
|
|||||||
.carousel :deep(.slick-slide > div) {
|
.carousel :deep(.slick-slide > div) {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.carousel-nav {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
z-index: 5;
|
||||||
|
width: 42px;
|
||||||
|
height: 42px;
|
||||||
|
border-radius: 9999px;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.55);
|
||||||
|
background: rgba(0, 0, 0, 0.35);
|
||||||
|
color: rgba(255, 255, 255, 0.95);
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
cursor: pointer;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.carousel-nav:hover {
|
||||||
|
background: rgba(0, 0, 0, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.carousel-nav-left {
|
||||||
|
left: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.carousel-nav-right {
|
||||||
|
right: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.carousel-nav span {
|
||||||
|
font-size: 26px;
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -30,10 +30,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<a-affix :offset-top="0">
|
<a-affix :offset-top="0" @change="onAffixChange">
|
||||||
<div class="navbar">
|
<div class="navbar">
|
||||||
<div class="mx-auto flex max-w-screen-xl items-center justify-between gap-3 px-4">
|
<div class="mx-auto flex max-w-screen-xl items-center justify-between gap-20 px-">
|
||||||
<NuxtLink to="/" class="navbar-brand">
|
<NuxtLink v-if="isAffixed" to="/" class="navbar-brand" :class="{ 'navbar-brand-hidden': !isAffixed }">
|
||||||
<img class="navbar-logo" :src="logoUrl" :alt="siteName" />
|
<img class="navbar-logo" :src="logoUrl" :alt="siteName" />
|
||||||
<span class="navbar-brand-name">
|
<span class="navbar-brand-name">
|
||||||
{{ siteName }}
|
{{ siteName }}
|
||||||
@@ -119,6 +119,7 @@ import { COMPANY } from '@/config/company'
|
|||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const open = ref(false)
|
const open = ref(false)
|
||||||
|
const isAffixed = ref(false)
|
||||||
|
|
||||||
type HeaderNavItem = {
|
type HeaderNavItem = {
|
||||||
key: string
|
key: string
|
||||||
@@ -281,6 +282,10 @@ const todayText = computed(() => {
|
|||||||
const pad = (n: number) => String(n).padStart(2, '0')
|
const pad = (n: number) => String(n).padStart(2, '0')
|
||||||
return `${d.getFullYear()}年${pad(d.getMonth() + 1)}月${pad(d.getDate())}日 星期${week}`
|
return `${d.getFullYear()}年${pad(d.getMonth() + 1)}月${pad(d.getDate())}日 星期${week}`
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function onAffixChange(affixed: boolean) {
|
||||||
|
isAffixed.value = affixed
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
@@ -362,11 +367,19 @@ const todayText = computed(() => {
|
|||||||
.navbar-brand {
|
.navbar-brand {
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 10px;
|
gap: 20px;
|
||||||
height: 48px;
|
height: 48px;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
color: rgba(255, 255, 255, 0.95);
|
color: rgba(255, 255, 255, 0.95);
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
|
transition: opacity 0.18s ease, transform 0.18s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navbar-brand-hidden {
|
||||||
|
opacity: 0;
|
||||||
|
visibility: hidden;
|
||||||
|
pointer-events: none;
|
||||||
|
transform: translateY(-4px);
|
||||||
}
|
}
|
||||||
|
|
||||||
.navbar-logo {
|
.navbar-logo {
|
||||||
@@ -392,7 +405,7 @@ const todayText = computed(() => {
|
|||||||
|
|
||||||
.nav {
|
.nav {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 2px;
|
gap: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.nav-link {
|
.nav-link {
|
||||||
|
|||||||
Reference in New Issue
Block a user