1. 程式人生 > >如何在限制請求頭的情況下,去匯出報告之類

如何在限制請求頭的情況下,去匯出報告之類

使用流的方式:

    // 匯出報告
    exportReport () {
        // window.open(`${baseUrl.baseUrl}/media/export?orderId=${this.searchItem}&promotionId=${this.currrentFormName}&activityId=${this.currrentFormActive}&starTime=${this.startTime}&endTime=${this.endTime}&status=${this.currrentOrderState}`)
let token = getToken() return new Promise((resolve, reject) => { baseUrl.request({ url: `${baseUrl.baseUrl}/media/export?orderId=${this.searchItem}&promotionId=${this.currrentFormName}&activityId=${this.currrentFormActive}&starTime=${this.startTime}&endTime=${this
.endTime}&status=${this.currrentOrderState}`, headers: { Authorization: 'Bearer ' + token }, responseType: 'blob' }).then(res => { console.log('this', this) console.log('res', res) let blob = new Blob([res.data], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8'}) let link
= document.createElement('a') link.href = window.URL.createObjectURL(blob) link.download = `訂單媒介報告匯出${formatTime2(new Date())}.xlsx` link.click() }) }) }