diff --git a/src/app/wall/[cate]/page.tsx b/src/app/wall/[cate]/page.tsx index 686aa85..8a0bc3d 100755 --- a/src/app/wall/[cate]/page.tsx +++ b/src/app/wall/[cate]/page.tsx @@ -1,8 +1,8 @@ import Link from 'next/link'; import Pagination from '@/components/Pagination'; import AddWallInfo from '../components/AddWallInfo'; +import WallMasonry from '../components/WallMasonry'; import { getCateListAPI, getCateWallListAPI } from '@/api/wall'; -import dayjs from 'dayjs'; import { Cate } from '@/types/app/cate'; import { Wall } from '@/types/app/wall'; @@ -11,15 +11,6 @@ interface Props { searchParams: Promise<{ page: number }>; } -// 颜色映射表,将颜色值映射到对应的 Tailwind 类名 -const colorMap: Record = { - '#fcafa24d': 'bg-[#fcafa24d]', - '#a8ed8a4d': 'bg-[#a8ed8a4d]', - '#caa7f74d': 'bg-[#caa7f74d]', - '#ffe3944d': 'bg-[#ffe3944d]', - '#92e6f54d': 'bg-[#92e6f54d]', -}; - export default async (props: Props) => { const searchParams = await props.searchParams; const params = await props.params; @@ -75,55 +66,8 @@ export default async (props: Props) => { ))} - {/* 留言卡片网格 */} -
- {tallList.result?.map((item, index) => { - const bgColor = colorMap[item.color] || 'bg-[#ffe3944d]'; - return ( -
- {/* 卡片装饰边框 */} -
- - {/* 顶部信息 */} -
- {dayjs(+item.createTime!).format('YYYY-MM-DD HH:mm')} - {item.cate.name} -
- - {/* 留言内容 */} -
{item.content}
- - {/* 底部署名 */} -
-
- - {item.name ? item.name : '匿名'} -
-
- - {/* Hover 时的光效 */} -
-
- ); - })} -
+ {/* 留言卡片瀑布流 */} +
{tallList.result && tallList.result.length > 0 ? :
暂无留言
}
{/* 分页 */} {tallList.total && ( diff --git a/src/app/wall/components/WallMasonry/index.scss b/src/app/wall/components/WallMasonry/index.scss new file mode 100644 index 0000000..4efad62 --- /dev/null +++ b/src/app/wall/components/WallMasonry/index.scss @@ -0,0 +1,20 @@ +// 留言墙瀑布流样式优化 +.wall-masonry-grid { + margin-left: -20px; // 调整左侧间距 + + @media (min-width: 640px) { + margin-left: -15px; + } + + @media (min-width: 768px) { + margin-left: -20px; + } + + @media (min-width: 1024px) { + margin-left: -24px; + } +} + +.wall-masonry-grid .masonry-grid_column { + padding-left: 12px; // 列间距 +} diff --git a/src/app/wall/components/WallMasonry/index.tsx b/src/app/wall/components/WallMasonry/index.tsx new file mode 100644 index 0000000..fec862f --- /dev/null +++ b/src/app/wall/components/WallMasonry/index.tsx @@ -0,0 +1,81 @@ +'use client'; + +import Masonry from 'react-masonry-css'; +import dayjs from 'dayjs'; +import { Wall } from '@/types/app/wall'; +import '@/components/ArticleLayout/Waterfall/index.scss'; +import './index.scss'; + +// 颜色映射表,将颜色值映射到对应的 Tailwind 类名 +const colorMap: Record = { + '#fcafa24d': 'bg-[#fcafa24d]', + '#a8ed8a4d': 'bg-[#a8ed8a4d]', + '#caa7f74d': 'bg-[#caa7f74d]', + '#ffe3944d': 'bg-[#ffe3944d]', + '#92e6f54d': 'bg-[#92e6f54d]', +}; + +// 瀑布流断点配置 +const breakpointColumnsObj = { + default: 4, + 1024: 3, + 768: 2, + 640: 1, +}; + +interface WallMasonryProps { + walls: Wall[]; +} + +export default ({ walls }: WallMasonryProps) => { + return ( + + {walls.map((item, index) => { + const bgColor = colorMap[item.color] || 'bg-[#ffe3944d]'; + return ( +
+ {/* 卡片装饰边框 */} +
+ + {/* 顶部信息 */} +
+ {dayjs(+item.createTime!).format('YYYY-MM-DD HH:mm')} + {item.cate.name} +
+ + {/* 留言内容 */} +
{item.content}
+ + {/* 底部署名 */} +
+
+ + {item.name ? item.name : '匿名'} +
+
+ + {/* Hover 时的光效 */} +
+
+ ); + })} +
+ ); +};