|
@@ -1,6 +1,7 @@
|
|
|
import { kebabCase } from 'lodash-es';
|
|
|
|
|
|
import { t } from '@/i18n';
|
|
|
+import { fileContentTypeRegExp } from '@/constants';
|
|
|
|
|
|
import { fetchWithTimeout } from './fetch';
|
|
|
|
|
@@ -57,6 +58,12 @@ export const request = async <T>(url: string, init: RequestInit = {}, timeout?:
|
|
|
// saveToken(token);
|
|
|
// }
|
|
|
// }
|
|
|
+ const contentType = res.headers.get('content-type');
|
|
|
+ const isBlob = fileContentTypeRegExp.test(contentType || '');
|
|
|
+
|
|
|
+ if (isBlob) {
|
|
|
+ return (await res.blob()) as T;
|
|
|
+ }
|
|
|
|
|
|
const json: ApiResponse<T> = await res.json();
|
|
|
const { data, code, msg } = json;
|
|
@@ -92,3 +99,17 @@ export const generateThemeCSSVar = (token: GlobalToken, prefix: string): string
|
|
|
export const addUnit = (val: number, unit: string = 'px'): string => {
|
|
|
return val + unit;
|
|
|
};
|
|
|
+
|
|
|
+export const downloadBlob = (blob: Blob, name: string) => {
|
|
|
+ const url = window.URL.createObjectURL(blob);
|
|
|
+ const a = document.createElement('a');
|
|
|
+
|
|
|
+ a.href = url;
|
|
|
+ a.download = name;
|
|
|
+
|
|
|
+ document.body.appendChild(a);
|
|
|
+ a.click();
|
|
|
+
|
|
|
+ document.body.removeChild(a);
|
|
|
+ window.URL.revokeObjectURL(url);
|
|
|
+};
|