This commit is contained in:
张成
2025-10-28 15:51:56 +08:00
parent 42c977b815
commit 0a723c4dfe
3 changed files with 14 additions and 12 deletions

View File

@@ -210,8 +210,7 @@ class Http {
let res = await axios.post(url, formData, config) let res = await axios.post(url, formData, config)
filename = filename || res.headers['content-disposition'].split('filename=')[1].split(';')[0] filename = filename || res.headers['content-disposition'].split('filename=')[1].split(';')[0]
// 开头和结尾去掉 中间不去掉
filename = filename.replace(/^[_-]+|[_-]+$/g, '')
// 直接下载 // 直接下载
if (is_down) { if (is_down) {

View File

@@ -34,6 +34,9 @@ export default class uiTool {
* @param {String} fileName - 文件名(可选,默认为时间戳.csv * @param {String} fileName - 文件名(可选,默认为时间戳.csv
*/ */
static downloadFile(res, fileName) { static downloadFile(res, fileName) {
// 开头和结尾去掉 中间不去掉
fileName = fileName.replace(/^[_-]+|[_-]+$/g, '')
const blob = new Blob([res.data || res]) const blob = new Blob([res.data || res])
const downloadElement = document.createElement('a') const downloadElement = document.createElement('a')
const href = window.URL.createObjectURL(blob) const href = window.URL.createObjectURL(blob)

View File

@@ -168,7 +168,7 @@ this.$tools.formatDate(new Date())
this.$tools.deepClone(obj) this.$tools.deepClone(obj)
// 文件下载 // 文件下载
this.$funTool.downloadFile(response, 'filename.xlsx') this.$uiTool.downloadFile(response, 'filename.xlsx')
// 配置信息 // 配置信息
this.$config.title this.$config.title