Skip to content

Commit

Permalink
fix(imgupload): resultField causing with error display && setField un…
Browse files Browse the repository at this point in the history
…certain (#3798)

* fix(imgupload): resultField causing with error display

* perf(imgUpload):judge about getValue

* fix(imgUpload): set string but return uncertain
  • Loading branch information
electroluxcode committed Apr 29, 2024
1 parent 29ef0d3 commit 06018ad
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/components/Upload/src/components/ImageUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
isInnerOperate.value = false;
return;
}
let value: string[] = [];
if (v) {
let value: string[] = [];
if (isArray(v)) {
value = v;
} else {
Expand All @@ -92,6 +92,8 @@
}
}) as UploadProps['fileList'];
}
emit('update:value', value);
emit('change', value);
},
{
immediate: true,
Expand Down Expand Up @@ -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);
Expand All @@ -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>

Expand Down

0 comments on commit 06018ad

Please sign in to comment.