返回 AiToEarn
replyComment.tsx
1 import { toolsApi } from '@/api/tools';
2 import { CommentData, icpReplyCommentByOther } from '@/icp/replyother';
3 import { Button, Form, Input, message, Modal } from 'antd';
4 import { forwardRef, useImperativeHandle, useState } from 'react';
5
6 export interface ReplyCommentRef {
7 init: (accountId: number, inInfo: CommentData) => Promise<void>;
8 }
9
10 interface FormData {
11 content: string;
12 }
13
14 const Com = forwardRef<ReplyCommentRef>((props: any, ref) => {
15 const [isModalOpen, setIsModalOpen] = useState(false);
16 const [accountId, setAccountId] = useState<number>(0);
17 const [commentData, setCommentData] = useState<CommentData | null>(null);
18 const [form] = Form.useForm<FormData>();
19 async function init(accountId: number, inInfo: CommentData) {
20 setAccountId(accountId);
21 setCommentData(inInfo);
22 setIsModalOpen(true);
23 }
24
25 useImperativeHandle(ref, () => ({
26 init: init,
27 }));
28
29 function handleCancel() {
30 setIsModalOpen(false);
31 }
32
33 /**
34 * 回复评论
35 */
36 async function replyComment(content: string) {
37 // console.log('----- replyComment commentData', commentData!.commentId,
38 // content,
39 // {
40 // dataId: commentData!.dataId,
41 // comment: commentData!.data,
42 // }
43 // );
44 // return;
45
46 const res: any = await icpReplyCommentByOther(
47 accountId,
48 commentData!.commentId,
49 content,
50 {
51 dataId: commentData!.dataId,
52 comment: commentData!.data,
53 videoAuthId: commentData!.videoAuthId,
54 },
55 );
56 console.log('----- replyComment res', res);
57 if (
58 res.status_code == 0 ||
59 res.data.code == 0 ||
60 res.data.data.visionAddComment?.result == 1
61 ) {
62 message.success('回复成功');
63 setIsModalOpen(false);
64 } else {
65 message.error('回复失败');
66 }
67 }
68
69 async function onFinish(values: FormData) {
70 await replyComment(values.content);
71 console.log('Success:', values);
72 }
73
74 async function onFinishFailed(errorInfo: any) {
75 console.log('Failed:', errorInfo);
76 }
77
78 async function getAiContent() {
79 if (!commentData?.content) return;
80 const res = await toolsApi.apiReviewAiRecover({
81 content: commentData?.content,
82 });
83
84 form.setFieldsValue({
85 content: res,
86 });
87 }
88
89 return (
90 <>
91 <Modal
92 title={null}
93 open={isModalOpen}
94 onCancel={handleCancel}
95 footer={null}
96 width={800}
97 >
98 <Form
99 form={form}
100 name="basic"
101 labelCol={{ span: 8 }}
102 wrapperCol={{ span: 16 }}
103 initialValues={{ remember: true }}
104 onFinish={onFinish}
105 onFinishFailed={onFinishFailed}
106 autoComplete="off"
107 >
108 <Form.Item
109 label="content"
110 name="content"
111 rules={[{ required: true, message: '请输入评论!' }]}
112 >
113 <Input />
114 </Form.Item>
115
116 <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
117 <Button type="primary" onClick={getAiContent}>
118 AI建议
119 </Button>
120 <Button type="primary" htmlType="submit">
121 提交
122 </Button>
123 </Form.Item>
124 </Form>
125 </Modal>
126 </>
127 );
128 });
129 export default Com;
130
130 lines Plain Text