feat(home): 替换首页轮播图实现为广告系统驱动

- 移除原有的硬编码轮播图组件和相关样式
- 新增 getAdByCode 方法用于获取广告数据
- 实现解析广告数据的工具函数 parseSlides 和 parsePx
- 集成 useAsyncData 获取 flash 广告数据
- 添加备用图片以确保加载失败时的显示
- 更新页面样式适配新的轮播组件结构
This commit is contained in:
2026-01-29 14:05:01 +08:00
parent 08134d4598
commit aaef9e0dba
3 changed files with 78 additions and 73 deletions

View File

@@ -8,15 +8,16 @@
:autoplay-speed="autoplaySpeed"
:dots="dotsEnabled"
:effect="effect"
:style="{ height: heightCss }"
>
<div v-for="it in normalizedItems" :key="it.src" class="carousel-item">
<div v-for="it in normalizedItems" :key="it.src" class="carousel-item" :style="{ height: heightCss }">
<NuxtLink
v-if="it.href && !isExternal(it.href)"
:to="it.href"
class="carousel-link"
aria-label="carousel-slide"
>
<div class="carousel-bg" :style="{ backgroundImage: `url(${it.src})` }"></div>
<img class="carousel-img" :src="it.src" :alt="it.alt || 'slide'" loading="lazy" />
</NuxtLink>
<a
v-else-if="it.href"
@@ -26,14 +27,14 @@
rel="noopener noreferrer"
aria-label="carousel-slide"
>
<div class="carousel-bg" :style="{ backgroundImage: `url(${it.src})` }"></div>
<img class="carousel-img" :src="it.src" :alt="it.alt || 'slide'" loading="lazy" />
</a>
<div v-else class="carousel-bg" :style="{ backgroundImage: `url(${it.src})` }"></div>
<img v-else class="carousel-img" :src="it.src" :alt="it.alt || 'slide'" loading="lazy" />
</div>
</a-carousel>
<template #fallback>
<div class="carousel-bg" :style="{ height: heightCss, backgroundImage: `url(${fallbackSrc})` }"></div>
<img class="carousel-img" :style="{ height: heightCss }" :src="fallbackSrc" alt="slide" />
</template>
</ClientOnly>
</div>
@@ -44,6 +45,7 @@
type CarouselItem = {
src: string
href?: string
alt?: string
}
const props = withDefaults(
@@ -77,8 +79,6 @@ function isExternal(href: string) {
<style scoped>
.carousel-panel {
background: #fff;
border: 1px solid rgba(0, 0, 0, 0.06);
border-radius: 10px;
overflow: hidden;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.04);
}
@@ -96,11 +96,11 @@ function isExternal(href: string) {
height: 100%;
}
.carousel-bg {
.carousel-img {
width: 100%;
height: 100%;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
object-fit: cover;
display: block;
}
.carousel :deep(.slick-list),

View File

@@ -18,7 +18,7 @@
</div>
<div v-if="showBrandbar" class="brandbar">
<div class="mx-auto grid max-w-screen-xl grid-cols-12 items-center gap-6 px-4 py-8">
<div class="mx-auto grid max-w-screen-xl grid-cols-12 items-center gap-6 px-4 py-4">
<NuxtLink to="/" class="col-span-12 flex items-center gap-4 md:col-span-6">
<img class="brand-logo" :src="`https://oss.wsdns.cn/20260127/989e5cf82b0847ed9168023baf68f4a9.png`" :alt="siteName" />
</NuxtLink>