From c3488e8651d3b3b5494e3392f2a0429810102bd5 Mon Sep 17 00:00:00 2001 From: yiqiu Date: Mon, 24 Nov 2025 15:42:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=A6=96=E9=A1=B5=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=8A=A0=E8=BD=BD=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BC=98?= =?UTF-8?q?=E5=85=88=E4=BD=BF=E7=94=A8=20SSR=20=E6=B3=A8=E5=85=A5=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 setIndexData 函数接收 commentObj 参数 - 优先使用 window.__themeCommon(SSR 注入数据) - 其次使用 sessionStorage 缓存数据 - 最后降级到 AJAX 请求 - 添加空值检查防止报错 - 支持主题配置插件的合作伙伴配置 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- js/index.js | 70 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 29 deletions(-) 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,