index.tsx 914 Bytes
Newer Older
dechen lin's avatar
dechen lin committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// cl 2022/4/21 18:22
import { customUploadToOss } from "@/api/oss";
import { Upload as AntdUpload } from "antd";
import { DraggerProps, UploadProps } from "antd/es/upload";
import React from "react";

interface IProps extends UploadProps, DraggerProps {
  isDragger?: boolean;
  openRead?: boolean;
  taskType?: string;
  changeOption?: (option: any) => any;
}

const Upload: React.FC<IProps> = (props) => {
  const { isDragger, openRead, taskType, changeOption, ...rest } = props;
  const Component = isDragger ? AntdUpload.Dragger : AntdUpload;

  return (
    <Component
      {...rest}
      customRequest={(options: any) =>
        customUploadToOss(changeOption ? changeOption?.(options) : options, {
          openRead: openRead || false,
          fileType: taskType || "pdf",
          uploadType: "local",
        })
      }
    >
      {props.children}
    </Component>
  );
};

export default Upload;