样式修改完成,待测试
This commit is contained in:
+78
-21
@@ -110,7 +110,7 @@
|
||||
<script>
|
||||
const $ = layui.$;
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
let menuId = urlParams.get("id") || "";
|
||||
let menuId = urlParams.get("id") || urlParams.get("code") || "";
|
||||
let currentPage = 1;
|
||||
const pageSize = 15;
|
||||
let lotteryMenus = [];
|
||||
@@ -153,16 +153,15 @@
|
||||
|
||||
function resolveCurrentMenuId() {
|
||||
if (!lotteryMenus.length) return;
|
||||
if (
|
||||
menuId &&
|
||||
lotteryMenus.some(function (item) {
|
||||
return sameLotteryKey(item, menuId);
|
||||
})
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
menuId = String((lotteryMenus[0] && lotteryMenus[0].id) || "");
|
||||
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() {
|
||||
@@ -184,9 +183,10 @@
|
||||
$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(id) +
|
||||
encodeURIComponent(linkKey) +
|
||||
'" class="cxz-lottery-tab" data-id="' +
|
||||
escapeHtml(id) +
|
||||
'">' +
|
||||
@@ -244,6 +244,44 @@
|
||||
);
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -253,16 +291,26 @@
|
||||
renderPagination(0);
|
||||
return;
|
||||
}
|
||||
const requestMenuId = currentRequestMenuId();
|
||||
if (!requestMenuId) {
|
||||
renderFallbackArticles();
|
||||
return;
|
||||
}
|
||||
ApiClient.get(ApiClient.API.freeArticleList, {
|
||||
menuId: menuId,
|
||||
menuId: requestMenuId,
|
||||
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);
|
||||
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();
|
||||
}
|
||||
@@ -273,7 +321,9 @@
|
||||
|
||||
function renderFallbackArticles() {
|
||||
const group = currentFallbackGroup();
|
||||
const allArticles = ApiClient.asArray(group && group.articles);
|
||||
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);
|
||||
@@ -291,13 +341,16 @@
|
||||
}
|
||||
$.each(list, function (i, item) {
|
||||
let displayDate = "";
|
||||
if (item.createTime) displayDate = item.createTime.substring(0, 10);
|
||||
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(item.id || "") +
|
||||
CommonUtil.freeArticleHref(article.id || "") +
|
||||
'" target="_blank">' +
|
||||
escapeHtml(item.title || "无标题") +
|
||||
escapeHtml(title) +
|
||||
"</a>" +
|
||||
'<span class="cxz-article-date">' +
|
||||
escapeHtml(displayDate) +
|
||||
@@ -308,6 +361,10 @@
|
||||
}
|
||||
|
||||
function renderPagination(total) {
|
||||
$("#pagination").empty();
|
||||
if (!total || total <= pageSize) {
|
||||
return;
|
||||
}
|
||||
layui.laypage.render({
|
||||
elem: "pagination",
|
||||
count: total,
|
||||
|
||||
Reference in New Issue
Block a user