From 99dcbe0207eed69ed2613f3cd9a11d0529bd7265 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期一, 27 九月 2021 17:24:37 +0800 Subject: [PATCH] update 封装通用下载方法简化下载使用 --- ruoyi-ui/src/plugins/download.js | 37 ++++++++++++++++++++++++++++++------- 1 files changed, 30 insertions(+), 7 deletions(-) diff --git a/ruoyi-ui/src/plugins/download.js b/ruoyi-ui/src/plugins/download.js index cb10ab0..248ed01 100644 --- a/ruoyi-ui/src/plugins/download.js +++ b/ruoyi-ui/src/plugins/download.js @@ -5,28 +5,51 @@ const baseURL = process.env.VUE_APP_BASE_API export default { - name(name, isDelete = true) { - var url = baseURL + "/common/download?fileName=" + encodeURI(name) + "&delete=" + isDelete + excel(url, params) { + // get璇锋眰鏄犲皠params鍙傛暟 + if (params) { + let urlparams = url + '?'; + for (const propName of Object.keys(params)) { + const value = params[propName]; + var part = encodeURIComponent(propName) + "="; + if (value !== null && typeof(value) !== "undefined") { + if (typeof value === 'object') { + for (const key of Object.keys(value)) { + if (value[key] !== null && typeof (value[key]) !== 'undefined') { + let params = propName + '[' + key + ']'; + let subPart = encodeURIComponent(params) + '='; + urlparams += subPart + encodeURIComponent(value[key]) + '&'; + } + } + } else { + urlparams += part + encodeURIComponent(value) + "&"; + } + } + } + urlparams = urlparams.slice(0, -1); + url = urlparams; + } + url = baseURL + url axios({ method: 'get', url: url, responseType: 'blob', headers: { 'Authorization': 'Bearer ' + getToken() } }).then(res => { - const blob = new Blob([res.data]) + const blob = new Blob([res.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }) this.saveAs(blob, decodeURI(res.headers['download-filename'])) }) }, - resource(resource) { - var url = baseURL + "/common/download/resource?resource=" + encodeURI(resource); + oss(ossId, name) { + var url = baseURL + '/system/oss/download/' + ossId axios({ method: 'get', url: url, responseType: 'blob', headers: { 'Authorization': 'Bearer ' + getToken() } }).then(res => { - const blob = new Blob([res.data]) - this.saveAs(blob, decodeURI(res.headers['download-filename'])) + const blob = new Blob([res.data], { type: 'application/octet-stream' }) + this.saveAs(blob, name) }) }, zip(url, name) { -- Gitblit v1.9.3