diff --git a/src/modules/crud/api.ts b/src/modules/crud/api.ts index c42d101..bdc44a6 100644 --- a/src/modules/crud/api.ts +++ b/src/modules/crud/api.ts @@ -1,4 +1,4 @@ -import { Connection, TestRequest, ConnectionPoolType, SocketResult } from './crud.typings'; +import { Connection, TestRequest, ConnectionPoolType, SocketResult, ResultType } from './crud.typings'; export interface Api { /** @@ -9,24 +9,24 @@ export interface Api { /** * 获取已添加的数据连接 */ - getConnectionlist(): Promise<{data: Connection[]}>; + getConnectionlist(): Promise<{data?: Connection[]}>; /** * 删除数据连接 * @param connectionName 数据连接名称 */ - deleteConnection(connectionName: string): Promise<{data: string}>; + deleteConnection(connectionName: string): Promise; /** * 添加数据连接 * @param data */ - addConnection(data: Connection): Promise<{data: string}>; + addConnection(data: Connection): Promise; /** * 更新数据连接 */ - updateConnection(data: Connection): Promise<{data: string}>; + updateConnection(data: Connection): Promise; /** * 测试数据连接 @@ -38,7 +38,7 @@ export interface Api { * 获取连接池数据 * @param name */ - getConnectionPool(name: string): Promise<{data: ConnectionPoolType}>; + getConnectionPool(name: string): Promise<{data?: ConnectionPoolType}>; /** * 获取连接状态 diff --git a/src/modules/crud/crud.service.ts b/src/modules/crud/crud.service.ts index 72f85d1..5c54fbe 100644 --- a/src/modules/crud/crud.service.ts +++ b/src/modules/crud/crud.service.ts @@ -1,6 +1,6 @@ import 'es6-promise/auto'; import axios, { AxiosResponse, AxiosError } from 'axios'; -import { CrudReqOpts, CrudParams } from './crud.typings.d'; +import { CrudReqOpts, CrudParams, ResultType } from './crud.typings.d'; import { ReqPrefix } from '../constants/env'; const defaultHeaders = { 'Content-Type': 'application/json', @@ -39,7 +39,7 @@ function getCookieByName(name: string):string { return value; } -export async function request(reqOptions: CrudReqOpts = {}) { +export async function request(reqOptions: CrudReqOpts = {}): Promise { const { url, type, headers, data, params } = reqOptions; return axios diff --git a/src/modules/crud/crud.typings.d.ts b/src/modules/crud/crud.typings.d.ts index 2b9d8c4..0e3ecf6 100644 --- a/src/modules/crud/crud.typings.d.ts +++ b/src/modules/crud/crud.typings.d.ts @@ -210,3 +210,9 @@ export interface SocketResult { errorCode?: string; errorMsg?: string; } + +export interface ResultType { + data?: any; + errorCode?: string; + errorMsg?: string; +} diff --git a/src/modules/crud/decision.api.ts b/src/modules/crud/decision.api.ts index bf7651c..1bf5e55 100644 --- a/src/modules/crud/decision.api.ts +++ b/src/modules/crud/decision.api.ts @@ -6,17 +6,17 @@ import { editStatusEvent } from '@constants/env'; export class DecisionApi implements Api { isDec = true; - getConnectionlist(): Promise<{data: Connection[]}> { + getConnectionlist(): Promise<{data?: Connection[]}> { return requestGet('list'); } - deleteConnection(connectionName: string): Promise<{data: string}> { + deleteConnection(connectionName: string) { return requestDelete('', { connectionName, }); } - addConnection(data: Connection): Promise<{data: string}> { + addConnection(data: Connection) { const form = { ...data, connectionId: data.connectionName, @@ -26,7 +26,7 @@ export class DecisionApi implements Api { return requestPost('', form); } - updateConnection(data: Connection): Promise<{data: string}> { + updateConnection(data: Connection) { const form = { ...data, connectionData : JSON.stringify(data.connectionData), @@ -44,7 +44,7 @@ export class DecisionApi implements Api { return requestPost('test', form); } - getConnectionPool(name: string): Promise<{data: ConnectionPoolType}> { + getConnectionPool(name: string): Promise<{data?: ConnectionPoolType}> { return requestGet(`pool/info?connectionName=${name}`); } diff --git a/src/modules/pages/maintain/forms/form.model.ts b/src/modules/pages/maintain/forms/form.model.ts index 018a679..a41f4dd 100644 --- a/src/modules/pages/maintain/forms/form.model.ts +++ b/src/modules/pages/maintain/forms/form.model.ts @@ -22,7 +22,14 @@ export class MaintainFormModel extends Model<{ actions = { addConnection: (data: Connection) => { - api.addConnection(data).then(() => { + api.addConnection(data).then(result => { + if (result.errorCode) { + BI.Msg.toast(BI.i18nText(result.errorMsg), { + level: 'error', + }); + + return; + } this.model.pageIndex = PAGE_INDEX.CONNECTION; }); },