|
@@ -57,69 +57,40 @@ export function useMethods() {
|
|
|
* @param url
|
|
|
*/
|
|
|
async function exportXlsPost(name, url, params, isXlsx = false) {
|
|
|
-
|
|
|
- const data = await defHttp.post({ 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对象
|
|
|
- }
|
|
|
-
|
|
|
- // const key = 'updatable';
|
|
|
- // message.loading({ content: '正在导出,请稍等...', key });
|
|
|
- // defHttp
|
|
|
- // .post({ url: url, params: params, timeout: 1000 * 1000 }, { isTransformResponse: false })
|
|
|
- // .then((data) => {
|
|
|
- // debugger;
|
|
|
- // if (data.code == 200 && data.result) {
|
|
|
- // const messageArr = data.result.split('/');
|
|
|
- // const fileUrl = messageArr[messageArr.length - 1];
|
|
|
- // if (fileUrl) {
|
|
|
- // const baseApiUrl = glob.domainUrl;
|
|
|
- // // 下载文件
|
|
|
- // const a = document.createElement('a');
|
|
|
- // // 定义下载名称
|
|
|
- // a.download = name;
|
|
|
- // // 隐藏标签
|
|
|
- // a.style.display = 'none';
|
|
|
- // // 设置文件路径
|
|
|
- // a.href = `${baseApiUrl}/sys/common/static/${fileUrl}`;
|
|
|
- // // 将创建的标签插入dom
|
|
|
- // document.body.appendChild(a);
|
|
|
- // // 点击标签,执行下载
|
|
|
- // a.click();
|
|
|
- // // 将标签从dom移除
|
|
|
- // document.body.removeChild(a);
|
|
|
- // message.success({ content: '导出成功!', key, duration: 1 });
|
|
|
- // }
|
|
|
- // } else {
|
|
|
- // message.error({ content: '下载失败!', key, duration: 1 });
|
|
|
- // }
|
|
|
- // })
|
|
|
- // .catch(() => {
|
|
|
- // message.error({ content: '下载失败!', key, duration: 1 });
|
|
|
- // });
|
|
|
+ const key = 'updatable';
|
|
|
+ message.loading({ content: '正在导出,请稍等...', key });
|
|
|
+ defHttp
|
|
|
+ .post({ url: url, params: params, timeout: 1000 * 1000 }, { isTransformResponse: false })
|
|
|
+ .then((data) => {
|
|
|
+ debugger;
|
|
|
+ if (data.code == 200 && data.result) {
|
|
|
+ const messageArr = data.result.split('/');
|
|
|
+ const fileUrl = messageArr[messageArr.length - 1];
|
|
|
+ if (fileUrl) {
|
|
|
+ const baseApiUrl = glob.domainUrl;
|
|
|
+ // 下载文件
|
|
|
+ const a = document.createElement('a');
|
|
|
+ // 定义下载名称
|
|
|
+ a.download = name;
|
|
|
+ // 隐藏标签
|
|
|
+ a.style.display = 'none';
|
|
|
+ // 设置文件路径
|
|
|
+ a.href = `${baseApiUrl}/sys/common/static/${fileUrl}`;
|
|
|
+ // 将创建的标签插入dom
|
|
|
+ document.body.appendChild(a);
|
|
|
+ // 点击标签,执行下载
|
|
|
+ a.click();
|
|
|
+ // 将标签从dom移除
|
|
|
+ document.body.removeChild(a);
|
|
|
+ message.success({ content: '导出成功!', key, duration: 1 });
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ message.error({ content: '下载失败!', key, duration: 1 });
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ message.error({ content: '下载失败!', key, duration: 1 });
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
async function exportXlsPost1(name, url, params, isXlsx = false) {
|