diff --git a/ruoyi-ui/src/api/tool/codegen.js b/ruoyi-ui/src/api/tool/codegen.js index 63856d3bf..3fa8b865a 100644 --- a/ruoyi-ui/src/api/tool/codegen.js +++ b/ruoyi-ui/src/api/tool/codegen.js @@ -30,7 +30,7 @@ export function updateCodegen(data) { export function previewCodegen(tableId) { return request({ url: '/tool/codegen/preview?tableId=' + tableId, - method: 'get' + method: 'get', }) } diff --git a/ruoyi-ui/src/utils/ruoyi.js b/ruoyi-ui/src/utils/ruoyi.js index d79e9f5e7..1b73f9b68 100644 --- a/ruoyi-ui/src/utils/ruoyi.js +++ b/ruoyi-ui/src/utils/ruoyi.js @@ -103,23 +103,17 @@ export function download(fileName) { // 下载 Excel 方法 export function downloadExcel(data, fileName) { - // 创建 blob - let blob = new Blob([data], {type: 'application/vnd.ms-excel'}); - // 创建 href 超链接,点击进行下载 - window.URL = window.URL || window.webkitURL; - let href = URL.createObjectURL(blob); - let downA = document.createElement("a"); - downA.href = href; - downA.download = fileName; - downA.click(); - // 销毁超连接 - window.URL.revokeObjectURL(href); + download0(data, fileName, 'application/vnd.ms-excel'); } // 下载 Zip 方法 export function downloadZip(data, fileName) { + download0(data, fileName, 'application/zip'); +} + +function download0(data, fileName, mineType) { // 创建 blob - let blob = new Blob([data], {type: 'application/zip'}); + let blob = new Blob([data], {type: mineType}); // 创建 href 超链接,点击进行下载 window.URL = window.URL || window.webkitURL; let href = URL.createObjectURL(blob); diff --git a/ruoyi-ui/src/utils/zipdownload.js b/ruoyi-ui/src/utils/zipdownload.js deleted file mode 100644 index 3a8681468..000000000 --- a/ruoyi-ui/src/utils/zipdownload.js +++ /dev/null @@ -1,40 +0,0 @@ -import axios from 'axios' -import { getToken } from '@/utils/auth' - -const mimeMap = { - xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - zip: 'application/zip' -} - -const baseUrl = process.env.VUE_APP_BASE_API -export function downLoadZip(str, filename) { - var url = baseUrl + str - axios({ - method: 'get', - url: url, - responseType: 'blob', - headers: { 'Authorization': 'Bearer ' + getToken() } - }).then(res => { - resolveBlob(res, mimeMap.zip) - }) -} -/** - * 解析blob响应内容并下载 - * @param {*} res blob响应内容 - * @param {String} mimeType MIME类型 - */ -export function resolveBlob(res, mimeType) { - const aLink = document.createElement('a') - var blob = new Blob([res.data], { type: mimeType }) - // //从response的headers中获取filename, 后端response.setHeader("Content-disposition", "attachment; filename=xxxx.docx") 设置的文件名; - var patt = new RegExp('filename=([^;]+\\.[^\\.;]+);*') - var contentDisposition = decodeURI(res.headers['content-disposition']) - var result = patt.exec(contentDisposition) - var fileName = result[1] - fileName = fileName.replace(/\"/g, '') - aLink.href = URL.createObjectURL(blob) - aLink.setAttribute('download', fileName) // 设置下载文件名称 - document.body.appendChild(aLink) - aLink.click() - document.body.appendChild(aLink) -} diff --git a/ruoyi-ui/src/views/tool/gen/index.vue b/ruoyi-ui/src/views/tool/gen/index.vue index 9ac16ed5a..0a80e1c53 100644 --- a/ruoyi-ui/src/views/tool/gen/index.vue +++ b/ruoyi-ui/src/views/tool/gen/index.vue @@ -85,15 +85,15 @@