diff --git a/src/modules/constants/env.ts b/src/modules/constants/env.ts index 3ddd37c..8095b92 100644 --- a/src/modules/constants/env.ts +++ b/src/modules/constants/env.ts @@ -3,9 +3,15 @@ export const ReqPrefix = `${fineServletURL}/v10/config/connection`; export const ImgPrefix = `${fineServletURL}/resources?path=/com/fr/web/resources/dist/images/2x/icon/database/`; export const PluginImgPrefix = `${fineServletURL}/resources?path=`; -export const connectionType = DecCst.Connect.ConnectionType; +export const connectionType: { + JDBC: string; + JNDI: string; +} = DecCst.Connect.ConnectionType; -export const editStatusEvent = DecCst.Connect.EditStatusEvent; +export const editStatusEvent: { + OPEN: string; + SHUTDOWN: string; +} = DecCst.Connect.EditStatusEvent; export const errorCode: { CONNECTION_DELETED: string; diff --git a/src/modules/pages/maintain/forms/form.ts b/src/modules/pages/maintain/forms/form.ts index 704be55..0952894 100644 --- a/src/modules/pages/maintain/forms/form.ts +++ b/src/modules/pages/maintain/forms/form.ts @@ -46,15 +46,7 @@ export class MaintainForm extends BI.Widget { form.connectionId = this.connectionName; // DEC-10155 为了适配插件的数据连接,在外层也加一个creator字段 form.creator = Dec ? Dec.personal.username : ''; - this.store.addConnection(form).then(result => { - if (result.errorCode) { - this.showError(result); - - return; - } - this.store.goFirstPage(); - this.store.setIsCopy(false); - }); + this.addConnection(form); } }, testEvent: () => { @@ -252,4 +244,32 @@ export class MaintainForm extends BI.Widget { this.form.setSchemas(re); }); } + + private addConnection(form: Connection) { + this.store.addConnection(form).then(result => { + if (result.errorCode) { + if (result.errorCode === errorCode.DUPLICATE_NAMES) { + if (form.connectionType !== connectionType.JDBC && form.connectionType !== connectionType.JNDI) { + // 如果不是jdbc或jndi,即如果是插件,名称重复的时候需要修改名字重新提交给后台 + const newName = `${form.connectionName}${Math.floor(Math.random() * 10)}`; + form.connectionName = newName; + if (!this.model.isCopy) { + form.connectionId = newName; + } + this.addConnection(form); + } else { + this.setFromError(result.errorMsg); + } + } else { + BI.Msg.toast(BI.i18nText(result.errorMsg), { + level: 'error', + }); + } + + return; + } + this.store.goFirstPage(); + this.store.setIsCopy(false); + }); + } }