Showing
2 changed files
with
27 additions
and
2 deletions
| ... | @@ -6,7 +6,7 @@ const mimeMap = { | ... | @@ -6,7 +6,7 @@ const mimeMap = { |
| 6 | zip: 'application/zip' | 6 | zip: 'application/zip' |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | -const baseUrl = process.env.VUE_APP_BASE_API | 9 | +const baseUrl = 'http://192.168.1.134:18080' |
| 10 | export function downLoadZip(str, filename) { | 10 | export function downLoadZip(str, filename) { |
| 11 | var url = baseUrl + str | 11 | var url = baseUrl + str |
| 12 | axios({ | 12 | axios({ |
| ... | @@ -18,6 +18,20 @@ export function downLoadZip(str, filename) { | ... | @@ -18,6 +18,20 @@ export function downLoadZip(str, filename) { |
| 18 | resolveBlob(res, mimeMap.zip) | 18 | resolveBlob(res, mimeMap.zip) |
| 19 | }) | 19 | }) |
| 20 | } | 20 | } |
| 21 | +export function cargoXlsx(str,data) { | ||
| 22 | + var url = baseUrl + str | ||
| 23 | + axios({ | ||
| 24 | + method: 'post', | ||
| 25 | + url: url, | ||
| 26 | + data:data, | ||
| 27 | + responseType: 'blob', | ||
| 28 | + headers: { 'Authorization': getToken() } | ||
| 29 | + }).then(res => { | ||
| 30 | + if(res.status === 200){ | ||
| 31 | + cargoTableXlsx(res) | ||
| 32 | + } | ||
| 33 | + }) | ||
| 34 | +} | ||
| 21 | /** | 35 | /** |
| 22 | * 解析blob响应内容并下载 | 36 | * 解析blob响应内容并下载 |
| 23 | * @param {*} res blob响应内容 | 37 | * @param {*} res blob响应内容 |
| ... | @@ -25,7 +39,7 @@ export function downLoadZip(str, filename) { | ... | @@ -25,7 +39,7 @@ export function downLoadZip(str, filename) { |
| 25 | */ | 39 | */ |
| 26 | export function resolveBlob(res, mimeType) { | 40 | export function resolveBlob(res, mimeType) { |
| 27 | const aLink = document.createElement('a') | 41 | const aLink = document.createElement('a') |
| 28 | - var blob = new Blob([res.data], { type: mimeType }) | 42 | + var blob = new Blob([res], { type: mimeType }) |
| 29 | // //从response的headers中获取filename, 后端response.setHeader("Content-disposition", "attachment; filename=xxxx.docx") 设置的文件名; | 43 | // //从response的headers中获取filename, 后端response.setHeader("Content-disposition", "attachment; filename=xxxx.docx") 设置的文件名; |
| 30 | var patt = new RegExp('filename=([^;]+\\.[^\\.;]+);*') | 44 | var patt = new RegExp('filename=([^;]+\\.[^\\.;]+);*') |
| 31 | var contentDisposition = decodeURI(res.headers['content-disposition']) | 45 | var contentDisposition = decodeURI(res.headers['content-disposition']) |
| ... | @@ -38,3 +52,14 @@ export function resolveBlob(res, mimeType) { | ... | @@ -38,3 +52,14 @@ export function resolveBlob(res, mimeType) { |
| 38 | aLink.click() | 52 | aLink.click() |
| 39 | document.body.removeChild(aLink); | 53 | document.body.removeChild(aLink); |
| 40 | } | 54 | } |
| 55 | + | ||
| 56 | +//货物查询表导出 | ||
| 57 | +export function cargoTableXlsx(res){ | ||
| 58 | + const aLink = document.createElement('a') | ||
| 59 | + const fileName = "货物查询表.xlsx" | ||
| 60 | + aLink.href = URL.createObjectURL(res.data) | ||
| 61 | + aLink.setAttribute('download', fileName) // 设置下载文件名称 | ||
| 62 | + document.body.appendChild(aLink) | ||
| 63 | + aLink.click() | ||
| 64 | + document.body.removeChild(aLink); | ||
| 65 | +} | ... | ... |
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment