Browse Source

:sparkles: 单词上传附件

visuddhinanda 3 năm trước cách đây
mục cha
commit
f4d9c6a8f6

+ 1 - 1
dashboard/src/components/template/Wbw/WbwDetailAdvance.tsx

@@ -43,7 +43,7 @@ const Widget = ({ data, onChange }: IWidget) => {
       <Divider>附件</Divider>
       <div></div>
       <div>
-        <WbwDetailUpload />
+        <WbwDetailUpload data={data} />
       </div>
     </>
   );

+ 26 - 19
dashboard/src/components/template/Wbw/WbwDetailUpload.tsx

@@ -3,27 +3,34 @@ import { UploadOutlined } from "@ant-design/icons";
 import type { UploadProps } from "antd";
 import { Button, message, Upload } from "antd";
 import { API_HOST } from "../../../request";
+import { IWbw } from "./WbwWord";
 
-const props: UploadProps = {
-  name: "file",
-  action: `${API_HOST}/api/v2/upload`,
-  headers: {
-    authorization: "authorization-text",
-  },
-  onChange(info) {
-    if (info.file.status !== "uploading") {
-      console.log(info.file, info.fileList);
-    }
-    if (info.file.status === "done") {
-      message.success(`${info.file.name} file uploaded successfully`);
-    } else if (info.file.status === "error") {
-      message.error(`${info.file.name} file upload failed.`);
-    }
-  },
-};
-
-const Widget = () => {
+interface IWidget {
+  data: IWbw;
+  onChange?: Function;
+}
+const Widget = ({ data, onChange }: IWidget) => {
   const intl = useIntl();
+
+  const props: UploadProps = {
+    name: "file",
+    action: `${API_HOST}/api/v2/upload`,
+    headers: {
+      authorization: "authorization-text",
+    },
+    defaultFileList: data.attachments,
+    onChange(info) {
+      if (info.file.status !== "uploading") {
+        console.log(info.file, info.fileList);
+      }
+      if (info.file.status === "done") {
+        message.success(`${info.file.name} file uploaded successfully`);
+      } else if (info.file.status === "error") {
+        message.error(`${info.file.name} file upload failed.`);
+      }
+    },
+  };
+
   return (
     <Upload {...props}>
       <Button icon={<UploadOutlined />}>