54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
import WuhuBase from "../WuhuBase";
|
|
import POPUP_HTML from "../../static/html/popup.html";
|
|
import Log from "../Log";
|
|
|
|
export default class Popup extends WuhuBase {
|
|
className = 'Popup';
|
|
private readonly container: HTMLElement = null;
|
|
private readonly node: HTMLElement = null;
|
|
|
|
constructor(innerHTML: string, title: string = '芜湖助手') {
|
|
super();
|
|
if (Popup.glob.popup_node) {
|
|
Log.info('关闭前一个弹窗');
|
|
Popup.glob.popup_node.close();
|
|
}
|
|
Log.info('新建弹窗', { innerHTML, title });
|
|
const popup = document.createElement('div');
|
|
popup.id = 'wh-popup';
|
|
popup.innerHTML = POPUP_HTML.replace('{{}}', title).replace('{{}}', innerHTML);
|
|
document.body.append(popup);
|
|
popup.addEventListener('click', e => {
|
|
e.stopImmediatePropagation();
|
|
if (e.target === popup) this.close();
|
|
});
|
|
this.container = popup;
|
|
this.node = popup.querySelector('#wh-popup-cont');
|
|
this.hideChat();
|
|
Popup.glob.popup_node = this;
|
|
}
|
|
|
|
public close() {
|
|
this.container.remove();
|
|
this.showChat();
|
|
}
|
|
|
|
/**
|
|
* @return {HTMLElement} id=wh-popup-cont
|
|
*/
|
|
public getElement(): HTMLElement {
|
|
return this.node;
|
|
}
|
|
|
|
private hideChat() {
|
|
document.querySelector('#chatRoot').classList.add('wh-hide');
|
|
}
|
|
|
|
private showChat() {
|
|
document.querySelector('#chatRoot').classList.remove('wh-hide');
|
|
}
|
|
|
|
// 禁止单例调用
|
|
private getInstance() {
|
|
}
|
|
} |