import React from 'react'; import { UploadFile } from 'antd/es/upload/interface'; import type { UploadRequestOption } from '@rc-component/upload/es/interface'; export type UploadType = 'drag' | 'button' | 'image'; export interface UploadFileResType { /** * @description 上传文件返回的URL * @default - */ url: string; /** * @description 允许扩展字段 */ [key: string]: any; } export interface ExampleModalType { /** * @description 弹窗宽度 * @default - */ width?: string | number; /** * @description 弹窗外层容器类名 * @default - */ wrapClassName?: string; /** * @description 允许扩展字段 */ [key: string]: any; } export interface FieldNamesType { /** * @description 文件唯一标识字段 * @default - */ uid?: number; /** * @description 文件名称字段 * @default - */ name?: string; /** * @description 文件URL字段 * @default - */ url?: string; /** * @description 文件状态字段 * @default - */ status?: 'done' | 'uploading' | 'error'; } export interface ProUploadType { /** * @description 顶部的内容(button类型的上传不适用) * @default - */ headerRender?: React.ReactNode | (() => React.ReactNode); /** * @description 是否过滤掉file对象中的originFileObj * @default false */ filterOriginFileObj?: boolean; /** * @description 拖拽框底部内容 * @default - */ footerRender?: React.ReactNode | (() => React.ReactNode); /** * @description 自定义上传区域的内容 * @default - */ centerRender?: React.ReactNode | (() => React.ReactNode); /** * @description 自定义上传区域的文案 * @default - */ customTextRender?: React.ReactNode; /** * @description 是否显示示例弹窗 * @default false */ showExampleContent?: boolean; /** * @description 示例弹窗的内容 * @default - */ exampleContent?: React.ReactNode; /** * @description 示例弹窗的属性配置继承与antd 的Modal对话框 * @default - */ exampleModalProps?: ExampleModalType; /** * @description 接受上传的文件类型, '.png,.jpeg,.jpg,.xlsx,.xls,.json,.doc,.docx' 详见 input accept Attribute * @default - */ accept?: string; /** * @description 控制文件的上传大小,单位MB * @default 10 */ size?: number; /** * @description 上传请求的地址 * @default - */ action?: string; /** * @description 组件的ui类型 drag 拖拽 button 上传按钮 image 类型 * @default drag */ uploadType: UploadType; /** * @description 上传格式提示文案 * @default - */ extraTipText?: string | (() => React.ReactNode); /** * @description 组件类型为button时可用, 参考 [antd button的api](https://ant-design.gitee.io/components/button-cn#api) * @default - */ buttonProps?: Object; /** * @description 组件文案 仅按钮类型的可用。 * @default - */ buttonText?: string; /** * @description 上传所需额外参数或返回上传额外参数的方法 * @default - */ dataParams?: Object; /** * @description 用来设置控件的默认已经上传的文件列表 * @default - */ defaultValue?: UploadFile[]; /** * @description 用来设置控件的已经上传的文件列表 * @default - */ value?: UploadFile[]; /** * @description 是否禁用 * @default false */ disabled?: boolean; /** * @description 设置上传的请求头部,IE10 以上有效 * @default - */ headers?: { [key: string]: any; }; /** * @description 限制上传数量。当为 1 时,始终用最新上传的文件代替当前文件 * @default 1 */ maxCount?: number; /** * @description 上传请求的 http method * @default "post" */ method?: 'post' | 'POST' | 'PUT' | 'PATCH' | 'put' | 'patch'; /** * @description 发到后台的文件参数名 * @default - */ name?: string; /** * @description 查看示例title * @default "查看示例" */ exampleTitle?: string | React.ReactNode; /** * @description 上传文件之前的钩子,参数为上传的文件,若返回 false 则停止上传。支持返回一个 Promise 对象,Promise 对象 reject 时则停止上传,resolve 时开始上传( resolve 传入 File 或 Blob 对象则上传 resolve 传入对象);也可以返回 Upload.LIST_IGNORE,此时列表中将不展示此文件。 注意:IE9 不支持该方法 * @default - */ beforeUpload?: (file: any, fileList: any) => boolean | Promise; /** * @description 上传文件改变时的回调,详见 onChange * @default - */ onChange?: (value: Array) => void; /** * @description 点击下载文件时的回调,如果没有指定,则默认跳转到文件 url 对应的标签页 * @default - */ onDownload?: (file: UploadFile) => void; /** * @description 点击文件链接或预览图标时的回调 * @default - */ onPreview?: (file: UploadFile) => any; /** * @description 点击移除文件时的回调,返回值为 false 时不移除。支持返回一个 Promise 对象,Promise 对象 resolve(false) 或 reject 时不移除 * @default - */ onRemove?: (file: UploadFile) => boolean | Promise; /** * @description 样式类名 * @default - */ className?: string; /** * @description 上传接口处理方法 返回一个数组 UploadFile【】 * @default - */ transformResponse?: (res: any) => UploadFileResType; /** * @description 可以调用组件的内部方法,例如:uploadStart方式 * @default - */ ref?: any; /** * @description 按钮类型的右侧辅助信息 * @default - */ afterRender?: React.ReactNode; /** * @description 是否展示文件列表 * @default true */ showUploadList?: boolean; /** * @description 文件对象的字段映射 * @default true */ fieldNames?: FieldNamesType; /** * @description 删除已经上传的文件时是否二次提示 * @default false */ isConfirmDelete?: boolean; /** * @description 组件ID * @default - */ id?: string; /** * @description 查看模式 * @default false */ isView?: boolean; /** * @description 自定义上传实现 * @default false */ customRequest?: (option: UploadRequestOption) => void; } export interface DraggableUploadListItemType { /** * @description 文件对象 * @default - */ file: UploadFile; /** * @description 子元素 * @default - */ children: React.ReactNode; }