Skip to content

Commit

Permalink
feat(共享模块): 添加dialog模块 dialog组件 附带confirm组件
Browse files Browse the repository at this point in the history
  • Loading branch information
jiayisheji committed Nov 10, 2017
1 parent 97c4d7a commit 4f7d931
Show file tree
Hide file tree
Showing 31 changed files with 881 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/app/shared/dialog/README.md
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
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 src/app/shared/dialog/dialog-body/dialog-body.component.spec.ts
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 src/app/shared/dialog/dialog-body/dialog-body.component.ts
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() {
}

}
8 changes: 8 additions & 0 deletions src/app/shared/dialog/dialog-close.directive.spec.ts
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();
});
});
21 changes: 21 additions & 0 deletions src/app/shared/dialog/dialog-close.directive.ts
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');
}
}
}
15 changes: 15 additions & 0 deletions src/app/shared/dialog/dialog-config.service.spec.ts
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();
}));
});
12 changes: 12 additions & 0 deletions src/app/shared/dialog/dialog-config.service.ts
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 src/app/shared/dialog/dialog-confirm/dialog-confirm.component.html
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.
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 src/app/shared/dialog/dialog-confirm/dialog-confirm.component.ts
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');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<ng-content></ng-content>
Empty file.
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 src/app/shared/dialog/dialog-footer/dialog-footer.component.ts
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() {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<ng-content></ng-content>
Empty file.
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 src/app/shared/dialog/dialog-header/dialog-header.component.ts
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() {
}

}
15 changes: 15 additions & 0 deletions src/app/shared/dialog/dialog-subject.service.spec.ts
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();
}));
});
Loading

0 comments on commit 4f7d931

Please sign in to comment.