Skip to content

Let's use AI to Earn!

feat: AI生成回复

牛文政359247278c23
diff --git a/src/icp/reply.ts b/src/icp/reply.ts
index 8ab2accc..7b4c3458 100644
--- a/src/icp/reply.ts
+++ b/src/icp/reply.ts
@@ -108,7 +108,7 @@ export async function icpReplyComment(
content: string,
option: {
dataId?: string; // 作品ID
- data: any; // 辅助数据,原数据
+ comment: any; // 辅助数据,原数据
},
) {
const res: boolean = await window.ipcRenderer.invoke(
diff --git a/src/views/reply/components/replyComment.tsx b/src/views/reply/components/replyComment.tsx
index 1321f6f8..94d4c366 100644
--- a/src/views/reply/components/replyComment.tsx
+++ b/src/views/reply/components/replyComment.tsx
@@ -1,16 +1,21 @@
+import { toolsApi } from '@/api/tools';
import { CommentData, icpReplyComment } from '@/icp/reply';
-import { Modal } from 'antd';
+import { Button, Form, Input, Modal } from 'antd';
import { forwardRef, useImperativeHandle, useState } from 'react';
export interface ReplyCommentRef {
init: (accountId: number, inInfo: CommentData) => Promise<void>;
}
+interface FormData {
+ content: string;
+}
+
const Com = forwardRef<ReplyCommentRef>((props: any, ref) => {
const [isModalOpen, setIsModalOpen] = useState(false);
const [accountId, setAccountId] = useState<number>(0);
const [commentData, setCommentData] = useState<CommentData | null>(null);
-
+ const [form] = Form.useForm<FormData>();
async function init(accountId: number, inInfo: CommentData) {
setAccountId(accountId);
setCommentData(inInfo);
@@ -28,17 +33,39 @@ const Com = forwardRef<ReplyCommentRef>((props: any, ref) => {
/**
* 回复评论
*/
- async function replyComment(
- commentId: string,
- option: {
- dataId?: string; // 作品ID
- data: any; // 辅助数据,原数据
- },
- ) {
- const res = await icpReplyComment(accountId, commentId, '真不错', option);
+ async function replyComment(content: string) {
+ const res = await icpReplyComment(
+ accountId,
+ commentData!.commentId,
+ content,
+ {
+ dataId: commentData!.dataId,
+ comment: commentData!.data,
+ },
+ );
console.log('----- res', res);
}
+ async function onFinish(values: FormData) {
+ await replyComment(values.content);
+ console.log('Success:', values);
+ }
+
+ async function onFinishFailed(errorInfo: any) {
+ console.log('Failed:', errorInfo);
+ }
+
+ async function getAiContent() {
+ if (!commentData?.content) return;
+ const res = await toolsApi.apiReviewAiRecover({
+ content: commentData?.content,
+ });
+
+ form.setFieldsValue({
+ content: res,
+ });
+ }
+
return (
<>
<Modal
@@ -48,7 +75,33 @@ const Com = forwardRef<ReplyCommentRef>((props: any, ref) => {
footer={null}
width={800}
>
- 1111
+ <Form
+ form={form}
+ name="basic"
+ labelCol={{ span: 8 }}
+ wrapperCol={{ span: 16 }}
+ initialValues={{ remember: true }}
+ onFinish={onFinish}
+ onFinishFailed={onFinishFailed}
+ autoComplete="off"
+ >
+ <Form.Item
+ label="content"
+ name="content"
+ rules={[{ required: true, message: '请输入评论!' }]}
+ >
+ <Input />
+ </Form.Item>
+
+ <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
+ <Button type="primary" onClick={getAiContent}>
+ AI建议
+ </Button>
+ <Button type="primary" htmlType="submit">
+ 提交
+ </Button>
+ </Form.Item>
+ </Form>
</Modal>
</>
);
diff --git a/src/views/reply/components/replyWorks.tsx b/src/views/reply/components/replyWorks.tsx
index 97d1d9da..2229ea0c 100644
--- a/src/views/reply/components/replyWorks.tsx
+++ b/src/views/reply/components/replyWorks.tsx
@@ -1,15 +1,20 @@
import { icpCreateComment, WorkData } from '@/icp/reply';
-import { Button, Modal } from 'antd';
+import { Button, Form, Input, Modal } from 'antd';
import { forwardRef, useImperativeHandle, useState } from 'react';
export interface ReplyWorksRef {
init: (accountId: number, inWorkData: WorkData) => Promise<void>;
}
+interface FormData {
+ content: string;
+}
+
const Com = forwardRef<ReplyWorksRef>((props: any, ref) => {
const [isModalOpen, setIsModalOpen] = useState(false);
const [accountId, setAccountId] = useState<number>(0);
const [workData, setWorkData] = useState<WorkData | null>(null);
+ const [formData, setFormData] = useState<Partial<FormData>>();
async function init(accountId: number, inWorkData: WorkData) {
setAccountId(accountId);
@@ -33,6 +38,14 @@ const Com = forwardRef<ReplyWorksRef>((props: any, ref) => {
console.log('----- res', res);
}
+ async function onFinish(values: FormData) {
+ createComment(values.content);
+ }
+
+ async function onFinishFailed(errorInfo: any) {
+ console.log('Failed:', errorInfo);
+ }
+
return (
<>
<Modal
@@ -42,14 +55,29 @@ const Com = forwardRef<ReplyWorksRef>((props: any, ref) => {
footer={null}
width={800}
>
- <Button
- type="primary"
- onClick={() => {
- createComment('测试评论');
- }}
+ <Form
+ name="basic"
+ labelCol={{ span: 8 }}
+ wrapperCol={{ span: 16 }}
+ initialValues={{ remember: true }}
+ onFinish={onFinish}
+ onFinishFailed={onFinishFailed}
+ autoComplete="off"
>
- 测试评论
- </Button>
+ <Form.Item
+ label="content"
+ name="content"
+ rules={[{ required: true, message: '请输入评论!' }]}
+ >
+ <Input value={formData?.content} />
+ </Form.Item>
+
+ <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
+ <Button type="primary" htmlType="submit">
+ 提交评论
+ </Button>
+ </Form.Item>
+ </Form>
</Modal>
</>
);