|
@@ -87,33 +87,49 @@ serviceNew.interceptors.response.use(res => {
|
|
|
|
|
|
// 通用下载方法
|
|
|
export function downloadNew(url, params, filename) {
|
|
|
- return serviceNew.get(url, params, {
|
|
|
- transformRequest: [(params) => {
|
|
|
- return tansParams(params)
|
|
|
- }],
|
|
|
- headers: {
|
|
|
- 'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
- },
|
|
|
- responseType: 'blob'
|
|
|
+ console.log(params)
|
|
|
+ return serviceNew({
|
|
|
+ url: url,
|
|
|
+ method: 'get',
|
|
|
+ params: params
|
|
|
}).then((data) => {
|
|
|
- const content = data
|
|
|
- const blob = new Blob([content])
|
|
|
- if ('download' in document.createElement('a')) {
|
|
|
- const elink = document.createElement('a')
|
|
|
- elink.download = filename
|
|
|
- elink.style.display = 'none'
|
|
|
- elink.href = URL.createObjectURL(blob)
|
|
|
- document.body.appendChild(elink)
|
|
|
- elink.click()
|
|
|
- URL.revokeObjectURL(elink.href)
|
|
|
- document.body.removeChild(elink)
|
|
|
- return data;
|
|
|
- } else {
|
|
|
- navigator.msSaveBlob(blob, filename)
|
|
|
- }
|
|
|
- }).catch((r) => {
|
|
|
- console.error(r)
|
|
|
- })
|
|
|
+ const content = data
|
|
|
+ const blob = new Blob([content])
|
|
|
+ if ('download' in document.createElement('a')) {
|
|
|
+ const elink = document.createElement('a')
|
|
|
+ elink.download = filename
|
|
|
+ elink.style.display = 'none'
|
|
|
+ elink.href = URL.createObjectURL(blob)
|
|
|
+ document.body.appendChild(elink)
|
|
|
+ elink.click()
|
|
|
+ URL.revokeObjectURL(elink.href)
|
|
|
+ document.body.removeChild(elink)
|
|
|
+ return data;
|
|
|
+ } else {
|
|
|
+ navigator.msSaveBlob(blob, filename)
|
|
|
+ }
|
|
|
+ }).catch((r) => {
|
|
|
+ console.error(r)
|
|
|
+ })
|
|
|
+ // return serviceNew.get(url, params).then((data) => {
|
|
|
+ // const content = data
|
|
|
+ // const blob = new Blob([content])
|
|
|
+ // if ('download' in document.createElement('a')) {
|
|
|
+ // const elink = document.createElement('a')
|
|
|
+ // elink.download = filename
|
|
|
+ // elink.style.display = 'none'
|
|
|
+ // elink.href = URL.createObjectURL(blob)
|
|
|
+ // document.body.appendChild(elink)
|
|
|
+ // elink.click()
|
|
|
+ // URL.revokeObjectURL(elink.href)
|
|
|
+ // document.body.removeChild(elink)
|
|
|
+ // return data;
|
|
|
+ // } else {
|
|
|
+ // navigator.msSaveBlob(blob, filename)
|
|
|
+ // }
|
|
|
+ // }).catch((r) => {
|
|
|
+ // console.error(r)
|
|
|
+ // })
|
|
|
}
|
|
|
|
|
|
export default serviceNew
|