修复 file downloadUrl 处理不正确的问题

This commit is contained in:
liaoxuezhi 2021-04-12 15:59:32 +08:00
parent 6ff5214522
commit ce86019b71
2 changed files with 7 additions and 3 deletions

View File

@ -538,7 +538,7 @@ export default class FileControl extends React.Component<FileProps, FileState> {
const apiObject = normalizeApi(api);
if (apiObject.method?.toLowerCase() === 'get' && !apiObject.data) {
window.open(apiObject.url);
window.open(buildApi(apiObject, ctx).url);
} else {
apiObject.responseType = apiObject.responseType ?? 'blob';
env.fetcher(apiObject, ctx, {
@ -1100,6 +1100,7 @@ export default class FileControl extends React.Component<FileProps, FileState> {
} = this.props;
let {files, uploading, error} = this.state;
const nameField = this.props.nameField || 'name';
const urlField = this.props.urlField || 'url';
const hasPending = files.some(file => file.state == 'pending');
@ -1181,7 +1182,7 @@ export default class FileControl extends React.Component<FileProps, FileState> {
})}
>
<Icon icon="file" className="icon" />
{(file as FileValue).url || downloadUrl ? (
{(file as FileValue)[urlField] || downloadUrl ? (
<a
className={cx('FileControl-itemInfoText')}
target="_blank"

View File

@ -22,7 +22,10 @@ interface ApiCacheConfig extends ApiObject {
const apiCaches: Array<ApiCacheConfig> = [];
export function normalizeApi(api: Api, defaultMethod?: string): ApiObject {
export function normalizeApi(
api: Api,
defaultMethod: string = 'get'
): ApiObject {
if (typeof api === 'string') {
let method = rSchema.test(api) ? RegExp.$1 : '';
method && (api = api.replace(method + ':', ''));