mirror of
https://github.com/dromara/RuoYi-Vue-Plus.git
synced 2025-09-24 07:19:46 +08:00
update OSS下载文件名改为后端传输
This commit is contained in:
@ -6,7 +6,7 @@ const mimeMap = {
|
||||
}
|
||||
|
||||
const baseUrl = process.env.VUE_APP_BASE_API
|
||||
export function downLoadOss(ossId, filename) {
|
||||
export function downLoadOss(ossId) {
|
||||
var url = baseUrl + '/system/oss/download/' + ossId
|
||||
axios({
|
||||
method: 'get',
|
||||
@ -14,7 +14,7 @@ export function downLoadOss(ossId, filename) {
|
||||
responseType: 'blob',
|
||||
headers: { 'Authorization': 'Bearer ' + getToken() }
|
||||
}).then(res => {
|
||||
resolveBlob(res, mimeMap.oss, filename)
|
||||
resolveBlob(res, mimeMap.oss)
|
||||
})
|
||||
}
|
||||
/**
|
||||
@ -22,11 +22,17 @@ export function downLoadOss(ossId, filename) {
|
||||
* @param {*} res blob响应内容
|
||||
* @param {String} mimeType MIME类型
|
||||
*/
|
||||
export function resolveBlob(res, mimeType, filename) {
|
||||
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) // 设置下载文件名称
|
||||
aLink.setAttribute('download', decodeURI(fileName)) // 设置下载文件名称
|
||||
document.body.appendChild(aLink)
|
||||
aLink.click()
|
||||
document.body.removeChild(aLink);
|
||||
|
@ -289,7 +289,7 @@ export default {
|
||||
},
|
||||
/** 下载按钮操作 */
|
||||
handleDownload(row) {
|
||||
downLoadOss(row.ossId, row.originalName)
|
||||
downLoadOss(row.ossId)
|
||||
},
|
||||
/** 删除按钮操作 */
|
||||
handleDelete(row) {
|
||||
|
Reference in New Issue
Block a user