Skip to content

Commit 25649db

Browse files
fix: 🐛 修复 Upload 组件自定义上传方法不支持asyncfunction的问题 (#890)
Closes: #859
1 parent ebbe7e4 commit 25649db

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/uni_modules/wot-design-uni/components/common/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ export function isArray(value: any): value is Array<any> {
315315
*/
316316
// eslint-disable-next-line @typescript-eslint/ban-types
317317
export function isFunction<T extends Function>(value: any): value is T {
318-
return getType(value) === 'function'
318+
return getType(value) === 'function' || getType(value) === 'asyncfunction'
319319
}
320320

321321
/**

src/uni_modules/wot-design-uni/components/wd-upload/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export type UploadMethod = (
124124
onError: (res: UniApp.GeneralCallbackResult, file: UploadFileItem, formData: UploadFormData) => void
125125
onProgress: (res: UniApp.OnProgressUpdateResult, file: UploadFileItem) => void
126126
}
127-
) => void
127+
) => void | Promise<void>
128128

129129
export const uploadProps = {
130130
...baseProps,

src/uni_modules/wot-design-uni/components/wd-upload/wd-upload.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ watch(
178178
watch(
179179
() => props.beforePreview,
180180
(fn) => {
181-
if (fn && !isFunction(fn) && getType(fn) !== 'asyncfunction') {
181+
if (fn && !isFunction(fn)) {
182182
console.error('The type of beforePreview must be Function')
183183
}
184184
},
@@ -191,7 +191,7 @@ watch(
191191
watch(
192192
() => props.onPreviewFail,
193193
(fn) => {
194-
if (fn && !isFunction(fn) && getType(fn) !== 'asyncfunction') {
194+
if (fn && !isFunction(fn)) {
195195
console.error('The type of onPreviewFail must be Function')
196196
}
197197
},
@@ -204,7 +204,7 @@ watch(
204204
watch(
205205
() => props.beforeRemove,
206206
(fn) => {
207-
if (fn && !isFunction(fn) && getType(fn) !== 'asyncfunction') {
207+
if (fn && !isFunction(fn)) {
208208
console.error('The type of beforeRemove must be Function')
209209
}
210210
},
@@ -217,7 +217,7 @@ watch(
217217
watch(
218218
() => props.beforeUpload,
219219
(fn) => {
220-
if (fn && !isFunction(fn) && getType(fn) !== 'asyncfunction') {
220+
if (fn && !isFunction(fn)) {
221221
console.error('The type of beforeUpload must be Function')
222222
}
223223
},
@@ -230,7 +230,7 @@ watch(
230230
watch(
231231
() => props.beforeChoose,
232232
(fn) => {
233-
if (fn && !isFunction(fn) && getType(fn) !== 'asyncfunction') {
233+
if (fn && !isFunction(fn)) {
234234
console.error('The type of beforeChoose must be Function')
235235
}
236236
},
@@ -243,7 +243,7 @@ watch(
243243
watch(
244244
() => props.buildFormData,
245245
(fn) => {
246-
if (fn && !isFunction(fn) && getType(fn) !== 'asyncfunction') {
246+
if (fn && !isFunction(fn)) {
247247
console.error('The type of buildFormData must be Function')
248248
}
249249
},

0 commit comments

Comments
 (0)