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:
parent
29ef0d3915
commit
06018add79
|
|
@ -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>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue