From 0e89e1c7dd2e0ba44372235da06bfc65bc9ff7de Mon Sep 17 00:00:00 2001 From: yiqiu Date: Fri, 21 Nov 2025 17:56:13 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=AE=E6=92=AD=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/index.js | 58 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/js/index.js b/js/index.js index 83fd7e9..367fd03 100644 --- a/js/index.js +++ b/js/index.js @@ -31,8 +31,32 @@ $(function () { setCookie("recommend_c", urlParams.recommend_c); } } - isRecommend(); + isRecommend(); 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 = () => { if (bannerSwiper) { bannerSwiper.destroy(true, true); @@ -44,6 +68,12 @@ $(function () { el: ".swiper-pagination", clickable: true, }, + on: { + slideChange: function () { + // realIndex 对应原始数据下标 + updateBannerText(this.realIndex || 0); + }, + }, }); }; @@ -76,28 +106,10 @@ $(function () { // 设置首页函数 function setIndexData() { const commentObj = JSON.parse(sessionStorage.commentData); - const bannerList = commentObj.banner || []; - - // 使用第一张轮播图的标题/描述/按钮渲染固定文案区域 - if (bannerList.length) { - 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); + bannerData = commentObj.banner || []; + renderBannerSlides(bannerData); + // 初始化时使用第一张轮播图的文案 + updateBannerText(0); if (commentObj.honor.length > 0) { commentObj.honor.forEach((item) => { $("#certBox").append(`