|
|
@@ -6,6 +6,58 @@ import { postClient } from '@/client/api';
|
|
|
import { InferResponseType } from 'hono/client';
|
|
|
|
|
|
// 定义帖子类型
|
|
|
+// Mock数据
|
|
|
+const MOCK_POSTS: Post[] = [
|
|
|
+ {
|
|
|
+ id: 1,
|
|
|
+ content: "欢迎加入社交媒体平台!这是一条系统推荐的示例动态。",
|
|
|
+ likesCount: 42,
|
|
|
+ commentsCount: 8,
|
|
|
+ createdAt: new Date(Date.now() - 3600000 * 2).toISOString(),
|
|
|
+ user: {
|
|
|
+ id: 1,
|
|
|
+ username: "系统推荐",
|
|
|
+ avatar: "https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png"
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 2,
|
|
|
+ content: "刚刚完成了一个重要项目,感谢团队的支持!#工作日常 #团队合作",
|
|
|
+ likesCount: 89,
|
|
|
+ commentsCount: 12,
|
|
|
+ createdAt: new Date(Date.now() - 3600000 * 8).toISOString(),
|
|
|
+ user: {
|
|
|
+ id: 3,
|
|
|
+ username: "程序员小李",
|
|
|
+ avatar: "https://gw.alipayobjects.com/zos/rmsportal/gaOngJwsRYRaVAuXXcmB.png"
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 3,
|
|
|
+ content: "分享一张我今天拍摄的风景照片,希望大家喜欢!#自然风光 #摄影",
|
|
|
+ likesCount: 156,
|
|
|
+ commentsCount: 23,
|
|
|
+ createdAt: new Date(Date.now() - 3600000 * 16).toISOString(),
|
|
|
+ user: {
|
|
|
+ id: 2,
|
|
|
+ username: "旅行爱好者",
|
|
|
+ avatar: "https://gw.alipayobjects.com/zos/rmsportal/cnrhVkzwxjPwAaCfPbdc.png"
|
|
|
+ },
|
|
|
+ images: ["https://gw.alipayobjects.com/zos/rmsportal/JiqGstEfoWAOHiTxclqi.png"]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 4,
|
|
|
+ content: "今天尝试了新的咖啡配方,味道很不错!#美食分享 #咖啡",
|
|
|
+ likesCount: 67,
|
|
|
+ commentsCount: 9,
|
|
|
+ createdAt: new Date(Date.now() - 3600000 * 24).toISOString(),
|
|
|
+ user: {
|
|
|
+ id: 4,
|
|
|
+ username: "美食家小王",
|
|
|
+ avatar: "https://gw.alipayobjects.com/zos/rmsportal/ubnKSIfAJTxIgXOKlciN.png"
|
|
|
+ }
|
|
|
+ }
|
|
|
+];
|
|
|
type Post = InferResponseType<typeof postClient.$get, 200>['data'][0];
|
|
|
|
|
|
const MemberPage: React.FC = () => {
|
|
|
@@ -29,7 +81,8 @@ const MemberPage: React.FC = () => {
|
|
|
if (!response.ok) throw new Error('获取内容失败');
|
|
|
|
|
|
const data = await response.json();
|
|
|
- setPosts(data.data);
|
|
|
+ // 如果API返回数据为空,则使用mock数据
|
|
|
+ setPosts(data.data.length > 0 ? data.data : MOCK_POSTS);
|
|
|
} catch (error) {
|
|
|
console.error('Error fetching posts:', error);
|
|
|
} finally {
|