Browse Source
fix(imgupload): resultField causing with error display && setField uncertain (#3798)
* fix(imgupload): resultField causing with error display
* perf(imgUpload):judge about getValue
* fix(imgUpload): set string but return uncertain
pull/3806/head
Electrolux
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with
13 additions and
10 deletions
-
src/components/Upload/src/components/ImageUpload.vue
|
|
|
@ -70,8 +70,8 @@ |
|
|
|
isInnerOperate.value = false; |
|
|
|
return; |
|
|
|
} |
|
|
|
let value: string[] = []; |
|
|
|
if (v) { |
|
|
|
let value: string[] = []; |
|
|
|
if (isArray(v)) { |
|
|
|
value = v; |
|
|
|
} else { |
|
|
|
@ -92,6 +92,8 @@ |
|
|
|
} |
|
|
|
}) as UploadProps['fileList']; |
|
|
|
} |
|
|
|
emit('update:value', value); |
|
|
|
emit('change', value); |
|
|
|
}, |
|
|
|
{ |
|
|
|
immediate: true, |
|
|
|
@ -157,21 +159,22 @@ |
|
|
|
}; |
|
|
|
|
|
|
|
async function customRequest(info: UploadRequestOption<any>) { |
|
|
|
const { api } = props; |
|
|
|
const { api, uploadParams = {}, name, filename, resultField } = props; |
|
|
|
if (!api || !isFunction(api)) { |
|
|
|
return warn('upload api must exist and be a function'); |
|
|
|
} |
|
|
|
try { |
|
|
|
const res = await props.api?.({ |
|
|
|
const res = await api?.({ |
|
|
|
data: { |
|
|
|
...(props.uploadParams || {}), |
|
|
|
...uploadParams, |
|
|
|
}, |
|
|
|
file: info.file, |
|
|
|
name: props.name, |
|
|
|
filename: props.filename, |
|
|
|
name: name, |
|
|
|
filename: filename, |
|
|
|
}); |
|
|
|
if (props.resultField) { |
|
|
|
info.onSuccess!(res); |
|
|
|
let result = get(res, resultField); |
|
|
|
info.onSuccess!(result); |
|
|
|
} else { |
|
|
|
// 不传入 resultField 的情况 |
|
|
|
info.onSuccess!(res.data); |
|
|
|
@ -190,12 +193,12 @@ |
|
|
|
const list = (fileList.value || []) |
|
|
|
.filter((item) => item?.status === UploadResultStatus.DONE) |
|
|
|
.map((item: any) => { |
|
|
|
if (props.resultField) { |
|
|
|
return get(item?.response, props.resultField); |
|
|
|
if(item?.response && props?.resultField){ |
|
|
|
return item?.response |
|
|
|
} |
|
|
|
return item?.url || item?.response?.url; |
|
|
|
}); |
|
|
|
return props.multiple ? list : list.length > 0 ? list[0] : ''; |
|
|
|
return list; |
|
|
|
} |
|
|
|
</script> |
|
|
|
|
|
|
|
|