东方大厦
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
yiqiu
2025-11-22 01:14:47 +08:00
parent 095ff222a1
commit 51fd1035aa
8 changed files with 299 additions and 483 deletions

View File

@@ -106,13 +106,15 @@ $(function () {
}, 5000);
};
// 设置首页函数
// 设置首页函数:直接使用服务端注入的 window.__themeCommonSSR 数据),避免再次请求配置
function setIndexData() {
const commentObj = JSON.parse(sessionStorage.commentData);
const commentObj = window.__themeCommon
? window.__themeCommon
: (sessionStorage.commentData ? JSON.parse(sessionStorage.commentData) : {});
bannerData = commentObj.banner || [];
// 仅轮播文案
startBannerTextLoop();
if (commentObj.honor.length > 0) {
if (Array.isArray(commentObj.honor) && commentObj.honor.length > 0) {
commentObj.honor.forEach((item) => {
$("#certBox").append(`<div class="cert-item">
<img src=${item.img} alt="">
@@ -120,7 +122,7 @@ $(function () {
</div>`);
});
}
if (commentObj.partner.length > 0 && commentObj.partner.length <= 3) {
if (Array.isArray(commentObj.partner) && commentObj.partner.length > 0 && commentObj.partner.length <= 3) {
commentObj.partner.forEach((item) => {
$("#practiceBox").append(`<div class="practice-box">
<img src="${item.img}" alt="">
@@ -128,7 +130,7 @@ $(function () {
<p class="tr font-grey mt-20 font12">${item.name}</p>
</div>`);
});
} else if (commentObj.partner.length > 3) {
} else if (Array.isArray(commentObj.partner) && commentObj.partner.length > 3) {
const arr1 = commentObj.partner.slice(0, 3);
const arr2 = commentObj.partner.slice(3);
arr1.forEach((item) => {
@@ -146,56 +148,8 @@ $(function () {
});
}
}
// 获取通用配置信息(首页:先用 /console/v1/common再用插件配置覆盖后渲染荣誉/合作伙伴)
function getCommentInfo() {
$.ajax({
url: "/console/v1/common",
method: "get",
headers: {
Authorization: "Bearer" + " " + localStorage.jwt,
},
success: function (res) {
if (!res || res.status !== 200 || !res.data) {
return;
}
var baseData = res.data || {};
$.ajax({
url: "/console/v1/theme/config",
method: "get",
headers: {
Authorization: "Bearer" + " " + localStorage.jwt,
},
success: function (pluginRes) {
if (pluginRes && pluginRes.status === 200 && pluginRes.data) {
var cfg = pluginRes.data || {};
// 仅覆盖首页会用到的字段honor/partner/banner/friendly_link 等
if (cfg.honor) {
baseData.honor = cfg.honor;
}
if (cfg.partner) {
baseData.partner = cfg.partner;
}
if (cfg.banner) {
baseData.banner = cfg.banner;
}
if (cfg.friendly_link) {
baseData.friendly_link = cfg.friendly_link;
}
}
sessionStorage.commentData = JSON.stringify(baseData);
setIndexData();
},
error: function () {
sessionStorage.commentData = JSON.stringify(baseData);
setIndexData();
},
});
},
});
}
// 获取首页数据
getCommentInfo();
// 首页直接使用服务端注入的数据渲染SSR不再请求 /console/v1/common 或 /console/v1/theme/config
setIndexData();
var viewer = new Viewer(document.getElementById("viewer"), {
button: true,
inline: false,