import { useState } from "react"; import { useIntl } from "react-intl"; import { Button, Card } from "antd"; import { Input, message } from "antd"; import { SaveOutlined } from "@ant-design/icons"; import { ProForm, ProFormText, ProFormTextArea, } from "@ant-design/pro-components"; import { Col, Row, Space } from "antd"; import { IComment } from "./CommentItem"; import { post, put } from "../../request"; import { ICommentRequest, ICommentResponse } from "../api/Comment"; const { TextArea } = Input; interface IWidget { data: IComment; onCreated?: Function; } const Widget = ({ data, onCreated }: IWidget) => { const intl = useIntl(); const [value, setValue] = useState(data.content); const [saving, setSaving] = useState(false); const save = () => { setSaving(true); put(`/v2/discussion/${data.id}`, { content: value, }) .then((json) => { console.log(json); setSaving(false); if (json.ok) { message.success(intl.formatMessage({ id: "flashes.success" })); } else { message.error(json.message); } }) .catch((e) => { setSaving(false); console.error("catch", e); message.error(e.message); }); }; const formItemLayout = { labelCol: { span: 4 }, wrapperCol: { span: 20 }, }; return (
{...formItemLayout} layout="horizontal" submitter={{ render: (props, doms) => { return ( {doms} ); }, }} onFinish={async (values) => { if (typeof values.id === "undefined") { //新建 post(`/v2/discussion`, { res_id: data.resId, res_type: data.resType, title: values.title, content: values.content, }) .then((json) => { console.log(json); if (json.ok) { message.success( intl.formatMessage({ id: "flashes.success" }) ); if (typeof onCreated !== "undefined") { onCreated(json.data); } } else { message.error(json.message); } }) .catch((e) => { message.error(e.message); }); } else { //修改 } }} params={{}} request={async () => { return data; }} > {data.user.nickName}} extra={ } style={{ width: "auto" }} >