diff --git a/src/utils/request.js b/src/utils/request.js index 28c3458..2b81f4e 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -31,11 +31,18 @@ service.interceptors.response.use( (response) => { // 对响应数据做一些处理 const res = response.data; - if (!res.status) { + return response.config.returnFullResponse ? response : res; + // if (!res.status) { // 如果返回的 status 不是 true,则视为错误 // return Promise.reject(new Error(res.info || "请求失败")); - } - return res; + // } +// response包含内容 + // const { + // config, // 包含请求头(config.headers) + // headers, // 响应头(headers) + // data, // 响应体数据 + // status // HTTP状态码 + // } = response; }, (error) => { // 对响应错误做些什么 diff --git a/src/views/agent/checkOrderList.vue b/src/views/agent/checkOrderList.vue index 5772407..1b79fc1 100644 --- a/src/views/agent/checkOrderList.vue +++ b/src/views/agent/checkOrderList.vue @@ -368,20 +368,26 @@ export default { if (this.searchType) params.type = this.searchType; if (this.searchUid) params.uid = this.searchUid; - this.$http('GET', '/agentnew/export_order', params, { + this.$http('GET', '/agentnew/export_order', params,{ + returnFullResponse: true , headers: { - 'Auth': this.token + 'Auth': this.token, }, responseType: 'blob' - }).then(response => { - console.log(response) - console.log(response.headers) - const blob = new Blob([response], { type: 'application/force-download' }); + }).then(response => { + const { + headers, // 响应头(headers) + data, // 响应体数据 + } = response; + const filename = this.decodeRFC5987Filename(headers['content-disposition']); + // console.log(headers,data,filename,'ajax_get_check_order_list====='); + + const blob = new Blob([data], { type: 'application/force-download' }); const downloadUrl = window.URL.createObjectURL(blob); const link = document.createElement('a'); link.href = downloadUrl; - link.setAttribute('download', 'filename.xls'); + link.setAttribute('download', filename); document.body.appendChild(link); link.click(); @@ -409,14 +415,16 @@ export default { // location.href = url; }, - // 从响应头解析文件名 - getFilenameFromHeaders(headers) { - const disposition = headers['content-disposition']; - if (!disposition) return null; - - // 匹配形如:attachment; filename="example.txt" - const matches = disposition.match(/filename="?([^"]+)"?/i); - return matches && matches[1] ? matches[1] : null; + decodeRFC5987Filename(header) { + // 匹配 RFC 5987 编码的文件名(如 filename*=utf8''xxx) + const match = header.match(/filename\*=(?:utf8|UTF-8)''([^;]+)/i); + console.log(match,'match'); + if (match) { + return decodeURIComponent(match[1]); + } + // 回退到普通文件名(如 filename="xxx") + const fallbackMatch = header.match(/filename="?([^"]+)"?/i); + return fallbackMatch ? fallbackMatch[1] : 'download'; }, getPayImg(pay_type) { return require('@/assets/pay/pay_' + pay_type + '.svg');