的撒法
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
yiqiu
2025-11-22 22:35:44 +08:00
parent 28d2efb4f2
commit 0f9f96c596
3 changed files with 153 additions and 351 deletions

View File

@@ -1,155 +1,90 @@
$(function () {
// 获取url地址栏参数函数
function getUrlParams() {
const url = window.location.href;
// 判断是否有参数
if (url.indexOf("?") === -1) {
return {};
}
const params = url.split("?")[1];
const paramsArr = params.split("&");
const paramsObj = {};
paramsArr.forEach((item) => {
const key = item.split("=")[0];
const value = item.split("=")[1];
// 解析中文
paramsObj[key] = decodeURI(value);
});
return paramsObj;
}
//设置cookie
function setCookie(c_name, value, expiredays = 1) {
const exdate = new Date();
exdate.setDate(exdate.getDate() + expiredays);
document.cookie =
c_name + "=" + value + (";expires=" + exdate.toGMTString());
}
// 判断首页是否为推荐页面
function isRecommend() {
const urlParams = getUrlParams();
if (urlParams.recommend_c) {
setCookie("recommend_c", urlParams.recommend_c);
}
$(function () {
// 获取url地址栏参数函数
function getUrlParams() {
const url = window.location.href;
// 判断是否有参数
if (url.indexOf("?") === -1) {
return {};
}
const params = url.split("?")[1];
const paramsArr = params.split("&");
const paramsObj = {};
paramsArr.forEach((item) => {
const key = item.split("=")[0];
const value = item.split("=")[1];
// 解析中文
paramsObj[key] = decodeURI(value);
});
return paramsObj;
}
//设置cookie
function setCookie(c_name, value, expiredays = 1) {
const exdate = new Date();
exdate.setDate(exdate.getDate() + expiredays);
document.cookie =
c_name + "=" + value + (";expires=" + exdate.toGMTString());
}
// 判断首页是否为推荐页面
function isRecommend() {
const urlParams = getUrlParams();
if (urlParams.recommend_c) {
setCookie("recommend_c", urlParams.recommend_c);
}
}
isRecommend();
let bannerData = [];
let bannerTextTimer = null;
const updateBannerText = (index) => {
if (!Array.isArray(bannerData) || bannerData.length === 0) {
return;
}
const idx = index >= 0 && index < bannerData.length ? index : 0;
const item = bannerData[idx] || {};
// 标签渲染:标题上方的小块标签
const $tagsWrap = $("#bannerTags");
if ($tagsWrap.length) {
$tagsWrap.empty();
const rawTags = item.tags || "";
const tags = rawTags
.split(/[,]/)
.map((t) => t.trim())
.filter((t) => t);
tags.forEach((tag) => {
$tagsWrap.append(
`<span class="banner-tag-pill">${tag}</span>`
);
});
if (tags.length === 0) {
$tagsWrap.hide();
} else {
$tagsWrap.show();
}
}
$("#bannerTitle").text(item.title || "");
$("#bannerDesc").text(item.description || "");
const $btn = $("#bannerButton");
if (item.button_text) {
const link = item.button_link || item.url || "javascript:;";
const target = item.button_blank ? "_blank" : "_self";
$btn
.text(item.button_text)
.attr("href", link)
.attr("target", target)
.show();
} else {
$btn.hide();
}
};
// 简单的文案轮播(不再使用 Swiper 图片,仅轮播标题/描述/按钮)
const startBannerTextLoop = () => {
if (!Array.isArray(bannerData) || bannerData.length === 0) {
return;
}
let current = 0;
// 初始化先展示第一条
updateBannerText(current);
// 清理旧定时器
if (bannerTextTimer) {
clearInterval(bannerTextTimer);
bannerTextTimer = null;
}
// 只有一条时不需要轮播
if (bannerData.length === 1) {
return;
}
bannerTextTimer = setInterval(() => {
current = (current + 1) % bannerData.length;
// 淡入动画:先让文案透明,再渐显
const $copy = $(".banner-copy");
$copy
.stop(true, true)
.css({ opacity: 0 })
.animate({ opacity: 1 }, 400);
updateBannerText(current);
}, 5000);
};
// 设置首页函数:直接使用服务端注入的 window.__themeCommonSSR 数据),避免再次请求配置
// 设置首页函数
function setIndexData() {
const commentObj = window.__themeCommon
? window.__themeCommon
: (sessionStorage.commentData ? JSON.parse(sessionStorage.commentData) : {});
bannerData = commentObj.banner || [];
// 仅轮播文案
startBannerTextLoop();
if (Array.isArray(commentObj.honor) && commentObj.honor.length > 0) {
const commentObj = JSON.parse(sessionStorage.commentData);
if (commentObj.honor.length > 0) {
commentObj.honor.forEach((item) => {
$("#certBox").append(`<div class="cert-item">
<img src=${item.img} alt="">
<p class="mt-20">${item.name}</p>
</div>`);
});
}
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="">
<div class="mt-10">${item.description}</div>
<p class="tr font-grey mt-20 font12">${item.name}</p>
</div>`);
});
} 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) => {
$("#practiceBox").append(`<div class="practice-box">
<img src="${item.img}" alt="">
<div class="mt-10">${item.description}</div>
<p class="tr font-grey mt-20 font12">${item.name}</p>
</div>`);
});
$("#morPracticeBox").attr("style", "display: flex;");
arr2.forEach((item) => {
$("#morPracticeBox").append(` <div class="brand-box">
<img src="${item.img}" alt="">
</div>`);
});
}
<img src=${item.img} alt="">
<p class="mt-20">${item.name}</p>
</div>`);
});
}
if (commentObj.partner.length > 0 && commentObj.partner.length <= 3) {
commentObj.partner.forEach((item) => {
$("#practiceBox").append(`<div class="practice-box">
<img src="${item.img}" alt="">
<div class="mt-10">${item.description}</div>
<p class="tr font-grey mt-20 font12">${item.name}</p>
</div>`);
});
} else if (commentObj.partner.length > 3) {
const arr1 = commentObj.partner.slice(0, 3);
const arr2 = commentObj.partner.slice(3);
arr1.forEach((item) => {
$("#practiceBox").append(`<div class="practice-box">
<img src="${item.img}" alt="">
<div class="mt-10">${item.description}</div>
<p class="tr font-grey mt-20 font12">${item.name}</p>
</div>`);
});
$("#morPracticeBox").attr("style", "display: flex;");
arr2.forEach((item) => {
$("#morPracticeBox").append(` <div class="brand-box">
<img src="${item.img}" alt="">
</div>`);
});
}
}
// 首页直接使用服务端注入的数据渲染SSR不再请求 /console/v1/common 或 /console/v1/theme/config
setIndexData();
// 获取通用配置信息
function getCommentInfo() {
$.ajax({
url: "/console/v1/common",
method: "get",
headers: {
Authorization: "Bearer" + " " + localStorage.jwt,
},
success: function (res) {
sessionStorage.commentData = JSON.stringify(res.data);
setIndexData();
},
});
}
// 获取首页数据
getCommentInfo();
var viewer = new Viewer(document.getElementById("viewer"), {
button: true,
inline: false,
@@ -180,7 +115,7 @@ $(function () {
D = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
return Y + M + D;
}
// 公告列表
// 公告列表
function getAnnounceList() {
$.ajax({
url: "/console/v1/announcement",