33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
import ZhongIcon from "../ZhongIcon";
|
|
import ClassName from "../../container/ClassName";
|
|
import { Injectable } from "../../container/Injectable";
|
|
import Logger from "../Logger";
|
|
|
|
@ClassName('ActionButtonUtils')
|
|
@Injectable()
|
|
export default class ActionButtonUtils {
|
|
private hasAdded: boolean = false;
|
|
|
|
constructor(
|
|
private readonly logger: Logger,
|
|
) {
|
|
}
|
|
|
|
public add(txt: string, func: (ev: Event) => void = () => null): void {
|
|
if (!this.hasAdded) this.handle(txt, func);
|
|
else this.logger.warn('ActionButton已存在');
|
|
}
|
|
|
|
private handle(txt, func): void {
|
|
let btn = document.createElement('button');
|
|
btn.style.padding = '8px 13px 8px 0';
|
|
btn.style.verticalAlign = 'bottom';
|
|
btn.style.color = '#4CAF50';
|
|
btn.innerHTML = txt;
|
|
btn.addEventListener('click', func);
|
|
ZhongIcon.ZhongNode.querySelector('button').after(btn);
|
|
this.hasAdded = true;
|
|
this.logger.info('ActionButton已添加', { txt, func, btn });
|
|
}
|
|
}
|