Browse Source

Merge pull request '请求方法增加参数,可返回全部内容' (#91) from zq-sliderDev into master

Reviewed-on: #91
master
zhangqi 2 days ago
parent
commit
2fd5a2dc73
  1. 13
      src/utils/request.js
  2. 34
      src/views/agent/checkOrderList.vue

13
src/utils/request.js

@ -31,11 +31,18 @@ service.interceptors.response.use(
(response) => { (response) => {
// 对响应数据做一些处理 // 对响应数据做一些处理
const res = response.data; const res = response.data;
if (!res.status) { return response.config.returnFullResponse ? response : res;
// if (!res.status) {
// 如果返回的 status 不是 true,则视为错误 // 如果返回的 status 不是 true,则视为错误
// return Promise.reject(new Error(res.info || "请求失败")); // return Promise.reject(new Error(res.info || "请求失败"));
} // }
return res; // response包含内容
// const {
// config, // 包含请求头(config.headers)
// headers, // 响应头(headers)
// data, // 响应体数据
// status // HTTP状态码
// } = response;
}, },
(error) => { (error) => {
// 对响应错误做些什么 // 对响应错误做些什么

34
src/views/agent/checkOrderList.vue

@ -369,19 +369,25 @@ export default {
if (this.searchUid) params.uid = this.searchUid; if (this.searchUid) params.uid = this.searchUid;
this.$http('GET', '/agentnew/export_order', params,{ this.$http('GET', '/agentnew/export_order', params,{
returnFullResponse: true ,
headers: { headers: {
'Auth': this.token 'Auth': this.token,
}, },
responseType: 'blob' responseType: 'blob'
}).then(response => { }).then(response => {
console.log(response) const {
console.log(response.headers) headers, // headers
const blob = new Blob([response], { type: 'application/force-download' }); 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 downloadUrl = window.URL.createObjectURL(blob);
const link = document.createElement('a'); const link = document.createElement('a');
link.href = downloadUrl; link.href = downloadUrl;
link.setAttribute('download', 'filename.xls'); link.setAttribute('download', filename);
document.body.appendChild(link); document.body.appendChild(link);
link.click(); link.click();
@ -409,14 +415,16 @@ export default {
// location.href = url; // location.href = url;
}, },
// decodeRFC5987Filename(header) {
getFilenameFromHeaders(headers) { // RFC 5987 filename*=utf8''xxx
const disposition = headers['content-disposition']; const match = header.match(/filename\*=(?:utf8|UTF-8)''([^;]+)/i);
if (!disposition) return null; console.log(match,'match');
if (match) {
// attachment; filename="example.txt" return decodeURIComponent(match[1]);
const matches = disposition.match(/filename="?([^"]+)"?/i); }
return matches && matches[1] ? matches[1] : null; // 退 filename="xxx"
const fallbackMatch = header.match(/filename="?([^"]+)"?/i);
return fallbackMatch ? fallbackMatch[1] : 'download';
}, },
getPayImg(pay_type) { getPayImg(pay_type) {
return require('@/assets/pay/pay_' + pay_type + '.svg'); return require('@/assets/pay/pay_' + pay_type + '.svg');

Loading…
Cancel
Save