( fileName: string, url: string, params: any, loading?: NProgress | Ref<boolean>, )
| 229 | params: any, |
| 230 | loading?: NProgress | Ref<boolean>, |
| 231 | ) => Promise<any> = ( |
| 232 | fileName: string, |
| 233 | url: string, |
| 234 | params: any, |
| 235 | loading?: NProgress | Ref<boolean>, |
| 236 | ) => { |
| 237 | return promise(request({ url: url, method: 'get', params, responseType: 'blob' }), loading).then( |
| 238 | (res: any) => { |
| 239 | if (res) { |
| 240 | const blob = new Blob([res], { |
| 241 | type: 'application/vnd.ms-excel', |
| 242 | }) |
| 243 | const link = document.createElement('a') |
| 244 | link.href = window.URL.createObjectURL(blob) |
| 245 | link.download = fileName |
| 246 | link.click() |
| 247 | //释放内存 |
| 248 | window.URL.revokeObjectURL(link.href) |
| 249 | } |
| 250 | return true |
| 251 | }, |
| 252 | ) |
| 253 | } |
| 254 | |
| 255 | function extractFilename(contentDisposition: string) { |
| 256 | if (!contentDisposition) return null |
no test coverage detected