@@ -77,7 +77,9 @@ instance.interceptors.response.use(
7777
7878 if ( err . response ?. status === 403 && ! err . response . config . url . includes ( 'chat/open' ) ) {
7979 MsgError (
80- err . response . data && err . response . data . message ? err . response . data . message : '没有权限访问' ,
80+ err . response . data && err . response . data . message
81+ ? err . response . data . message
82+ : 'No permission to access' ,
8183 )
8284 }
8385 return Promise . reject ( err )
@@ -249,15 +251,15 @@ export const exportExcel: (
249251
250252function decodeFilenameBrowser ( contentDisposition : string ) {
251253 // 提取并解码 Base64 部分
252- const base64Part = contentDisposition . match ( / = \? u t f - 8 \? b \? ( .* ?) \? = / i) ?. [ 1 ] ;
253- if ( ! base64Part ) return null ;
254+ const base64Part = contentDisposition . match ( / = \? u t f - 8 \? b \? ( .* ?) \? = / i) ?. [ 1 ]
255+ if ( ! base64Part ) return null
254256
255257 // 使用 atob 解码 Base64
256- const decoded = decodeURIComponent ( escape ( atob ( base64Part ) ) ) ;
258+ const decoded = decodeURIComponent ( escape ( atob ( base64Part ) ) )
257259
258260 // 提取文件名
259- const filenameMatch = decoded . match ( / f i l e n a m e = " ( .* ?) " / i) ;
260- return filenameMatch ? filenameMatch [ 1 ] : null ;
261+ const filenameMatch = decoded . match ( / f i l e n a m e = " ( .* ?) " / i)
262+ return filenameMatch ? filenameMatch [ 1 ] : null
261263}
262264
263265export const exportFile : (
@@ -271,37 +273,40 @@ export const exportFile: (
271273 params : any ,
272274 loading ?: NProgress | Ref < boolean > ,
273275) => {
274- return promise ( request ( {
275- url : url ,
276- method : 'get' ,
277- params,
278- responseType : 'blob' ,
279- transformResponse : [ function ( data , headers ) {
280- // 在这里可以访问 headers
281- // const contentType = headers['content-type'];
282- const contentDisposition = headers [ 'content-disposition' ] ;
283- // console.log('Content-Type:', contentType);
284- // console.log('Content-Disposition:', decodeFilenameBrowser(contentDisposition));
285- // 如果没有提供文件名,则使用默认名称
286- fileName = decodeFilenameBrowser ( contentDisposition ) || fileName ;
287- return data ; // 必须返回数据
288- } ]
289- } ) , loading ) . then (
290- ( res : any ) => {
291- if ( res ) {
292- const blob = new Blob ( [ res ] , {
293- type : 'application/octet-stream' ,
294- } )
295- const link = document . createElement ( 'a' )
296- link . href = window . URL . createObjectURL ( blob )
297- link . download = fileName
298- link . click ( )
299- //释放内存
300- window . URL . revokeObjectURL ( link . href )
301- }
302- return true
303- } ,
304- )
276+ return promise (
277+ request ( {
278+ url : url ,
279+ method : 'get' ,
280+ params,
281+ responseType : 'blob' ,
282+ transformResponse : [
283+ function ( data , headers ) {
284+ // 在这里可以访问 headers
285+ // const contentType = headers['content-type'];
286+ const contentDisposition = headers [ 'content-disposition' ]
287+ // console.log('Content-Type:', contentType);
288+ // console.log('Content-Disposition:', decodeFilenameBrowser(contentDisposition));
289+ // 如果没有提供文件名,则使用默认名称
290+ fileName = decodeFilenameBrowser ( contentDisposition ) || fileName
291+ return data // 必须返回数据
292+ } ,
293+ ] ,
294+ } ) ,
295+ loading ,
296+ ) . then ( ( res : any ) => {
297+ if ( res ) {
298+ const blob = new Blob ( [ res ] , {
299+ type : 'application/octet-stream' ,
300+ } )
301+ const link = document . createElement ( 'a' )
302+ link . href = window . URL . createObjectURL ( blob )
303+ link . download = fileName
304+ link . click ( )
305+ //释放内存
306+ window . URL . revokeObjectURL ( link . href )
307+ }
308+ return true
309+ } )
305310}
306311
307312export const exportExcelPost : (
0 commit comments