feat 页面页尾

This commit is contained in:
Ironsp
2026-10-01 14:23:58 +08:00
parent b99b2a0a88
commit 0d2389e49a
11 changed files with 166 additions and 35 deletions

View File

@@ -1,10 +1,24 @@
<script setup lang="ts">
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
import { useRouter } from 'vue-router'
import bannerIllustration from '@/assets/home/banner-illustration.png'
import type { Banner } from '@/types/business/home'
const props = defineProps<{
banners: Banner[]
}>()
// 设计稿顶部为静态头图(非轮播、不走接口):底 #F3F4F8 渐变,
// 左侧标题 60px + 副标题 24px + 双按钮 183×55,右侧插画 723×598(蓝湖设计稿切图)
const router = useRouter()
const activeIndex = ref(0)
let timer: ReturnType<typeof setInterval> | null = null
/** 接口无图时用设计稿插画兜底,保证头图始终有一层视觉 */
const slides = computed(() => {
if (props.banners.length > 0) {
return props.banners.map((item) => item.imageUrl)
}
return [bannerIllustration]
})
function goDemand(): void {
router.push('/demand')
@@ -13,10 +27,50 @@ function goDemand(): void {
function goCases(): void {
router.push('/cases')
}
function goTo(index: number): void {
activeIndex.value = index
}
function startAutoplay(): void {
stopAutoplay()
if (slides.value.length <= 1) return
timer = setInterval(() => {
activeIndex.value = (activeIndex.value + 1) % slides.value.length
}, 5000)
}
function stopAutoplay(): void {
if (timer) {
clearInterval(timer)
timer = null
}
}
watch(slides, () => {
activeIndex.value = 0
startAutoplay()
})
onMounted(startAutoplay)
onBeforeUnmount(stopAutoplay)
</script>
<template>
<section class="home-banner">
<!-- 底层:图片轮播(文案层始终叠在其上) -->
<div class="home-banner__carousel" aria-hidden="true">
<div
v-for="(src, index) in slides"
:key="`${src}-${index}`"
class="home-banner__slide"
:class="{ 'home-banner__slide--active': index === activeIndex }"
>
<img class="home-banner__image" :src="src" alt="">
</div>
</div>
<!-- 顶层:标题 / 副标题 / 按钮,轮播切换时位置不变 -->
<div class="home-banner__inner">
<h1 class="home-banner__title">虫子智造研发一体化平台</h1>
<p class="home-banner__subtitle">一站式智能软硬件研发与量产综合服务商</p>
@@ -29,36 +83,66 @@ function goCases(): void {
案例中心
</button>
</div>
</div>
<div class="home-banner__visual">
<img
class="home-banner__illustration"
:src="bannerIllustration"
alt="虫子智造研发一体化平台"
>
</div>
<div v-if="slides.length > 1" class="home-banner__dots" role="tablist" aria-label="头图轮播">
<button
v-for="(_, index) in slides"
:key="index"
class="home-banner__dot"
:class="{ 'home-banner__dot--active': index === activeIndex }"
type="button"
role="tab"
:aria-selected="index === activeIndex"
@click="goTo(index)"
/>
</div>
</section>
</template>
<style lang="less" scoped>
.home-banner {
// 设计稿头图通栏 1920×661(画板 y73,位于顶栏 72 之下)
position: relative;
height: 661px;
overflow: hidden;
background: @home-banner-bg;
// .home 是 column flex 容器,需显式占满整行,否则被内容宽度收缩
width: 100%;
flex: 0 0 auto;
// 内容区按设计稿 1920 画布居中;两侧内容一律相对它定位,保证 1:1
// 底层轮播:通栏铺满,文案层叠在上面
&__carousel {
position: absolute;
inset: 0;
z-index: 0;
}
&__slide {
position: absolute;
inset: 0;
opacity: 0;
transition: opacity 0.6s ease;
&--active {
opacity: 1;
}
}
&__image {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
}
// 顶层文案:相对内容区定位,不随轮播切换
&__inner {
position: relative;
z-index: 1;
width: 100%;
max-width: @container-width;
height: 100%;
margin: 0 auto;
pointer-events: none;
}
// 设计稿标题 x150 y257(画板绝对)→ banner 内 y257−73=184
@@ -87,13 +171,14 @@ function goCases(): void {
white-space: nowrap;
}
// 设计稿按钮组 x150 y465 → banner 内 y392;两钮 183×55,间距 20(150+183=333 → 353)
// 设计稿按钮组 x150 y465 → banner 内 y392;两钮 183×55,间距 20
&__actions {
position: absolute;
top: 392px;
left: 150px;
.flex(row, flex-start, center);
gap: 20px;
pointer-events: auto;
}
&__btn {
@@ -111,7 +196,6 @@ function goCases(): void {
color: @white;
}
// 设计稿:2px 渐变描边 + 白底 + 蓝色文字(实测 #2B5FF0)
&--ghost {
position: relative;
background: @white;
@@ -138,20 +222,29 @@ function goCases(): void {
}
}
// 设计稿插画 723×598 @ canvas (928,104) → banner 内 y104−73=31
&__visual {
&__dots {
position: absolute;
top: 31px;
left: 928px;
width: 723px;
height: 598px;
right: 80px;
bottom: 40px;
z-index: 1;
.flex(row, flex-end, center);
gap: 8px;
}
&__illustration {
display: block;
width: 100%;
height: 100%;
object-fit: contain;
&__dot {
width: 8px;
height: 8px;
padding: 0;
border: none;
border-radius: 50%;
background: fade(@home-banner-dot, 40%);
cursor: pointer;
&--active {
width: 24px;
border-radius: 4px;
background: @home-banner-dot;
}
}
}
</style>