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. 38
      src/views/agent/checkOrderList.vue

13
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) => {
// 对响应错误做些什么

38
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');

Loading…
Cancel
Save