This commit is contained in:
58
js/index.js
58
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(`<div class="cert-item">
|
||||
|
||||
Reference in New Issue
Block a user