feat(首页): 添加新闻轮播组件并优化页面布局
移除左下角背景装饰图,新增新闻轮播功能及相关样式 设置页面标题为'西园戒幢律寺三坛大戒法会'
Showing
2 changed files
with
284 additions
and
31 deletions
1.18 MB
| 1 | <template> | 1 | <template> |
| 2 | <div class="home-container"> | 2 | <div class="home-container"> |
| 3 | 3 | ||
| 4 | - <!-- 左下角背景装饰图 - bg@2x.png --> | ||
| 5 | - <div class="bottom-left-decoration"></div> | ||
| 6 | - | ||
| 7 | <!-- 主要内容区域 --> | 4 | <!-- 主要内容区域 --> |
| 8 | <div class="main-content"> | 5 | <div class="main-content"> |
| 9 | <!-- 顶部Banner图片 --> | 6 | <!-- 顶部Banner图片 --> |
| ... | @@ -141,6 +138,47 @@ | ... | @@ -141,6 +138,47 @@ |
| 141 | </div> | 138 | </div> |
| 142 | </div> | 139 | </div> |
| 143 | </div> | 140 | </div> |
| 141 | + | ||
| 142 | + <!-- 相关新闻 --> | ||
| 143 | + <div class="news-section"> | ||
| 144 | + <!-- 标题 --> | ||
| 145 | + <div class="common-title"> | ||
| 146 | + <img src="/src/assets/images/02 西园戒幢律寺三坛大戒法会/相关新聞@2x.png" alt="相关新闻" class="title-image"> | ||
| 147 | + </div> | ||
| 148 | + | ||
| 149 | + <!-- 轮播容器 --> | ||
| 150 | + <div class="news-carousel-container"> | ||
| 151 | + <div class="news-carousel" ref="newsCarousel"> | ||
| 152 | + <div class="news-item" v-for="(item, index) in newsItems" :key="index" @click="handleNewsClick(item)"> | ||
| 153 | + <div class="news-image"> | ||
| 154 | + <img :src="item.image" :alt="item.title"> | ||
| 155 | + </div> | ||
| 156 | + <div class="news-content"> | ||
| 157 | + <div class="news-title">{{ item.title }}</div> | ||
| 158 | + <div class="news-date">{{ item.date }}</div> | ||
| 159 | + </div> | ||
| 160 | + </div> | ||
| 161 | + </div> | ||
| 162 | + | ||
| 163 | + <!-- 导航按钮 --> | ||
| 164 | + <div class="carousel-nav"> | ||
| 165 | + <img | ||
| 166 | + class="nav-btn prev-btn" | ||
| 167 | + src="/src/assets/images/02 西园戒幢律寺三坛大戒法会/上@2x.png" | ||
| 168 | + alt="上一张" | ||
| 169 | + @click="prevSlide" | ||
| 170 | + :class="{ disabled: currentSlide === 0 }" | ||
| 171 | + > | ||
| 172 | + <img | ||
| 173 | + class="nav-btn next-btn" | ||
| 174 | + src="/src/assets/images/02 西园戒幢律寺三坛大戒法会/下@2x.png" | ||
| 175 | + alt="下一张" | ||
| 176 | + @click="nextSlide" | ||
| 177 | + :class="{ disabled: currentSlide >= maxSlide }" | ||
| 178 | + > | ||
| 179 | + </div> | ||
| 180 | + </div> | ||
| 181 | + </div> | ||
| 144 | </div> | 182 | </div> |
| 145 | </div> | 183 | </div> |
| 146 | </template> | 184 | </template> |
| ... | @@ -148,6 +186,10 @@ | ... | @@ -148,6 +186,10 @@ |
| 148 | <script setup> | 186 | <script setup> |
| 149 | import { ref, computed, nextTick, onMounted, watch } from 'vue' | 187 | import { ref, computed, nextTick, onMounted, watch } from 'vue' |
| 150 | import VideoPlayer from '@/components/VideoPlayer.vue' | 188 | import VideoPlayer from '@/components/VideoPlayer.vue' |
| 189 | +import { useTitle } from '@vueuse/core'; | ||
| 190 | + | ||
| 191 | +// 页面标题 | ||
| 192 | +useTitle('西园戒幢律寺三坛大戒法会'); | ||
| 151 | 193 | ||
| 152 | // 视频配置 | 194 | // 视频配置 |
| 153 | const videoUrl = ref('/src/assets/images/02 西园戒幢律寺三坛大戒法会/sample-10s.mp4') | 195 | const videoUrl = ref('/src/assets/images/02 西园戒幢律寺三坛大戒法会/sample-10s.mp4') |
| ... | @@ -296,6 +338,91 @@ const viewMore = (type) => { | ... | @@ -296,6 +338,91 @@ const viewMore = (type) => { |
| 296 | // 这里可以添加跳转到详情页面的逻辑 | 338 | // 这里可以添加跳转到详情页面的逻辑 |
| 297 | } | 339 | } |
| 298 | } | 340 | } |
| 341 | + | ||
| 342 | +// 新闻轮播相关逻辑 | ||
| 343 | +const newsCarousel = ref(null) | ||
| 344 | +const currentSlide = ref(0) | ||
| 345 | + | ||
| 346 | +// 新闻数据 | ||
| 347 | +const newsItems = ref([ | ||
| 348 | + { | ||
| 349 | + image: '/src/assets/images/02 西园戒幢律寺三坛大戒法会/截图/全家福3_副本.jpg', | ||
| 350 | + title: '三坛大戒 | 护戒胜福田 成就最上因', | ||
| 351 | + date: '2025-10-01' | ||
| 352 | + }, | ||
| 353 | + { | ||
| 354 | + image: '/src/assets/images/02 西园戒幢律寺三坛大戒法会/截图/全家福3_副本.jpg', | ||
| 355 | + title: '西园戒幢律寺三坛大戒法会圆满举行', | ||
| 356 | + date: '2025-09-28' | ||
| 357 | + }, | ||
| 358 | + { | ||
| 359 | + image: '/src/assets/images/02 西园戒幢律寺三坛大戒法会/截图/全家福3_副本.jpg', | ||
| 360 | + title: '戒子们庄严受戒 功德圆满', | ||
| 361 | + date: '2025-09-25' | ||
| 362 | + }, | ||
| 363 | + { | ||
| 364 | + image: '/src/assets/images/02 西园戒幢律寺三坛大戒法会/截图/全家福3_副本.jpg', | ||
| 365 | + title: '三师七证齐聚 传承佛法精神', | ||
| 366 | + date: '2025-09-22' | ||
| 367 | + } | ||
| 368 | +]) | ||
| 369 | + | ||
| 370 | +// 计算最大滑动位置 | ||
| 371 | +const maxSlide = computed(() => { | ||
| 372 | + return Math.max(0, newsItems.value.length - 1) | ||
| 373 | +}) | ||
| 374 | + | ||
| 375 | +// 上一张 | ||
| 376 | +const prevSlide = () => { | ||
| 377 | + if (currentSlide.value > 0) { | ||
| 378 | + currentSlide.value-- | ||
| 379 | + updateCarouselPosition() | ||
| 380 | + } | ||
| 381 | +} | ||
| 382 | + | ||
| 383 | +// 下一张 | ||
| 384 | +const nextSlide = () => { | ||
| 385 | + if (currentSlide.value < maxSlide.value) { | ||
| 386 | + currentSlide.value++ | ||
| 387 | + updateCarouselPosition() | ||
| 388 | + } | ||
| 389 | +} | ||
| 390 | + | ||
| 391 | +// 更新轮播位置:按卡片宽度+间距进行像素级位移 | ||
| 392 | +const updateCarouselPosition = () => { | ||
| 393 | + const carouselEl = newsCarousel.value | ||
| 394 | + if (!carouselEl) return | ||
| 395 | + | ||
| 396 | + const containerEl = carouselEl.parentElement | ||
| 397 | + const containerWidth = containerEl ? containerEl.clientWidth : 0 | ||
| 398 | + const firstItem = carouselEl.querySelector('.news-item') | ||
| 399 | + if (!firstItem) return | ||
| 400 | + | ||
| 401 | + const itemWidth = firstItem.getBoundingClientRect().width | ||
| 402 | + // 读取gap像素值,回退到0.5rem(8px) | ||
| 403 | + let gapStr = getComputedStyle(carouselEl).gap | ||
| 404 | + if (!gapStr || gapStr === 'normal') { | ||
| 405 | + gapStr = '8px' | ||
| 406 | + } | ||
| 407 | + const gapPx = parseFloat(gapStr) || 8 | ||
| 408 | + | ||
| 409 | + let distance = currentSlide.value * (itemWidth + gapPx) | ||
| 410 | + | ||
| 411 | + // 最后一张时,保证完整显示(居中显示,无下一张时不被裁切) | ||
| 412 | + if (currentSlide.value === maxSlide.value) { | ||
| 413 | + const lastOffset = (newsItems.value.length - 1) * (itemWidth + gapPx) | ||
| 414 | + const centerOffset = Math.max(0, (containerWidth - itemWidth) / 2) | ||
| 415 | + distance = lastOffset - centerOffset | ||
| 416 | + } | ||
| 417 | + | ||
| 418 | + carouselEl.style.transform = `translateX(-${distance}px)` | ||
| 419 | +} | ||
| 420 | + | ||
| 421 | +// 处理新闻点击事件 | ||
| 422 | +const handleNewsClick = (item) => { | ||
| 423 | + console.log('点击新闻:', item) | ||
| 424 | + // 这里可以添加跳转到新闻详情页面的逻辑 | ||
| 425 | +} | ||
| 299 | </script> | 426 | </script> |
| 300 | 427 | ||
| 301 | <style scoped> | 428 | <style scoped> |
| ... | @@ -306,21 +433,6 @@ const viewMore = (type) => { | ... | @@ -306,21 +433,6 @@ const viewMore = (type) => { |
| 306 | overflow-x: hidden; | 433 | overflow-x: hidden; |
| 307 | } | 434 | } |
| 308 | 435 | ||
| 309 | -/* 左下角背景装饰图 - bg@2x.png */ | ||
| 310 | -.bottom-left-decoration { | ||
| 311 | - position: fixed; | ||
| 312 | - bottom: 0; | ||
| 313 | - left: 0; | ||
| 314 | - width: 50%; | ||
| 315 | - height: 50%; | ||
| 316 | - background-image: url('@/assets/images/02 西园戒幢律寺三坛大戒法会/bg@2x.png'); | ||
| 317 | - background-size: contain; | ||
| 318 | - background-position: bottom left; | ||
| 319 | - background-repeat: no-repeat; | ||
| 320 | - z-index: -1; | ||
| 321 | - pointer-events: none; | ||
| 322 | -} | ||
| 323 | - | ||
| 324 | /* 主要内容区域 */ | 436 | /* 主要内容区域 */ |
| 325 | .main-content { | 437 | .main-content { |
| 326 | position: relative; | 438 | position: relative; |
| ... | @@ -413,6 +525,8 @@ const viewMore = (type) => { | ... | @@ -413,6 +525,8 @@ const viewMore = (type) => { |
| 413 | .common-title { | 525 | .common-title { |
| 414 | text-align: center; | 526 | text-align: center; |
| 415 | margin-bottom: 2rem; | 527 | margin-bottom: 2rem; |
| 528 | + position: relative; | ||
| 529 | + z-index: 3; | ||
| 416 | } | 530 | } |
| 417 | 531 | ||
| 418 | .common-title img { | 532 | .common-title img { |
| ... | @@ -653,19 +767,6 @@ const viewMore = (type) => { | ... | @@ -653,19 +767,6 @@ const viewMore = (type) => { |
| 653 | padding: 0.75rem; | 767 | padding: 0.75rem; |
| 654 | } | 768 | } |
| 655 | } | 769 | } |
| 656 | -@media (max-width: 48rem) { | ||
| 657 | - .bottom-left-decoration { | ||
| 658 | - width: 60%; | ||
| 659 | - height: 40%; | ||
| 660 | - } | ||
| 661 | -} | ||
| 662 | - | ||
| 663 | -@media (max-width: 30rem) { | ||
| 664 | - .bottom-left-decoration { | ||
| 665 | - width: 70%; | ||
| 666 | - height: 35%; | ||
| 667 | - } | ||
| 668 | -} | ||
| 669 | 770 | ||
| 670 | /* 法会流程容器 */ | 771 | /* 法会流程容器 */ |
| 671 | .ceremony-wrapper { | 772 | .ceremony-wrapper { |
| ... | @@ -1043,4 +1144,156 @@ const viewMore = (type) => { | ... | @@ -1043,4 +1144,156 @@ const viewMore = (type) => { |
| 1043 | font-size: 0.7rem; | 1144 | font-size: 0.7rem; |
| 1044 | } | 1145 | } |
| 1045 | } | 1146 | } |
| 1147 | + | ||
| 1148 | +/* 相关新闻样式 */ | ||
| 1149 | +.news-section { | ||
| 1150 | + padding: 3rem 1.5rem; | ||
| 1151 | + position: relative; | ||
| 1152 | + background-image: url('/src/assets/images/02 西园戒幢律寺三坛大戒法会/背景@2x.png'); | ||
| 1153 | + background-size: cover; | ||
| 1154 | + background-position: center; | ||
| 1155 | + background-repeat: no-repeat; | ||
| 1156 | +} | ||
| 1157 | + | ||
| 1158 | +/* 左下角装饰图片 */ | ||
| 1159 | +.news-section::before { | ||
| 1160 | + content: ''; | ||
| 1161 | + position: absolute; | ||
| 1162 | + bottom: 0; | ||
| 1163 | + left: 0; | ||
| 1164 | + width: 100%; /* 可根据实际图片大小调整 */ | ||
| 1165 | + height: 200px; /* 可根据实际图片大小调整 */ | ||
| 1166 | + background-image: url('/src/assets/images/02 西园戒幢律寺三坛大戒法会/bg@2x.png'); | ||
| 1167 | + background-size: cover; | ||
| 1168 | + background-repeat: no-repeat; | ||
| 1169 | + z-index: 1; | ||
| 1170 | + pointer-events: none; /* 确保不影响交互 */ | ||
| 1171 | +} | ||
| 1172 | + | ||
| 1173 | +.news-carousel-container { | ||
| 1174 | + position: relative; | ||
| 1175 | + overflow: hidden; | ||
| 1176 | + margin-top: 2rem; | ||
| 1177 | + z-index: 2; /* 确保轮播容器在背景图片之上 */ | ||
| 1178 | +} | ||
| 1179 | + | ||
| 1180 | +.news-carousel { | ||
| 1181 | + display: flex; | ||
| 1182 | + transition: transform 0.3s ease; | ||
| 1183 | + gap: 0.5rem; /* 减小间距 */ | ||
| 1184 | +} | ||
| 1185 | + | ||
| 1186 | +.news-item { | ||
| 1187 | + flex: 0 0 75%; /* 调整宽度为75% */ | ||
| 1188 | + background: white; | ||
| 1189 | + border-radius: 0.75rem; | ||
| 1190 | + overflow: hidden; | ||
| 1191 | + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); | ||
| 1192 | +} | ||
| 1193 | + | ||
| 1194 | +.news-image { | ||
| 1195 | + width: 100%; | ||
| 1196 | + height: 12rem; | ||
| 1197 | + overflow: hidden; | ||
| 1198 | +} | ||
| 1199 | + | ||
| 1200 | +.news-image img { | ||
| 1201 | + width: 100%; | ||
| 1202 | + height: 100%; | ||
| 1203 | + object-fit: cover; | ||
| 1204 | +} | ||
| 1205 | + | ||
| 1206 | +.news-content { | ||
| 1207 | + padding: 1rem; | ||
| 1208 | + background: white; | ||
| 1209 | +} | ||
| 1210 | + | ||
| 1211 | +.news-title { | ||
| 1212 | + font-size: 1rem; | ||
| 1213 | + font-weight: 600; | ||
| 1214 | + color: #333; | ||
| 1215 | + line-height: 1.4; | ||
| 1216 | + margin-bottom: 0.5rem; | ||
| 1217 | +} | ||
| 1218 | + | ||
| 1219 | +.news-date { | ||
| 1220 | + font-size: 0.875rem; | ||
| 1221 | + color: #999; | ||
| 1222 | +} | ||
| 1223 | + | ||
| 1224 | +.carousel-nav { | ||
| 1225 | + display: flex; | ||
| 1226 | + justify-content: center; | ||
| 1227 | + gap: 1rem; | ||
| 1228 | + margin-top: 1.5rem; | ||
| 1229 | + position: relative; | ||
| 1230 | + z-index: 3; /* 确保导航按钮在最上层 */ | ||
| 1231 | +} | ||
| 1232 | + | ||
| 1233 | +.nav-btn { | ||
| 1234 | + width: 3rem; | ||
| 1235 | + height: 3rem; | ||
| 1236 | + cursor: pointer; | ||
| 1237 | + transition: all 0.3s ease; | ||
| 1238 | + object-fit: contain; | ||
| 1239 | +} | ||
| 1240 | + | ||
| 1241 | +.nav-btn:hover:not(.disabled) { | ||
| 1242 | + transform: scale(1.1); | ||
| 1243 | +} | ||
| 1244 | + | ||
| 1245 | +.nav-btn.disabled { | ||
| 1246 | + opacity: 0.3; | ||
| 1247 | + cursor: not-allowed; | ||
| 1248 | +} | ||
| 1249 | + | ||
| 1250 | +/* 响应式设计 */ | ||
| 1251 | +@media (max-width: 48rem) { | ||
| 1252 | + .news-section { | ||
| 1253 | + padding: 3rem 1rem; | ||
| 1254 | + } | ||
| 1255 | + | ||
| 1256 | + .news-item { | ||
| 1257 | + flex: 0 0 78%; /* 调整中等屏幕宽度 */ | ||
| 1258 | + } | ||
| 1259 | + | ||
| 1260 | + .news-image { | ||
| 1261 | + height: 10rem; | ||
| 1262 | + } | ||
| 1263 | + | ||
| 1264 | + .news-title { | ||
| 1265 | + font-size: 0.9rem; | ||
| 1266 | + } | ||
| 1267 | + | ||
| 1268 | + .nav-btn { | ||
| 1269 | + width: 2.5rem; | ||
| 1270 | + height: 2.5rem; | ||
| 1271 | + } | ||
| 1272 | +} | ||
| 1273 | + | ||
| 1274 | +@media (max-width: 30rem) { | ||
| 1275 | + .news-section { | ||
| 1276 | + padding: 3rem 0.75rem; | ||
| 1277 | + } | ||
| 1278 | + | ||
| 1279 | + .news-item { | ||
| 1280 | + flex: 0 0 82%; /* 调整小屏幕宽度 */ | ||
| 1281 | + } | ||
| 1282 | + | ||
| 1283 | + .news-image { | ||
| 1284 | + height: 8rem; | ||
| 1285 | + } | ||
| 1286 | + | ||
| 1287 | + .news-content { | ||
| 1288 | + padding: 0.75rem; | ||
| 1289 | + } | ||
| 1290 | + | ||
| 1291 | + .news-title { | ||
| 1292 | + font-size: 0.85rem; | ||
| 1293 | + } | ||
| 1294 | + | ||
| 1295 | + .news-date { | ||
| 1296 | + font-size: 0.75rem; | ||
| 1297 | + } | ||
| 1298 | +} | ||
| 1046 | </style> | 1299 | </style> | ... | ... |
-
Please register or login to post a comment