From 8456cbaf879995ecd4b81942b07d951025f913e7 Mon Sep 17 00:00:00 2001 From: xuxzh <136676092+xuxzh@users.noreply.github.com> Date: Tue, 8 Aug 2023 15:42:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=A8=A1=E6=80=81=E5=BC=B9=E7=AA=97?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9C=80=E5=A4=A7=E5=8C=96=E5=92=8C=E9=80=80?= =?UTF-8?q?=E5=87=BA=E6=9C=80=E5=A4=A7=E5=8C=96=E5=8A=9F=E8=83=BD=20(#320)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/maximize/maximize.component.html | 2 + .../modal/demo/maximize/maximize.component.ts | 54 +++++++++++ devui/modal/demo/modal-demo.component.html | 7 ++ devui/modal/demo/modal-demo.component.ts | 9 +- devui/modal/demo/modal-demo.module.ts | 92 ++++++++++--------- devui/modal/dialog.service.ts | 48 ++++++---- devui/modal/modal-container.component.html | 4 +- devui/modal/modal-container.component.ts | 27 ++++-- devui/modal/modal-header.component.html | 23 +++++ devui/modal/modal-header.component.scss | 6 ++ devui/modal/modal-header.component.ts | 21 +++-- devui/modal/modal.component.html | 8 +- devui/modal/modal.component.scss | 22 +++++ devui/modal/modal.component.ts | 78 +++++++++------- devui/modal/modal.types.ts | 2 + devui/style/devui-for-mobile.scss | 18 ++++ src/assets/i18n/en-us.json | 7 +- src/assets/i18n/zh-cn.json | 7 +- 18 files changed, 313 insertions(+), 122 deletions(-) create mode 100644 devui/modal/demo/maximize/maximize.component.html create mode 100644 devui/modal/demo/maximize/maximize.component.ts diff --git a/devui/modal/demo/maximize/maximize.component.html b/devui/modal/demo/maximize/maximize.component.html new file mode 100644 index 00000000..9a874c3f --- /dev/null +++ b/devui/modal/demo/maximize/maximize.component.html @@ -0,0 +1,2 @@ +open dialog +open dialog without animation diff --git a/devui/modal/demo/maximize/maximize.component.ts b/devui/modal/demo/maximize/maximize.component.ts new file mode 100644 index 00000000..8eccf592 --- /dev/null +++ b/devui/modal/demo/maximize/maximize.component.ts @@ -0,0 +1,54 @@ +import { Component } from '@angular/core'; +import { DialogService } from 'ng-devui/modal'; +import { ModalTestComponent } from '../modal-test.component'; + +@Component({ + selector: 'd-maximize', + templateUrl: './maximize.component.html', + }) +export class MaximizeComponent { + config = { + id: 'dialog-service', + width: '346px', + maxHeight: '600px', + title: 'Start Snapshot Version', + content: ModalTestComponent, + backdropCloseable: true, + onClose: () => console.log('on dialog closed'), + data: { + name: 'Tom', + age: 10, + address: 'Chengdu', + }, + }; + + constructor(private dialogService: DialogService) {} + + openDialog(dialogtype?: string, showAnimation?: boolean) { + const results = this.dialogService.open({ + ...this.config, + showMaximizeBtn: true, + dialogtype: dialogtype, + showAnimation: showAnimation, + buttons: [ + { + cssClass: 'primary', + text: 'Ok', + disabled: false, + handler: ($event: Event) => { + results.modalInstance.hide(); + }, + }, + { + id: 'btn-cancel', + cssClass: 'common', + text: 'Cancel', + handler: ($event: Event) => { + results.modalInstance.hide(); + }, + }, + ], + }); + console.log(results.modalContentInstance); + } +} diff --git a/devui/modal/demo/modal-demo.component.html b/devui/modal/demo/modal-demo.component.html index ad4f139e..bddf69cd 100755 --- a/devui/modal/demo/modal-demo.component.html +++ b/devui/modal/demo/modal-demo.component.html @@ -7,6 +7,13 @@ +
+
{{ 'components.modal.maximizeDemo.title' | translate }}
+
{{ 'components.modal.maximizeDemo.description' | translate }}
+ + + +
{{ 'components.modal.hideDemo.title' | translate }}
{{ 'components.modal.hideDemo.description' | translate }}
diff --git a/devui/modal/demo/modal-demo.component.ts b/devui/modal/demo/modal-demo.component.ts index ddc2a9e7..e8d99534 100755 --- a/devui/modal/demo/modal-demo.component.ts +++ b/devui/modal/demo/modal-demo.component.ts @@ -7,7 +7,7 @@ import { Subscription } from 'rxjs'; selector: 'd-modal-demo', templateUrl: './modal-demo.component.html', styles: [':host ::ng-deep d-button:not(first-child) { margin-left: 8px }'], -}) + }) export class ModalDemoComponent implements OnInit, OnDestroy { basicSource: Array = [ { title: 'HTML', language: 'xml', code: require('./basic/basic.component.html?raw') }, @@ -15,6 +15,12 @@ export class ModalDemoComponent implements OnInit, OnDestroy { { title: 'Dialog HTML', language: 'xml', code: require('./modal-test.component.html?raw') }, { title: 'Dialog TS', language: 'typescript', code: require('./modal-test.component.ts?raw') }, ]; + maximizeSource: Array = [ + { title: 'HTML', language: 'xml', code: require('./maximize/maximize.component.html?raw') }, + { title: 'TS', language: 'typescript', code: require('./maximize/maximize.component.ts?raw') }, + { title: 'Dialog HTML', language: 'xml', code: require('./modal-test.component.html?raw') }, + { title: 'Dialog TS', language: 'typescript', code: require('./modal-test.component.ts?raw') }, + ]; basicUpdateSource: Array = [ { title: 'HTML', language: 'xml', code: require('./basic-update/basic-update.component.html?raw') }, { title: 'TS', language: 'typescript', code: require('./basic-update/basic-update.component.ts?raw') }, @@ -102,6 +108,7 @@ export class ModalDemoComponent implements OnInit, OnDestroy { setNavValues(values) { this.navItems = [ { dAnchorLink: 'standard-dialog', value: values['standard-dialog'] }, + { dAnchorLink: 'maximize-dialog', value: values['maximize-dialog'] }, { dAnchorLink: 'custom-dialog', value: values['custom-dialog'] }, { dAnchorLink: 'intercept-dialog-closed', value: values['intercept-dialog-closed'] }, { dAnchorLink: 'message-hint', value: values['message-hint'] }, diff --git a/devui/modal/demo/modal-demo.module.ts b/devui/modal/demo/modal-demo.module.ts index 95514c34..9079763c 100755 --- a/devui/modal/demo/modal-demo.module.ts +++ b/devui/modal/demo/modal-demo.module.ts @@ -15,6 +15,7 @@ import { DDemoNavModule } from 'devui-commons/src/demo-nav/d-demo-nav.module'; import { AutofocusComponent } from './autofocus/autofocus.component'; import { BasicUpdateComponent } from './basic-update/basic-update.component'; import { BasicComponent } from './basic/basic.component'; +import { MaximizeComponent } from './maximize/maximize.component'; import { CasesComponent } from './cases/cases.component'; import { ModalCasesComponent } from './cases/modal-cases.component'; import { CustomizeComponent } from './customize/customize.component'; @@ -33,53 +34,54 @@ import { TipsComponent } from './tips/tips.component'; @NgModule({ imports: [ - FormsModule, - TranslateModule, - CommonModule, - ModalModule, - ButtonModule, - PopoverModule, - FormModule, - DevUICodeboxModule, - DevUIApiModule, - DDemoNavModule, - TextInputModule, - RouterModule.forChild([ - { path: '', redirectTo: 'demo', pathMatch: 'full' }, - { - path: 'design', - component: ModalDesignComponent, - }, - { path: 'demo', component: ModalDemoComponent }, - { - path: 'api', - component: DevUIApiComponent, - data: { - 'zh-cn': require('!html-loader!markdown-loader!../doc/api-cn.md'), - 'en-us': require('!html-loader!markdown-loader!../doc/api-en.md'), - }, - }, + FormsModule, + TranslateModule, + CommonModule, + ModalModule, + ButtonModule, + PopoverModule, + FormModule, + DevUICodeboxModule, + DevUIApiModule, + DDemoNavModule, + TextInputModule, + RouterModule.forChild([ + { path: '', redirectTo: 'demo', pathMatch: 'full' }, + { + path: 'design', + component: ModalDesignComponent, + }, + { path: 'demo', component: ModalDemoComponent }, + { + path: 'api', + component: DevUIApiComponent, + data: { + 'zh-cn': require('!html-loader!markdown-loader!../doc/api-cn.md'), + 'en-us': require('!html-loader!markdown-loader!../doc/api-en.md'), + }, + }, ]), ], declarations: [ - ModalDemoComponent, - ModalDesignComponent, - ModalTestComponent, - ModalAlertComponent, - ModalNoBtnComponent, - BasicComponent, - CustomizeComponent, - TipsComponent, - HideComponent, - ModalFormComponent, - AutofocusComponent, - TemplateComponent, - DialogContentComponent, - ModalContentComponent, - BasicUpdateComponent, - FixedWrapperComponent, - CasesComponent, - ModalCasesComponent + ModalDemoComponent, + ModalDesignComponent, + ModalTestComponent, + ModalAlertComponent, + ModalNoBtnComponent, + BasicComponent, + MaximizeComponent, + CustomizeComponent, + TipsComponent, + HideComponent, + ModalFormComponent, + AutofocusComponent, + TemplateComponent, + DialogContentComponent, + ModalContentComponent, + BasicUpdateComponent, + FixedWrapperComponent, + CasesComponent, + ModalCasesComponent, ], -}) + }) export class ModalDemoModule {} diff --git a/devui/modal/dialog.service.ts b/devui/modal/dialog.service.ts index 99190d1a..29d431e2 100755 --- a/devui/modal/dialog.service.ts +++ b/devui/modal/dialog.service.ts @@ -1,11 +1,5 @@ import { DOCUMENT } from '@angular/common'; -import { - ComponentFactoryResolver, - ComponentRef, - Inject, - Injectable, - Renderer2, RendererFactory2 -} from '@angular/core'; +import { ComponentFactoryResolver, ComponentRef, Inject, Injectable, Renderer2, RendererFactory2 } from '@angular/core'; import { OverlayContainerRef } from 'ng-devui/overlay-container'; import { DevConfigService } from 'ng-devui/utils'; import { assign, isUndefined } from 'lodash-es'; @@ -19,10 +13,13 @@ export class DialogService { private renderer: Renderer2; document: Document; - constructor(private componentFactoryResolver: ComponentFactoryResolver, - private overlayContainerRef: OverlayContainerRef, private rendererFactory: RendererFactory2, - private devConfigService: DevConfigService, - @Inject(DOCUMENT) private doc: any) { + constructor( + private componentFactoryResolver: ComponentFactoryResolver, + private overlayContainerRef: OverlayContainerRef, + private rendererFactory: RendererFactory2, + private devConfigService: DevConfigService, + @Inject(DOCUMENT) private doc: any + ) { this.renderer = this.rendererFactory.createRenderer(null, null); this.document = this.doc; } @@ -48,6 +45,7 @@ export class DialogService { componentFactoryResolver, beforeHidden, onClose, + onMaximize, dialogtype = 'standard', showCloseBtn = true, draggable = true, @@ -56,7 +54,8 @@ export class DialogService { offsetY, bodyScrollable = true, contentTemplate, - escapable = true + escapable = true, + showMaximizeBtn = false, }: IDialogOptions) { const finalComponentFactoryResolver = componentFactoryResolver || this.componentFactoryResolver; @@ -95,12 +94,15 @@ export class DialogService { offsetX, offsetY, bodyScrollable, - escapable + escapable, }); - const modalContainerRef = modalRef.instance.modalContainerHost.viewContainerRef - .createComponent(finalComponentFactoryResolver.resolveComponentFactory(ModalContainerComponent), 0, injector); - assign(modalContainerRef.instance, { title, buttons, maxHeight, dialogtype, showCloseBtn }); + const modalContainerRef = modalRef.instance.modalContainerHost.viewContainerRef.createComponent( + finalComponentFactoryResolver.resolveComponentFactory(ModalContainerComponent), + 0, + injector + ); + assign(modalContainerRef.instance, { title, buttons, maxHeight, dialogtype, showCloseBtn, showMaximizeBtn }); if (contentTemplate) { assign(modalContainerRef.instance, { contentTemplate }); @@ -108,8 +110,9 @@ export class DialogService { if (typeof content === 'string') { assign(modalContainerRef.instance, { content, html }); } else { - this.contentRef = modalContainerRef.instance.modalContentHost.viewContainerRef - .createComponent(finalComponentFactoryResolver.resolveComponentFactory(content)); + this.contentRef = modalContainerRef.instance.modalContentHost.viewContainerRef.createComponent( + finalComponentFactoryResolver.resolveComponentFactory(content) + ); assign(this.contentRef.instance, { data, dialogtype }); } } @@ -118,7 +121,14 @@ export class DialogService { modalRef.instance.hide(); }; - modalRef.instance.updateButtonOptions = buttonOptions => modalContainerRef.instance.updateButtonOptions(buttonOptions); + modalContainerRef.instance.onMaximize = () => { + modalRef.instance.maximize(); + if (onMaximize) { + onMaximize(modalRef.instance.maximized); + } + }; + + modalRef.instance.updateButtonOptions = (buttonOptions) => modalContainerRef.instance.updateButtonOptions(buttonOptions); modalRef.instance.onHidden = () => { if (modalRef.instance.documentOverFlow) { diff --git a/devui/modal/modal-container.component.html b/devui/modal/modal-container.component.html index f7088323..e69c534e 100755 --- a/devui/modal/modal-container.component.html +++ b/devui/modal/modal-container.component.html @@ -3,7 +3,9 @@ id="d-modal-header" [title]="title" (closeEvent)="close($event)" + (maximizeEvent)="maximize($event)" [dialogtype]="dialogtype" + [showMaximizeBtn]="showMaximizeBtn" [showCloseBtn]="showCloseBtn" >
{{ i18nText?.info }}
+ + + + + + + + + + + = new EventEmitter(); + @Input() showMaximizeBtn = false; + @Output() maximizeEvent = new EventEmitter(); + maximized = false; + i18nText: I18nInterface['modal']; i18nSubscription: Subscription; @@ -47,4 +43,9 @@ export class ModalHeaderComponent implements OnInit, OnDestroy { this.i18nSubscription.unsubscribe(); } } + + maximize() { + this.maximized = !this.maximized; + this.maximizeEvent.emit(this.maximized); + } } diff --git a/devui/modal/modal.component.html b/devui/modal/modal.component.html index 8a518b59..a891361a 100755 --- a/devui/modal/modal.component.html +++ b/devui/modal/modal.component.html @@ -22,7 +22,13 @@ tabindex="1" #dialog > -