import { RequestConfig } from 'umi' ; import { getToken , getSocketId } from '@/utils/authority' ; export const request = { timeout : 30000 , prefix : '/api/' , credentials : 'omit' , headers : { Accept : 'application/json' , 'Content-Type' : 'application/json; charset=utf-8' , 'X-Socket-ID' : getSocketId ( ) , } , errorConfig : { adaptor : ( resData ) => ( { ... resData , errorMessage : resData . message , } ) , } , middlewares : [ async function withToken ( ctx , next ) { ctx . req . options . headers = { ... ctx . req . options . headers , Authorization : `Bearer ${ getToken ( ) }` , } ; await next ( ) ; } , ] , } ; export const dva = { config : { onError ( e ) { e . preventDefault ( ) ; } , } , } ; let lastPathname = '' ; export function onRouteChange ( { location } ) { if ( lastPathname !== location . pathname ) { window . scrollTo ( 0 , 0 ) ; lastPathname = location . pathname ; } }