| | |
| | | // 深拷贝 |
| | | export function deepClone(obj) { |
| | | let objClone = Array.isArray(obj) ? [] : {}; |
| | | if (obj && typeof obj === 'object' && obj != null) { |
| | | if (obj && typeof obj === 'object') { |
| | | for (let key in obj) { |
| | | if (obj.hasOwnProperty(key)) { |
| | | if (obj[key] && typeof obj[key] === 'object') { |
| | |
| | | // data: 文件, contentDisposition:请求头中文件的名字 |
| | | // 默认不用修改,直接将返回的res传入即可 |
| | | export function downloadFile(res) { |
| | | const blob = new Blob([res.data], { type: '.xlsx' }); |
| | | const blob = new Blob([res.data], { type: 'application/octet-stream' }); |
| | | const fileName = res.contentDisposition.split(`''`)[1]; |
| | | if (window.navigator && window.navigator.msSaveBlob) { |
| | | navigator.msSaveBlob(blob, fileName); |
| | | window.navigator.msSaveBlob(blob, fileName); |
| | | } else { |
| | | const link = document.createElement('a'); |
| | | link.style.display = 'none'; |
| | | link.href = URL.createObjectURL(blob); |
| | | link.setAttribute('download', decodeURI(fileName)); |
| | | link.href = window.URL.createObjectURL(blob); |
| | | link.download = decodeURI(fileName); |
| | | document.body.appendChild(link); |
| | | link.click(); |
| | | URL.revokeObjectURL(link.href); |
| | | window.URL.revokeObjectURL(link.href); |
| | | document.body.removeChild(link); |
| | | } |
| | | } |