diff --git a/app/page.jsx b/app/page.jsx
index 22c0562..41bb75b 100644
--- a/app/page.jsx
+++ b/app/page.jsx
@@ -41,7 +41,7 @@ export default function Page() {
diff --git a/components/homes/home-15/CategoryItems.jsx b/components/homes/home-15/CategoryItems.jsx
index a4edce8..0af6ca2 100644
--- a/components/homes/home-15/CategoryItems.jsx
+++ b/components/homes/home-15/CategoryItems.jsx
@@ -6,13 +6,8 @@ import Link from "next/link";
import Image from "next/image";
import PropTypes from "prop-types";
-const PAGE_SIZE = 8; // 每页8条,4列2行
-const PAGE_SLUG = "case"; // 博客slug常量
-
-export default function CategoryItems({ pagetype = "", category = "", count = undefined }) {
+export default function CategoryItems({ pagetype = "", category = "", category_slug = "" , count = 8, columns = 4 }) {
const [posts, setPosts] = useState([]);
- const [currentPage, setCurrentPage] = useState(1);
- const [totalPages, setTotalPages] = useState(1);
const [loading, setLoading] = useState(false);
useEffect(() => {
@@ -22,49 +17,22 @@ export default function CategoryItems({ pagetype = "", category = "", count = un
const params = new URLSearchParams({ pagetype });
if (category) params.append("category", category);
if (count !== undefined && count !== null) params.append("count", count);
- params.append("page", currentPage);
- params.append("page_size", PAGE_SIZE);
const res = await fetch(`/api/get-listview-data?${params.toString()}`);
const json = await res.json();
if (Array.isArray(json.data)) {
setPosts(json.data);
- setTotalPages(Math.ceil((json.total || json.data.length || 0) / PAGE_SIZE));
} else {
setPosts([]);
- setTotalPages(1);
}
} catch (e) {
setPosts([]);
- setTotalPages(1);
}
setLoading(false);
}
fetchData();
- }, [currentPage, pagetype, category, count]);
+ }, [pagetype, category, count]);
- // 分页控件
- function PaginationComp() {
- if (totalPages <= 1) return null;
- return (
-
- );
- }
-
- // 渲染卡片内容(只返回图片部分,结构在下方article里)
+ // 渲染卡片内容
function renderCardImage(post, idx) {
// 多图轮播
if (Array.isArray(post.images) && post.images.length > 1) {
@@ -128,7 +96,7 @@ export default function CategoryItems({ pagetype = "", category = "", count = un
return null;
}
- function getSummary(text, maxLen = 100) {
+ function getSummary(text, maxLen = 60) {
if (!text) return "";
// 中文:直接按字符截断
if (/[\u4e00-\u9fa5]/.test(text)) {
@@ -145,20 +113,39 @@ export default function CategoryItems({ pagetype = "", category = "", count = un
return cut + "...";
}
+ // 日期格式化函数,支持自定义是否显示时分秒
+ function formatDate(dateStr, options = {}) {
+ if (!dateStr) return "";
+ const d = new Date(dateStr);
+ if (isNaN(d.getTime())) return dateStr;
+ const { showTime = false } = options;
+ const yyyy = d.getFullYear();
+ const mm = String(d.getMonth() + 1).padStart(2, '0');
+ const dd = String(d.getDate()).padStart(2, '0');
+ let result = `${yyyy}-${mm}-${dd}`;
+ if (showTime) {
+ const hh = String(d.getHours()).padStart(2, '0');
+ const min = String(d.getMinutes()).padStart(2, '0');
+ const ss = String(d.getSeconds()).padStart(2, '0');
+ result += ` ${hh}:${min}:${ss}`;
+ }
+ return result;
+ }
+
return (
-
+
{loading ? (
-
加载中...
+
加载中...
) : posts.length === 0 ? (
-
暂无数据
+
暂无数据
) : (
posts.map((post, idx) => (
{/* 图片/轮播/视频部分 */}
-
+
{renderCardImage(post, idx)}
@@ -172,14 +159,14 @@ export default function CategoryItems({ pagetype = "", category = "", count = un
{post.title}
@@ -194,14 +181,12 @@ export default function CategoryItems({ pagetype = "", category = "", count = un
-
- {post.date || post.published_at || ""}
+ {formatDate(post.creation)}
{post.author && (
-
-
{post.author}
-
)}
{typeof post.comments === 'number' && (
@@ -227,7 +212,6 @@ export default function CategoryItems({ pagetype = "", category = "", count = un
))
)}
-
);
}
@@ -239,4 +223,6 @@ CategoryItems.propTypes = {
PropTypes.string,
PropTypes.number
]),
+ columns: PropTypes.number,
+ category_slug: PropTypes.string,
};