import axios from 'axios' ; import { print , getGlobalInfo } from '@arco-design/arco-dev-utils' ; const ARCO_TOKEN = 'x-arco-token' ; const request = ( method , { url , data = { } , option = { } , } ) => { const cliConfig = getGlobalInfo ( ) ; const instance = axios . create ( { baseURL : `${ cliConfig . host . arco }/material/api/` , } ) ; option . headers = { ... option . headers , [ ARCO_TOKEN ] : ( option . headers && option . headers [ ARCO_TOKEN ] ) || ( cliConfig && cliConfig [ ARCO_TOKEN ] ) || '' , 'x-arco-dev' : '1' , } ; const req = method === 'get' || method === 'delete' ? instance [ method ] ( url , option ) : instance [ method ] ( url , data , option ) ; return req . then ( ( res ) => { return res . data ; } ) . catch ( ( err ) => { print . error ( err ) ; return Promise . reject ( err ) ; } ) ; } ; export default { all : ( arr ) => { return axios . all ( arr ) ; } , get : ( url , option ? ) => request ( 'get' , { url , option } ) , delete : ( url , option ? ) => request ( 'delete' , { url , option } ) , post : ( url , data ? , option ? ) => request ( 'post' , { url , option , data } ) , put : ( url , data ? , option ? ) => request ( 'put' , { url , option , data } ) , } ;