285 lines
9.1 KiB
HTML
285 lines
9.1 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/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") || "";
|
|
let currentPage = 1;
|
|
const pageSize = 15;
|
|
let lotteryMenus = [];
|
|
|
|
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;
|
|
if (
|
|
menuId &&
|
|
lotteryMenus.some(function (item) {
|
|
return String(item.id) === String(menuId);
|
|
})
|
|
) {
|
|
return;
|
|
}
|
|
|
|
menuId = String((lotteryMenus[0] && lotteryMenus[0].id) || "");
|
|
}
|
|
|
|
function renderLotteryTabs() {
|
|
return ApiClient.get(ApiClient.API.homeNav)
|
|
.then(function (res) {
|
|
lotteryMenus = normalizeLotteryMenus(ApiClient.pickData(res, []));
|
|
resolveCurrentMenuId();
|
|
const $tabs = $("#lotteryTabs");
|
|
$tabs.empty();
|
|
$.each(lotteryMenus, function (_, item) {
|
|
const id = item.id || "";
|
|
$tabs.append(
|
|
'<a href="mianfeilist.html?id=' +
|
|
encodeURIComponent(id) +
|
|
'" 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 String(item.id) === String(menuId);
|
|
});
|
|
const name = (currentMenu && currentMenu.name) || "免费推荐";
|
|
$("#listTitle").text(name + " - 免费推荐");
|
|
document.title = "彩先知 - " + name + "免费推荐";
|
|
}
|
|
|
|
// Load articles
|
|
function loadArticles() {
|
|
if (!menuId) {
|
|
$("#articleList").html(
|
|
'<div class="cxz-article-item"><span style="color:var(--text-muted);">暂无数据</span></div>',
|
|
);
|
|
renderPagination(0);
|
|
return;
|
|
}
|
|
ApiClient.get("/api/web/free-article/list", {
|
|
menuId: menuId,
|
|
pageNum: currentPage,
|
|
pageSize: pageSize,
|
|
}).then(function (res) {
|
|
if (ApiClient.isSuccess(res) && ApiClient.pickData(res, null)) {
|
|
const data = ApiClient.pickData(res, {}) || {};
|
|
const list = data.records || data.rows || data.list || ApiClient.asArray(data);
|
|
renderArticles(list);
|
|
renderPagination(data.totalRow || data.total || data.count || list.length || 0);
|
|
} else {
|
|
$("#articleList").html(
|
|
'<div class="cxz-article-item"><span style="color:var(--text-muted);">暂无数据</span></div>',
|
|
);
|
|
}
|
|
});
|
|
}
|
|
|
|
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 = "";
|
|
if (item.createTime) displayDate = item.createTime.substring(0, 10);
|
|
$container.append(
|
|
'<div class="cxz-article-item">' +
|
|
'<a href="' +
|
|
CommonUtil.freeArticleHref(item.id || "") +
|
|
'" target="_blank">' +
|
|
escapeHtml(item.title || "无标题") +
|
|
"</a>" +
|
|
'<span class="cxz-article-date">' +
|
|
escapeHtml(displayDate) +
|
|
"</span>" +
|
|
"</div>",
|
|
);
|
|
});
|
|
}
|
|
|
|
function renderPagination(total) {
|
|
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>
|