import { RequestBodyType , RequestFunctionParams } from 'yapi-to-typescript' ; declare const wx ; declare const qq ; declare const my ; declare const jd ; declare const swan ; declare const tt ; declare const dd ; const mp = typeof wx !== 'undefined' ? wx : typeof qq !== 'undefined' ? qq : typeof my !== 'undefined' ? my : typeof jd !== 'undefined' ? jd : typeof swan !== 'undefined' ? swan : typeof tt !== 'undefined' ? tt : typeof dd !== 'undefined' ? dd : undefined ; export interface RequestOptions { /**
     * 是否返回 Blob 结果，适用某些返回文件流的接口。
     */ returnBlob ? : boolean ; } export default async function request < TResponseData > ( payload , options ? ) { const baseUrl = payload . prodUrl ; const url = `${ baseUrl }${ payload . path }` ; let requestOptions ! ; if ( payload . hasFileData ) { const firstFileKey = Object . keys ( payload . fileData ) [ 0 ] ; requestOptions = { url : url , filePath : payload . fileData [ firstFileKey ] , name : firstFileKey , header : { } , formData : payload . data , timeout : 6000 , } ; } else { requestOptions = { url : url , method : payload . method , header : { ... ( payload . requestBodyType === RequestBodyType . json ? { 'Content-Type' : 'application/json; charset=UTF-8' } : payload . requestBodyType === RequestBodyType . form ? { 'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8' , } : { } ) , } , data : payload . requestBodyType === RequestBodyType . json ? JSON . stringify ( payload . data ) : payload . requestBodyType === RequestBodyType . form ? Object . keys ( payload . data ) . filter ( key => payload . data [ key ] != null ) . map ( key => `${ encodeURIComponent ( key ) }=${ encodeURIComponent ( payload . data [ key ] ) }` ) . join ( '&' ) : undefined , responseType : 'arraybuffer' , dataType : 'arraybuffer' , timeout : 6000 , } ; } const [ fetchErr , fetchRes ] = await new Promise ( ( resolve , reject ) => { mp [ payload . hasFileData ? 'uploadFile' : 'request' ] ( { ... requestOptions , success : resolve , fail : reject , } ) ; } ) . then < [ TypeError , Response ] > ( res => [ null , res ] as any , err => [ err , null ] as any ) ; if ( fetchErr ) { throw fetchErr ; } if ( fetchRes . status < 200 || fetchRes . status >= 300 ) { throw new Error ( `${ fetchRes . status }: ${ fetchRes . statusText }` ) ; } const res = options ?. returnBlob ? await fetchRes . blob ( ) : ( fetchRes . headers . get ( 'Content-Type' ) || '' ) . indexOf ( 'application/json' ) >= 0 ? await fetchRes . json ( ) . catch ( ( ) => ( { } ) ) : await fetchRes . text ( ) ; if ( res != null && typeof res === 'object' && res . code != null && res . code !== 0 ) { throw new Error ( res . msg ) ; } const data = res != null && typeof res === 'object' && payload . dataKey != null && res [ payload . dataKey ] != null ? res [ payload . dataKey ] : res ; return data ; }