-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(共享模块): 添加dialog模块 dialog组件 附带confirm组件
- Loading branch information
1 parent
97c4d7a
commit 4f7d931
Showing
31 changed files
with
881 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Dialog | ||
|
||
## Services | ||
|
||
### open 打开方法 | ||
打开一个包含给定组件的模式对话框。 | ||
|
||
#### Parameters | ||
componentRef | ||
|
||
加载到对话框中的组件的类型,或作为对话框内容实例化的TemplateRef。 | ||
|
||
config | ||
|
||
额外的配置选项。参考Config | ||
|
||
#### Returns | ||
|
||
DialogRef<T> | ||
|
||
引用新打开的对话框。 | ||
|
||
## Directives | ||
|
||
### appDialogHeader | ||
对话框头部 | ||
Selector:[app-dialog-header],[appDialogHeader] | ||
|
||
### appDialogBody | ||
对话框内容 | ||
Selector:[app-dialog-body],[appDialogBody] | ||
|
||
### appDialogFooter | ||
对话框尾部 | ||
Selector:[app-dialog-footer],[appDialogFooter] | ||
|
||
可选配置: | ||
align 按钮对齐方式(默认左对齐) | ||
center 居中对齐 | ||
end 右对齐 | ||
|
||
### appDialogClose | ||
关闭对话框 | ||
Selector:[appDialogClose],[app-dialog-close] | ||
|
||
## Config | ||
|
||
resolve?: {} | null = null; // 给组件传入数据 keys 会注入子组件的inputs里 | ||
zIndex?: number; // 层级 默认Backdrop 1040 Dialog 1050 Dialog总是比Backdrop多10 | ||
height?: string; // 高度 默认宽度600px | ||
width?: string; // 宽度 auto | ||
hasBackdrop?: boolean; // 是否有遮罩背景 | ||
customClass?: string; // 自定义样式 dialog-backdrop-customClass dialog-customClass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<ng-content></ng-content> |
Empty file.
25 changes: 25 additions & 0 deletions
25
src/app/shared/dialog/dialog-body/dialog-body.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { DialogBodyComponent } from './dialog-body.component'; | ||
|
||
describe('DialogBodyComponent', () => { | ||
let component: DialogBodyComponent; | ||
let fixture: ComponentFixture<DialogBodyComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ DialogBodyComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(DialogBodyComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
src/app/shared/dialog/dialog-body/dialog-body.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Component, OnInit, HostBinding } from '@angular/core'; | ||
|
||
@Component({ | ||
// tslint:disable-next-line:component-selector | ||
selector: '[app-dialog-body],[appDialogBody]', | ||
templateUrl: './dialog-body.component.html', | ||
styleUrls: ['./dialog-body.component.scss'] | ||
}) | ||
export class DialogBodyComponent implements OnInit { | ||
/** | ||
* 绑定类 | ||
*/ | ||
@HostBinding('class.dialog-body') | ||
get _setDialogBodyClass() { | ||
return true; | ||
} | ||
constructor() { } | ||
|
||
ngOnInit() { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { DialogCloseDirective } from './dialog-close.directive'; | ||
|
||
describe('DialogCloseDirective', () => { | ||
it('should create an instance', () => { | ||
const directive = new DialogCloseDirective(); | ||
expect(directive).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Directive, HostListener } from '@angular/core'; | ||
import { DialogSubjectService } from './dialog-subject.service'; | ||
|
||
@Directive({ | ||
selector: '[appDialogClose],[app-dialog-close]' | ||
}) | ||
export class DialogCloseDirective { | ||
|
||
constructor(private subject: DialogSubjectService) { } | ||
|
||
/** clear all item selected status except this */ | ||
@HostListener('click', ['$event']) | ||
_onClickItem(event: Event) { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
// 如果没有dialogId 说明不是一个弹窗 | ||
if (this.subject.dialogId) { | ||
this.subject.next('onCancel'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { TestBed, inject } from '@angular/core/testing'; | ||
|
||
import { DialogConfigService } from './dialog-config.service'; | ||
|
||
describe('DialogConfigService', () => { | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [DialogConfigService] | ||
}); | ||
}); | ||
|
||
it('should be created', inject([DialogConfigService], (service: DialogConfigService) => { | ||
expect(service).toBeTruthy(); | ||
})); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* dialog 配置参数 | ||
*/ | ||
export class DialogConfig<D = any> { | ||
/** 传递给组件的数据 */ | ||
resolve?: D | null = null; // 给组件传入数据 | ||
zIndex?: number; // 层级 | ||
height?: string; // 高度 | ||
width?: string; // 宽度 | ||
hasBackdrop?: boolean; // 是否有遮罩背景 | ||
customClass?: string; // 自定义样式 dialog-backdrop-customClass dialog-customClass | ||
} |
12 changes: 12 additions & 0 deletions
12
src/app/shared/dialog/dialog-confirm/dialog-confirm.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<div app-dialog-body> | ||
<ng-template #defaultContent> | ||
<div class="dialog-confirm-content"> | ||
<i>icon</i> {{ _content }} | ||
</div> | ||
</ng-template> | ||
<ng-template [ngTemplateOutlet]="_contentTpl || defaultContent"></ng-template> | ||
</div> | ||
<div app-dialog-footer align="center"> | ||
<button type="button" class="u-btn u-btn-default" (click)="clickCancel($event)"><span>取消</span></button> | ||
<button type="button" class="u-btn u-btn-primary" (click)="clickConfirm($event)"><span>确定</span></button> | ||
</div> |
Empty file.
25 changes: 25 additions & 0 deletions
25
src/app/shared/dialog/dialog-confirm/dialog-confirm.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { DialogConfirmComponent } from './dialog-confirm.component'; | ||
|
||
describe('DialogConfirmComponent', () => { | ||
let component: DialogConfirmComponent; | ||
let fixture: ComponentFixture<DialogConfirmComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ DialogConfirmComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(DialogConfirmComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
src/app/shared/dialog/dialog-confirm/dialog-confirm.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Component, OnInit, OnDestroy, Input, TemplateRef } from '@angular/core'; | ||
import { DialogSubjectService } from '../dialog-subject.service'; | ||
|
||
@Component({ | ||
selector: 'app-dialog-confirm', | ||
templateUrl: './dialog-confirm.component.html', | ||
styleUrls: ['./dialog-confirm.component.scss'] | ||
}) | ||
export class DialogConfirmComponent implements OnInit { | ||
_contentTpl: TemplateRef<any>; | ||
_content: string; | ||
|
||
@Input() | ||
set content(value: string | TemplateRef<any>) { | ||
if (value instanceof TemplateRef) { | ||
this._contentTpl = value; | ||
} else { | ||
this._content = value; | ||
} | ||
} | ||
constructor(private subject: DialogSubjectService) { } | ||
|
||
ngOnInit() { | ||
} | ||
|
||
clickCancel() { | ||
this.subject.next('onCancel'); | ||
} | ||
|
||
clickConfirm() { | ||
this.subject.next({ data: 'hahah' }); | ||
this.subject.next('onConfirm'); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
src/app/shared/dialog/dialog-footer/dialog-footer.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<ng-content></ng-content> |
Empty file.
25 changes: 25 additions & 0 deletions
25
src/app/shared/dialog/dialog-footer/dialog-footer.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { DialogFooterComponent } from './dialog-footer.component'; | ||
|
||
describe('DialogFooterComponent', () => { | ||
let component: DialogFooterComponent; | ||
let fixture: ComponentFixture<DialogFooterComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ DialogFooterComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(DialogFooterComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
26 changes: 26 additions & 0 deletions
26
src/app/shared/dialog/dialog-footer/dialog-footer.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Component, OnInit, HostBinding, Input, ViewEncapsulation } from '@angular/core'; | ||
|
||
|
||
@Component({ | ||
// tslint:disable-next-line:component-selector | ||
selector: '[app-dialog-footer],[appDialogFooter]', | ||
templateUrl: './dialog-footer.component.html', | ||
styleUrls: ['./dialog-footer.component.scss'], | ||
encapsulation: ViewEncapsulation.None | ||
}) | ||
export class DialogFooterComponent implements OnInit { | ||
|
||
/** | ||
* 绑定类 | ||
*/ | ||
@HostBinding('class.dialog-footer') | ||
get _setDialogFooterClass() { | ||
return true; | ||
} | ||
|
||
constructor() { } | ||
|
||
ngOnInit() { | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
src/app/shared/dialog/dialog-header/dialog-header.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<ng-content></ng-content> |
Empty file.
25 changes: 25 additions & 0 deletions
25
src/app/shared/dialog/dialog-header/dialog-header.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { DialogHeaderComponent } from './dialog-header.component'; | ||
|
||
describe('DialogHeaderComponent', () => { | ||
let component: DialogHeaderComponent; | ||
let fixture: ComponentFixture<DialogHeaderComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ DialogHeaderComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(DialogHeaderComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
23 changes: 23 additions & 0 deletions
23
src/app/shared/dialog/dialog-header/dialog-header.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Component, OnInit, HostBinding, ViewEncapsulation } from '@angular/core'; | ||
|
||
@Component({ | ||
// tslint:disable-next-line:component-selector | ||
selector: '[app-dialog-header],[appDialogHeader]', | ||
templateUrl: './dialog-header.component.html', | ||
styleUrls: ['./dialog-header.component.scss'], | ||
encapsulation: ViewEncapsulation.None | ||
}) | ||
export class DialogHeaderComponent implements OnInit { | ||
/** | ||
* 绑定类 | ||
*/ | ||
@HostBinding('class.dialog-header') | ||
get _setDialogHeaderClass() { | ||
return true; | ||
} | ||
constructor() { } | ||
|
||
ngOnInit() { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { TestBed, inject } from '@angular/core/testing'; | ||
|
||
import { DialogSubjectService } from './dialog-subject.service'; | ||
|
||
describe('DialogSubjectService', () => { | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [DialogSubjectService] | ||
}); | ||
}); | ||
|
||
it('should be created', inject([DialogSubjectService], (service: DialogSubjectService) => { | ||
expect(service).toBeTruthy(); | ||
})); | ||
}); |
Oops, something went wrong.