From 3c053bb854b245e9b3e0b22677bef9589708262e Mon Sep 17 00:00:00 2001 From: alan Date: Wed, 12 Jun 2019 09:50:33 +0800 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20=E4=BF=AE=E6=AD=A3=E4=B8=8D?= =?UTF-8?q?=E8=A7=84=E8=8C=83=E7=9A=84=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/shared/service/dialog.service.ts | 37 +++++++++++----------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/src/shared/service/dialog.service.ts b/src/shared/service/dialog.service.ts index c7ddb77..0ada72a 100644 --- a/src/shared/service/dialog.service.ts +++ b/src/shared/service/dialog.service.ts @@ -131,17 +131,16 @@ class Dialog { } public linkFail(text: string, more: string, cb?: Function): string { - let dialogPopover = null; let dialogMore = null; + let showErrMessage = false; const id = BI.UUID(); - const that = this; const body = { type: Vertical, items: [ { - type: 'bi.center_adapt', + type: CenterAdapt, cls: 'bi-card', - tgap: 10, + vgap: 10, items: [ { type: Vertical, @@ -160,7 +159,6 @@ class Dialog { }, { type: VerticalAdapt, - cls: 'buttons', hgap: 5, items: [ { @@ -168,27 +166,24 @@ class Dialog { text: BI.i18nText('Dec-Dcm_Connection_Detailed_Information'), level: 'ignore', handler() { - const isHide = !dialogMore.isVisible(); - dialogPopover.element.css({ - height: isHide ? '290' : '220', - }); - dialogMore.setVisible(isHide); - this.setText(isHide ? BI.i18nText('Dec-Dcm_Connection_Handup_Information') : BI.i18nText('Dec-Dcm_Connection_Detailed_Information')); + showErrMessage = !showErrMessage; + dialogMore.setVisible(showErrMessage); + this.setText(showErrMessage ? BI.i18nText('Dec-Dcm_Connection_Handup_Information') : BI.i18nText('Dec-Dcm_Connection_Detailed_Information')); }, }, { type: Button, text: BI.i18nText('Dec-Dcm_Back'), level: 'ignore', - handler() { - that.remove(id); + handler: () => { + this.remove(id); }, }, { type: Button, text: BI.i18nText('Dec-Dcm_Connection_ReConnect'), - handler() { - that.close(id); + handler: () => { + this.remove(id); cb ? cb() : null; }, }, @@ -202,10 +197,12 @@ class Dialog { type: Label, cls: 'bi-header-background', text: more, - invisible: true, + invisible: !showErrMessage, + textAlign: 'left', height: 73, width: 400, - value: false, + vgap: 10, + lgap: 5, ref: _ref => { dialogMore = _ref; }, @@ -219,14 +216,10 @@ class Dialog { cls: 'bi-z-index-mask', items: [{ el: { - type: 'bi.center_adapt', + type: CenterAdapt, cls: 'bi-card', width: 450, - height: 220, items: [body], - ref: _ref => { - dialogPopover = _ref; - }, }, }], }, From 99e64a42d89251548ed17cc0254a230eb62eadfa Mon Sep 17 00:00:00 2001 From: alan Date: Wed, 12 Jun 2019 11:20:30 +0800 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20=E7=94=A8model=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E7=BB=84=E4=BB=B6=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/linkfail/linkfail.model.ts | 15 +++ src/shared/components/linkfail/linkfail.ts | 108 ++++++++++++++++++ src/shared/service/dialog.service.ts | 107 ++++------------- 3 files changed, 143 insertions(+), 87 deletions(-) create mode 100644 src/shared/components/linkfail/linkfail.model.ts create mode 100644 src/shared/components/linkfail/linkfail.ts diff --git a/src/shared/components/linkfail/linkfail.model.ts b/src/shared/components/linkfail/linkfail.model.ts new file mode 100644 index 0000000..7238e34 --- /dev/null +++ b/src/shared/components/linkfail/linkfail.model.ts @@ -0,0 +1,15 @@ +const className = 'dec.dcm.model.shared.linkfail'; +export const Model = BI.inherit(Fix.Model, { + state() { + return { + showErrMessage: false, + }; + }, + actions: { + setShowErrMessage(isShow: boolean) { + this.model.showErrMessage = isShow; + }, + }, +}); +BI.model(className, Model); +export default className; diff --git a/src/shared/components/linkfail/linkfail.ts b/src/shared/components/linkfail/linkfail.ts new file mode 100644 index 0000000..2fbc276 --- /dev/null +++ b/src/shared/components/linkfail/linkfail.ts @@ -0,0 +1,108 @@ +import ModelName from './linkfail.model'; +import {CenterAdapt, Vertical, Layout, Label, VerticalAdapt, Button} from '@ui/index'; +export const EVENT_CLOSE = 'EVENT_CLOSE'; +export const EVENT_RETRY = 'EVENT_RETRY'; +const className = 'dec.dcm.shared.linkfail'; +const Widget = BI.inherit(BI.Widget, { + _store() { + return BI.Models.getModel(ModelName); + }, + watch: { + showErrMessage(err: string) { + this.dialogMore.setVisible(!!err); + this.setText(err ? BI.i18nText('Dec-Dcm_Connection_Handup_Information') : BI.i18nText('Dec-Dcm_Connection_Detailed_Information')); + }, + }, + render() { + const {text, errMessage} = this.options; + const {showErrMessage} = this.model; + + return { + type: CenterAdapt, + cls: 'bi-z-index-mask', + items: [{ + el: { + type: CenterAdapt, + cls: 'bi-card', + width: 450, + items: [ + { + type: Vertical, + items: [ + { + type: CenterAdapt, + cls: 'bi-card', + vgap: 10, + items: [ + { + type: Vertical, + vgap: 10, + items: [ + { + type: Layout, + cls: 'dcm-error-icon', + width: 270, + height: 100, + textAlign: 'center', + }, + { + type: Label, + text, + }, + { + type: VerticalAdapt, + hgap: 5, + items: [ + { + type: Button, + text: BI.i18nText('Dec-Dcm_Connection_Detailed_Information'), + level: 'ignore', + handler: () => { + this.store.setShowErrMessage(!this.model.showErrMessage); + }, + }, + { + type: Button, + text: BI.i18nText('Dec-Dcm_Back'), + level: 'ignore', + handler: () => { + this.fireEvent(EVENT_CLOSE); + }, + }, + { + type: Button, + text: BI.i18nText('Dec-Dcm_Connection_ReConnect'), + handler: () => { + this.fireEvent(EVENT_RETRY); + }, + }, + ], + }, + + ], + }, + ], + }, { + type: Label, + cls: 'bi-header-background', + text: errMessage, + invisible: !showErrMessage, + textAlign: 'left', + height: 73, + width: 400, + vgap: 10, + lgap: 5, + ref: _ref => { + this.dialogMore = _ref; + }, + }, + ], + }, + ], + }, + }], + }; + }, +}); +BI.shortcut(className, Widget); +export default className; diff --git a/src/shared/service/dialog.service.ts b/src/shared/service/dialog.service.ts index 0ada72a..05ac8e0 100644 --- a/src/shared/service/dialog.service.ts +++ b/src/shared/service/dialog.service.ts @@ -1,4 +1,6 @@ -import {Label, Vertical, Button, Layout, CenterAdapt, VerticalAdapt} from '@ui/index'; +import {Label, Vertical, CenterAdapt} from '@ui/index'; +import LinkFail, {EVENT_CLOSE, EVENT_RETRY} from '../components/linkfail/linkfail'; + class Dialog { /** * 提示 @@ -131,98 +133,29 @@ class Dialog { } public linkFail(text: string, more: string, cb?: Function): string { - let dialogMore = null; - let showErrMessage = false; const id = BI.UUID(); - const body = { - type: Vertical, - items: [ + const linkFailWidget = BI.createWidget({ + type: LinkFail, + text, + errMessage: more, + listeners: [ { - type: CenterAdapt, - cls: 'bi-card', - vgap: 10, - items: [ - { - type: Vertical, - vgap: 10, - items: [ - { - type: Layout, - cls: 'dcm-error-icon', - width: 270, - height: 100, - textAlign: 'center', - }, - { - type: Label, - text, - }, - { - type: VerticalAdapt, - hgap: 5, - items: [ - { - type: Button, - text: BI.i18nText('Dec-Dcm_Connection_Detailed_Information'), - level: 'ignore', - handler() { - showErrMessage = !showErrMessage; - dialogMore.setVisible(showErrMessage); - this.setText(showErrMessage ? BI.i18nText('Dec-Dcm_Connection_Handup_Information') : BI.i18nText('Dec-Dcm_Connection_Detailed_Information')); - }, - }, - { - type: Button, - text: BI.i18nText('Dec-Dcm_Back'), - level: 'ignore', - handler: () => { - this.remove(id); - }, - }, - { - type: Button, - text: BI.i18nText('Dec-Dcm_Connection_ReConnect'), - handler: () => { - this.remove(id); - cb ? cb() : null; - }, - }, - ], - }, - - ], - }, - ], - }, { - type: Label, - cls: 'bi-header-background', - text: more, - invisible: !showErrMessage, - textAlign: 'left', - height: 73, - width: 400, - vgap: 10, - lgap: 5, - ref: _ref => { - dialogMore = _ref; + eventName: EVENT_CLOSE, + action: () => { + BI.Maskers.remove(id); + }, + }, + { + eventName: EVENT_RETRY, + action: () => { + BI.Maskers.remove(id); + cb ? cb() : null; }, }, ], - }; - + }); BI.Maskers.create(id, null, { - render: { - type: CenterAdapt, - cls: 'bi-z-index-mask', - items: [{ - el: { - type: CenterAdapt, - cls: 'bi-card', - width: 450, - items: [body], - }, - }], - }, + render: linkFailWidget, }); BI.Maskers.show(id);