@@ -31,21 +31,27 @@ function download(url: string, query?: IObject, name?: string) {
3131 responseType : 'blob' ,
3232 // contentType: 'application/octet-stream;charset=UTF-8',
3333 cancelToken : source . token ,
34- } ) . then ( res => {
35- if ( ! name ) {
36- name = res . headers [ 'content-disposition' ] . split ( ';' )
37- name = ( name as any ) [ ( name as any ) . length - 1 ] . split ( '=' )
38- name = ( name as any ) [ ( name as any ) . length - 1 ]
39- }
40- const type = ( name as string ) . split ( '.' )
34+ } )
35+ . then ( res => {
36+ ; ( source as any ) . cancel = 0 // 已完成不可取消
37+ if ( ! name ) {
38+ name = res . headers [ 'content-disposition' ] . split ( ';' )
39+ name = ( name as any ) [ ( name as any ) . length - 1 ] . split ( '=' )
40+ name = ( name as any ) [ ( name as any ) . length - 1 ]
41+ }
42+ const type = ( name as string ) . split ( '.' )
4143
42- return {
43- name,
44- size : res . data . size ,
45- type : type [ type . length - 1 ] , // res.data.type, // application/x-msdownload
46- src : window . URL . createObjectURL ( res . data ) ,
47- }
48- } ) as IPromiseCancelable < IFile >
44+ return {
45+ name,
46+ size : res . data . size ,
47+ type : type [ type . length - 1 ] , // res.data.type, // application/x-msdownload
48+ src : window . URL . createObjectURL ( res . data ) ,
49+ }
50+ } )
51+ . catch ( err => {
52+ ; ( source as any ) . cancel = 0 // 已完成不可取消
53+ throw err
54+ } ) as IPromiseCancelable < IFile >
4955 promise . cancel = ( message ?: string ) => {
5056 if ( source . cancel ) {
5157 console . warn ( message || '取消下载:' , url , query , name )
0 commit comments