diff --git a/js/index.js b/js/index.js index ba852ff..a099bed 100644 --- a/js/index.js +++ b/js/index.js @@ -84,9 +84,9 @@ $(function () { } isRecommend(); // 设置首页函数 - function setIndexData() { - const commentObj = JSON.parse(sessionStorage.commentData); - if (commentObj.honor.length > 0) { + function setIndexData(commentObj) { + // 荣誉资质 + if (commentObj.honor && commentObj.honor.length > 0) { commentObj.honor.forEach((item) => { $("#certBox").append(`
@@ -94,30 +94,33 @@ $(function () {
`); }); } - if (commentObj.partner.length > 0 && commentObj.partner.length <= 3) { - commentObj.partner.forEach((item) => { - $("#practiceBox").append(`
- -
${item.description}
-

${item.name}

-
`); - }); - } else if (commentObj.partner.length > 3) { - const arr1 = commentObj.partner.slice(0, 3); - const arr2 = commentObj.partner.slice(3); - arr1.forEach((item) => { - $("#practiceBox").append(`
- -
${item.description}
-

${item.name}

-
`); - }); - $("#morPracticeBox").attr("style", "display: flex;"); - arr2.forEach((item) => { - $("#morPracticeBox").append(`
+ // 合作伙伴 + if (commentObj.partner && commentObj.partner.length > 0) { + if (commentObj.partner.length <= 3) { + commentObj.partner.forEach((item) => { + $("#practiceBox").append(`
-
`); - }); +
${item.description}
+

${item.name}

+
`); + }); + } else { + const arr1 = commentObj.partner.slice(0, 3); + const arr2 = commentObj.partner.slice(3); + arr1.forEach((item) => { + $("#practiceBox").append(`
+ +
${item.description}
+

${item.name}

+
`); + }); + $("#morPracticeBox").attr("style", "display: flex;"); + arr2.forEach((item) => { + $("#morPracticeBox").append(`
+ +
`); + }); + } } } // 获取通用配置信息 @@ -130,12 +133,21 @@ $(function () { }, success: function (res) { sessionStorage.commentData = JSON.stringify(res.data); - setIndexData(); + setIndexData(res.data); }, }); } - // 获取首页数据 - getCommentInfo(); + // 获取首页数据 - 优先使用 SSR 注入的数据 + if (window.__themeCommon) { + // 如果有 SSR 数据,直接使用 + setIndexData(window.__themeCommon); + } else if (sessionStorage.commentData) { + // 如果有缓存数据,使用缓存 + setIndexData(JSON.parse(sessionStorage.commentData)); + } else { + // 否则通过 AJAX 获取 + getCommentInfo(); + } var viewer = new Viewer(document.getElementById("viewer"), { button: true, inline: false,