| | |
| | | downloadLoadingInstance.close(); |
| | | }); |
| | | }, |
| | | async downloadFileFromUrl(url, filename) { |
| | | try { |
| | | let state = /\.(jpg|jpeg|png|gif)$/i.test(url) // 判断是否为图片 |
| | | let url1 = '' |
| | | if (state) { |
| | | url1 = Vue.prototype.javaApi + '/img/' + url; |
| | | } else { |
| | | url1 = Vue.prototype.javaApi + '/word/' + url |
| | | async saveAs(text, name, opts) { |
| | | if (typeof text === "string") { |
| | | try { |
| | | let state = /\.(jpg|jpeg|png|gif)$/i.test(text) // 判断是否为图片 |
| | | let url1 = '' |
| | | if (state) { |
| | | url1 = Vue.prototype.javaApi + '/img/' + text; |
| | | } else { |
| | | url1 = Vue.prototype.javaApi + '/word/' + text |
| | | } |
| | | // 使用 fetch 获取文件 |
| | | const response = await fetch(url1); |
| | | if (!response.ok) { |
| | | throw new Error('文件下载失败: ' + response.statusText); |
| | | } |
| | | // 将文件转换为 Blob |
| | | const blob = await response.blob(); |
| | | // 使用 saveAs 保存文件 |
| | | saveAs(blob, filename); |
| | | Message.success("数据导出成功"); |
| | | } catch (error) { |
| | | Message.error(error); |
| | | } |
| | | // 使用 fetch 获取文件 |
| | | const response = await fetch(url1); |
| | | if (!response.ok) { |
| | | throw new Error('文件下载失败: ' + response.statusText); |
| | | } |
| | | // 将文件转换为 Blob |
| | | const blob = await response.blob(); |
| | | // 使用 saveAs 保存文件 |
| | | saveAs(blob, filename); |
| | | Message.success("数据导出成功"); |
| | | } catch (error) { |
| | | Message.error(error); |
| | | } else { |
| | | // 流下载 |
| | | blobToText(text) |
| | | .then((result) => { |
| | | Message.error(result.msg); |
| | | }) |
| | | .catch(() => { |
| | | saveAs(text, name, opts); |
| | | Message.success("数据导出成功"); |
| | | }); |
| | | } |
| | | }, |
| | | saveAs(text, name, opts) { |
| | | // 流下载 |
| | | blobToText(text).then((result) => { |
| | | Message.error(result.msg); |
| | | }).catch(() => { |
| | | saveAs(text, name, opts); |
| | | Message.success("数据导出成功"); |
| | | }); |
| | | }, |
| | | async printErrMsg(data) { |
| | | const resText = await data.text(); |