import { RenderFunction, SetupContext, Ref, ComputedRef } from 'vue' import { DefineVxeComponentApp, DefineVxeComponentOptions, DefineVxeComponentInstance, VxeComponentBaseOptions, VxeComponentEventParams, ValueOf, VxeComponentSizeType } from '@vxe-ui/core' import { VxeImagePropTypes } from './image' import { VxeImagePreviewProps } from './image-preview' /* eslint-disable no-use-before-define,@typescript-eslint/ban-types */ export declare const VxeUpload: DefineVxeComponentApp export type VxeUploadComponent = DefineVxeComponentOptions export type VxeUploadInstance = DefineVxeComponentInstance export interface VxeUploadConstructor extends VxeComponentBaseOptions, VxeUploadMethods { props: VxeUploadProps context: SetupContext reactData: UploadReactData getRefMaps(): UploadPrivateRef getComputeMaps(): UploadPrivateComputed renderVN: RenderFunction } export interface UploadPrivateRef { refElem: Ref } export interface VxeUploadPrivateRef extends UploadPrivateRef {} export namespace VxeUploadPropTypes { export type ModelValue = VxeUploadDefines.FileObjItem | VxeUploadDefines.FileObjItem[] | string | string[] export type Size = VxeComponentSizeType export type ShowList = boolean export interface MoreConfig { maxCount?: number showMoreButton?: boolean layout?: '' | 'vertical' | 'horizontal' moreButtonText?: string | ((params: { $upload: VxeUploadConstructor; options: VxeUploadDefines.FileObjItem[] }) => string | number) } export type Mode = null | '' | 'all' | 'image' export type Readonly = boolean export type Disabled = boolean export type AutoSubmit = boolean export type ImageTypes = string[] export interface ImageConfig { width?: VxeImagePropTypes.Width height?: VxeImagePropTypes.Height circle?: VxeImagePropTypes.Circle } /** * 已废弃,被 imageConfig 替换 * @deprecated */ export interface ImageStyle { width?: VxeImagePropTypes.Width height?: VxeImagePropTypes.Height } export type FileTypes = string[] export type SingleMode = boolean export type DragSort = boolean export type DragToUpload = boolean export type DragPlaceholder = string export type PasteToUpload = boolean export type KeyField = string export type UrlMode = boolean export type UrlArgs = boolean export type Multiple = boolean export type LimitSize = number | string export type ShowLimitSize = boolean export type LimitSizeText = number | string | ((params: { maxSize: number }) => number | string) export type LimitCount = number | string export type ShowLimitCount = boolean export type LimitCountText = number | string | ((params: { maxCount: number }) => number | string) export type NameField = string export type TypeField = string export type UrlField = string export type SizeField = string export type ShowTip = boolean export type MaxSimultaneousUploads = number | string export type TipText = number | string | ((params: {}) => number | string) export type ButtonText = number | string | ((params: {}) => number | string) export type ButtonIcon = string export type ShowButtonText = boolean export type ShowButtonIcon = boolean export type ShowRemoveButton = boolean export type ShowDownloadButton = boolean export type ShowPreview = boolean export type ShowErrorStatus = boolean export type ShowProgress = boolean export type ProgressText = number | string | ((params: {}) => number | string) export type ShowSubmitButton = boolean export type AutoHiddenButton = boolean export type ShowUploadButton = boolean export interface PreviewImageConfig extends Omit {} export type PreviewMethod = undefined | ((params: { $upload: VxeUploadConstructor; option: VxeUploadDefines.FileObjItem }) => Promise) export type BeforeSelectMethod = undefined | ((params: { $upload: VxeUploadConstructor; file: File }) => boolean) export type UploadMethod = undefined | ((params: { $upload: VxeUploadConstructor; file: File; option: VxeUploadDefines.FileObjItem; updateProgress: (percentNum: number) => void }) => Promise) export type BeforeRemoveMethod = undefined | ((params: { $upload: VxeUploadConstructor; option: VxeUploadDefines.FileObjItem }) => boolean | Promise) export type RemoveMethod = undefined | ((params: { $upload: VxeUploadConstructor; option: VxeUploadDefines.FileObjItem }) => Promise) export type BeforeDownloadMethod = undefined | ((params: { $upload: VxeUploadConstructor; option: VxeUploadDefines.FileObjItem }) => boolean | Promise) export type DownloadMethod = undefined | ((params: { $upload: VxeUploadConstructor; option: VxeUploadDefines.FileObjItem }) => Promise) export type GetUrlMethod = undefined | ((params: { $upload: VxeUploadConstructor; option: VxeUploadDefines.FileObjItem }) => string) export type GetThumbnailUrlMethod = undefined | ((params: { $upload: VxeUploadConstructor; option: VxeUploadDefines.FileObjItem }) => string) /** * 已废弃,请使用 TipText * @deprecated */ export type HintText = string } export interface VxeUploadProps { modelValue?: VxeUploadPropTypes.ModelValue size?: VxeUploadPropTypes.Size showList?: VxeUploadPropTypes.ShowList moreConfig?: VxeUploadPropTypes.MoreConfig mode?: VxeUploadPropTypes.Mode readonly?: VxeUploadPropTypes.Readonly disabled?: VxeUploadPropTypes.Disabled autoSubmit?: VxeUploadPropTypes.AutoSubmit imageTypes?: VxeUploadPropTypes.ImageTypes imageConfig?: VxeUploadPropTypes.ImageConfig /** * 已废弃,被 imageConfig 替换 * @deprecated */ imageStyle?: VxeUploadPropTypes.ImageStyle fileTypes?: VxeUploadPropTypes.FileTypes multiple?: VxeUploadPropTypes.Multiple singleMode?: VxeUploadPropTypes.SingleMode dragSort?: VxeUploadPropTypes.DragSort dragToUpload?: VxeUploadPropTypes.DragToUpload dragPlaceholder?: VxeUploadPropTypes.DragPlaceholder pasteToUpload?: VxeUploadPropTypes.PasteToUpload keyField?: VxeUploadPropTypes.KeyField urlMode?: VxeUploadPropTypes.UrlMode urlArgs?: VxeUploadPropTypes.UrlArgs /** * 限制文件大小,单位M */ limitSize?: VxeUploadPropTypes.LimitSize showLimitSize?: VxeUploadPropTypes.ShowLimitSize limitSizeText?: VxeUploadPropTypes.LimitSizeText limitCount?: VxeUploadPropTypes.LimitCount showLimitCount?: VxeUploadPropTypes.ShowLimitCount limitCountText?: VxeUploadPropTypes.LimitCountText nameField?: VxeUploadPropTypes.NameField typeField?: VxeUploadPropTypes.TypeField urlField?: VxeUploadPropTypes.UrlField sizeField?: VxeUploadPropTypes.SizeField buttonText?: VxeUploadPropTypes.ButtonText buttonIcon?: VxeUploadPropTypes.ButtonIcon showButtonText?: VxeUploadPropTypes.ShowButtonText showUploadButton?: VxeUploadPropTypes.ShowUploadButton showButtonIcon?: VxeUploadPropTypes.ShowButtonIcon showRemoveButton?: VxeUploadPropTypes.ShowRemoveButton showDownloadButton?: VxeUploadPropTypes.ShowDownloadButton showPreview?: VxeUploadPropTypes.ShowPreview previewImageConfig?: VxeUploadPropTypes.PreviewImageConfig showErrorStatus?: VxeUploadPropTypes.ShowErrorStatus showProgress?: VxeUploadPropTypes.ShowProgress progressText?: VxeUploadPropTypes.ProgressText showSubmitButton?: VxeUploadPropTypes.ShowSubmitButton autoHiddenButton?: VxeUploadPropTypes.AutoHiddenButton showTip?: VxeUploadPropTypes.ShowTip tipText?: VxeUploadPropTypes.TipText /** * 用于 autoSubmit=false,最大同时上传数量 */ maxSimultaneousUploads?: VxeUploadPropTypes.MaxSimultaneousUploads previewMethod?: VxeUploadPropTypes.PreviewMethod beforeSelectMethod?: VxeUploadPropTypes.BeforeSelectMethod uploadMethod?: VxeUploadPropTypes.UploadMethod beforeRemoveMethod?: VxeUploadPropTypes.BeforeRemoveMethod removeMethod?: VxeUploadPropTypes.RemoveMethod beforeDownloadMethod?: VxeUploadPropTypes.BeforeDownloadMethod downloadMethod?: VxeUploadPropTypes.DownloadMethod getUrlMethod?: VxeUploadPropTypes.GetUrlMethod getThumbnailUrlMethod?: VxeUploadPropTypes.GetThumbnailUrlMethod /** * 已废弃,请使用 tipText * @deprecated */ hintText?: VxeUploadPropTypes.HintText } export interface UploadPrivateComputed { computeUrlProp: ComputedRef } export interface VxeUploadPrivateComputed extends UploadPrivateComputed {} export interface UploadReactData { isDragUploadStatus: boolean showMorePopup: boolean isActivated: boolean fileList: VxeUploadDefines.FileObjItem[] fileCacheMaps: Record isDragMove: boolean dragIndex: number dragTipText: string } export interface UploadInternalData { moreId: string imagePreviewTypes: string[] prevDragIndex: number prevDragPos?: 'top' | 'bottom' | 'left' | 'right' | '' } export interface UploadMethods { dispatchEvent(type: ValueOf, params: Record, evnt: Event | null): void /** * 手动调用选择文件 */ choose(): Promise<{ status: boolean files: File[] file: File | null }> /** * 获取未上传的文件对象 */ getPendingFiles(): File[] /** * 用于 auto-upload 模式,手动调用上传附件;如果传 true,这包含未上传和上传失败的都会重新提交 */ submit(isFull?: boolean): Promise /** * 清除所有文件 */ clear(): Promise< { url: string status: boolean }[] > /** * 区别就是会触发对应的事件 */ clearByEvent(event: Event): Promise< { url: string status: boolean }[] > /** * 获取更多弹窗的可视状态 */ getMoreVisible(): boolean /** * 打开更多弹窗 */ openMore(): Promise /** * 区别就是会触发对应的事件 */ openMoreByEvent(event: Event): Promise /** * 关闭更多弹窗 */ closeMore(): Promise /** * 删除指定文件 */ remove(urlOrItem: string | VxeUploadDefines.FileObjItem | string[] | VxeUploadDefines.FileObjItem[] | null): Promise< { url: string status: boolean }[] > /** * 区别就是会触发对应的事件 */ removeByEvent( event: Event, urlOrItem: string | VxeUploadDefines.FileObjItem | string[] | VxeUploadDefines.FileObjItem[] | null ): Promise< { url: string status: boolean }[] > } export interface VxeUploadMethods extends UploadMethods {} export interface UploadPrivateMethods { /** * 内部方法 * @private */ removeFileEvent(evnt: Event | null, item: VxeUploadDefines.FileObjItem, index: number): Promise } export interface VxeUploadPrivateMethods extends UploadPrivateMethods {} export type VxeUploadEmits = ['update:modelValue', 'change', 'add', 'remove', 'remove-fail', 'download', 'download-fail', 'upload-start', 'upload-success', 'upload-error', 'upload-end', 'upload-queue-start', 'upload-queue-end', 'sort-dragend', 'more-visible'] export namespace VxeUploadDefines { export interface UploadEventParams extends VxeComponentEventParams { $upload: VxeUploadConstructor } export type SaveFileFunction = ( options: | { filename: string type: string content: string | Blob } | { filename: string type?: string content: Blob } ) => Promise export type ReadFileFunction = (options?: { multiple?: boolean; types?: string[]; message?: boolean }) => Promise<{ status: boolean files: File[] file: File }> export interface UploadResultObj { option: VxeUploadDefines.FileObjItem status: 'error' | 'success' | 'pending' | null response: any } export interface FileCacheItem { file: File loading: boolean status: 'error' | 'success' | 'pending' percent: number response: any } export interface FileObjItem { [key: string]: any } export interface ChangeEventParams { value: VxeUploadPropTypes.ModelValue } export interface AddParams { options: VxeUploadDefines.FileObjItem[] option: VxeUploadDefines.FileObjItem } export interface AddEventParams extends UploadEventParams, AddParams {} export interface RemoveEventParams extends UploadEventParams { options: VxeUploadDefines.FileObjItem[] option: VxeUploadDefines.FileObjItem } export interface RemoveFailEventParams extends RemoveEventParams {} export interface DownloadEventParams extends UploadEventParams { options: VxeUploadDefines.FileObjItem[] option: VxeUploadDefines.FileObjItem } export interface DownloadFailEventParams extends DownloadEventParams {} export interface UploadSuccessEventParams extends UploadEventParams { options: VxeUploadDefines.FileObjItem[] option: VxeUploadDefines.FileObjItem data: any } export interface UploadErrorEventParams extends UploadSuccessEventParams {} export interface UploadStartEventParams extends UploadSuccessEventParams { option: VxeUploadDefines.FileObjItem } export interface UploadEndEventParams extends UploadStartEventParams { results: VxeUploadDefines.UploadResultObj } export interface UploadQueueStartEventParams extends UploadSuccessEventParams { files: File[] } export interface UploadQueueEndEventParams extends UploadQueueStartEventParams { value: VxeUploadPropTypes.ModelValue options: VxeUploadDefines.FileObjItem[] results: VxeUploadDefines.UploadResultObj[] } export interface MoreVisibleEventParams { visible: boolean } } export type VxeUploadEventProps = { 'onUpdate:modelValue'?: VxeUploadEvents.UpdateModelValue onChange?: VxeUploadEvents.Change onAdd?: VxeUploadEvents.Add onRemove?: VxeUploadEvents.Remove onRemoveFail?: VxeUploadEvents.RemoveFail onDownload?: VxeUploadEvents.Download onDownloadFail?: VxeUploadEvents.DownloadFail onUploadSuccess?: VxeUploadEvents.UploadSuccess onUploadError?: VxeUploadEvents.UploadError onUploadStart?: VxeUploadEvents.UploadStart onUploadEnd?: VxeUploadEvents.UploadEnd onUploadQueueStart?: VxeUploadEvents.UploadQueueStart onUploadQueueEnd?: VxeUploadEvents.UploadQueueEnd onMoreVisible?: VxeUploadEvents.MoreVisible } export interface VxeUploadListeners { 'update:modelValue'?: VxeUploadEvents.UpdateModelValue change?: VxeUploadEvents.Change add?: VxeUploadEvents.Add remove?: VxeUploadEvents.Remove removeFail?: VxeUploadEvents.RemoveFail download?: VxeUploadEvents.Download downloadFail?: VxeUploadEvents.DownloadFail uploadSuccess?: VxeUploadEvents.UploadSuccess uploadError?: VxeUploadEvents.UploadError uploadStart?: VxeUploadEvents.UploadStart uploadEnd?: VxeUploadEvents.UploadEnd uploadQueueStart?: VxeUploadEvents.UploadQueueStart uploadQueueEnd?: VxeUploadEvents.UploadQueueEnd moreVisible?: VxeUploadEvents.MoreVisible } export namespace VxeUploadEvents { export type UpdateModelValue = (modelValue: VxeUploadPropTypes.ModelValue) => void export type Change = (params: VxeUploadDefines.ChangeEventParams) => void export type Add = (params: VxeUploadDefines.AddEventParams) => void export type Remove = (params: VxeUploadDefines.RemoveEventParams) => void export type RemoveFail = (params: VxeUploadDefines.RemoveFailEventParams) => void export type Download = (params: VxeUploadDefines.DownloadEventParams) => void export type DownloadFail = (params: VxeUploadDefines.DownloadFailEventParams) => void export type UploadSuccess = (params: VxeUploadDefines.UploadSuccessEventParams) => void export type UploadError = (params: VxeUploadDefines.UploadErrorEventParams) => void export type UploadStart = (params: VxeUploadDefines.UploadStartEventParams) => void export type UploadEnd = (params: VxeUploadDefines.UploadEndEventParams) => void export type UploadQueueStart = (params: VxeUploadDefines.UploadQueueStartEventParams) => void export type UploadQueueEnd = (params: VxeUploadDefines.UploadQueueEndEventParams) => void export type MoreVisible = (params: VxeUploadDefines.MoreVisibleEventParams) => void } export namespace VxeUploadSlotTypes { export interface DefaultSlotParams { options: VxeUploadDefines.FileObjItem[] isMoreView: boolean } export interface TipSlotParams extends DefaultSlotParams {} export interface OptionSlotParams { options: VxeUploadDefines.FileObjItem[] option: VxeUploadDefines.FileObjItem isMoreView: boolean } export interface ActionSlotParams extends OptionSlotParams {} export interface NameSlotParams extends OptionSlotParams {} export interface MoreButtonSlotParams { options: VxeUploadDefines.FileObjItem[] } export interface MoreContentSlotParams { options: VxeUploadDefines.FileObjItem[] } } export interface VxeUploadSlots { default?: (params: VxeUploadSlotTypes.DefaultSlotParams) => any tip?: (params: VxeUploadSlotTypes.TipSlotParams) => any action?: (params: VxeUploadSlotTypes.ActionSlotParams) => any corner?: (params: VxeUploadSlotTypes.ActionSlotParams) => any name?: (params: VxeUploadSlotTypes.NameSlotParams) => any option?: (params: VxeUploadSlotTypes.OptionSlotParams) => any moreButton?: (params: VxeUploadSlotTypes.MoreButtonSlotParams) => any 'more-button'?: (params: VxeUploadSlotTypes.MoreButtonSlotParams) => any moreContent?: (params: VxeUploadSlotTypes.MoreContentSlotParams) => any 'more-content'?: (params: VxeUploadSlotTypes.MoreContentSlotParams) => any } export const Upload: typeof VxeUpload export default VxeUpload