blob: 81c8a6bf314fb7145a66ff958357a06b05b0860a [file] [log] [blame]
LaoeGaociee7c5772025-05-28 12:34:47 +08001'use client';
2
3import { useState, useEffect, useRef } from 'react';
4import { Button } from 'primereact/button';
5import { Card } from 'primereact/card';
6import { Image } from 'primereact/image';
7//幻灯片
8import { Carousel } from 'primereact/carousel';
9//评分图标
10import { Fire } from '@icon-park/react';
11// 页面跳转
12import { useRouter } from 'next/navigation';
13import Link from 'next/link';
14// 消息提醒
15import { Toast } from 'primereact/toast';
16// 接口传输
17import axios from 'axios';
18// 样式
19import './community.scss';
20
21
22// 热门社区信息
23interface hotCommunity {
24 communityId: number;
25 communityName: string;
26 hot: number;
27 status: number; // 热门状态
28 threadNumber: number;
29 description: string;
30 communityPicture: string;
31 type: string;
32}
33interface Community {
34 communityId: number;
35 communityName: string;
36 hot: number;
37 threadNumber: number;
38 description: string;
39 communityPicture: string;
40 type: string;
41}
42
43
44// 社区主页面
45export default function CommunityPage() {
46 // 路由
47 const router = useRouter();
48 // 消息提醒
49 const toast = useRef<Toast>(null);
50 // 热门社区数据
51 const [hotCommunities, setHotCommunities] = useState<hotCommunity[]>([]);
52 // 社区数据
53 const [communities, setCommunities] = useState<Community[]>([]);
54 // 获取热门社区信息
55 useEffect(() => {
56 const fetchHotCommunity = async () => {
57 try {
LaoeGaoci388f7762025-05-29 22:24:35 +080058 const { data } = await axios.get(process.env.PUBLIC_URL + `/community/hot`);
LaoeGaociee7c5772025-05-28 12:34:47 +080059 setHotCommunities(data.communityList);
60 } catch (err) {
61 console.error(err);
62 toast.current?.show({ severity: 'error', summary: 'error', detail: '获取热门社区失败' });
63 }
64 };
65 fetchHotCommunity();
66 }, []);
67
68 // 获取社区信息
69 useEffect(() => {
70 const fetchCommunity = async () => {
71 try {
LaoeGaoci388f7762025-05-29 22:24:35 +080072 const { data } = await axios.get(process.env.PUBLIC_URL + `/community/common`);
LaoeGaociee7c5772025-05-28 12:34:47 +080073 setCommunities(data.communityList);
74 console.log(data.communityList);
75 } catch (err) {
76 console.error(err);
77 toast.current?.show({ severity: 'error', summary: 'error', detail: '获取社区失败' });
78 }
79 };
80 fetchCommunity();
81 }, []);
82 return (
83 <div className="community-container">
84
85 {/* 热门社区 */}
86 <div className="hot-communities">
87 <h1>热门社区</h1>
88 <Carousel
89 showIndicators={false}
90 showNavigators={false}
91 value={hotCommunities}
92 numVisible={3}
93 numScroll={1}
94 className="hot-communities-carousel"
95 itemTemplate={(item) => (
96 <div className="hot-communities-card">
97 <Card
98 onClick={() => router.push(`/community/community-detail/${item.communityId}`)}
99 title={item.communityName}
100 header={
101 <div className="card-header">
102 <div className="card-tag">
103 <Image
104 src={`/images/${item.status}.svg`}
105 alt="热门标签"
106 width="24"
107 height="24"
108 /></div>
LaoeGaoci388f7762025-05-29 22:24:35 +0800109 <Image src={process.env.NEXT_PUBLIC_NGINX_URL + item.communityPicture} alt={item.communityName} height="200" className="w-full h-48 object-cover" />
LaoeGaociee7c5772025-05-28 12:34:47 +0800110 </div>
111 }
112 >
113 <p>{item.description}</p>
114 </Card>
115 </div>
116 )}
117 />
118 </div>
119
120 {/* 全部分类 */}
LaoeGaoci8f6d0db2025-06-03 22:57:04 +0800121 <h1>分类</h1>
LaoeGaociee7c5772025-05-28 12:34:47 +0800122 <div className="all-communities-classifications">
123 <Link href="/community/resource-community-list/材质包">
124 <Image
125 className='communities-classification-card'
126 src="/images/材质包.png"
127 alt="Image"
128 width="250"
129 />
130 </Link>
131 <Link href="/community/resource-community-list/整合包">
132 <Image
133 className='communities-classification-card'
134 src="/images/整合包.png"
135 alt="Image"
136 width="250"
137 />
138 </Link>
139 <Link href="/community/resource-community-list/模组">
140 <Image
141 className='communities-classification-card'
142 src="/images/模组.png"
143 alt="Image"
144 width="250"
145 />
146 </Link>
147 <Link href="/community/resource-community-list/地图">
148 <Image
149 className='communities-classification-card'
150 src="/images/地图.png"
151 alt="Image"
152 width="250"
153 />
154 </Link>
155 </div>
156
157 {/* 全部社区 */}
158 <div className="all-communities">
159 <div className="all-communities-header">
160 <h1>全部社区</h1>
161 <Link href="/community/resource-community-list/all">
162 <Button label="查看更多" link />
163 </Link>
164 </div>
165 <div className="all-communities-list">
166 {communities.map((community) => (
167 <Card key={community.communityId} className="all-communities-card" onClick={() => router.push(`/community/community-detail/${community.communityId}`)}>
168 <Image alt="avatar" src={process.env.NEXT_PUBLIC_NGINX_URL + community.communityPicture} className="community-avatar" width="250" height="140" />
169 <div className="community-header">
170 <div className="community-content">
171 <h3>{community.communityName}</h3>
172 <p className="community-introduction">{community.description}</p>
173 </div>
174 <div className="community-states">
175 <div className="state-item">
176 <Fire theme="outline" size="16" fill="#FF8D1A" />
177 <span>热度: {community.hot}</span>
178 </div>
179 <div className="state-item">
180 <i className="pi pi-book" />
181 <span>贴子数: {community.threadNumber}</span>
182 </div>
183 </div>
184 </div>
185 </Card>
186 ))}
187 </div>
188 </div>
189 </div>
190 );
191}