| | |
| | | |
| | | const mimeMap = { |
| | | xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', |
| | | zip: 'application/zip' |
| | | zip: 'application/zip', |
| | | excel: 'application/vnd.ms-excel', |
| | | oss: 'application/octet-stream' |
| | | } |
| | | |
| | | const baseUrl = process.env.VUE_APP_BASE_API |
| | |
| | | resolveBlob(res, mimeMap.zip) |
| | | }) |
| | | } |
| | | |
| | | export function downLoadOss(ossId) { |
| | | var url = baseUrl + '/system/oss/download/' + ossId |
| | | axios({ |
| | | method: 'get', |
| | | url: url, |
| | | responseType: 'blob', |
| | | headers: { 'Authorization': 'Bearer ' + getToken() } |
| | | }).then(res => { |
| | | resolveBlob(res, mimeMap.oss) |
| | | }) |
| | | } |
| | | |
| | | export function downLoadExcel(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)) { |
| | | let params = propName + '[' + key + ']'; |
| | | var subPart = encodeURIComponent(params) + "="; |
| | | urlparams += subPart + encodeURIComponent(value[key]) + "&"; |
| | | } |
| | | } else { |
| | | urlparams += part + encodeURIComponent(value) + "&"; |
| | | } |
| | | } |
| | | } |
| | | urlparams = urlparams.slice(0, -1); |
| | | params = {}; |
| | | url = urlparams; |
| | | } |
| | | url = baseUrl + url |
| | | axios({ |
| | | method: 'get', |
| | | url: url, |
| | | params: params, |
| | | responseType: 'blob', |
| | | headers: { 'Authorization': 'Bearer ' + getToken() } |
| | | }).then(res => { |
| | | resolveBlob(res, mimeMap.excel) |
| | | }) |
| | | } |
| | | |
| | | /** |
| | | * è§£æblobååºå
容并ä¸è½½ |
| | | * @param {*} res blobååºå
容 |
| | |
| | | fileName = fileName.replace(/\"/g, '') |
| | | aLink.style.display = 'none' |
| | | aLink.href = URL.createObjectURL(blob) |
| | | aLink.setAttribute('download', fileName) // 设置ä¸è½½æä»¶åç§° |
| | | aLink.setAttribute('download', decodeURI(fileName)) // 设置ä¸è½½æä»¶åç§° |
| | | document.body.appendChild(aLink) |
| | | aLink.click() |
| | | URL.revokeObjectURL(aLink.href);//æ¸
é¤å¼ç¨ |