|
|
@ -1,7 +1,7 @@ |
|
|
|
import 'es6-promise/auto'; |
|
|
|
import 'es6-promise/auto'; |
|
|
|
import axios, { AxiosResponse, AxiosError } from 'axios'; |
|
|
|
import axios, { AxiosResponse, AxiosError } from 'axios'; |
|
|
|
import { CrudReqOpts, CrudParams, ResultType } from './crud.typings.d'; |
|
|
|
import { CrudReqOpts, CrudParams, ResultType } from './crud.typings.d'; |
|
|
|
import { ReqPrefix } from '../constants/env'; |
|
|
|
import { ReqPrefix, errorCode } from '../constants/env'; |
|
|
|
const defaultHeaders = { |
|
|
|
const defaultHeaders = { |
|
|
|
'Content-Type': 'application/json', |
|
|
|
'Content-Type': 'application/json', |
|
|
|
'X-Requested-With': 'XMLHttpRequest', |
|
|
|
'X-Requested-With': 'XMLHttpRequest', |
|
|
@ -39,6 +39,26 @@ function getCookieByName(name: string):string { |
|
|
|
return value; |
|
|
|
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> { |
|
|
|
export async function request(reqOptions: CrudReqOpts = {}): Promise<ResultType> { |
|
|
|
const { url, type, headers, data, params } = reqOptions; |
|
|
|
const { url, type, headers, data, params } = reqOptions; |
|
|
|
|
|
|
|
|
|
|
@ -57,15 +77,7 @@ export async function request(reqOptions: CrudReqOpts = {}): Promise<ResultType> |
|
|
|
paramsSerializer, |
|
|
|
paramsSerializer, |
|
|
|
data, |
|
|
|
data, |
|
|
|
}) |
|
|
|
}) |
|
|
|
.then((response: AxiosResponse) => { |
|
|
|
.then(checkStatus) |
|
|
|
const status = response.status; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return status === 200 |
|
|
|
|
|
|
|
? typeof response.data === 'string' |
|
|
|
|
|
|
|
? BI.jsonDecode(response.data) |
|
|
|
|
|
|
|
: response.data |
|
|
|
|
|
|
|
: {}; |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.catch((error: AxiosError) => { |
|
|
|
.catch((error: AxiosError) => { |
|
|
|
console.log(error); |
|
|
|
console.log(error); |
|
|
|
}); |
|
|
|
}); |
|
|
|