fix: 🐛 修复 Upload 组件自定义上传方法不支持asyncfunction的问题 (#890)

 Closes: #859
This commit is contained in:
不如摸鱼去 2025-02-12 14:04:59 +08:00 committed by GitHub
parent ebbe7e4079
commit 25649dbca5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 8 deletions

View File

@ -315,7 +315,7 @@ export function isArray(value: any): value is Array<any> {
*/ */
// eslint-disable-next-line @typescript-eslint/ban-types // eslint-disable-next-line @typescript-eslint/ban-types
export function isFunction<T extends Function>(value: any): value is T { export function isFunction<T extends Function>(value: any): value is T {
return getType(value) === 'function' return getType(value) === 'function' || getType(value) === 'asyncfunction'
} }
/** /**

View File

@ -124,7 +124,7 @@ export type UploadMethod = (
onError: (res: UniApp.GeneralCallbackResult, file: UploadFileItem, formData: UploadFormData) => void onError: (res: UniApp.GeneralCallbackResult, file: UploadFileItem, formData: UploadFormData) => void
onProgress: (res: UniApp.OnProgressUpdateResult, file: UploadFileItem) => void onProgress: (res: UniApp.OnProgressUpdateResult, file: UploadFileItem) => void
} }
) => void ) => void | Promise<void>
export const uploadProps = { export const uploadProps = {
...baseProps, ...baseProps,

View File

@ -178,7 +178,7 @@ watch(
watch( watch(
() => props.beforePreview, () => props.beforePreview,
(fn) => { (fn) => {
if (fn && !isFunction(fn) && getType(fn) !== 'asyncfunction') { if (fn && !isFunction(fn)) {
console.error('The type of beforePreview must be Function') console.error('The type of beforePreview must be Function')
} }
}, },
@ -191,7 +191,7 @@ watch(
watch( watch(
() => props.onPreviewFail, () => props.onPreviewFail,
(fn) => { (fn) => {
if (fn && !isFunction(fn) && getType(fn) !== 'asyncfunction') { if (fn && !isFunction(fn)) {
console.error('The type of onPreviewFail must be Function') console.error('The type of onPreviewFail must be Function')
} }
}, },
@ -204,7 +204,7 @@ watch(
watch( watch(
() => props.beforeRemove, () => props.beforeRemove,
(fn) => { (fn) => {
if (fn && !isFunction(fn) && getType(fn) !== 'asyncfunction') { if (fn && !isFunction(fn)) {
console.error('The type of beforeRemove must be Function') console.error('The type of beforeRemove must be Function')
} }
}, },
@ -217,7 +217,7 @@ watch(
watch( watch(
() => props.beforeUpload, () => props.beforeUpload,
(fn) => { (fn) => {
if (fn && !isFunction(fn) && getType(fn) !== 'asyncfunction') { if (fn && !isFunction(fn)) {
console.error('The type of beforeUpload must be Function') console.error('The type of beforeUpload must be Function')
} }
}, },
@ -230,7 +230,7 @@ watch(
watch( watch(
() => props.beforeChoose, () => props.beforeChoose,
(fn) => { (fn) => {
if (fn && !isFunction(fn) && getType(fn) !== 'asyncfunction') { if (fn && !isFunction(fn)) {
console.error('The type of beforeChoose must be Function') console.error('The type of beforeChoose must be Function')
} }
}, },
@ -243,7 +243,7 @@ watch(
watch( watch(
() => props.buildFormData, () => props.buildFormData,
(fn) => { (fn) => {
if (fn && !isFunction(fn) && getType(fn) !== 'asyncfunction') { if (fn && !isFunction(fn)) {
console.error('The type of buildFormData must be Function') console.error('The type of buildFormData must be Function')
} }
}, },