|
|
@@ -1,7 +1,10 @@ |
|
|
|
import { message } from 'antd'; |
|
|
|
import { request } from 'umi'; |
|
|
|
import { parseRequest } from './request.config'; |
|
|
|
import { firstCharToLowerCase, handleRequest } from './tool'; |
|
|
|
import { errorReponse, firstCharToLowerCase, handleRequest } from './tool'; |
|
|
|
|
|
|
|
const remoteUrl = window.systemConfig?.remoteUrl || ''; |
|
|
|
const gatewayPort = window.systemConfig?.gatewayPort || 0; |
|
|
|
|
|
|
|
export async function fetchApi<T = any>( |
|
|
|
path: string, |
|
|
@@ -10,8 +13,30 @@ export async function fetchApi<T = any>( |
|
|
|
) { |
|
|
|
const [method, fullpath] = parseRequest(path); |
|
|
|
const { silent, ...restOptions } = options; |
|
|
|
const res = await request<API.ResponseData<T>>(`${remoteUrl}${fullpath}`, { |
|
|
|
method, |
|
|
|
[method === 'GET' ? 'params' : 'data']: params, |
|
|
|
...restOptions, |
|
|
|
}); |
|
|
|
if (!silent) { |
|
|
|
handleRequest(res).error(() => { |
|
|
|
message.error(res.message); |
|
|
|
}); |
|
|
|
} |
|
|
|
return res; |
|
|
|
} |
|
|
|
|
|
|
|
export async function fetchLocalApi<T = any>( |
|
|
|
path: string, |
|
|
|
params = {}, |
|
|
|
options = { silent: false, method: 'GET' }, |
|
|
|
) { |
|
|
|
if (!gatewayPort) { |
|
|
|
return errorReponse('gateway infomation failed'); |
|
|
|
} |
|
|
|
const { silent, method = 'GET', ...restOptions } = options; |
|
|
|
const res = await request<API.ResponseData<T>>( |
|
|
|
`${global.URL_PREFIX || ''}${fullpath}`, |
|
|
|
`http://127.0.0.1:${gatewayPort}/api/${path}`, |
|
|
|
{ method, [method === 'GET' ? 'params' : 'data']: params, ...restOptions }, |
|
|
|
); |
|
|
|
if (!silent) { |
|
|
|