391 lines
13 KiB
HTML
391 lines
13 KiB
HTML
<!doctype html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title id="page-title">神彩算 - 免费推荐</title>
|
|
<script src="../public/css/layui/layui.js"></script>
|
|
<script src="../config.js"></script>
|
|
<script src="../utils/ApiClient.js"></script>
|
|
<script src="../utils/DateUtil.js"></script>
|
|
<script src="../utils/CommonUtil.js"></script>
|
|
<link rel="stylesheet" href="../public/css/layui/css/layui.css" />
|
|
<link rel="stylesheet" href="../public/css/public.css" />
|
|
<link rel="stylesheet" href="../public/css/layout-fix.css" />
|
|
<link rel="stylesheet" href="../public/css/mianfei.css" />
|
|
</head>
|
|
<body>
|
|
<!-- Header -->
|
|
<nav class="topbar" id="navbar">
|
|
<div class="topbar__inner">
|
|
<a href="index.html" class="topbar__brand">
|
|
<img
|
|
src="../images/home-logo.png"
|
|
alt="神彩算"
|
|
class="topbar__logo"
|
|
/>
|
|
</a>
|
|
<div class="topbar__nav" id="navLotteryItems">
|
|
<!-- <a href="index.html" class="topbar__nav-link">首页</a> -->
|
|
</div>
|
|
<div class="topbar__user">
|
|
<div id="notLoggedInBox" class="topbar__guest">
|
|
<a href="login.html" class="topbar__btn topbar__btn--ghost">登录</a>
|
|
<a href="reg.html" class="topbar__btn topbar__btn--primary"
|
|
>免费注册</a
|
|
>
|
|
</div>
|
|
<div id="loggedInBox" class="topbar__logged" style="display: none">
|
|
<a href="usercenter.html" class="topbar__profile">
|
|
<img
|
|
id="userAvatar"
|
|
src="../public/img/userimg.png"
|
|
alt=""
|
|
class="topbar__avatar"
|
|
/>
|
|
<div class="topbar__meta">
|
|
<span id="userName" class="topbar__uname">用户</span>
|
|
<span id="userLevel" class="topbar__ubadge">会员</span>
|
|
</div>
|
|
</a>
|
|
<button class="topbar__btn topbar__btn--logout" onclick="logout()">
|
|
退出登录
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<!-- Main -->
|
|
<main class="cxz-main">
|
|
<div class="cxz-breadcrumb">
|
|
<a href="index.html">首页</a><span class="sep">></span>
|
|
<span>免费推荐</span>
|
|
</div>
|
|
|
|
<!-- Lottery Tabs -->
|
|
<div class="cxz-lottery-tabs" id="lotteryTabs"></div>
|
|
|
|
<div class="cxz-section-header">
|
|
<div class="cxz-section-title" id="listTitle">免费推荐</div>
|
|
</div>
|
|
|
|
<div class="cxz-article-list" id="articleList">
|
|
<div class="cxz-article-item">
|
|
<span style="color: var(--text-muted)">加载中...</span>
|
|
</div>
|
|
</div>
|
|
<div class="cxz-pagination" id="pagination"></div>
|
|
</main>
|
|
|
|
<!-- Footer -->
|
|
<footer class="site-footer">
|
|
<div class="site-footer__inner">
|
|
<img
|
|
src="../images/home-logo.png"
|
|
alt="神彩算"
|
|
class="site-footer__logo"
|
|
/>
|
|
<p id="copyright-info">神彩算以开奖数据、免费文章、资讯推荐为核心</p>
|
|
<div class="site-footer__meta">
|
|
<a
|
|
id="beian"
|
|
href="https://beian.miit.gov.cn/"
|
|
target="_blank"
|
|
style="font-size: 12px; color: rgba(255, 255, 255, 0.5)"
|
|
>工信部备案号</a
|
|
>
|
|
<span id="additional-info">本站仅供数据分析参考</span>
|
|
</div>
|
|
</div>
|
|
</footer>
|
|
<button
|
|
class="gotop"
|
|
id="backTop"
|
|
type="button"
|
|
onclick="window.scrollTo({ top: 0, behavior: 'smooth' })"
|
|
>
|
|
↑
|
|
</button>
|
|
|
|
<script>
|
|
const $ = layui.$;
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
let menuId = urlParams.get("id") || urlParams.get("code") || "";
|
|
let currentPage = 1;
|
|
const pageSize = 15;
|
|
let lotteryMenus = [];
|
|
let freeArticleGroups = [];
|
|
|
|
function logout() {
|
|
localStorage.removeItem("token");
|
|
window.location.reload();
|
|
}
|
|
|
|
function checkLogin() {
|
|
const token = localStorage.getItem("token");
|
|
if (token) {
|
|
$("#notLoggedInBox").hide();
|
|
$("#loggedInBox").css("display", "flex");
|
|
CommonUtil.getCurrentUserDetail(function (data) {
|
|
$("#userName").text(data.nickName || "用户");
|
|
$("#userAvatar").attr(
|
|
"src",
|
|
data.avatar || "../public/img/userimg.png",
|
|
);
|
|
});
|
|
}
|
|
}
|
|
|
|
function escapeHtml(str) {
|
|
if (!str) return "";
|
|
return String(str)
|
|
.replace(/&/g, "&")
|
|
.replace(/</g, "<")
|
|
.replace(/>/g, ">")
|
|
.replace(/"/g, """);
|
|
}
|
|
|
|
function normalizeLotteryMenus(list) {
|
|
return ApiClient.asArray(list).filter(function (item) {
|
|
return item && (!item.type || item.type === "lottery");
|
|
});
|
|
}
|
|
|
|
function resolveCurrentMenuId() {
|
|
if (!lotteryMenus.length) return;
|
|
const matched = menuId
|
|
? lotteryMenus.find(function (item) {
|
|
return sameLotteryKey(item, menuId);
|
|
})
|
|
: null;
|
|
const current = matched || lotteryMenus[0];
|
|
menuId = String(
|
|
(current && (current.id || current.menuId || current.code || current.suoxie)) || "",
|
|
);
|
|
}
|
|
|
|
function renderLotteryTabs() {
|
|
return Promise.all([
|
|
ApiClient.get(ApiClient.API.homeNav).catch(function () {
|
|
return { data: [] };
|
|
}),
|
|
ApiClient.get(ApiClient.API.freeArticleRecommend, { articleCount: pageSize }).catch(function () {
|
|
return { data: [] };
|
|
}),
|
|
])
|
|
.then(function (results) {
|
|
const res = results[0];
|
|
const recommendRes = results[1];
|
|
lotteryMenus = normalizeLotteryMenus(ApiClient.pickData(res, []));
|
|
freeArticleGroups = ApiClient.asArray(ApiClient.pickData(recommendRes, []));
|
|
resolveCurrentMenuId();
|
|
const $tabs = $("#lotteryTabs");
|
|
$tabs.empty();
|
|
$.each(lotteryMenus, function (_, item) {
|
|
const id = item.id || item.menuId || item.code || item.suoxie || "";
|
|
const linkKey = item.code || item.suoxie || item.lotteryCode || id;
|
|
$tabs.append(
|
|
'<a href="mianfeilist.html?id=' +
|
|
encodeURIComponent(linkKey) +
|
|
'" class="cxz-lottery-tab" data-id="' +
|
|
escapeHtml(id) +
|
|
'">' +
|
|
escapeHtml(item.name || "") +
|
|
"</a>",
|
|
);
|
|
});
|
|
highlightTab();
|
|
})
|
|
.catch(function () {
|
|
lotteryMenus = [];
|
|
$("#lotteryTabs").empty();
|
|
$("#listTitle").text("免费推荐");
|
|
document.title = "神彩算 - 免费推荐";
|
|
});
|
|
}
|
|
|
|
// Highlight active tab
|
|
function highlightTab() {
|
|
$(".cxz-lottery-tab").removeClass("active");
|
|
$('.cxz-lottery-tab[data-id="' + menuId + '"]').addClass("active");
|
|
const currentMenu = lotteryMenus.find(function (item) {
|
|
return sameLotteryKey(item, menuId);
|
|
});
|
|
const name = (currentMenu && currentMenu.name) || "免费推荐";
|
|
$("#listTitle").text(name + " - 免费推荐");
|
|
document.title = "神彩算 - " + name + "免费推荐";
|
|
}
|
|
|
|
function sameLotteryKey(item, value) {
|
|
const key = String(value || "").toLowerCase();
|
|
if (!key || !item) return false;
|
|
return (
|
|
String(item.id || "").toLowerCase() === key ||
|
|
String(item.menuId || "").toLowerCase() === key ||
|
|
String(item.code || "").toLowerCase() === key ||
|
|
String(item.suoxie || "").toLowerCase() === key ||
|
|
String(item.lotteryCode || "").toLowerCase() === key ||
|
|
String(item.name || "").toLowerCase() === key
|
|
);
|
|
}
|
|
|
|
function currentMenuInfo() {
|
|
return lotteryMenus.find(function (item) {
|
|
return sameLotteryKey(item, menuId);
|
|
});
|
|
}
|
|
|
|
function currentFallbackGroup() {
|
|
const menu = currentMenuInfo();
|
|
return (
|
|
freeArticleGroups.find(function (group) {
|
|
return sameLotteryKey(group, menuId) || sameLotteryKey(group, menu && (menu.code || menu.suoxie || menu.id));
|
|
}) || null
|
|
);
|
|
}
|
|
|
|
function currentRequestMenuId() {
|
|
const menu = currentMenuInfo();
|
|
return String((menu && (menu.id || menu.menuId)) || "");
|
|
}
|
|
|
|
function getArticlePageData(res) {
|
|
const data = ApiClient.pickData(res, {}) || {};
|
|
const records = ApiClient.asArray(
|
|
data.records || data.rows || data.list || data.data || data,
|
|
);
|
|
const total =
|
|
Number(data.total) ||
|
|
Number(data.totalRow) ||
|
|
Number(data.totalCount) ||
|
|
Number(data.count) ||
|
|
Number(res && res.total) ||
|
|
records.length;
|
|
return {
|
|
records: records,
|
|
total: total,
|
|
};
|
|
}
|
|
|
|
function normalizeArticle(article, group) {
|
|
article = article || {};
|
|
group = group || {};
|
|
return Object.assign({}, article, {
|
|
id: article.id || article.articleId || article.freeArticleId || "",
|
|
title: article.title || article.articleTitle || article.name || "无标题",
|
|
dateText:
|
|
article.dateText ||
|
|
article.updateTime ||
|
|
article.createTime ||
|
|
article.publishTime ||
|
|
group.dateText,
|
|
});
|
|
}
|
|
|
|
// Load articles
|
|
function loadArticles() {
|
|
if (!menuId) {
|
|
$("#articleList").html(
|
|
'<div class="cxz-article-item"><span style="color:var(--text-muted);">暂无数据</span></div>',
|
|
);
|
|
renderPagination(0);
|
|
return;
|
|
}
|
|
const requestMenuId = currentRequestMenuId();
|
|
if (!requestMenuId) {
|
|
renderFallbackArticles();
|
|
return;
|
|
}
|
|
ApiClient.get(ApiClient.API.freeArticleList, {
|
|
menuId: requestMenuId,
|
|
pageNum: currentPage,
|
|
pageSize: pageSize,
|
|
}).then(function (res) {
|
|
if (ApiClient.isSuccess(res) && ApiClient.pickData(res, null)) {
|
|
const pageData = getArticlePageData(res);
|
|
if (pageData.records.length || pageData.total) {
|
|
renderArticles(pageData.records.map(function (item) {
|
|
return normalizeArticle(item, currentFallbackGroup());
|
|
}));
|
|
renderPagination(pageData.total);
|
|
} else {
|
|
renderFallbackArticles();
|
|
}
|
|
} else {
|
|
renderFallbackArticles();
|
|
}
|
|
}).catch(function () {
|
|
renderFallbackArticles();
|
|
});
|
|
}
|
|
|
|
function renderFallbackArticles() {
|
|
const group = currentFallbackGroup();
|
|
const allArticles = ApiClient.asArray(group && group.articles).map(function (item) {
|
|
return normalizeArticle(item, group);
|
|
});
|
|
const startIndex = (currentPage - 1) * pageSize;
|
|
const records = allArticles.slice(startIndex, startIndex + pageSize);
|
|
renderArticles(records);
|
|
renderPagination(allArticles.length);
|
|
}
|
|
|
|
function renderArticles(list) {
|
|
const $container = $("#articleList");
|
|
$container.empty();
|
|
if (!list || list.length === 0) {
|
|
$container.html(
|
|
'<div class="cxz-article-item"><span style="color:var(--text-muted);">暂无数据</span></div>',
|
|
);
|
|
return;
|
|
}
|
|
$.each(list, function (i, item) {
|
|
let displayDate = "";
|
|
const article = normalizeArticle(item);
|
|
const dateText = article.dateText || "";
|
|
const title = article.title || "无标题";
|
|
if (dateText) displayDate = String(dateText).substring(0, 10);
|
|
$container.append(
|
|
'<div class="cxz-article-item">' +
|
|
'<a href="' +
|
|
CommonUtil.freeArticleHref(article.id || "") +
|
|
'" target="_blank">' +
|
|
escapeHtml(title) +
|
|
"</a>" +
|
|
'<span class="cxz-article-date">' +
|
|
escapeHtml(displayDate) +
|
|
"</span>" +
|
|
"</div>",
|
|
);
|
|
});
|
|
}
|
|
|
|
function renderPagination(total) {
|
|
$("#pagination").empty();
|
|
if (!total || total <= pageSize) {
|
|
return;
|
|
}
|
|
layui.laypage.render({
|
|
elem: "pagination",
|
|
count: total,
|
|
limit: pageSize,
|
|
curr: currentPage,
|
|
jump: function (obj, first) {
|
|
if (!first) {
|
|
currentPage = obj.curr;
|
|
loadArticles();
|
|
}
|
|
},
|
|
});
|
|
}
|
|
|
|
$(function () {
|
|
checkLogin();
|
|
renderLotteryTabs().then(loadArticles);
|
|
CommonUtil.loadPageConfig();
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|