Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(imgupload): resultField causing with error display && setField uncertain #3798

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading