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:
33
ruoyi-ui/src/utils/ossdownload.js
Normal file
33
ruoyi-ui/src/utils/ossdownload.js
Normal file
@ -0,0 +1,33 @@
|
||||
import axios from 'axios'
|
||||
import { getToken } from '@/utils/auth'
|
||||
|
||||
const mimeMap = {
|
||||
oss: 'application/octet-stream'
|
||||
}
|
||||
|
||||
const baseUrl = process.env.VUE_APP_BASE_API
|
||||
export function downLoadOss(ossId, filename) {
|
||||
var url = baseUrl + '/system/oss/download/' + ossId
|
||||
axios({
|
||||
method: 'get',
|
||||
url: url,
|
||||
responseType: 'blob',
|
||||
headers: { 'Authorization': 'Bearer ' + getToken() }
|
||||
}).then(res => {
|
||||
resolveBlob(res, mimeMap.oss, filename)
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 解析blob响应内容并下载
|
||||
* @param {*} res blob响应内容
|
||||
* @param {String} mimeType MIME类型
|
||||
*/
|
||||
export function resolveBlob(res, mimeType, filename) {
|
||||
const aLink = document.createElement('a')
|
||||
var blob = new Blob([res.data], { type: mimeType })
|
||||
aLink.href = URL.createObjectURL(blob)
|
||||
aLink.setAttribute('download', filename) // 设置下载文件名称
|
||||
document.body.appendChild(aLink)
|
||||
aLink.click()
|
||||
document.body.removeChild(aLink);
|
||||
}
|
Reference in New Issue
Block a user