Browse Source

undefined([object Object]):

qufenxi
alan 5 years ago
parent
commit
6f8343bdff
  1. 3
      assets/scripts/dec.js
  2. 1
      i18n/zh_cn.properties
  3. 1
      private/i18n.ts
  4. 3
      src/modules/constants/env.ts
  5. 32
      src/modules/crud/crud.service.ts

3
assets/scripts/dec.js

@ -3,6 +3,9 @@ window.DecCst = {
CONNECTION_DELETED: '21300035',
CONNECTION_UNDER_EDIT: '21300034',
DUPLICATE_NAMES: '21300005',
LOGIN_INFO_NOT_AVAILABLE: '21300014',
LOGIN_INFO_ERROR: '21300018',
TIMEOUT: '21300001',
},
Connect: {
ConnectionType: {

1
i18n/zh_cn.properties

@ -111,6 +111,7 @@ Dec-Dcm_Connection_Click_Connect_Database=点击连接数据库
Dec-Dcm_Connection_Read_Mode_List=以读取模式列表
Dec-Dcm_Connection_NO_Connection_Pool=无数据连接,可在数据连接管理页面添加
Dec-Dcm_Connection_Cannot_Too_Lang=文本长度不能大于200个字符
Dec-Dcm_Login_Error=登录信息已失效,请重新登录
BI-Multi_Date_Quarter_End= 季度末
BI-Multi_Date_Month_Begin= 月初
BI-Multi_Date_YMD= 年月日

1
private/i18n.ts

@ -110,6 +110,7 @@ export default {
'Dec-Dcm_Connection_Read_Mode_List': '以读取模式列表',
'Dec-Dcm_Connection_NO_Connection_Pool': '无数据连接,可在数据连接管理页面添加',
'Dec-Dcm_Connection_Cannot_Too_Lang': '文本长度不能大于200个字符',
'Dec-Dcm_Login_Error': '登录信息已失效,请重新登录',
'BI-Multi_Date_Quarter_End': '季度末',
'BI-Multi_Date_Month_Begin': '月初',
'BI-Multi_Date_YMD': '年月日',

3
src/modules/constants/env.ts

@ -17,4 +17,7 @@ export const errorCode: {
CONNECTION_DELETED: string;
CONNECTION_UNDER_EDIT: string;
DUPLICATE_NAMES: string;
LOGIN_INFO_NOT_AVAILABLE: string;
LOGIN_INFO_ERROR: string;
TIMEOUT: string;
} = DecCst.ErrorCode;

32
src/modules/crud/crud.service.ts

@ -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);
});

Loading…
Cancel
Save