From 6f8343bdffecdd00cd9ce06aef4575182cc41b1e Mon Sep 17 00:00:00 2001 From: alan Date: Mon, 14 Oct 2019 09:42:35 +0800 Subject: [PATCH] undefined([object Object]): --- assets/scripts/dec.js | 3 +++ i18n/zh_cn.properties | 1 + private/i18n.ts | 1 + src/modules/constants/env.ts | 3 +++ src/modules/crud/crud.service.ts | 32 ++++++++++++++++++++++---------- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/assets/scripts/dec.js b/assets/scripts/dec.js index a9a806e..7e9ad92 100644 --- a/assets/scripts/dec.js +++ b/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: { diff --git a/i18n/zh_cn.properties b/i18n/zh_cn.properties index 1f0edee..4154eed 100644 --- a/i18n/zh_cn.properties +++ b/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= 年月日 diff --git a/private/i18n.ts b/private/i18n.ts index 1fdf08b..77be638 100644 --- a/private/i18n.ts +++ b/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': '年月日', diff --git a/src/modules/constants/env.ts b/src/modules/constants/env.ts index 8095b92..3030fbb 100644 --- a/src/modules/constants/env.ts +++ b/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; diff --git a/src/modules/crud/crud.service.ts b/src/modules/crud/crud.service.ts index c67636e..ce0872a 100644 --- a/src/modules/crud/crud.service.ts +++ b/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 { const { url, type, headers, data, params } = reqOptions; @@ -57,15 +77,7 @@ export async function request(reqOptions: CrudReqOpts = {}): Promise 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); });