|
@@ -102,6 +102,36 @@ export function useMethods() {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ async function exportXlsPost1(name, url, params, isXlsx = false) {
|
|
|
+ const data = await defHttp.get({ url: url, params: params, responseType: 'blob', timeout: 1000 * 1000 }, { isTransformResponse: false });
|
|
|
+ if (!data) {
|
|
|
+ createMessage.warning('文件下载失败');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!name || typeof name != 'string') {
|
|
|
+ name = '导出文件';
|
|
|
+ }
|
|
|
+ const blobOptions = { type: 'application/vnd.ms-excel' };
|
|
|
+ let fileSuffix = '.xls';
|
|
|
+ if (isXlsx === true) {
|
|
|
+ blobOptions['type'] = XLSX_MIME_TYPE;
|
|
|
+ fileSuffix = XLSX_FILE_SUFFIX;
|
|
|
+ }
|
|
|
+ if (typeof window.navigator.msSaveBlob !== 'undefined') {
|
|
|
+ window.navigator.msSaveBlob(new Blob([data], blobOptions), name + fileSuffix);
|
|
|
+ } else {
|
|
|
+ const url = window.URL.createObjectURL(new Blob([data], blobOptions));
|
|
|
+ const link = document.createElement('a');
|
|
|
+ link.style.display = 'none';
|
|
|
+ link.href = url;
|
|
|
+ link.setAttribute('download', name + fileSuffix);
|
|
|
+ document.body.appendChild(link);
|
|
|
+ link.click();
|
|
|
+ document.body.removeChild(link); //下载完成移除元素
|
|
|
+ window.URL.revokeObjectURL(url); //释放掉blob对象
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 导入xls
|
|
|
* @param data 导入的数据
|
|
@@ -144,6 +174,7 @@ export function useMethods() {
|
|
|
return {
|
|
|
handleExportXls: (name: string, url: string, params?: object) => exportXls(name, url, params),
|
|
|
handleExportXlsPost: (name: string, url: string, params?: object) => exportXlsPost(name, url, params),
|
|
|
+ exportXlsPost0: (name: string, url: string, params?: object) => exportXlsPost1(name, url, params),
|
|
|
handleImportXls: (data, url, success) => importXls(data, url, success),
|
|
|
handleExportXlsx: (name: string, url: string, params?: object) => exportXls(name, url, params, true),
|
|
|
};
|