This commit is contained in:
40
js/index.js
40
js/index.js
@@ -60,16 +60,6 @@ $(function () {
|
||||
list.forEach((item) => {
|
||||
const slide = document.createElement("div");
|
||||
slide.className = "swiper-slide";
|
||||
const title = item.title ? `<h1>${item.title}</h1>` : "";
|
||||
const desc = item.description
|
||||
? `<p class="banner-desc">${item.description}</p>`
|
||||
: "";
|
||||
let buttonHtml = "";
|
||||
if (item.button_text) {
|
||||
const link = item.button_link || "javascript:;";
|
||||
const target = item.button_blank ? "_blank" : "_self";
|
||||
buttonHtml = `<a class="btn btn2 btn-normal" href="${link}" target="${target}">${item.button_text}</a>`;
|
||||
}
|
||||
const targetAttr = item.blank ? "_blank" : "_self";
|
||||
const imgHtml = `<img class="img-responsive img center-block" src="${
|
||||
item.img || ""
|
||||
@@ -77,14 +67,7 @@ $(function () {
|
||||
const mediaBlock = item.url
|
||||
? `<a href="${item.url}" target="${targetAttr}">${imgHtml}</a>`
|
||||
: imgHtml;
|
||||
const contentBlock =
|
||||
title || desc || buttonHtml
|
||||
? `<div class="section-content">${title}${desc}${buttonHtml}</div>`
|
||||
: "";
|
||||
slide.innerHTML = `
|
||||
${mediaBlock}
|
||||
${contentBlock}
|
||||
`;
|
||||
slide.innerHTML = mediaBlock;
|
||||
wrapper.appendChild(slide);
|
||||
});
|
||||
initBannerSwiper();
|
||||
@@ -93,6 +76,27 @@ $(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);
|
||||
if (commentObj.honor.length > 0) {
|
||||
commentObj.honor.forEach((item) => {
|
||||
|
||||
Reference in New Issue
Block a user