mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 12:08:13 +08:00
fix: promise 的 finally 可能没有 (#2231)
* fix: promise 的 finally 可能没有 * 少了 await
This commit is contained in:
parent
1d57c616ba
commit
c05cb34283
@ -870,7 +870,7 @@ export default class FileControl extends React.Component<FileProps, FileState> {
|
||||
}
|
||||
}
|
||||
|
||||
uploadFile(
|
||||
async uploadFile(
|
||||
file: FileX,
|
||||
receiver: string,
|
||||
params: object,
|
||||
@ -892,9 +892,11 @@ export default class FileControl extends React.Component<FileProps, FileState> {
|
||||
// Note: File类型字段放在后面,可以支持第三方云存储鉴权
|
||||
fd.append(config.fieldName || 'file', file);
|
||||
|
||||
return this._send(file, api, fd, {}, onProgress).finally(() => {
|
||||
try {
|
||||
return await this._send(file, api, fd, {}, onProgress);
|
||||
} finally {
|
||||
this.removeFileCanelExecutor(file);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
uploadBigFile(
|
||||
@ -986,7 +988,7 @@ export default class FileControl extends React.Component<FileProps, FileState> {
|
||||
);
|
||||
}
|
||||
|
||||
function finishChunk(
|
||||
async function finishChunk(
|
||||
partList: Array<any> | undefined,
|
||||
state: ObjectState
|
||||
) {
|
||||
@ -1007,13 +1009,14 @@ export default class FileControl extends React.Component<FileProps, FileState> {
|
||||
}
|
||||
);
|
||||
|
||||
self
|
||||
._send(file, endApi)
|
||||
.finally(() => {
|
||||
self.removeFileCanelExecutor(file);
|
||||
})
|
||||
.then(resolve)
|
||||
.catch(reject);
|
||||
try {
|
||||
const ret = await self._send(file, endApi);
|
||||
resolve(ret);
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
} finally {
|
||||
self.removeFileCanelExecutor(file);
|
||||
}
|
||||
}
|
||||
|
||||
function uploadPartFile(state: ObjectState, conf: Partial<FileProps>) {
|
||||
|
@ -1015,7 +1015,7 @@ export default class ImageControl extends React.Component<
|
||||
.catch(error => cb(error.message || __('File.errorRetry'), file));
|
||||
}
|
||||
|
||||
_send(
|
||||
async _send(
|
||||
file: Blob,
|
||||
receiver: string,
|
||||
params: object,
|
||||
@ -1058,8 +1058,8 @@ export default class ImageControl extends React.Component<
|
||||
throw new Error('fetcher is required');
|
||||
}
|
||||
|
||||
return env
|
||||
.fetcher(api, fd, {
|
||||
try {
|
||||
return await env.fetcher(api, fd, {
|
||||
method: 'post',
|
||||
cancelExecutor: (cancelExecutor: () => void) => {
|
||||
// 记录取消器,取消的时候要调用
|
||||
@ -1070,10 +1070,10 @@ export default class ImageControl extends React.Component<
|
||||
},
|
||||
onUploadProgress: (event: {loaded: number; total: number}) =>
|
||||
onProgress(event.loaded / event.total)
|
||||
})
|
||||
.finally(() => {
|
||||
this.removeFileCanelExecutor(file);
|
||||
});
|
||||
} finally {
|
||||
this.removeFileCanelExecutor(file);
|
||||
}
|
||||
}
|
||||
|
||||
removeFileCanelExecutor(file: any, execute = false) {
|
||||
|
@ -135,7 +135,7 @@ export default class SelectControl extends React.Component<SelectProps, any> {
|
||||
onChange(newValue);
|
||||
}
|
||||
|
||||
loadRemote(input: string) {
|
||||
async loadRemote(input: string) {
|
||||
const {
|
||||
autoComplete,
|
||||
env,
|
||||
@ -167,18 +167,19 @@ export default class SelectControl extends React.Component<SelectProps, any> {
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
return env
|
||||
.fetcher(autoComplete, ctx)
|
||||
.then(ret => {
|
||||
let options = (ret.data && (ret.data as any).options) || ret.data || [];
|
||||
let combinedOptions = this.mergeOptions(options);
|
||||
setOptions(combinedOptions);
|
||||
try {
|
||||
const ret = await env.fetcher(autoComplete, ctx);
|
||||
|
||||
return {
|
||||
options: combinedOptions
|
||||
};
|
||||
})
|
||||
.finally(() => setLoading(false));
|
||||
let options = (ret.data && (ret.data as any).options) || ret.data || [];
|
||||
let combinedOptions = this.mergeOptions(options);
|
||||
setOptions(combinedOptions);
|
||||
|
||||
return {
|
||||
options: combinedOptions
|
||||
};
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
mergeOptions(options: Array<object>) {
|
||||
|
@ -307,7 +307,7 @@ export default class TreeSelectControl extends React.Component<
|
||||
});
|
||||
}
|
||||
|
||||
loadRemote(input: string) {
|
||||
async loadRemote(input: string) {
|
||||
const {autoComplete, env, data, setOptions, setLoading} = this.props;
|
||||
|
||||
if (!isEffectiveApi(autoComplete, data)) {
|
||||
@ -327,23 +327,25 @@ export default class TreeSelectControl extends React.Component<
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
return env
|
||||
.fetcher(autoComplete, {
|
||||
|
||||
try {
|
||||
const ret: any = await env.fetcher(autoComplete, {
|
||||
...data,
|
||||
term: input,
|
||||
value: input
|
||||
})
|
||||
.then(ret => {
|
||||
let options = (ret.data && (ret.data as any).options) || ret.data || [];
|
||||
this.cache[input] = options;
|
||||
let combinedOptions = this.mergeOptions(options);
|
||||
setOptions(combinedOptions);
|
||||
});
|
||||
|
||||
return Promise.resolve({
|
||||
options: combinedOptions
|
||||
});
|
||||
})
|
||||
.finally(() => setLoading(false));
|
||||
let options = (ret.data && (ret.data as any).options) || ret.data || [];
|
||||
this.cache[input] = options;
|
||||
let combinedOptions = this.mergeOptions(options);
|
||||
setOptions(combinedOptions);
|
||||
|
||||
return {
|
||||
options: combinedOptions
|
||||
};
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
mergeOptions(options: Array<object>) {
|
||||
|
Loading…
Reference in New Issue
Block a user