Browse Source

修改用proform

visuddhinanda 3 years ago
parent
commit
e7f3cf87a9
1 changed files with 45 additions and 99 deletions
  1. 45 99
      dashboard/src/components/comment/CommentEdit.tsx

+ 45 - 99
dashboard/src/components/comment/CommentEdit.tsx

@@ -22,60 +22,44 @@ interface IWidget {
 }
 const Widget = ({ data, onCreated }: IWidget) => {
   const intl = useIntl();
-  const [value, setValue] = useState(data.content);
-
-  const [saving, setSaving] = useState<boolean>(false);
-
-  const save = () => {
-    setSaving(true);
-    put<ICommentRequest, ICommentResponse>(`/v2/discussion/${data.id}`, {
-      content: value,
-    })
-      .then((json) => {
-        console.log(json);
-        setSaving(false);
-
-        if (json.ok) {
-          console.log(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 (
     <div>
-      <ProForm<IComment>
-        {...formItemLayout}
-        layout="horizontal"
-        submitter={{
-          render: (props, doms) => {
-            return (
-              <Row>
-                <Col span={14} offset={4}>
-                  <Space>{doms}</Space>
-                </Col>
-              </Row>
-            );
-          },
-        }}
-        onFinish={async (values) => {
-          if (typeof values.id === "undefined") {
+      <Card
+        title={<span>{data.user.nickName}</span>}
+        extra={
+          <Button shape="circle" size="small">
+            xxx
+          </Button>
+        }
+        style={{ width: "auto" }}
+      >
+        <ProForm<IComment>
+          {...formItemLayout}
+          layout="horizontal"
+          submitter={{
+            render: (props, doms) => {
+              return (
+                <Row>
+                  <Col span={14} offset={4}>
+                    <Space>{doms}</Space>
+                  </Col>
+                </Row>
+              );
+            },
+          }}
+          onFinish={async (values) => {
             //新建
-            post<ICommentRequest, ICommentResponse>(`/v2/discussion`, {
-              res_id: data.resId,
-              res_type: data.resType,
-              title: values.title,
-              content: values.content,
-            })
+            put<ICommentRequest, ICommentResponse>(
+              `/v2/discussion/${data.id}`,
+              {
+                title: values.title,
+                content: values.content,
+              }
+            )
               .then((json) => {
                 console.log(json);
                 if (json.ok) {
@@ -90,58 +74,20 @@ const Widget = ({ data, onCreated }: IWidget) => {
               .catch((e) => {
                 message.error(e.message);
               });
-          } else {
-            //修改
-          }
-        }}
-        params={{}}
-        request={async () => {
-          return data;
-        }}
-      >
-        <ProFormText
-          name="title"
-          label={intl.formatMessage({ id: "forms.fields.title.label" })}
-          tooltip="最长为 24 位"
-          placeholder={intl.formatMessage({
-            id: "forms.message.title.required",
-          })}
-        />
-        <ProFormTextArea
-          name="content"
-          label={intl.formatMessage({ id: "forms.fields.content.label" })}
-          placeholder={intl.formatMessage({
-            id: "forms.fields.content.placeholder",
-          })}
-        />
-      </ProForm>
-      <Card
-        title={<span>{data.user.nickName}</span>}
-        extra={
-          <Button shape="circle" size="small">
-            xxx
-          </Button>
-        }
-        style={{ width: "auto" }}
-      >
-        <TextArea
-          rows={4}
-          showCount
-          maxLength={2048}
-          value={value}
-          onChange={(e) => setValue(e.target.value)}
-        />
-
-        <div>
-          <Button
-            type="primary"
-            icon={<SaveOutlined />}
-            loading={saving}
-            onClick={() => save()}
-          >
-            Save
-          </Button>
-        </div>
+          }}
+          params={{}}
+          request={async () => {
+            return data;
+          }}
+        >
+          <ProFormTextArea
+            name="content"
+            label={intl.formatMessage({ id: "forms.fields.content.label" })}
+            placeholder={intl.formatMessage({
+              id: "forms.fields.content.placeholder",
+            })}
+          />
+        </ProForm>
       </Card>
     </div>
   );