diff --git a/mock/_utils/result.ts b/mock/_utils/result.ts
new file mode 100644
index 00000000..220aa462
--- /dev/null
+++ b/mock/_utils/result.ts
@@ -0,0 +1,18 @@
+/**
+ * 模拟返回结构
+ */
+export default function result(success: boolean, message: string, data?: any) {
+ return {
+ success: success,
+ message: message,
+ data: data,
+ };
+}
+
+export function success(data: any = null) {
+ return result(true, 'ok', data);
+}
+
+export function error(message = 'error', data: any = null) {
+ return result(false, message, data);
+}
diff --git a/mock/api.ts b/mock/api.ts
new file mode 100644
index 00000000..a0b539ee
--- /dev/null
+++ b/mock/api.ts
@@ -0,0 +1,8 @@
+import { success } from './_utils/result';
+
+// http://mockjs.com/examples.html
+export default {
+ 'GET /api/worked': (req: any, res: any) => {
+ return res.json(success());
+ },
+};
diff --git a/mock/comment.ts b/mock/comment.ts
new file mode 100644
index 00000000..f9ba9c88
--- /dev/null
+++ b/mock/comment.ts
@@ -0,0 +1,65 @@
+import { success } from './_utils/result';
+import Mock from 'mockjs';
+import { CommentType } from '@/Comment/components/type';
+import { UserType } from '@/Utils/interface';
+
+// http://mockjs.com/examples.html
+export default {
+ 'GET /api/ums/account': (req: any, res: any) =>
+ res.json(
+ success({
+ id: 1,
+ nickname: 'hocgin',
+ username: 'hocgin',
+ avatar: Mock.Random.image('100x100'),
+ }),
+ ),
+ 'POST /api/com/comment/:refType/:refId/like': (req: any, res: any) =>
+ res.json(success(mockData())),
+ 'POST /api/com/comment/:refType/:refId/dislike': (req: any, res: any) =>
+ res.json(success(mockData())),
+ 'POST /api/com/comment/:refType/:refId/report': (req: any, res: any) =>
+ res.json(success(mockData())),
+ 'POST /api/com/comment/:refType/:refId/reply': (req: any, res: any) =>
+ res.json(success(mockData())),
+ 'POST /api/com/comment/:refType/:refId/_scroll': (req: any, res: any) =>
+ res.json(
+ success({
+ nextId: 1,
+ hasMore: true,
+ records: [mockData()],
+ }),
+ ),
+ 'POST /api/com/comment/:refType/:refId/_paging': (req: any, res: any) =>
+ res.json(
+ success({
+ current: 1,
+ total: 1,
+ size: 1,
+ pages: 1,
+ records: [mockData()],
+ }),
+ ),
+};
+
+let mockData = () => {
+ return Mock.mock({
+ id: '@integer()',
+ replyId: 1,
+ likes: '@integer(0, 10)',
+ disliked: '@integer(0, 10)',
+ action: 'none',
+ content: '@string()',
+ hasReply: '@bool()',
+ author: mockUser(),
+ replier: mockUser(),
+ });
+};
+
+let mockUser = () => {
+ return {
+ id: 1,
+ title: 'hocgin',
+ avatarUrl: Mock.Random.image('100x100'),
+ } as UserType;
+};
diff --git a/mock/file.ts b/mock/file.ts
new file mode 100644
index 00000000..c05a7316
--- /dev/null
+++ b/mock/file.ts
@@ -0,0 +1,12 @@
+import { success } from './_utils/result';
+import Mock from 'mockjs';
+
+// http://mockjs.com/examples.html
+export default {
+ 'POST /api/com/file/upload': (req: any, res: any) => {
+ return res.json(success(Mock.Random.image('100x100')));
+ },
+ 'GET /api/com/file/upload': (req: any, res: any) => {
+ return res.json(success(Mock.Random.image('100x100')));
+ },
+};
diff --git a/package.json b/package.json
index 6afda206..618b588f 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@hocgin/ui",
- "version": "4.0.41",
+ "version": "4.0.42",
"sideEffects": [
".less",
".css"
@@ -54,6 +54,7 @@
"draft-js-prism": "^1.0.6",
"emoji-mart": "^3.0.1",
"memoize-one": "^5.2.1",
+ "mockjs": "^1.1.0",
"randexp": "^0.5.3",
"react-copy-to-clipboard": "^5.0.4",
"react-countup": "^5.2.0",
diff --git a/src/Comment/components/Comment/index.tsx b/src/Comment/components/Comment/index.tsx
index 2164b906..f55d27d0 100644
--- a/src/Comment/components/Comment/index.tsx
+++ b/src/Comment/components/Comment/index.tsx
@@ -52,13 +52,11 @@ const UserOptions: React.FC<{
comment: CommentType;
useAction: UseAction;
userAction?: string;
- likesCount?: number;
- dislikedCount?: number;
}> = (props, ref) => {
let { useAction, comment } = props;
let [userAction, setUserAction] = useState(props?.userAction);
- let [likesCount, setLikesCount] = useState(props?.likesCount || 0);
- let [dislikedCount, setDislikedCount] = useState(props?.dislikedCount || 0);
+ let [likesCount, setLikesCount] = useState(comment?.likes || 0);
+ let [dislikedCount, setDislikedCount] = useState(comment?.disliked || 0);
let commentId = comment.id;
let options = {
@@ -207,7 +205,7 @@ const Comment: React.FC<{
)}
>
}
- content={
{content}
}
+ content={{content}
}
actions={actions}
>
{children}
@@ -284,7 +282,7 @@ const Index: React.FC<{
datetime={datetime}
author={author}
replier={replier}
- content={{content}
}
+ content={{content}
}
actions={[
(undefined);
let [content, setContent] = useState('');
+ let [replied, setReplied] = useState(false);
+ useInterval(() => setReplied?.(false), 2000);
+
reply$.useSubscription((comment?: CommentType) => {
setReply(comment);
});
@@ -54,6 +62,10 @@ const Editor: React.FC<{
debounceWait: 300,
onSuccess: (data: ReplyDataType) => {
replied$.emit(data);
+
+ // 清除原先内容
+ setContent('');
+ setReplied(true);
},
});
@@ -86,7 +98,7 @@ const Editor: React.FC<{
-