BannerSwiper.vue
3.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!--
* @Date: 2025-01-20 10:00:00
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-07-24 14:20:22
* @FilePath: /jgdl/src/components/BannerSwiper.vue
* @Description: 轮播图组件
-->
<template>
<view class="px-4 pt-4" style="background: linear-gradient( 180deg, #fb923c 0%, rgba(255,203,53,0) 61%);">
<nut-swiper :init-page="0" :pagination-visible="true" pagination-color="#ffffff" auto-play="3000"
class="rounded-lg overflow-hidden" height="160">
<nut-swiper-item v-for="(item, index) in bannerList" :key="index" @click="onBannerClick(item)">
<image :src="item.image" mode="aspectFill" class="w-full h-40 object-cover" />
</nut-swiper-item>
</nut-swiper>
</view>
<!-- 图片预览组件 -->
<nut-image-preview
v-model:show="showImagePreview"
:images="previewImages"
:init-no="currentImageIndex"
/>
<!-- 文章弹框组件 -->
<nut-popup
v-model:visible="showArticleModal"
position="bottom"
:style="{ height: '100vh' }"
close-icon-position="bottom-right"
:safe-area-inset-bottom="true"
>
<view class="article-modal">
<!-- <view class="article-header p-4 border-b">
<text class="text-lg font-bold">{{ currentArticle.title }}</text>
</view> -->
<scroll-view :scroll-y="true" :catch-move="true" class="article-content" style="height: calc(100vh - 140rpx);">
<view class="p-4">
<rich-text :nodes="currentArticle.content"></rich-text>
</view>
</scroll-view>
<view class="article-footer p-4">
<nut-button type="primary" block color="#fb923c" @click="closeArticleModal">
关闭
</nut-button>
</view>
</view>
</nut-popup>
</template>
<script setup>
import Taro from '@tarojs/taro'
import { ref } from 'vue'
// 定义props
defineProps({
bannerList: {
type: Array,
default: () => []
}
})
// 定义emits
const emit = defineEmits(['bannerClick'])
// 响应式数据
const showImagePreview = ref(false)
const previewImages = ref([])
const currentImageIndex = ref(0)
const showArticleModal = ref(false)
const currentArticle = ref({
title: '',
content: ''
})
/**
* 点击轮播图处理函数
*/
const onBannerClick = (item) => {
switch (item.type) {
case 'poster':
// 海报图 - 显示图片预览
previewImages.value = [item.image]
currentImageIndex.value = 0
showImagePreview.value = true
break
case 'article':
// 文章封面图 - 显示文章弹框
currentArticle.value = {
title: item.title,
content: item.content
}
showArticleModal.value = true
break
case 'vehicle':
// 车辆封面图 - 跳转到车辆详情页
Taro.navigateTo({
url: `/pages/productDetail/index?id=${item.id}`
})
break
default:
console.warn('未知的轮播图类型:', item.type)
}
// 触发父组件事件
emit('bannerClick', item)
}
/**
* 关闭文章弹框
*/
const closeArticleModal = () => {
showArticleModal.value = false
}
</script>
<style scoped>
.article-modal {
height: 100vh;
display: flex;
flex-direction: column;
}
.article-content {
overflow-y: auto;
}
.article-footer {
position: sticky;
bottom: 0;
left: 0;
right: 0;
background: white;
border-top: 1px solid #eee;
padding: 16px;
z-index: 1000;
margin-top: auto;
}
</style>