Files
shencaisuan/html/c.html
T
2026-06-04 11:43:41 +08:00

268 lines
8.3 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>
<a href="usercenter.html">个人中心</a><span class="sep">></span>
<span>我的收藏</span>
</div>
<div class="cxz-section-header">
<div class="cxz-section-title">免费文章收藏</div>
</div>
<div class="cxz-collect-grid" id="collectGrid"></div>
<div class="cxz-empty" id="emptyState" style="display: none">
<div class="cxz-empty-icon">
<i
class="layui-icon layui-icon-star-fill"
style="font-size: 48px"
></i>
</div>
<div class="cxz-empty-text">暂无收藏文章</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.$;
let currentPage = 1;
const pageSize = 12;
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",
);
});
} else {
window.location.href = "login.html";
return;
}
}
function authHeaders() {
const token = localStorage.getItem("token");
return { Authorization: "Bearer " + token };
}
// Load collection list
function loadCollections() {
const token = localStorage.getItem("token");
if (!token) {
window.location.href = "login.html";
return;
}
ApiClient.get(
"/api/user/collect/list?page=" +
currentPage +
"&pageSize=" +
pageSize,
{ headers: authHeaders() },
).then(function (res) {
if (res.code === 0 && res.data) {
const list = res.data.records || res.data || [];
const total = res.data.total || 0;
renderCollections(list);
renderPagination(total);
if (list.length === 0) {
$("#emptyState").show();
} else {
$("#emptyState").hide();
}
} else {
$("#collectGrid").empty();
$("#emptyState").show();
}
});
}
function renderCollections(list) {
const $grid = $("#collectGrid");
$grid.empty();
if (!list || list.length === 0) {
$grid.empty();
return;
}
$.each(list, function (i, item) {
let displayDate = "";
if (item.createTime) displayDate = item.createTime.substring(0, 10);
const articleId = item.articleId || item.id || "";
$grid.append(
'<div class="cxz-collect-card" data-collect-id="' +
(item.id || "") +
'">' +
'<div class="cxz-card-body">' +
'<div class="cxz-card-title"><a href="' +
CommonUtil.freeArticleHref(articleId) +
'">' +
(item.articleTitle || item.title || "无标题") +
"</a></div>" +
'<div class="cxz-card-meta">' +
"<span>" +
displayDate +
"</span>" +
'<button class="cxz-card-remove" onclick="removeCollect(this, ' +
(item.id || 0) +
')">取消收藏</button>' +
"</div>" +
"</div>" +
"</div>",
);
});
}
function removeCollect(btn, collectId) {
layui.layer.confirm(
"确定要取消收藏吗?",
{ icon: 3, title: "提示" },
function (index) {
layui.layer.close(index);
ApiClient.post(
"/api/user/collect/delete",
{ id: collectId },
{ headers: authHeaders() },
).then(function (res) {
if (res.code === 0) {
layui.layer.msg("已取消收藏", { icon: 1 });
const $card = $(btn).closest(".cxz-collect-card");
$card.addClass("removing");
setTimeout(function () {
$card.remove();
// Check if empty
if ($("#collectGrid .cxz-collect-card").length === 0) {
loadCollections();
}
}, 400);
} else {
layui.layer.msg(res.msg || "操作失败", { icon: 2 });
}
});
},
);
}
function renderPagination(total) {
layui.use("laypage", function () {
layui.laypage.render({
elem: "pagination",
count: total,
limit: pageSize,
curr: currentPage,
jump: function (obj, first) {
if (!first) {
currentPage = obj.curr;
loadCollections();
}
},
});
});
}
$(function () {
checkLogin();
loadCollections();
CommonUtil.loadPageConfig();
});
</script>
</body>
</html>