|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
import 'es6-promise/auto'; |
|
|
|
|
import axios, { AxiosResponse, AxiosError } from 'axios'; |
|
|
|
|
import { CrudReqOpts, CrudParams, ResultType } from './crud.typings.d'; |
|
|
|
|
import { ReqPrefix } from '../constants/env'; |
|
|
|
|
import { ReqPrefix, errorCode } from '../constants/env'; |
|
|
|
|
const defaultHeaders = { |
|
|
|
|
'Content-Type': 'application/json', |
|
|
|
|
'X-Requested-With': 'XMLHttpRequest', |
|
|
|
@ -39,6 +39,26 @@ function getCookieByName(name: string):string {
|
|
|
|
|
return value; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function checkStatus(response: AxiosResponse) { |
|
|
|
|
const status = response.status; |
|
|
|
|
const noLoginErr = [errorCode.LOGIN_INFO_ERROR, errorCode.LOGIN_INFO_NOT_AVAILABLE, errorCode.TIMEOUT]; |
|
|
|
|
|
|
|
|
|
const resData = status === 200 |
|
|
|
|
? typeof response.data === 'string' |
|
|
|
|
? BI.jsonDecode(response.data) |
|
|
|
|
: response.data |
|
|
|
|
: {}; |
|
|
|
|
if (noLoginErr.includes(BI.get(resData, 'errorCode'))) { |
|
|
|
|
BI.Msg.alert(BI.i18nText('BI-Basic_Prompt'), BI.i18nText('Dec-Dcm_Login_Error'), () => { |
|
|
|
|
window.location.reload(true); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
return new Promise(() => {}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return resData; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export async function request(reqOptions: CrudReqOpts = {}): Promise<ResultType> { |
|
|
|
|
const { url, type, headers, data, params } = reqOptions; |
|
|
|
|
|
|
|
|
@ -57,15 +77,7 @@ export async function request(reqOptions: CrudReqOpts = {}): Promise<ResultType>
|
|
|
|
|
paramsSerializer, |
|
|
|
|
data, |
|
|
|
|
}) |
|
|
|
|
.then((response: AxiosResponse) => { |
|
|
|
|
const status = response.status; |
|
|
|
|
|
|
|
|
|
return status === 200 |
|
|
|
|
? typeof response.data === 'string' |
|
|
|
|
? BI.jsonDecode(response.data) |
|
|
|
|
: response.data |
|
|
|
|
: {}; |
|
|
|
|
}) |
|
|
|
|
.then(checkStatus) |
|
|
|
|
.catch((error: AxiosError) => { |
|
|
|
|
console.log(error); |
|
|
|
|
}); |
|
|
|
|