优化useUploadFile
parent
27771e965e
commit
b55fa7d9da
|
|
@ -38,16 +38,24 @@ function useUploadFile(returnType = "object") {
|
||||||
throw new Error(`未找到 type ${params.type} 对应的 path `);
|
throw new Error(`未找到 type ${params.type} 对应的 path `);
|
||||||
|
|
||||||
// 当single为false时,foreignKey是必需的
|
// 当single为false时,foreignKey是必需的
|
||||||
if (!single && (params.foreignKey === undefined || params.foreignKey === null))
|
if (!single) {
|
||||||
throw new Error("请传入 options.params.foreignKey");
|
if (!params.hasOwnProperty('foreignKey'))
|
||||||
|
throw new Error("请传入 options.params.foreignKey");
|
||||||
|
// 如果 foreignKey 是 undefined,设置默认值为空字符串
|
||||||
|
if (params.foreignKey === undefined || params.foreignKey === null)
|
||||||
|
params.foreignKey = "";
|
||||||
|
}
|
||||||
|
|
||||||
// 如果没有文件则直接返回
|
// 如果没有文件则直接返回
|
||||||
if (files.length === 0)
|
if (files.length === 0) {
|
||||||
|
setLoading(false);
|
||||||
resolve(
|
resolve(
|
||||||
single
|
single
|
||||||
? { filePath: '' }
|
? { filePath: '' }
|
||||||
: { id: '' },
|
: { id: params.foreignKey },
|
||||||
);
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue