帖子分类
Change-Id: I17bafbfe3c1c8fd26c1e12499cb3c17cd1738e23
diff --git a/src/mock/comment.js b/src/mock/comment.js
new file mode 100644
index 0000000..695ccc4
--- /dev/null
+++ b/src/mock/comment.js
@@ -0,0 +1,34 @@
+import mockjs from "mockjs";
+import MockAdapter from "axios-mock-adapter";
+import { getPostComments} from "@/api/comment";
+
+export function setupCommentMock(mock) {
+ const getPostCommentsPattern = new RegExp(`^${getPostComments}/\\d+$`);
+ mock.onGet(getPostCommentsPattern).reply(config => {
+ let data = mockjs.mock({
+ [`list|5`]: [
+ {
+ "commentId|+1": 1, // 自增评论 ID
+ "content": "@cparagraph(1, 3)", // 随机生成 1-3 段评论内容
+ "createdAt": "@datetime('T')", // 随机生成时间戳
+ "parentCommentId": null, // 顶级评论的父评论 ID 为 null
+ "postId|1-100": 1, // 随机生成帖子 ID
+ "userId|1-100": 1, // 随机生成用户 ID
+ "replies|0-3": [ // 随机生成 0-3 条子评论
+ {
+ "commentId|+1": 100, // 子评论的 ID 从 100 开始自增
+ "content": "@cparagraph(1, 2)", // 随机生成 1-2 段子评论内容
+ "createdAt": "@datetime('T')", // 随机生成时间戳
+ "parentCommentId": "@increment(1)", // 父评论 ID
+ "postId|1-100": 1, // 随机生成帖子 ID
+ "userId|1-100": 1, // 随机生成用户 ID
+ "replies": [] // 子评论的子评论为空
+ }
+ ]
+ },
+ ],
+ });
+ return [200, data.list];
+ });
+
+}
\ No newline at end of file