From fdf009c96cdc9f32fcea9eed7cfb3723ad535cac Mon Sep 17 00:00:00 2001 From: alan Date: Tue, 14 May 2019 17:17:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 12 +++++- src/app/app.component.ts | 1 + src/app/app.plugin.ts | 20 +++++++++ src/app/link_set/link-set.model.ts | 9 +++- .../right_detail/right.detail.component.ts | 41 +++++++++---------- src/app/link_set/select/select.constant.ts | 3 +- src/shared/service/dialog.service.ts | 25 +++++++++++ 7 files changed, 86 insertions(+), 25 deletions(-) create mode 100644 src/app/app.plugin.ts diff --git a/README.md b/README.md index afd02b8..6a40165 100644 --- a/README.md +++ b/README.md @@ -17,4 +17,14 @@ yarn 开始开发 ``` yarn start -``` \ No newline at end of file +``` + +## 接口 +### 增加数据连接类型 +使用`BI.config`,ConstantName名称为`bi.constant.database.conf.connect.list`,值为连接的名称 + +### 数据连接表单 +ConstantName名称为`bi.constant.database.conf.connect.form.${name.toLowerCase()}.edit`,值为组件shortcut的名称 + +### 数据连接显示 +ConstantName名称为`bi.constant.database.conf.connect.form.${name.toLowerCase()}.show`,值为组件shortcut的名称 \ No newline at end of file diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 8fea873..1aa1c55 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -4,6 +4,7 @@ import appModel from './app.model'; import title from './title/title.component'; import linkSet from './link_set/link-set.component'; import linkStatus from './link_status/link_status.component'; +import './app.plugin'; import {fetchLinkList} from '../shared/crud/crud.request'; import './app.component.scss'; diff --git a/src/app/app.plugin.ts b/src/app/app.plugin.ts new file mode 100644 index 0000000..1b8b289 --- /dev/null +++ b/src/app/app.plugin.ts @@ -0,0 +1,20 @@ +import {Left, WidgetType, Label} from '@ui/index'; +const className = 'fr.plugin.text'; +const Widget: WidgetType = { + render() { + return { + type: Left, + cls: 'title', + items: [{ + type: Label, + text:'123', + }], + }; + }, +}; +BI.shortcut(className, BI.inherit(BI.Widget, Widget)); + +export default className; + +BI.constant('bi.constant.database.conf.connect.form.redis.edit', className); +BI.constant('bi.constant.database.conf.connect.form.redis.show', className); diff --git a/src/app/link_set/link-set.model.ts b/src/app/link_set/link-set.model.ts index bde5261..3fec365 100644 --- a/src/app/link_set/link-set.model.ts +++ b/src/app/link_set/link-set.model.ts @@ -123,6 +123,11 @@ const Model: ModelType = { } }, setNewLink(value: string) { + if (!databaseTyle.some(item => item.text === value) && !BI.Constants.getConstant(`bi.constant.database.conf.connect.form.${value.toLowerCase()}.edit`)) { + dialog.error('找不到该连接的配置信息'); + + return; + } this.noSaveConfirm(() => { this._setNewLink(value); }); @@ -140,6 +145,7 @@ const Model: ModelType = { connectionName:name, isSelected: true, ...data, + text: value, }, ...this.model.linkList, ]; @@ -147,6 +153,7 @@ const Model: ModelType = { ...data, connectionName:name, isSelected: true, + text: value, }; this.model.linkUpdate = { ...data, @@ -161,7 +168,7 @@ const Model: ModelType = { dialog.confirm('当前设置尚未保存,是否保存?', (isConfirm: boolean) => { if (isConfirm) { saveConnection(this.model.linkUpdate).then(() => { - this.setEdit(true); + this.setEdit(false); }); } else { this.setCancel(); diff --git a/src/app/link_set/right/right_detail/right.detail.component.ts b/src/app/link_set/right/right_detail/right.detail.component.ts index 991a555..26ef47b 100644 --- a/src/app/link_set/right/right_detail/right.detail.component.ts +++ b/src/app/link_set/right/right_detail/right.detail.component.ts @@ -7,23 +7,30 @@ import RightEditMysql from '../right_edit/right.edit.mysql.component'; import {LinkType} from '@ui/type'; const className = 'fr.component.right.detail'; let rightDetail: any = null; +const renderEdit = (linkSelected: LinkType): void => { + let typeEdit = linkSelected.databaseType === 'mysql' ? RightEditMysql : RightEdit; + if (!linkSelected.driver) { + typeEdit = BI.Constants.getConstant(`bi.constant.database.conf.connect.form.${linkSelected.text.toLowerCase()}.edit`); + } + const showPage = linkSelected.driver ? RightShow : BI.Constants.getConstant(`bi.constant.database.conf.connect.form.${linkSelected.text.toLowerCase()}.show`); + rightDetail.populate(BI.createItems([ + { + type: Title, + isEdit: linkSelected.isSelected, + linkSelected, + }, { + type: linkSelected.isSelected ? typeEdit : showPage, + linkSelected, + }, + ])); +}; const Widget: WidgetType = { _store() { return BI.Models.getModel(Model); }, watch:{ linkSelected(linkSelected: LinkType) { - const typeEdit = linkSelected.databaseType === 'mysql' ? RightEditMysql : RightEdit; - rightDetail.populate(BI.createItems([ - { - type: Title, - isEdit: linkSelected.isSelected, - linkSelected, - }, { - type: linkSelected.isSelected ? typeEdit : RightShow, - linkSelected, - }, - ])); + renderEdit(linkSelected); }, }, render() { @@ -37,17 +44,7 @@ const Widget: WidgetType = { }, mounted() { const linkSelected: LinkType = this.model.linkSelected; - const typeEdit = linkSelected.databaseType === 'mysql' ? RightEditMysql : RightEdit; - rightDetail.populate(BI.createItems([ - { - type: Title, - isEdit: linkSelected.isSelected, - linkSelected, - }, { - type: linkSelected.isSelected ? typeEdit : RightShow, - linkSelected, - }, - ])); + renderEdit(linkSelected); }, }; BI.shortcut(className, BI.inherit(BI.Widget, Widget)); diff --git a/src/app/link_set/select/select.constant.ts b/src/app/link_set/select/select.constant.ts index 13ffac8..0d803b3 100644 --- a/src/app/link_set/select/select.constant.ts +++ b/src/app/link_set/select/select.constant.ts @@ -1,5 +1,6 @@ export const ConstantName = 'bi.constant.database.conf.connect.list'; -export const Constant = BI.constant(ConstantName, [ +BI.constant(ConstantName, [ 'APACHE KYLIN', 'DERBY', 'HP Vertica', 'IBM DB2', 'INFORMIX', 'Microsoft SQL Server', 'MySQL', 'Oracle', 'Privotal Greenplum Database', 'Postgresql', 'GaussDB 200', ]); +BI.config(ConstantName, (datas: string[]) => [...datas, 'Redis']); export default ConstantName; diff --git a/src/shared/service/dialog.service.ts b/src/shared/service/dialog.service.ts index deb4935..349e25c 100644 --- a/src/shared/service/dialog.service.ts +++ b/src/shared/service/dialog.service.ts @@ -98,6 +98,31 @@ class Dialog { return this.show(body, 1000); } + public error(message: string): string { + const body = { + type: 'bi.center_adapt', + cls: 'show-content', + items: [ + { + type: Vertical, + items:[ + { + type: 'bi.layout', + cls: 'error-icon', + width: 100, + height: 100, + }, + { + type: Label, + text: message, + }, + ], + }, + ], + }; + + return this.show(body, 2000); + } public linkFail(text: string, more: string, cb?: Function): string { let Popover: any = null;