From 7ed9056bd98add1c9fa356e25a8cb7f0f9eb0447 Mon Sep 17 00:00:00 2001 From: "pudi.gmd" Date: Fri, 27 Aug 2021 16:52:01 +0800 Subject: [PATCH 1/3] feat(module: modal): Modal.operation support maskClosable params --- components/modal/demo/alert.ts | 2 +- components/modal/demo/basic.ts | 30 ++- components/modal/demo/operation.ts | 8 +- components/modal/doc/index.en-US.md | 1 + components/modal/doc/index.zh-CN.md | 15 +- components/modal/modal-options.provider.ts | 10 +- components/modal/modal.component.spec.ts | 28 +-- components/modal/modal.module.ts | 3 +- components/modal/modal.service.ts | 233 +++++++++------------ components/modal/public-api.ts | 2 +- 10 files changed, 149 insertions(+), 183 deletions(-) diff --git a/components/modal/demo/alert.ts b/components/modal/demo/alert.ts index 237e5989..31ab8b77 100644 --- a/components/modal/demo/alert.ts +++ b/components/modal/demo/alert.ts @@ -1,5 +1,5 @@ import { Component } from '@angular/core'; -import { ModalService, ToastService, ModalRef } from 'ng-zorro-antd-mobile'; +import { ModalService, ToastService } from 'ng-zorro-antd-mobile'; @Component({ selector: 'demo-modal-alert', diff --git a/components/modal/demo/basic.ts b/components/modal/demo/basic.ts index 2894e5c0..dafa5f67 100644 --- a/components/modal/demo/basic.ts +++ b/components/modal/demo/basic.ts @@ -1,5 +1,4 @@ import { Component } from '@angular/core'; -import { ModalService } from 'ng-zorro-antd-mobile'; @Component({ selector: 'demo-modal-basic', @@ -10,12 +9,12 @@ import { ModalService } from 'ng-zorro-antd-mobile';
- scoll content...
- scoll content...
- scoll content...
- scoll content...
- scoll content...
- scoll content...
+ scroll content...
+ scroll content...
+ scroll content...
+ scroll content...
+ scroll content...
+ scroll content...
popup
@@ -38,9 +37,9 @@ import { ModalService } from 'ng-zorro-antd-mobile'; (onClose)="onClose('modal3')" >
- scoll content...
- scoll content...
- scoll content...
+ scroll content...
+ scroll content...
+ scroll content...
closable
@@ -53,9 +52,9 @@ import { ModalService } from 'ng-zorro-antd-mobile'; (onClose)="onClose('modal4')" >
- scoll content...
- scoll content...
- scoll content...
+ scroll content...
+ scroll content...
+ scroll content...
@@ -95,11 +94,6 @@ export class DemoModalBasicComponent { } ]; - constructor() {} - - modelChange(event) { - console.log('asdfasdf', event); - } onClose(key) { this.state[key] = false; } diff --git a/components/modal/demo/operation.ts b/components/modal/demo/operation.ts index a02fdef3..edf174d5 100644 --- a/components/modal/demo/operation.ts +++ b/components/modal/demo/operation.ts @@ -6,7 +6,7 @@ import { ModalService } from 'ng-zorro-antd-mobile'; template: ` -
operation
+
operation
` @@ -14,10 +14,12 @@ import { ModalService } from 'ng-zorro-antd-mobile'; export class DemoModalOperationComponent { constructor(private _modal: ModalService) {} - showOpeartion() { + showOperation() { this._modal.operation([ { text: '标为未读', onPress: () => console.log('标为未读被点击了') }, { text: '置顶聊天', onPress: () => console.log('置顶聊天被点击了') } - ]); + ], 'ios', { + maskClosable: true, + }); } } diff --git a/components/modal/doc/index.en-US.md b/components/modal/doc/index.en-US.md index ff1ea39e..6c9b72cd 100644 --- a/components/modal/doc/index.en-US.md +++ b/components/modal/doc/index.en-US.md @@ -60,6 +60,7 @@ Properties | Descrition | Type | Default -----------|------------|------|-------- | `[actions]` | button group | `Array` | - | | `[platform]` | Set the special style depends on platform, works on web only | `'android' \| 'ios'` | `'ios'`| +| `[customOptions]` | support `maskClosable` params,Determine whether to close the modal dialog when clicked mask of it | `Object` | - | call `ModalService.operation(actions?).close()` can close Operation Modal outside anywhere as you wish. diff --git a/components/modal/doc/index.zh-CN.md b/components/modal/doc/index.zh-CN.md index 12714a18..9862cf40 100644 --- a/components/modal/doc/index.zh-CN.md +++ b/components/modal/doc/index.zh-CN.md @@ -31,7 +31,7 @@ subtitle: 对话框 | `[platform]` | 设定组件的平台特有样式, 仅限web | `'android' \| 'ios'` | `'ios'`| | `(onClose)` | 点击 x 或 mask 回调 | `EventEmitter` | - | -### ModalSerivce.alert(title, message, actions?, platform?) +### ModalService.alert(title, message, actions?, platform?) 参数 | 说明 | 类型 | 默认值 ----|-----|------|------ @@ -40,9 +40,9 @@ subtitle: 对话框 | `[actions]` | 按钮组 | `Array` | - | | `[platform]` | 设定组件的平台特有样式, 仅限web | `'android' \| 'ios'` | `'ios'`| -`ModalSerivce.alert(title, message, actions?, platform?).close()` 可以在外部关闭 Alert +`ModalService.alert(title, message, actions?, platform?).close()` 可以在外部关闭 Alert -### ModalSerivce.prompt(title, message, callbackOrActions, type?, defaultValue?, placeholders?, platform?) +### ModalService.prompt(title, message, callbackOrActions, type?, defaultValue?, placeholders?, platform?) 参数 | 说明 | 类型 | 默认值 ----|-----|------|------ @@ -55,16 +55,17 @@ subtitle: 对话框 | `[platform]` | 设定组件的平台特有样式, 仅限web | `'android' \| 'ios'` | `'ios'`| -`ModalSerivce.prompt(title, message, callbackOrActions, type?, defaultValue?, placeholders?, platform?).close()` 可以在外部关闭 prompt` +`ModalService.prompt(title, message, callbackOrActions, type?, defaultValue?, placeholders?, platform?).close()` 可以在外部关闭 prompt` -### ModalSerivce.operation(actions?, platform?) +### ModalService.operation(actions?, platform?, customOptions?) 参数 | 说明 | 类型 | 默认值 ----|-----|------|------ | `[actions]` | 按钮组 | `Array` | - | -| `[platform]` | 设定组件的平台特有样式, 仅限web | `'android' \| 'ios'` | `'ios'`| +| `[platform]` | 设定组件的平台特有样式, 仅限 web | `'android' \| 'ios'` | `'ios'`| +| `[customOptions]` | 支持 `maskClosable` 入参,控制点击蒙层是否允许关闭 | `Object` | - | -`ModalSerivce.operation(actions?, platform?).close()` 可以在外部关闭 operation` +`ModalService.operation(actions?, platform?).close()` 可以在外部关闭 operation` 以上函数调用后,会返回一个引用,可以通过该引用关闭弹窗。 diff --git a/components/modal/modal-options.provider.ts b/components/modal/modal-options.provider.ts index 1e47c6bb..1bc0800d 100644 --- a/components/modal/modal-options.provider.ts +++ b/components/modal/modal-options.provider.ts @@ -29,18 +29,16 @@ export class ModalBaseOptions { closeWithAnimation: () => void; } +export class ModalServiceCustomOptions { + maskClosable?: boolean = false; +} + @Injectable() export class ModalOptions extends ModalBaseOptions { transitionName?: string = 'am-fade'; maskTransitionName?: string = 'am-fade'; } -@Injectable() -export class AlertOptions extends ModalBaseOptions { - message?: string | TemplateRef; - actions?: Array; -} - @Injectable() export class Action { text?: string; diff --git a/components/modal/modal.component.spec.ts b/components/modal/modal.component.spec.ts index dce8410b..503c4fac 100644 --- a/components/modal/modal.component.spec.ts +++ b/components/modal/modal.component.spec.ts @@ -1,12 +1,12 @@ -import { Component, ViewChild, ViewContainerRef } from '@angular/core'; +import { Component, ViewChild } from '@angular/core'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; -import { ComponentFixture, fakeAsync, tick, TestBed, flush, waitForAsync } from '@angular/core/testing'; +import { ComponentFixture, fakeAsync, TestBed, flush, waitForAsync } from '@angular/core/testing'; import { ModalModule, WingBlankModule, ListModule, WhiteSpaceModule, ButtonModule, ModalRef } from '../..'; import { By } from '@angular/platform-browser'; -import { ModalService, ModalServiceComponent, ModalComponent } from '../..'; +import { ModalService, ModalComponent } from '../..'; import { ButtonComponent } from '../button/button.component'; import { dispatchTouchEvent } from '../core/testing'; -import { ModalOptions, AlertOptions } from './modal-options.provider'; +import { ModalOptions } from './modal-options.provider'; import { Overlay } from '@angular/cdk/overlay'; describe('ModalComponent', () => { let component: TestModalBasicComponent; @@ -26,7 +26,7 @@ describe('ModalComponent', () => { FormsModule, ReactiveFormsModule ], - providers: [Overlay, ModalOptions, AlertOptions] + providers: [Overlay, ModalOptions] }).compileComponents(); TestBed.overrideModule(ModalModule, {}).compileComponents(); })); @@ -170,7 +170,7 @@ describe('ModalComponent', () => { expect(modalEle.nativeElement.querySelector('.am-modal-close')).toBeNull('closable is false'); })); - it('should showOpeartion work', () => { + it('should showOperation work', () => { const button = buttons[0].nativeElement; button.click(); fixture.detectChanges(); @@ -256,17 +256,17 @@ describe('ModalComponent', () => { [animationType]="animationType" >
- scoll content... + scroll content...
- scoll content...
- scoll content...
- scoll content...
- scoll content...
- scoll content... + scroll content...
+ scroll content...
+ scroll content...
+ scroll content...
+ scroll content...
-
operation
+
operation
customized buttons
defaultValue
promise
@@ -320,7 +320,7 @@ export class TestModalBasicComponent { this.state = false; } - showOpeartion() { + showOperation() { this._modal.operation([ { text: '标为未读', onPress: () => console.log('标为未读被点击了') }, { text: '置顶聊天', onPress: () => console.log('置顶聊天被点击了') } diff --git a/components/modal/modal.module.ts b/components/modal/modal.module.ts index cf6d10b8..7b582416 100644 --- a/components/modal/modal.module.ts +++ b/components/modal/modal.module.ts @@ -8,7 +8,6 @@ import { WhiteSpaceModule } from '../white-space/white-space.module'; import { ButtonModule } from '../button/button.module'; import { InputItemModule } from '../input-item/input-item.module'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; -import { AlertOptions } from './modal-options.provider'; import { OverlayModule } from '@angular/cdk/overlay'; import { PopupService } from '../core/services/popup.service'; @NgModule({ @@ -25,6 +24,6 @@ import { PopupService } from '../core/services/popup.service'; ], exports: [ModalComponent, ModalServiceComponent], declarations: [ModalComponent, ModalServiceComponent], - providers: [AlertOptions, ModalService, PopupService] + providers: [ModalService, PopupService] }) export class ModalModule {} diff --git a/components/modal/modal.service.ts b/components/modal/modal.service.ts index 7287be48..a28dbe6e 100644 --- a/components/modal/modal.service.ts +++ b/components/modal/modal.service.ts @@ -1,76 +1,23 @@ import { Injectable, Injector, ComponentRef, TemplateRef } from '@angular/core'; + import { ModalServiceComponent } from './modal.component'; -import { ModalBaseOptions, ModalOptions, AlertOptions, Action } from './modal-options.provider'; +import { ModalBaseOptions, ModalOptions, ModalServiceCustomOptions, Action } from './modal-options.provider'; import { PopupService } from '../core/services/popup.service'; -import { ModalRef } from './modal-ref.class'; + @Injectable({ providedIn: 'root' }) @Injectable() export class ModalService extends PopupService { modalRef: ComponentRef = null; - _initConfig(config: ModalBaseOptions, options: any): ModalBaseOptions { - const props: ModalBaseOptions = new ModalBaseOptions(); - const optionalParams: string[] = [ - 'visible', - 'focus', - 'prefixCls', - 'animated', - 'closable', - 'maskClosable', - 'onClose', - 'transparent', - 'popup', - 'animationType', - 'title', - 'footer', - 'platform', - 'className', - 'wrapClassName', - 'message', - 'actions', - 'callbackOrActions', - 'type', - 'defaultValue', - 'placeholders', - 'operation', - 'transitionName', - 'maskTransitionName', - 'close', - 'closeWithAnimation' - ]; - const self = this; - config = Object.assign( - options, - config, - { - close: (): void => { - if (config.maskClosable || config.closable) { - self.closeWithAnimation(); - } - } - }, - { - closeWithAnimation: (): void => { - self.closeWithAnimation(); - } - } - ); - optionalParams.forEach(key => { - if (config[key] !== undefined) { - props[key] = config[key]; - } - }); - return props; - } _open(props: ModalBaseOptions): any { - const childInjector = Injector.create([ + const childInjector = Injector.create( { - provide: ModalOptions, - useValue: props + providers: [{provide: ModalOptions, useValue: props}] } - ]); + ); + this.modalRef = this.showPopup(ModalServiceComponent, childInjector); return this.modalRef && this.modalRef.instance; } @@ -88,26 +35,33 @@ export class ModalService extends PopupService { title?: string | TemplateRef, message?: string | TemplateRef, actions?: Array, - platform?: string + platform?: string, ): any { - const options: AlertOptions = new AlertOptions(); - options.visible = true; - options.transparent = true; - options.closable = false; - options.maskClosable = false; - options.platform = 'ios'; - + const options: ModalOptions = new ModalOptions(); const footer = getFooter.call(this, actions); - - const config = Object.assign({ - title: title, - message: message, - footer: footer, + const defaultOptions = { + visible: true, + transparent: true, + closable: false, + maskClosable: false, + platform: platform || 'ios', + title: title || '', + message: message || '', + footer, actions: footer, - platform: platform ? platform : 'ios' - }); + close: () => { + this.closeWithAnimation(); + }, + closeWithAnimation: () => { + this.closeWithAnimation(); + } + } + + const props = { + ...options, + ...defaultOptions, + } - const props = this._initConfig(config, options); return this._open(props); } @@ -118,17 +72,9 @@ export class ModalService extends PopupService { type?: string, defaultValue?: Array, placeholders?: Array, - platform?: string + platform?: string, ): any { const options: ModalOptions = new ModalOptions(); - options.visible = true; - options.transparent = true; - options.closable = false; - options.maskClosable = false; - options.className = 'am-modal-alert-content'; - options.defaultValue = defaultValue || ['', '']; - options.placeholders = placeholders; - (options.type = type ? type : 'default'), (options.platform = platform ? platform : 'ios'); function getArgs(self: any, func: any) { let text: any, password: any; @@ -148,59 +94,83 @@ export class ModalService extends PopupService { return func(text); } - let actions; - if (typeof callbackOrActions === 'function') { - actions = [ - { text: 'Cancel' }, - { - text: 'OK', - onPress: () => { - getArgs(this, callbackOrActions); - } + const actions = (typeof callbackOrActions === 'function') ? [ + { text: 'Cancel' }, + { + text: 'OK', + onPress: () => { + getArgs(this, callbackOrActions); } - ]; - } else { - actions = callbackOrActions.map(item => { - return { - text: item.text, - onPress: () => { - if (item.onPress) { - return getArgs(this, item.onPress); - } + } + ] : callbackOrActions.map(item => { + return { + text: item.text, + onPress: () => { + if (item.onPress) { + return getArgs(this, item.onPress); } - }; - }); - } + } + }; + }); const footer = getFooter.call(this, actions); - const config = Object.assign({ - title: title, - message: message, - type: type ? type : 'default', - footer: footer, + const defaultOptions = { + visible: true, + transparent: true, + closable: false, + maskClosable: false, + operation: true, + className: 'm-modal-alert-content', + defaultValue: defaultValue || ['', ''], + placeholders: placeholders || [], + type: type || 'default', + title: title || '', + message: message || '', + footer, actions: footer, - platform: platform ? platform : 'ios' - }); - const props = this._initConfig(config, options); + platform: platform ? platform : 'ios', + close: () => { + this.closeWithAnimation(); + }, + closeWithAnimation: () => { + this.closeWithAnimation(); + } + } + + const props = { + ...options, + ...defaultOptions, + } + return this._open(props); } - operation(actions?: any, platform?: string): any { + operation(actions?: any, platform?: string, customOptions?: ModalServiceCustomOptions): any { const options: ModalOptions = new ModalOptions(); - options.visible = true; - options.transparent = true; - options.closable = false; - options.maskClosable = false; - options.operation = true; - options.className = 'am-modal-operation'; const footer = getFooter.call(this, actions); + const defaultOptions = { + visible: true, + transparent: true, + closable: false, + maskClosable: false, + operation: true, + className: 'am-modal-operation', + footer, + platform: platform ? platform : 'ios', + close: () => { + this.closeWithAnimation(); + }, + closeWithAnimation: () => { + this.closeWithAnimation(); + } + } + + const props = { + ...options, + ...defaultOptions, + ...customOptions + } - const config = Object.assign({ - footer: footer, - actions: footer, - platform: platform ? platform : 'ios' - }); - const props = this._initConfig(config, options); return this._open(props); } @@ -210,11 +180,12 @@ export class ModalService extends PopupService { } function getFooter(actions) { - let action = actions ? actions : [{ text: 'OK', onPress: () => {} }]; - return action.map((button: Action) => { - const orginPress = button.onPress || function() {}; + let _actions = actions ? actions : [{ text: 'OK', onPress: () => {} }]; + + return _actions.map((button: Action) => { + const originPress = button.onPress || function() {}; button.onPress = () => { - const res = orginPress(); + const res = originPress(); if (res && res.then) { res.then(() => { this.closeWithAnimation(); diff --git a/components/modal/public-api.ts b/components/modal/public-api.ts index 209f886a..e74aff53 100644 --- a/components/modal/public-api.ts +++ b/components/modal/public-api.ts @@ -1,5 +1,5 @@ export { ModalModule } from './modal.module'; export { ModalService, ModalService as Modal } from './modal.service'; export { ModalComponent, ModalServiceComponent } from './modal.component'; -export { ModalBaseOptions, ModalOptions, AlertOptions, Action } from './modal-options.provider'; +export { ModalBaseOptions, ModalOptions, Action } from './modal-options.provider'; export { ModalRef } from './modal-ref.class'; From 5bd4e133ce5a5f4cfadab57b6345e5d8a5fe91d9 Mon Sep 17 00:00:00 2001 From: "pudi.gmd" Date: Fri, 27 Aug 2021 17:09:17 +0800 Subject: [PATCH 2/3] feat(module: modal): code style formatting --- components/modal/modal.service.ts | 69 ++++++++++++++++--------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/components/modal/modal.service.ts b/components/modal/modal.service.ts index a28dbe6e..5235c6f5 100644 --- a/components/modal/modal.service.ts +++ b/components/modal/modal.service.ts @@ -12,11 +12,9 @@ export class ModalService extends PopupService { modalRef: ComponentRef = null; _open(props: ModalBaseOptions): any { - const childInjector = Injector.create( - { - providers: [{provide: ModalOptions, useValue: props}] - } - ); + const childInjector = Injector.create({ + providers: [{ provide: ModalOptions, useValue: props }] + }); this.modalRef = this.showPopup(ModalServiceComponent, childInjector); return this.modalRef && this.modalRef.instance; @@ -35,7 +33,7 @@ export class ModalService extends PopupService { title?: string | TemplateRef, message?: string | TemplateRef, actions?: Array, - platform?: string, + platform?: string ): any { const options: ModalOptions = new ModalOptions(); const footer = getFooter.call(this, actions); @@ -55,12 +53,12 @@ export class ModalService extends PopupService { closeWithAnimation: () => { this.closeWithAnimation(); } - } + }; const props = { ...options, - ...defaultOptions, - } + ...defaultOptions + }; return this._open(props); } @@ -72,7 +70,7 @@ export class ModalService extends PopupService { type?: string, defaultValue?: Array, placeholders?: Array, - platform?: string, + platform?: string ): any { const options: ModalOptions = new ModalOptions(); @@ -94,24 +92,27 @@ export class ModalService extends PopupService { return func(text); } - const actions = (typeof callbackOrActions === 'function') ? [ - { text: 'Cancel' }, - { - text: 'OK', - onPress: () => { - getArgs(this, callbackOrActions); - } - } - ] : callbackOrActions.map(item => { - return { - text: item.text, - onPress: () => { - if (item.onPress) { - return getArgs(this, item.onPress); - } - } - }; - }); + const actions = + typeof callbackOrActions === 'function' + ? [ + { text: 'Cancel' }, + { + text: 'OK', + onPress: () => { + getArgs(this, callbackOrActions); + } + } + ] + : callbackOrActions.map(item => { + return { + text: item.text, + onPress: () => { + if (item.onPress) { + return getArgs(this, item.onPress); + } + } + }; + }); const footer = getFooter.call(this, actions); const defaultOptions = { @@ -135,12 +136,12 @@ export class ModalService extends PopupService { closeWithAnimation: () => { this.closeWithAnimation(); } - } + }; const props = { ...options, - ...defaultOptions, - } + ...defaultOptions + }; return this._open(props); } @@ -163,13 +164,13 @@ export class ModalService extends PopupService { closeWithAnimation: () => { this.closeWithAnimation(); } - } - + }; + const props = { ...options, ...defaultOptions, ...customOptions - } + }; return this._open(props); } From 5bc56844b6a230f6632e6b27c1cf541419bc72cc Mon Sep 17 00:00:00 2001 From: "pudi.gmd" Date: Thu, 25 Nov 2021 17:37:47 +0800 Subject: [PATCH 3/3] fix(module: modal): upgrade travis node_js version --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d589831a..bbebf394 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ sudo: required dist: trusty language: node_js node_js: - - '14.15.0' + - 14 env: - TASK=pre-release