From 1bcfada0497f421d7b1f5943c2f55f246b36d703 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=2EKing-=E7=8E=8B=E5=87=AF=E5=A3=AE?= Date: Fri, 8 Sep 2023 19:05:26 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-102763=20fix:=E3=80=90=E5=BC=80=E4=B8=AA?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E3=80=91=E6=95=B0=E6=8D=AE=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=AF=B9=E6=8E=A5=E4=B8=9A=E5=8A=A1=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 67 +++++++++++++-- src/modules/app.model.ts | 3 +- src/modules/app.typings.d.ts | 1 + .../pages/connection/connection.model.ts | 3 + src/modules/pages/connection/connection.ts | 10 ++- .../pages/connection/list/list.constant.ts | 1 + .../pages/connection/list/list.model.ts | 4 +- src/modules/pages/connection/list/list.ts | 2 + .../connection/list/list_item/list_item.ts | 5 +- .../pages/database/database.constant.ts | 18 +++++ src/modules/pages/database/database.ts | 28 +++---- .../database/database_type/database_type.ts | 3 + .../maintain/forms/components/form.plugin.ts | 16 ++++ .../pages/maintain/forms/form.model.ts | 1 + src/modules/pages/maintain/forms/form.ts | 81 +++++++++++++------ src/modules/title/title.model.ts | 3 +- .../title_maintain/title_maintain.model.ts | 3 +- .../title/title_maintain/title_maintain.ts | 13 +++ 18 files changed, 200 insertions(+), 62 deletions(-) create mode 100644 src/modules/pages/connection/list/list.constant.ts create mode 100644 src/modules/pages/database/database.constant.ts diff --git a/README.md b/README.md index 50cd82d..5f46124 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,8 @@ BI.config("dec.connection.provider.datebase", function (provider) { 版本和平台保持一致 ## 接口文档: -### 增加数据连接类型 +### A 增加数据连接类型 +#### 1. 增加数据连接类型 使用`BI.config`,ConstantName名称为`dec.constant.database.conf.connect.types`,值为连接的名称 例如增加`Redis`的连接: @@ -128,25 +129,25 @@ BI.config(ConstantPluginTyps, (datas: string[]) => [...datas, { }]); ``` -### 数据连接填写页面 +#### 2. 数据连接填写页面 edit属性值为填写组件shortcut的名称 -### 数据连接展示页面 +#### 3. 数据连接展示页面 show属性值为组件shortcut的名称 -### 示例 -``` +#### 4. 示例 +```js const DataBaseConfigProvider = 'dec.connection.provider.datebase'; const RedisShowName = 'dec.dcm.connection.plugin.redis.show'; const RedisEditName = 'dec.dcm.connection.plugin.redis.edit'; BI.config(DataBaseConfigProvider, function (provider) { - provider.registerDatabaseType({ + provider.registerDatabaseType([{ text: "Redis", databaseType: "Redis", edit: "dec.dcm.connection.plugin.demo.edit", show: "dec.dcm.connection.plugin.demo.show", - }); + }]); }); const RedisShow = BI.inherit(BI.Widget, { @@ -214,7 +215,22 @@ const RedisShow = BI.inherit(BI.Widget, { ], }, ], - }; + }, + mounted() { + this.fireEvent('EVENT_HIDE_TEST_CONNECTION', true);//可以触发隐藏测试按钮 + }, + //可以触发组件的数据save方法,不需要则可不写 + async save() { + let result = 0; + await Promise.resolve().then(() => {result = 1}); + //要求返回是否成功的boolean变量 + return result; + }, + //可以阻止触发平台保存数据的方法 + preventParentSave() { + return true; + } + }, }); BI.shortcut(RedisShowName, RedisShow); @@ -313,3 +329,38 @@ const RedisEdit = BI.inherit(BI.Widget, { BI.shortcut(RedisEditName, RedisEdit); ``` +### B 添加数据连接实例 +#### 1. 增加数据连接 +```js +BI.config('dec.constant.connection.list', function (value) { + const result = [{ + "connectionType": "Redis",//和databaseType一致 + "connectionName": "CHART",//类似于id,唯一性 + "pluginConnection": true,//表示是外来添加的插件 + "connectionData": { + //表单保存数据 + }, + "connectionId": null, + }]; + return value.concat(result); + }) +``` +### C 添加数据连接类型分类 +#### 1. 添加分类DEMO +```js +BI.config('dec.constant.database.filter.type', (value) => { + value.push({text:"DEMO", value:"DEMO_VALUE"});return value; + }); +``` +#### 2. 添加数据连接类型进DEMO +```js + BI.config('dec.connection.provider.datebase', function (provider) { + text: "Redis",//必填 + databaseType: "Redis",//唯一值 + marker: 'DEMO_VALUE',//marker对标dec.constant.database.filter.type常量item的value,用于过滤 + iconUrl:'https://work.fineres.com/secure/projectavatar?pid=10301&avatarId=10011', + driver: 'com.amazon.redshift.jdbc41.Driver', + drivers: ['com.amazon.redshift.jdbc4.Driver', 'com.amazon.redshift.jdbc41.Driver'], + url: 'jdbc:redshift://endpoint:port/database', + } +``` diff --git a/src/modules/app.model.ts b/src/modules/app.model.ts index 200800c..01b74b5 100644 --- a/src/modules/app.model.ts +++ b/src/modules/app.model.ts @@ -7,7 +7,7 @@ import { getAllDatabaseTypes } from './app.service'; export class AppModel extends Model { static xtype = 'dec.dcm.model.main'; - childContext = ['pageIndex', 'datebaseTypeSelected', 'datebaseTypeSelectedOne', 'filter', 'connections', 'connectionSelected', 'connectionSelectedOne', 'saveEvent', 'testEvent', 'isCopy', 'connectionLicInfo']; + childContext = ['pageIndex', 'datebaseTypeSelected', 'datebaseTypeSelectedOne', 'filter', 'connections', 'connectionSelected', 'connectionSelectedOne', 'saveEvent', 'testEvent', 'isCopy', 'connectionLicInfo', 'noTestConnection']; state() { return { @@ -23,6 +23,7 @@ export class AppModel extends Model { currentConnectionNum: 0, maxConnectionNum: 0, }, + noTestConnection: false, }; } diff --git a/src/modules/app.typings.d.ts b/src/modules/app.typings.d.ts index f4d0fda..c0c9320 100644 --- a/src/modules/app.typings.d.ts +++ b/src/modules/app.typings.d.ts @@ -17,4 +17,5 @@ export interface DatabaseType { urls?: { [key: string]: string; }; + marker?: string; } diff --git a/src/modules/pages/connection/connection.model.ts b/src/modules/pages/connection/connection.model.ts index f037865..ea7db71 100644 --- a/src/modules/pages/connection/connection.model.ts +++ b/src/modules/pages/connection/connection.model.ts @@ -53,6 +53,9 @@ export class ConnectionModel extends Model<{ this.model.connectionSelected = name; }, getConnectionStatus() { + if (this.model.connectionSelectedOne.pluginConnection) { + return Promise.resolve(); + } return api.getConnectionStatus(this.model.connectionSelected); }, checkConnectionLic() { diff --git a/src/modules/pages/connection/connection.ts b/src/modules/pages/connection/connection.ts index 048eb6d..d540199 100644 --- a/src/modules/pages/connection/connection.ts +++ b/src/modules/pages/connection/connection.ts @@ -137,9 +137,8 @@ export class Connection extends BI.Widget { }, handler: () => { this.store.getConnectionStatus() - .then(re => { - this.store.setPageIndex(PAGE_INDEX.MAINTAIN); - this.store.setDatebaseTypeSelected(''); + .then(() => { + this.setMaintainPage(); }) .catch(() => { }); @@ -239,4 +238,9 @@ export class Connection extends BI.Widget { return databaseType; } + + private setMaintainPage() { + this.store.setPageIndex(PAGE_INDEX.MAINTAIN); + this.store.setDatebaseTypeSelected(''); + } } diff --git a/src/modules/pages/connection/list/list.constant.ts b/src/modules/pages/connection/list/list.constant.ts new file mode 100644 index 0000000..fa5112c --- /dev/null +++ b/src/modules/pages/connection/list/list.constant.ts @@ -0,0 +1 @@ +BI.constant('dec.constant.connection.list', []); \ No newline at end of file diff --git a/src/modules/pages/connection/list/list.model.ts b/src/modules/pages/connection/list/list.model.ts index 5d650e9..60f3fa6 100644 --- a/src/modules/pages/connection/list/list.model.ts +++ b/src/modules/pages/connection/list/list.model.ts @@ -21,10 +21,10 @@ export class ConnectionListModel extends Model<{ actions = { setConnections: ():Promise => api.getConnectionList().then(data => { if (BI.size(data.data) > 0) { - this.model.connections = data.data; + this.model.connections = data.data.concat(BI.Constants.getConstant('dec.constant.connection.list')); this.model.connections.forEach(item => { // 后端传过来的是字符串,转为对象 - item.connectionData = JSON.parse(item.connectionData as string); + BI.isString(item.connectionData) && (item.connectionData = JSON.parse(item.connectionData as string)); }); this.model.connectionSelected = data.data[0].connectionName; } else { diff --git a/src/modules/pages/connection/list/list.ts b/src/modules/pages/connection/list/list.ts index f674dab..8ffa81c 100644 --- a/src/modules/pages/connection/list/list.ts +++ b/src/modules/pages/connection/list/list.ts @@ -3,6 +3,7 @@ import { ListItem } from './list_item/list_item'; import { ConnectionListModel } from './list.model'; import { getDatabaseType } from './list.service'; import { Tab } from '@fui/core'; +import './list.constant' @shortcut() @store(ConnectionListModel) @@ -91,6 +92,7 @@ export class ConnectionList extends BI.Pane { creator: item.creator, databaseType: getDatabaseType(item), selected: this.model.connectionSelected ? this.model.connectionSelected === item.connectionName : index === 0, + pluginConnection: item.pluginConnection, }; }); } diff --git a/src/modules/pages/connection/list/list_item/list_item.ts b/src/modules/pages/connection/list/list_item/list_item.ts index 6723947..2d1fc0f 100644 --- a/src/modules/pages/connection/list/list_item/list_item.ts +++ b/src/modules/pages/connection/list/list_item/list_item.ts @@ -20,6 +20,7 @@ export class ListItem extends BI.BasicButton { name: '', creator: '', databaseType: '', + pluginConnection: false, height: 25, baseCls: 'dec-dcm-connection-list-item bi-list-item-active2', $testId: 'dec-dcm-connection-list-item', @@ -43,7 +44,7 @@ export class ListItem extends BI.BasicButton { }; render() { - const { name, databaseType } = this.options; + const { name, databaseType, pluginConnection } = this.options; return { type: BI.HTapeLayout.xtype, @@ -118,7 +119,7 @@ export class ListItem extends BI.BasicButton { }, ], }, { - el: databaseType ? { + el: databaseType && !pluginConnection ? { type: BI.DownListCombo.xtype, cls: 'link-item-icon', stopPropagation: true, diff --git a/src/modules/pages/database/database.constant.ts b/src/modules/pages/database/database.constant.ts new file mode 100644 index 0000000..0926244 --- /dev/null +++ b/src/modules/pages/database/database.constant.ts @@ -0,0 +1,18 @@ +import { DATEBASE_FILTER_TYPE } from "@constants/constant"; + +console.log('contant'); +BI.constant('dec.constant.database.filter.type', [ + { + text: BI.i18nText('Dec-Dcm_Connection_Commonly'), + value: DATEBASE_FILTER_TYPE.COMMONLY, + selected: true, + }, + { + text: BI.i18nText('Dec-Dcm_Connection_All'), + value: DATEBASE_FILTER_TYPE.ALL, + }, + { + text: BI.i18nText('Dec-Dcm_Connection_Other'), + value: DATEBASE_FILTER_TYPE.OTHER, + }, +]); \ No newline at end of file diff --git a/src/modules/pages/database/database.ts b/src/modules/pages/database/database.ts index f905765..85a4a3b 100644 --- a/src/modules/pages/database/database.ts +++ b/src/modules/pages/database/database.ts @@ -7,6 +7,7 @@ import { DatebaseType } from './database_type/database_type'; import { getAllDatabaseTypes } from '../../app.service'; import { ButtonGroup, MultiSelectItem, SearchEditor } from '@fui/core'; import { ApiFactory } from 'src/modules/crud/apiFactory'; +import './database.constant' const api = new ApiFactory().create(); @@ -121,24 +122,12 @@ export class Datebase extends BI.Widget { ref: (_ref: ButtonGroup) => { this.filter = _ref; }, - items: [ - { + items: () => BI.map(BI.Constants.getConstant('dec.constant.database.filter.type'), (_, value) => { + return { type: Filter.xtype, - text: BI.i18nText('Dec-Dcm_Connection_Commonly'), - value: DATEBASE_FILTER_TYPE.COMMONLY, - selected: true, - }, - { - type: Filter.xtype, - text: BI.i18nText('Dec-Dcm_Connection_All'), - value: DATEBASE_FILTER_TYPE.ALL, - }, - { - type: Filter.xtype, - text: BI.i18nText('Dec-Dcm_Connection_Other'), - value: DATEBASE_FILTER_TYPE.OTHER, - }, - ], + ...value, + } + }), }, width: 200, }, @@ -254,9 +243,12 @@ export class Datebase extends BI.Widget { case DATEBASE_FILTER_TYPE.OTHER: this.store.setDatebaseTypes(this.allDatabaseTypes.filter(item => this.model.otherDatabases.includes(item.type))); break; - default: + case DATEBASE_FILTER_TYPE.ALL: this.store.setDatebaseTypes(this.allDatabaseTypes.filter(item => item.type !== connectionType.JNDI && item.type !== OTHER_JDBC)); break; + default: + this.store.setDatebaseTypes(this.allDatabaseTypes.filter(item => item.marker && (item.marker === filter))); + break; } } diff --git a/src/modules/pages/database/database_type/database_type.ts b/src/modules/pages/database/database_type/database_type.ts index 6778564..3170b3b 100644 --- a/src/modules/pages/database/database_type/database_type.ts +++ b/src/modules/pages/database/database_type/database_type.ts @@ -88,6 +88,9 @@ export class DatebaseType extends BI.BasicButton { if (url.startsWith('/')) { return `${PluginImgPrefix}${url}`; } + if (url.startsWith('http')) { + return url; + } return `${PluginImgPrefix}/${url}`; } diff --git a/src/modules/pages/maintain/forms/components/form.plugin.ts b/src/modules/pages/maintain/forms/components/form.plugin.ts index 6282203..b3eba0c 100644 --- a/src/modules/pages/maintain/forms/components/form.plugin.ts +++ b/src/modules/pages/maintain/forms/components/form.plugin.ts @@ -5,6 +5,8 @@ import { getPluginWidgetEdit } from '../../../../app.service'; @shortcut() export class FormPlugin extends BI.Widget { static xtype = 'dec.dcm.maintain_plugin'; + static EVENTNOTEST = 'EVENT_HIDE_TEST_CONNECTION'; + static PREVENTPARENTSAVE = 'EVENT_PREVENT_PARENT_SAVE'; props = { formData: {} as Connection, }; @@ -24,6 +26,12 @@ export class FormPlugin extends BI.Widget { connectionId, connectionType, connectionName, + listeners: [{ + eventName: FormPlugin.EVENTNOTEST, + action: (value: boolean) => { + this.fireEvent(FormPlugin.EVENTNOTEST, value); + } + }] }; } @@ -37,4 +45,12 @@ export class FormPlugin extends BI.Widget { connectionData: BI.extend({}, connectionData, this.plugin.getValue()), }; } + + public save() { + return this.plugin.save; + } + + public preventParentSave() { + return this.plugin.preventParentSave ? this.plugin.preventParentSave() : false; + } } diff --git a/src/modules/pages/maintain/forms/form.model.ts b/src/modules/pages/maintain/forms/form.model.ts index 3bbc66e..ec76932 100644 --- a/src/modules/pages/maintain/forms/form.model.ts +++ b/src/modules/pages/maintain/forms/form.model.ts @@ -31,6 +31,7 @@ export class MaintainFormModel extends Model<{ 'testEvent', 'connections', 'isCopy', + 'noTestConnection', ]; actions = { diff --git a/src/modules/pages/maintain/forms/form.ts b/src/modules/pages/maintain/forms/form.ts index 4039f81..a48bfc5 100644 --- a/src/modules/pages/maintain/forms/form.ts +++ b/src/modules/pages/maintain/forms/form.ts @@ -14,6 +14,8 @@ import { checkIllegalStrings } from "@core/index"; @store(MaintainFormModel) export class MaintainForm extends BI.Widget { static xtype = 'dec.dcm.maintain.form'; + static TESTCONNECTION = 'EVENT_TEST_CONNECTION'; + static EVENTNOTEST = 'EVENT_HIDE_TEST_CONNECTION'; props = { connectionType: '', @@ -29,34 +31,25 @@ export class MaintainForm extends BI.Widget { watch = { saveEvent: () => { - if (!this.testValue()) { - return; - } - if (this.connectionName && !this.model.isCopy) { - const value = this.form.getSubmitValue(); - (value.connectionData as ConnectionJDBC).creator = BI.get(this.getFormData(), 'creator'); - // DEC-10155 为了适配插件的数据连接,在外层也加一个creator字段 - value.creator = BI.get(this.getFormData(), 'creator'); - this.store.updateConnection(this.connectionName, value).then(result => { - if (result.errorCode) { - if (result.errorCode === DecCst.ErrorCode.NO_IP_AUTHORIZED) { - BI.Msg.toast(BI.i18nText("Dec-Basic_Save_Fail"), { - level: "error", - }); - } - this.showError(result); - - return; + const sonSave = this.form.save?.(); + if (sonSave) { + sonSave().then((success: Boolean) => { + if (success) { + BI.Msg.toast(BI.i18nText("Dec-Basic_Save_Success"), { + level: "success", + }); + } else { + BI.Msg.toast(BI.i18nText("Dec-Basic_Save_Fail"), { + level: "error", + }); } - this.store.goFirstPage(); }); - } else { - const form = this.form.getSubmitValue(); - form.connectionId = this.connectionName; - // DEC-10155 为了适配插件的数据连接,在外层也加一个creator字段 - form.creator = Dec ? Dec.personal.username : ''; - this.addConnection(form); + + if (this.form.preventParentSave()) { + return; + } } + this.save(); }, testEvent: () => { this.testConnection(); @@ -77,10 +70,15 @@ export class MaintainForm extends BI.Widget { this.form = _ref; }, listeners: [{ - eventName: 'EVENT_TEST_CONNECTION', + eventName: MaintainForm.TESTCONNECTION, action: () => { this.testConnection(); }, + }, { + eventName: MaintainForm.EVENTNOTEST, + action: (value: boolean) => { + this.model.noTestConnection = value; + } }], }; } @@ -295,4 +293,35 @@ export class MaintainForm extends BI.Widget { this.store.setIsCopy(false); }); } + + private save() { + if (!this.testValue()) { + return; + } + if (this.connectionName && !this.model.isCopy) { + const value = this.form.getSubmitValue(); + (value.connectionData as ConnectionJDBC).creator = BI.get(this.getFormData(), 'creator'); + // DEC-10155 为了适配插件的数据连接,在外层也加一个creator字段 + value.creator = BI.get(this.getFormData(), 'creator'); + this.store.updateConnection(this.connectionName, value).then(result => { + if (result.errorCode) { + if (result.errorCode === DecCst.ErrorCode.NO_IP_AUTHORIZED) { + BI.Msg.toast(BI.i18nText("Dec-Basic_Save_Fail"), { + level: "error", + }); + } + this.showError(result); + + return; + } + this.store.goFirstPage(); + }); + } else { + const form = this.form.getSubmitValue(); + form.connectionId = this.connectionName; + // DEC-10155 为了适配插件的数据连接,在外层也加一个creator字段 + form.creator = Dec ? Dec.personal.username : ''; + this.addConnection(form); + } + } } diff --git a/src/modules/title/title.model.ts b/src/modules/title/title.model.ts index 737c324..6cb2fe8 100644 --- a/src/modules/title/title.model.ts +++ b/src/modules/title/title.model.ts @@ -6,12 +6,13 @@ export class TitleModel extends Model<{ types: { pageIndex: AppModel['TYPE']['pageIndex']; datebaseTypeSelected: AppModel['TYPE']['datebaseTypeSelected']; + noTestConnection: AppModel['TYPE']['noTestConnection']; }, context: TitleModel['context']; }> { static xtype = 'dec.dcm.model.title'; - context = ['pageIndex', 'datebaseTypeSelected'] + context = ['pageIndex', 'datebaseTypeSelected', 'noTestConnection'] actions = { setPageIndex: (index: string) => { diff --git a/src/modules/title/title_maintain/title_maintain.model.ts b/src/modules/title/title_maintain/title_maintain.model.ts index 21fd87a..c3bc416 100644 --- a/src/modules/title/title_maintain/title_maintain.model.ts +++ b/src/modules/title/title_maintain/title_maintain.model.ts @@ -11,12 +11,13 @@ export class TitleMaintainModel extends Model<{ connectionSelected: AppModel['TYPE']['connectionSelected']; testEvent: AppModel['TYPE']['testEvent']; isCopy: AppModel['TYPE']['isCopy']; + noTestConnection: AppModel['TYPE']['noTestConnection']; }, context: TitleMaintainModel['context']; }> { static xtype = 'dec.dcm.model.title_maintain'; - context = ['pageIndex', 'saveEvent', 'testEvent', 'connectionSelected', 'isCopy']; + context = ['pageIndex', 'saveEvent', 'testEvent', 'connectionSelected', 'isCopy', 'noTestConnection']; actions = { setPageIndex: (index: string) => { diff --git a/src/modules/title/title_maintain/title_maintain.ts b/src/modules/title/title_maintain/title_maintain.ts index b121cf1..7107fe9 100644 --- a/src/modules/title/title_maintain/title_maintain.ts +++ b/src/modules/title/title_maintain/title_maintain.ts @@ -1,6 +1,7 @@ import { shortcut, store } from '@core/core'; import { TitleMaintainModel } from './title_maintain.model'; import { PAGE_INDEX } from '@constants/constant'; +import { Button } from '@fui/core'; @shortcut() @store(TitleMaintainModel) @@ -9,6 +10,14 @@ export class TitleMaintain extends BI.Widget { store: TitleMaintainModel['store']; model: TitleMaintainModel['model']; + testConnectionBtn: Button; + + watch = { + noTestConnection: function (value) { + this.testConnectionBtn.setVisible(!value); + } + } + render() { return { type: BI.FloatRightLayout.xtype, @@ -30,6 +39,9 @@ export class TitleMaintain extends BI.Widget { }, { type: BI.Button.xtype, + ref: (_ref) => { + this.testConnectionBtn = _ref; + }, _rgap: 16, $value: 'title-maintain-connection-test', text: BI.i18nText('Dec-Dcm_Connection_Test'), @@ -57,5 +69,6 @@ export class TitleMaintain extends BI.Widget { window.onunload = () => { this.store.shutdownConnectionStatus(); }; + this.testConnectionBtn.setVisible(!this.model.noTestConnection); } }