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. 71
      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`,值为连接的名称
例如增加`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',
}
```

3
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 = <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() {
return {
@ -23,6 +23,7 @@ export class AppModel extends Model {
currentConnectionNum: 0,
maxConnectionNum: 0,
},
noTestConnection: false,
};
}

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

@ -17,4 +17,5 @@ export interface DatabaseType {
urls?: {
[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;
},
getConnectionStatus() {
if (this.model.connectionSelectedOne.pluginConnection) {
return Promise.resolve();
}
return api.getConnectionStatus(this.model.connectionSelected);
},
checkConnectionLic() {

10
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('');
}
}

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 = {
setConnections: ():Promise<void> => 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 {

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

5
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,

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 { 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: [
{
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,
},
{
items: () => BI.map(BI.Constants.getConstant('dec.constant.database.filter.type'), (_, value) => {
return {
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;
}
}

3
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}`;
}

16
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: <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',
'connections',
'isCopy',
'noTestConnection',
];
actions = {

71
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) {
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.showError(result);
});
if (this.form.preventParentSave()) {
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);
}
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);
}
}
}

3
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 = <const>['pageIndex', 'datebaseTypeSelected']
context = <const>['pageIndex', 'datebaseTypeSelected', 'noTestConnection']
actions = {
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'];
testEvent: AppModel['TYPE']['testEvent'];
isCopy: AppModel['TYPE']['isCopy'];
noTestConnection: AppModel['TYPE']['noTestConnection'];
},
context: TitleMaintainModel['context'];
}> {
static xtype = 'dec.dcm.model.title_maintain';
context = <const>['pageIndex', 'saveEvent', 'testEvent', 'connectionSelected', 'isCopy'];
context = <const>['pageIndex', 'saveEvent', 'testEvent', 'connectionSelected', 'isCopy', 'noTestConnection'];
actions = {
setPageIndex: (index: string) => {

13
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);
}
}

Loading…
Cancel
Save