my-lib/antd.ts
Properties |
Methods |
Accessors |
constructor(ele: ElementRef, render: Renderer2, name: string)
|
||||||||||||||||
Defined in my-lib/antd.ts:14
|
||||||||||||||||
Parameters :
|
_getPosition | ||||||||
_getPosition(event: MouseEvent | TouchEvent)
|
||||||||
Defined in my-lib/antd.ts:112
|
||||||||
Parameters :
Returns :
{ x: any; y: any; }
|
addClass | ||||||||
addClass(className: string)
|
||||||||
Defined in my-lib/antd.ts:68
|
||||||||
添加一个class
Parameters :
Returns :
void
|
addToClass | ||||||||||||||||
addToClass(name: , val: , hasPre: boolean)
|
||||||||||||||||
Defined in my-lib/antd.ts:50
|
||||||||||||||||
Parameters :
Returns :
void
|
classNames |
classNames()
|
Defined in my-lib/antd.ts:25
|
Returns :
any
|
hasClass | ||||||||
hasClass(className: string)
|
||||||||
Defined in my-lib/antd.ts:61
|
||||||||
是否存在class
Parameters :
Returns :
boolean
|
isMeepoTrue | ||||||||
isMeepoTrue(val: string)
|
||||||||
Defined in my-lib/antd.ts:104
|
||||||||
Parameters :
Returns :
any
|
ngClass |
ngClass(obj: any, name: string)
|
Defined in my-lib/antd.ts:93
|
Returns :
any
|
removeClass | ||||||||
removeClass(className: string)
|
||||||||
Defined in my-lib/antd.ts:87
|
||||||||
移除一个class
Parameters :
Returns :
void
|
setClassObj | ||||||||||||||||
setClassObj(arrs: , val: , pre: string)
|
||||||||||||||||
Defined in my-lib/antd.ts:108
|
||||||||||||||||
Parameters :
Returns :
void
|
setStyle |
setStyle(name: string, value: string)
|
Defined in my-lib/antd.ts:75
|
Returns :
void
|
setStyleObj | ||||||||
setStyleObj(styleObj: any)
|
||||||||
Defined in my-lib/antd.ts:79
|
||||||||
Parameters :
Returns :
void
|
_class |
_class:
|
Type : Object
|
Default value : {}
|
Defined in my-lib/antd.ts:4
|
_name |
_name:
|
Type : string
|
Default value : 'am-'
|
Defined in my-lib/antd.ts:5
|
Public ele |
ele:
|
Type : ElementRef
|
Defined in my-lib/antd.ts:17
|
Public render |
render:
|
Type : Renderer2
|
Defined in my-lib/antd.ts:18
|
class |
setclass(val: any)
|
Defined in my-lib/antd.ts:7
|
import { ansycClassObj, isMeepoTrue, setClassObj } from 'meepo-utils';
import { Renderer2, ElementRef, Input, HostBinding } from '@angular/core';
export class Antd {
_class: Object = {};
_name: string = 'am-';
@Input()
set class(val: any) {
this._class[val] = true;
}
@HostBinding(`class`)
get flexClass() {
return this.classNames.call(null, this._class);
}
constructor(
public ele: ElementRef,
public render: Renderer2,
name: string
) {
this._name = `am-${name}`;
this._class[this._name] = true;
}
classNames() {
const hasOwn = {}.hasOwnProperty;
const classes = [];
for (let i = 0; i < arguments.length; i++) {
const arg = arguments[i];
if (!arg) continue;
const argType = typeof arg;
if (argType === 'string' || argType === 'number') {
classes.push(arg);
} else if (Array.isArray(arg) && arg.length) {
const inner = this.classNames.apply(null, arg);
if (inner) {
classes.push(inner);
}
} else if (argType === 'object') {
for (const key in arg) {
if (hasOwn.call(arg, key) && arg[key]) {
classes.push(key);
}
}
}
}
return classes.join(' ');
}
addToClass(name, val, hasPre: boolean = true) {
if (hasPre) {
this._class[`${this._name}${name}`] = val;
} else {
this._class[`${name}`] = val;
}
}
/**
* 是否存在class
*/
hasClass(className: string) {
const originClass = this.ele.nativeElement.className;
return ` ${originClass} `.indexOf(` ${className} `) > -1;
}
/**
* 添加一个class
*/
addClass(className: string): void {
if (this.hasClass(className)) {
return;
}
this.render.addClass(this.ele.nativeElement, className);
}
// 设置单个样式
setStyle(name: string, value: string): void {
this.render.setStyle(this.ele.nativeElement, name, value);
}
// 批量设置样式
setStyleObj(styleObj: any) {
for (const key in styleObj) {
this.setStyle(key, styleObj[key]);
}
}
/**
* 移除一个class
*/
removeClass(className: string): void {
if (this.hasClass(className)) {
this.render.removeClass(this.ele.nativeElement, className);
}
}
// [ngClass]="{}"
ngClass(obj: any, name: string) {
for (const key in obj) {
if (obj[key]) {
this.addClass(key);
} else {
this.removeClass(key);
}
}
return ansycClassObj(obj, name);
}
// 是否为真
isMeepoTrue(val: string) {
return isMeepoTrue(val);
}
setClassObj(arrs, val, pre: string = '') {
this._class = setClassObj(arrs, this._class, val, this._name + pre);
}
_getPosition(event: MouseEvent | TouchEvent) {
let xPos, yPos, rect;
rect = this.ele.nativeElement.getBoundingClientRect();
if (event instanceof TouchEvent) {
xPos = event.touches[0].clientX - rect.left;
yPos = event.touches[0].clientY - rect.top;
} else {
xPos = event.clientX - rect.left;
yPos = event.clientY - rect.top;
}
return {
x: xPos,
y: yPos
};
}
}