-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
徐文清-前端开发组
committed
Nov 28, 2017
1 parent
e590c2b
commit 11ca3d0
Showing
4 changed files
with
85 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,28 @@ | ||
import { Directive, Input, HostListener } from '@angular/core'; | ||
const singleAvatarErrorIcon = '../../../assets/images/single-avatar.svg'; | ||
const groupAvatarErrorIcon = '../../../assets/images/group-avatar.svg'; | ||
|
||
/** | ||
* 群组或单聊默认头像 | ||
*/ | ||
|
||
@Directive({ selector: '[avatarError]' }) | ||
|
||
export class AvatarErrorDirective { | ||
@Input() | ||
private avatarError; | ||
constructor() { | ||
// pass | ||
} | ||
@HostListener('error', ['$event']) private onError(event) { | ||
/** | ||
* group 1 | ||
* single 0 | ||
*/ | ||
if (this.avatarError === 1) { | ||
event.target.src = groupAvatarErrorIcon; | ||
} else if (this.avatarError === 0) { | ||
event.target.src = singleAvatarErrorIcon; | ||
} | ||
} | ||
} |
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,20 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { FormsModule } from '@angular/forms'; | ||
import { NgModule } from '@angular/core'; | ||
import { AvatarErrorDirective } from './avatar-error.directive'; | ||
|
||
@NgModule({ | ||
declarations: [ | ||
AvatarErrorDirective | ||
], | ||
imports: [ | ||
CommonModule, | ||
FormsModule | ||
], | ||
exports: [ | ||
AvatarErrorDirective | ||
], | ||
providers: [] | ||
}) | ||
|
||
export class AvatarErrorModule {} |
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,17 @@ | ||
import { Directive, HostListener } from '@angular/core'; | ||
import { Util } from '../services/util'; | ||
|
||
/** | ||
* 对头像的宽高进行限制 | ||
*/ | ||
|
||
@Directive({ selector: '[avatarLoad]' }) | ||
|
||
export class AvatarLoadDirective { | ||
constructor() { | ||
// pass | ||
} | ||
@HostListener('load', ['$event']) private onLoad(event) { | ||
Util.reduceAvatarSize(event); | ||
} | ||
} |
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,20 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { FormsModule } from '@angular/forms'; | ||
import { NgModule } from '@angular/core'; | ||
import { AvatarLoadDirective } from './avatar-load.directive'; | ||
|
||
@NgModule({ | ||
declarations: [ | ||
AvatarLoadDirective | ||
], | ||
imports: [ | ||
CommonModule, | ||
FormsModule | ||
], | ||
exports: [ | ||
AvatarLoadDirective | ||
], | ||
providers: [] | ||
}) | ||
|
||
export class AvatarLoadModule {} |