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
This commit is contained in:
Electrolux 2024-04-30 06:54:55 +08:00 committed by GitHub
parent 29ef0d3915
commit 06018add79
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 10 deletions

View File

@ -70,8 +70,8 @@
isInnerOperate.value = false; isInnerOperate.value = false;
return; return;
} }
let value: string[] = [];
if (v) { if (v) {
let value: string[] = [];
if (isArray(v)) { if (isArray(v)) {
value = v; value = v;
} else { } else {
@ -92,6 +92,8 @@
} }
}) as UploadProps['fileList']; }) as UploadProps['fileList'];
} }
emit('update:value', value);
emit('change', value);
}, },
{ {
immediate: true, immediate: true,
@ -157,21 +159,22 @@
}; };
async function customRequest(info: UploadRequestOption<any>) { async function customRequest(info: UploadRequestOption<any>) {
const { api } = props; const { api, uploadParams = {}, name, filename, resultField } = props;
if (!api || !isFunction(api)) { if (!api || !isFunction(api)) {
return warn('upload api must exist and be a function'); return warn('upload api must exist and be a function');
} }
try { try {
const res = await props.api?.({ const res = await api?.({
data: { data: {
...(props.uploadParams || {}), ...uploadParams,
}, },
file: info.file, file: info.file,
name: props.name, name: name,
filename: props.filename, filename: filename,
}); });
if (props.resultField) { if (props.resultField) {
info.onSuccess!(res); let result = get(res, resultField);
info.onSuccess!(result);
} else { } else {
// resultField // resultField
info.onSuccess!(res.data); info.onSuccess!(res.data);
@ -190,12 +193,12 @@
const list = (fileList.value || []) const list = (fileList.value || [])
.filter((item) => item?.status === UploadResultStatus.DONE) .filter((item) => item?.status === UploadResultStatus.DONE)
.map((item: any) => { .map((item: any) => {
if (props.resultField) { if(item?.response && props?.resultField){
return get(item?.response, props.resultField); return item?.response
} }
return item?.url || item?.response?.url; return item?.url || item?.response?.url;
}); });
return props.multiple ? list : list.length > 0 ? list[0] : ''; return list;
} }
</script> </script>