This commit is contained in:
74
js/about.js
74
js/about.js
@@ -20,54 +20,12 @@ $(function () {
|
||||
viewer.show();
|
||||
});
|
||||
|
||||
// 获取通用配置信息(关于页:用插件覆盖 honor/partner)
|
||||
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 || {};
|
||||
if (cfg.honor) {
|
||||
baseData.honor = cfg.honor;
|
||||
}
|
||||
if (cfg.partner) {
|
||||
baseData.partner = cfg.partner;
|
||||
}
|
||||
}
|
||||
sessionStorage.commentData = JSON.stringify(baseData);
|
||||
setIndexData();
|
||||
},
|
||||
error: function () {
|
||||
sessionStorage.commentData = JSON.stringify(baseData);
|
||||
setIndexData();
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
// 获取首页数据
|
||||
getCommentInfo();
|
||||
|
||||
// 设置首页函数
|
||||
function setIndexData() {
|
||||
const commentObj = JSON.parse(sessionStorage.commentData);
|
||||
if (commentObj.honor.length > 0) {
|
||||
const commentObj = window.__themeCommon
|
||||
? window.__themeCommon
|
||||
: (sessionStorage.commentData ? JSON.parse(sessionStorage.commentData) : {});
|
||||
if (Array.isArray(commentObj.honor) && commentObj.honor.length > 0) {
|
||||
commentObj.honor.forEach((item) => {
|
||||
$("#honor-box").append(`
|
||||
<div class="box-item">
|
||||
@@ -77,14 +35,18 @@ $(function () {
|
||||
`);
|
||||
});
|
||||
}
|
||||
commentObj.partner.forEach((item) => {
|
||||
$("#partner-box").append(`
|
||||
<div class="box-item">
|
||||
<img src="${item.img}" alt="">
|
||||
<h4 class="mt-30">${item.name}</h4>
|
||||
<p class="mt-20">${item.description}</p>
|
||||
</div>
|
||||
`);
|
||||
});
|
||||
}
|
||||
if (Array.isArray(commentObj.partner)) {
|
||||
commentObj.partner.forEach((item) => {
|
||||
$("#partner-box").append(`
|
||||
<div class="box-item">
|
||||
<img src="${item.img}" alt="">
|
||||
<h4 class="mt-30">${item.name}</h4>
|
||||
<p class="mt-20">${item.description}</p>
|
||||
</div>
|
||||
`);
|
||||
});
|
||||
}
|
||||
}
|
||||
// 直接使用服务端注入的数据渲染关于页
|
||||
setIndexData();
|
||||
});
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
$(function () {
|
||||
const setIndexData = () => {
|
||||
const commentObj = JSON.parse(sessionStorage.commentData);
|
||||
commentObj.feedback_type.forEach((item, index) => {
|
||||
const setIndexData = () => {
|
||||
const commentObj = window.__themeCommon
|
||||
? window.__themeCommon
|
||||
: (sessionStorage.commentData ? JSON.parse(sessionStorage.commentData) : {});
|
||||
const types = Array.isArray(commentObj.feedback_type)
|
||||
? commentObj.feedback_type
|
||||
: [];
|
||||
types.forEach((item, index) => {
|
||||
$("#radioBox").append(`
|
||||
<div class="radio">
|
||||
<input type="radio" name="radioId" id="ptionsRadios${index}" value=${item.id} />
|
||||
@@ -65,43 +70,6 @@ $(function () {
|
||||
input.attr("style", "border: 1px solid #E6EAED;");
|
||||
return true;
|
||||
}
|
||||
// 获取通用配置信息(反馈页:用插件覆盖 feedback_type)
|
||||
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 || {};
|
||||
if (cfg.feedback_type) {
|
||||
baseData.feedback_type = cfg.feedback_type;
|
||||
}
|
||||
}
|
||||
sessionStorage.commentData = JSON.stringify(baseData);
|
||||
setIndexData();
|
||||
},
|
||||
error: function () {
|
||||
sessionStorage.commentData = JSON.stringify(baseData);
|
||||
setIndexData();
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
getCommentInfo();
|
||||
// 反馈页直接使用服务端注入的反馈类型渲染单选项
|
||||
setIndexData();
|
||||
});
|
||||
|
||||
64
js/index.js
64
js/index.js
@@ -106,13 +106,15 @@ $(function () {
|
||||
}, 5000);
|
||||
};
|
||||
|
||||
// 设置首页函数
|
||||
// 设置首页函数:直接使用服务端注入的 window.__themeCommon(SSR 数据),避免再次请求配置
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user