import { Component, OnInit} from '@angular/core';
import { Emoji, Comfirmable } from '../../decorators';
@Component({
selector: 'app-horizontal-grid',
templateUrl: './horizontal-grid.component.html',
styleUrls: ['./horizontal-grid.component.css']
})
export class HorizontalGridComponent implements OnInit {
constructor() { }
@Emoji() result = 'hello';
@Comfirmable("您确认要执行吗")
handleClick(){
console.log("已经执行了")
}
ngOnInit() {
}
}
export function Emoji(){
return (target:object,key:string) =>{
let val = target[key];
const getter = () =>{
return val;
}
const setter = (value:string) => {
val = `? ${value} ?`
}
Object.defineProperty(target,key,{
get:getter,
set:setter,
enumerable:true,
configurable:true
})
}
}
export function Comfirmable(message:string){
return (target:object,key:string,descriptor:PropertyDescriptor) => {
const original = descriptor.value;
descriptor.value = function name(...args:any) {
const allow = window.confirm(message);
if(allow){
const result = original.apply(this,args)
return result;
}
return null;
}
return descriptor;
}
}