Browse Source

REPORT-102763 fix:【开个接口】数据连接支持对接业务系统

feature/x
parent
commit
1bcfada049
  1. 67
      README.md
  2. 3
      src/modules/app.model.ts
  3. 1
      src/modules/app.typings.d.ts
  4. 3
      src/modules/pages/connection/connection.model.ts
  5. 10
      src/modules/pages/connection/connection.ts
  6. 1
      src/modules/pages/connection/list/list.constant.ts
  7. 4
      src/modules/pages/connection/list/list.model.ts
  8. 2
      src/modules/pages/connection/list/list.ts
  9. 5
      src/modules/pages/connection/list/list_item/list_item.ts
  10. 18
      src/modules/pages/database/database.constant.ts
  11. 28
      src/modules/pages/database/database.ts
  12. 3
      src/modules/pages/database/database_type/database_type.ts
  13. 16
      src/modules/pages/maintain/forms/components/form.plugin.ts
  14. 1
      src/modules/pages/maintain/forms/form.model.ts
  15. 81
      src/modules/pages/maintain/forms/form.ts
  16. 3
      src/modules/title/title.model.ts
  17. 3
      src/modules/title/title_maintain/title_maintain.model.ts
  18. 13
      src/modules/title/title_maintain/title_maintain.ts

67
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`,值为连接的名称 使用`BI.config`,ConstantName名称为`dec.constant.database.conf.connect.types`,值为连接的名称
例如增加`Redis`的连接: 例如增加`Redis`的连接:
@ -128,25 +129,25 @@ BI.config(ConstantPluginTyps, (datas: string[]) => [...datas, {
}]); }]);
``` ```
### 数据连接填写页面 #### 2. 数据连接填写页面
edit属性值为填写组件shortcut的名称 edit属性值为填写组件shortcut的名称
### 数据连接展示页面 #### 3. 数据连接展示页面
show属性值为组件shortcut的名称 show属性值为组件shortcut的名称
### 示例 #### 4. 示例
``` ```js
const DataBaseConfigProvider = 'dec.connection.provider.datebase'; const DataBaseConfigProvider = 'dec.connection.provider.datebase';
const RedisShowName = 'dec.dcm.connection.plugin.redis.show'; const RedisShowName = 'dec.dcm.connection.plugin.redis.show';
const RedisEditName = 'dec.dcm.connection.plugin.redis.edit'; const RedisEditName = 'dec.dcm.connection.plugin.redis.edit';
BI.config(DataBaseConfigProvider, function (provider) { BI.config(DataBaseConfigProvider, function (provider) {
provider.registerDatabaseType({ provider.registerDatabaseType([{
text: "Redis", text: "Redis",
databaseType: "Redis", databaseType: "Redis",
edit: "dec.dcm.connection.plugin.demo.edit", edit: "dec.dcm.connection.plugin.demo.edit",
show: "dec.dcm.connection.plugin.demo.show", show: "dec.dcm.connection.plugin.demo.show",
}); }]);
}); });
const RedisShow = BI.inherit(BI.Widget, { 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); BI.shortcut(RedisShowName, RedisShow);
@ -313,3 +329,38 @@ const RedisEdit = BI.inherit(BI.Widget, {
BI.shortcut(RedisEditName, RedisEdit); 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',
}
```

3
src/modules/app.model.ts

@ -7,7 +7,7 @@ import { getAllDatabaseTypes } from './app.service';
export class AppModel extends Model { export class AppModel extends Model {
static xtype = 'dec.dcm.model.main'; static xtype = 'dec.dcm.model.main';
childContext = <const>['pageIndex', 'datebaseTypeSelected', 'datebaseTypeSelectedOne', 'filter', 'connections', 'connectionSelected', 'connectionSelectedOne', 'saveEvent', 'testEvent', 'isCopy', 'connectionLicInfo']; childContext = <const>['pageIndex', 'datebaseTypeSelected', 'datebaseTypeSelectedOne', 'filter', 'connections', 'connectionSelected', 'connectionSelectedOne', 'saveEvent', 'testEvent', 'isCopy', 'connectionLicInfo', 'noTestConnection'];
state() { state() {
return { return {
@ -23,6 +23,7 @@ export class AppModel extends Model {
currentConnectionNum: 0, currentConnectionNum: 0,
maxConnectionNum: 0, maxConnectionNum: 0,
}, },
noTestConnection: false,
}; };
} }

1
src/modules/app.typings.d.ts vendored

@ -17,4 +17,5 @@ export interface DatabaseType {
urls?: { urls?: {
[key: string]: string; [key: string]: string;
}; };
marker?: string;
} }

3
src/modules/pages/connection/connection.model.ts

@ -53,6 +53,9 @@ export class ConnectionModel extends Model<{
this.model.connectionSelected = name; this.model.connectionSelected = name;
}, },
getConnectionStatus() { getConnectionStatus() {
if (this.model.connectionSelectedOne.pluginConnection) {
return Promise.resolve();
}
return api.getConnectionStatus(this.model.connectionSelected); return api.getConnectionStatus(this.model.connectionSelected);
}, },
checkConnectionLic() { checkConnectionLic() {

10
src/modules/pages/connection/connection.ts

@ -137,9 +137,8 @@ export class Connection extends BI.Widget {
}, },
handler: () => { handler: () => {
this.store.getConnectionStatus() this.store.getConnectionStatus()
.then(re => { .then(() => {
this.store.setPageIndex(PAGE_INDEX.MAINTAIN); this.setMaintainPage();
this.store.setDatebaseTypeSelected('');
}) })
.catch(() => { .catch(() => {
}); });
@ -239,4 +238,9 @@ export class Connection extends BI.Widget {
return databaseType; return databaseType;
} }
private setMaintainPage() {
this.store.setPageIndex(PAGE_INDEX.MAINTAIN);
this.store.setDatebaseTypeSelected('');
}
} }

1
src/modules/pages/connection/list/list.constant.ts

@ -0,0 +1 @@
BI.constant('dec.constant.connection.list', []);

4
src/modules/pages/connection/list/list.model.ts

@ -21,10 +21,10 @@ export class ConnectionListModel extends Model<{
actions = { actions = {
setConnections: ():Promise<void> => api.getConnectionList().then(data => { setConnections: ():Promise<void> => api.getConnectionList().then(data => {
if (BI.size(data.data) > 0) { 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 => { 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; this.model.connectionSelected = data.data[0].connectionName;
} else { } else {

2
src/modules/pages/connection/list/list.ts

@ -3,6 +3,7 @@ import { ListItem } from './list_item/list_item';
import { ConnectionListModel } from './list.model'; import { ConnectionListModel } from './list.model';
import { getDatabaseType } from './list.service'; import { getDatabaseType } from './list.service';
import { Tab } from '@fui/core'; import { Tab } from '@fui/core';
import './list.constant'
@shortcut() @shortcut()
@store(ConnectionListModel) @store(ConnectionListModel)
@ -91,6 +92,7 @@ export class ConnectionList extends BI.Pane {
creator: item.creator, creator: item.creator,
databaseType: getDatabaseType(item), databaseType: getDatabaseType(item),
selected: this.model.connectionSelected ? this.model.connectionSelected === item.connectionName : index === 0, selected: this.model.connectionSelected ? this.model.connectionSelected === item.connectionName : index === 0,
pluginConnection: item.pluginConnection,
}; };
}); });
} }

5
src/modules/pages/connection/list/list_item/list_item.ts

@ -20,6 +20,7 @@ export class ListItem extends BI.BasicButton {
name: '', name: '',
creator: '', creator: '',
databaseType: '', databaseType: '',
pluginConnection: false,
height: 25, height: 25,
baseCls: 'dec-dcm-connection-list-item bi-list-item-active2', baseCls: 'dec-dcm-connection-list-item bi-list-item-active2',
$testId: 'dec-dcm-connection-list-item', $testId: 'dec-dcm-connection-list-item',
@ -43,7 +44,7 @@ export class ListItem extends BI.BasicButton {
}; };
render() { render() {
const { name, databaseType } = this.options; const { name, databaseType, pluginConnection } = this.options;
return { return {
type: BI.HTapeLayout.xtype, type: BI.HTapeLayout.xtype,
@ -118,7 +119,7 @@ export class ListItem extends BI.BasicButton {
}, },
], ],
}, { }, {
el: databaseType ? { el: databaseType && !pluginConnection ? {
type: BI.DownListCombo.xtype, type: BI.DownListCombo.xtype,
cls: 'link-item-icon', cls: 'link-item-icon',
stopPropagation: true, stopPropagation: true,

18
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,
},
]);

28
src/modules/pages/database/database.ts

@ -7,6 +7,7 @@ import { DatebaseType } from './database_type/database_type';
import { getAllDatabaseTypes } from '../../app.service'; import { getAllDatabaseTypes } from '../../app.service';
import { ButtonGroup, MultiSelectItem, SearchEditor } from '@fui/core'; import { ButtonGroup, MultiSelectItem, SearchEditor } from '@fui/core';
import { ApiFactory } from 'src/modules/crud/apiFactory'; import { ApiFactory } from 'src/modules/crud/apiFactory';
import './database.constant'
const api = new ApiFactory().create(); const api = new ApiFactory().create();
@ -121,24 +122,12 @@ export class Datebase extends BI.Widget {
ref: (_ref: ButtonGroup) => { ref: (_ref: ButtonGroup) => {
this.filter = _ref; this.filter = _ref;
}, },
items: [ items: () => BI.map(BI.Constants.getConstant('dec.constant.database.filter.type'), (_, value) => {
{ return {
type: Filter.xtype, type: Filter.xtype,
text: BI.i18nText('Dec-Dcm_Connection_Commonly'), ...value,
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,
},
],
}, },
width: 200, width: 200,
}, },
@ -254,9 +243,12 @@ export class Datebase extends BI.Widget {
case DATEBASE_FILTER_TYPE.OTHER: case DATEBASE_FILTER_TYPE.OTHER:
this.store.setDatebaseTypes(this.allDatabaseTypes.filter(item => this.model.otherDatabases.includes(item.type))); this.store.setDatebaseTypes(this.allDatabaseTypes.filter(item => this.model.otherDatabases.includes(item.type)));
break; break;
default: case DATEBASE_FILTER_TYPE.ALL:
this.store.setDatebaseTypes(this.allDatabaseTypes.filter(item => item.type !== connectionType.JNDI && item.type !== OTHER_JDBC)); this.store.setDatebaseTypes(this.allDatabaseTypes.filter(item => item.type !== connectionType.JNDI && item.type !== OTHER_JDBC));
break; break;
default:
this.store.setDatebaseTypes(this.allDatabaseTypes.filter(item => item.marker && (item.marker === filter)));
break;
} }
} }

3
src/modules/pages/database/database_type/database_type.ts

@ -88,6 +88,9 @@ export class DatebaseType extends BI.BasicButton {
if (url.startsWith('/')) { if (url.startsWith('/')) {
return `${PluginImgPrefix}${url}`; return `${PluginImgPrefix}${url}`;
} }
if (url.startsWith('http')) {
return url;
}
return `${PluginImgPrefix}/${url}`; return `${PluginImgPrefix}/${url}`;
} }

16
src/modules/pages/maintain/forms/components/form.plugin.ts

@ -5,6 +5,8 @@ import { getPluginWidgetEdit } from '../../../../app.service';
@shortcut() @shortcut()
export class FormPlugin extends BI.Widget { export class FormPlugin extends BI.Widget {
static xtype = 'dec.dcm.maintain_plugin'; static xtype = 'dec.dcm.maintain_plugin';
static EVENTNOTEST = 'EVENT_HIDE_TEST_CONNECTION';
static PREVENTPARENTSAVE = 'EVENT_PREVENT_PARENT_SAVE';
props = { props = {
formData: {} as Connection, formData: {} as Connection,
}; };
@ -24,6 +26,12 @@ export class FormPlugin extends BI.Widget {
connectionId, connectionId,
connectionType, connectionType,
connectionName, connectionName,
listeners: [{
eventName: FormPlugin.EVENTNOTEST,
action: (value: boolean) => {
this.fireEvent(FormPlugin.EVENTNOTEST, value);
}
}]
}; };
} }
@ -37,4 +45,12 @@ export class FormPlugin extends BI.Widget {
connectionData: <ConnectionPlugin>BI.extend({}, connectionData, this.plugin.getValue()), connectionData: <ConnectionPlugin>BI.extend({}, connectionData, this.plugin.getValue()),
}; };
} }
public save() {
return this.plugin.save;
}
public preventParentSave() {
return this.plugin.preventParentSave ? this.plugin.preventParentSave() : false;
}
} }

1
src/modules/pages/maintain/forms/form.model.ts

@ -31,6 +31,7 @@ export class MaintainFormModel extends Model<{
'testEvent', 'testEvent',
'connections', 'connections',
'isCopy', 'isCopy',
'noTestConnection',
]; ];
actions = { actions = {

81
src/modules/pages/maintain/forms/form.ts

@ -14,6 +14,8 @@ import { checkIllegalStrings } from "@core/index";
@store(MaintainFormModel) @store(MaintainFormModel)
export class MaintainForm extends BI.Widget { export class MaintainForm extends BI.Widget {
static xtype = 'dec.dcm.maintain.form'; static xtype = 'dec.dcm.maintain.form';
static TESTCONNECTION = 'EVENT_TEST_CONNECTION';
static EVENTNOTEST = 'EVENT_HIDE_TEST_CONNECTION';
props = { props = {
connectionType: '', connectionType: '',
@ -29,34 +31,25 @@ export class MaintainForm extends BI.Widget {
watch = { watch = {
saveEvent: () => { saveEvent: () => {
if (!this.testValue()) { const sonSave = this.form.save?.();
return; if (sonSave) {
} sonSave().then((success: Boolean) => {
if (this.connectionName && !this.model.isCopy) { if (success) {
const value = this.form.getSubmitValue(); BI.Msg.toast(BI.i18nText("Dec-Basic_Save_Success"), {
(value.connectionData as ConnectionJDBC).creator = BI.get(this.getFormData(), 'creator'); level: "success",
// DEC-10155 为了适配插件的数据连接,在外层也加一个creator字段 });
value.creator = BI.get(this.getFormData(), 'creator'); } else {
this.store.updateConnection(this.connectionName, value).then(result => { BI.Msg.toast(BI.i18nText("Dec-Basic_Save_Fail"), {
if (result.errorCode) { level: "error",
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(); if (this.form.preventParentSave()) {
form.connectionId = this.connectionName; return;
// DEC-10155 为了适配插件的数据连接,在外层也加一个creator字段 }
form.creator = Dec ? Dec.personal.username : '';
this.addConnection(form);
} }
this.save();
}, },
testEvent: () => { testEvent: () => {
this.testConnection(); this.testConnection();
@ -77,10 +70,15 @@ export class MaintainForm extends BI.Widget {
this.form = _ref; this.form = _ref;
}, },
listeners: [{ listeners: [{
eventName: 'EVENT_TEST_CONNECTION', eventName: MaintainForm.TESTCONNECTION,
action: () => { action: () => {
this.testConnection(); 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); 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);
}
}
} }

3
src/modules/title/title.model.ts

@ -6,12 +6,13 @@ export class TitleModel extends Model<{
types: { types: {
pageIndex: AppModel['TYPE']['pageIndex']; pageIndex: AppModel['TYPE']['pageIndex'];
datebaseTypeSelected: AppModel['TYPE']['datebaseTypeSelected']; datebaseTypeSelected: AppModel['TYPE']['datebaseTypeSelected'];
noTestConnection: AppModel['TYPE']['noTestConnection'];
}, },
context: TitleModel['context']; context: TitleModel['context'];
}> { }> {
static xtype = 'dec.dcm.model.title'; static xtype = 'dec.dcm.model.title';
context = <const>['pageIndex', 'datebaseTypeSelected'] context = <const>['pageIndex', 'datebaseTypeSelected', 'noTestConnection']
actions = { actions = {
setPageIndex: (index: string) => { setPageIndex: (index: string) => {

3
src/modules/title/title_maintain/title_maintain.model.ts

@ -11,12 +11,13 @@ export class TitleMaintainModel extends Model<{
connectionSelected: AppModel['TYPE']['connectionSelected']; connectionSelected: AppModel['TYPE']['connectionSelected'];
testEvent: AppModel['TYPE']['testEvent']; testEvent: AppModel['TYPE']['testEvent'];
isCopy: AppModel['TYPE']['isCopy']; isCopy: AppModel['TYPE']['isCopy'];
noTestConnection: AppModel['TYPE']['noTestConnection'];
}, },
context: TitleMaintainModel['context']; context: TitleMaintainModel['context'];
}> { }> {
static xtype = 'dec.dcm.model.title_maintain'; static xtype = 'dec.dcm.model.title_maintain';
context = <const>['pageIndex', 'saveEvent', 'testEvent', 'connectionSelected', 'isCopy']; context = <const>['pageIndex', 'saveEvent', 'testEvent', 'connectionSelected', 'isCopy', 'noTestConnection'];
actions = { actions = {
setPageIndex: (index: string) => { setPageIndex: (index: string) => {

13
src/modules/title/title_maintain/title_maintain.ts

@ -1,6 +1,7 @@
import { shortcut, store } from '@core/core'; import { shortcut, store } from '@core/core';
import { TitleMaintainModel } from './title_maintain.model'; import { TitleMaintainModel } from './title_maintain.model';
import { PAGE_INDEX } from '@constants/constant'; import { PAGE_INDEX } from '@constants/constant';
import { Button } from '@fui/core';
@shortcut() @shortcut()
@store(TitleMaintainModel) @store(TitleMaintainModel)
@ -9,6 +10,14 @@ export class TitleMaintain extends BI.Widget {
store: TitleMaintainModel['store']; store: TitleMaintainModel['store'];
model: TitleMaintainModel['model']; model: TitleMaintainModel['model'];
testConnectionBtn: Button;
watch = {
noTestConnection: function (value) {
this.testConnectionBtn.setVisible(!value);
}
}
render() { render() {
return { return {
type: BI.FloatRightLayout.xtype, type: BI.FloatRightLayout.xtype,
@ -30,6 +39,9 @@ export class TitleMaintain extends BI.Widget {
}, },
{ {
type: BI.Button.xtype, type: BI.Button.xtype,
ref: (_ref) => {
this.testConnectionBtn = _ref;
},
_rgap: 16, _rgap: 16,
$value: 'title-maintain-connection-test', $value: 'title-maintain-connection-test',
text: BI.i18nText('Dec-Dcm_Connection_Test'), text: BI.i18nText('Dec-Dcm_Connection_Test'),
@ -57,5 +69,6 @@ export class TitleMaintain extends BI.Widget {
window.onunload = () => { window.onunload = () => {
this.store.shutdownConnectionStatus(); this.store.shutdownConnectionStatus();
}; };
this.testConnectionBtn.setVisible(!this.model.noTestConnection);
} }
} }

Loading…
Cancel
Save