Browse Source

Merge pull request #1043 from visuddhinanda/agile

:sparkles: upload in wbw
visuddhinanda 3 years ago
parent
commit
545a9eef77

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

@@ -1,4 +1,5 @@
-import { Input } from "antd";
+import { Input, Divider } from "antd";
+import WbwDetailUpload from "./WbwDetailUpload";
 
 import { IWbw } from "./WbwWord";
 
@@ -39,6 +40,11 @@ const Widget = ({ data, onChange }: IWidget) => {
         defaultValue={data.real?.value}
         onChange={onRealChange}
       />
+      <Divider>附件</Divider>
+      <div></div>
+      <div>
+        <WbwDetailUpload />
+      </div>
     </>
   );
 };

+ 36 - 0
dashboard/src/components/template/Wbw/WbwDetailUpload.tsx

@@ -0,0 +1,36 @@
+import { useIntl } from "react-intl";
+import { UploadOutlined } from "@ant-design/icons";
+import type { UploadProps } from "antd";
+import { Button, message, Upload } from "antd";
+import { API_HOST } from "../../../request";
+
+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 = () => {
+  const intl = useIntl();
+  return (
+    <Upload {...props}>
+      <Button icon={<UploadOutlined />}>
+        {intl.formatMessage({ id: "buttons.click.upload" })}
+      </Button>
+    </Upload>
+  );
+};
+
+export default Widget;

+ 1 - 0
dashboard/src/locales/zh-Hans/buttons.ts

@@ -18,6 +18,7 @@ const items = {
   "buttons.sign-in": "登录",
   "buttons.sign-out": "退出登录",
   "buttons.welcome": "欢迎遨游法的海洋",
+  "buttons.click.upload": "点击上传",
 };
 
 export default items;