轮播修复
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
yiqiu
2025-11-21 17:56:13 +08:00
parent 7a99ebef9d
commit 0e89e1c7dd

View File

@@ -31,8 +31,32 @@ $(function () {
setCookie("recommend_c", urlParams.recommend_c); setCookie("recommend_c", urlParams.recommend_c);
} }
} }
isRecommend(); isRecommend();
let bannerSwiper = null; let bannerSwiper = null;
let bannerData = [];
const updateBannerText = (index) => {
if (!Array.isArray(bannerData) || bannerData.length === 0) {
return;
}
const idx = index >= 0 && index < bannerData.length ? index : 0;
const item = bannerData[idx] || {};
$("#bannerTitle").text(item.title || "");
$("#bannerDesc").text(item.description || "");
const $btn = $("#bannerButton");
if (item.button_text) {
const link = item.button_link || item.url || "javascript:;";
const target = item.button_blank ? "_blank" : "_self";
$btn
.text(item.button_text)
.attr("href", link)
.attr("target", target)
.show();
} else {
$btn.hide();
}
};
const initBannerSwiper = () => { const initBannerSwiper = () => {
if (bannerSwiper) { if (bannerSwiper) {
bannerSwiper.destroy(true, true); bannerSwiper.destroy(true, true);
@@ -44,6 +68,12 @@ $(function () {
el: ".swiper-pagination", el: ".swiper-pagination",
clickable: true, clickable: true,
}, },
on: {
slideChange: function () {
// realIndex 对应原始数据下标
updateBannerText(this.realIndex || 0);
},
},
}); });
}; };
@@ -76,28 +106,10 @@ $(function () {
// 设置首页函数 // 设置首页函数
function setIndexData() { function setIndexData() {
const commentObj = JSON.parse(sessionStorage.commentData); const commentObj = JSON.parse(sessionStorage.commentData);
const bannerList = commentObj.banner || []; bannerData = commentObj.banner || [];
renderBannerSlides(bannerData);
// 使用第一张轮播图的标题/描述/按钮渲染固定文案区域 // 初始化时使用第一张轮播图的文案
if (bannerList.length) { updateBannerText(0);
const first = bannerList[0];
$("#bannerTitle").text(first.title || "");
$("#bannerDesc").text(first.description || "");
const $btn = $("#bannerButton");
if (first.button_text) {
const link = first.button_link || first.url || "javascript:;";
const target = first.button_blank ? "_blank" : "_self";
$btn
.text(first.button_text)
.attr("href", link)
.attr("target", target)
.show();
} else {
$btn.hide();
}
}
renderBannerSlides(commentObj.banner);
if (commentObj.honor.length > 0) { if (commentObj.honor.length > 0) {
commentObj.honor.forEach((item) => { commentObj.honor.forEach((item) => {
$("#certBox").append(`<div class="cert-item"> $("#certBox").append(`<div class="cert-item">