TS重构
This commit is contained in:
parent
6b85937b46
commit
e6b3477c71
@ -2,10 +2,10 @@ import Utils from "./Utils";
|
||||
import addStyle from "../../func/utils/addStyle";
|
||||
|
||||
export default class Alert extends Utils {
|
||||
static hasContainer: boolean = false;
|
||||
// static hasContainer: boolean = false;
|
||||
static container: HTMLElement = null;
|
||||
notify: HTMLElement = null;
|
||||
callback: Function = null;
|
||||
notify: MyHTMLElement = null;
|
||||
intervalID = -1;
|
||||
|
||||
constructor(msg: string, options: WHNotifyOpt = {}) {
|
||||
super();
|
||||
@ -25,11 +25,12 @@ export default class Alert extends Utils {
|
||||
|
||||
// 通知的容器
|
||||
if (!Alert.container) Alert.initContainer();
|
||||
this.notify = Alert.create(msg);
|
||||
this.notify = Alert.create(msg, timeout);
|
||||
this.intervalID = this.notify.loopId;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
static create(msg) {
|
||||
static create(msg, timeout) {
|
||||
const date = new Date();
|
||||
// 通知的唯一id
|
||||
const uid = '' + Utils.getRandomInt(1000, 9999);
|
||||
@ -53,11 +54,11 @@ export default class Alert extends Utils {
|
||||
// 通知进度条
|
||||
let progressCount = 101;
|
||||
// 删除通知
|
||||
new_node.close = () => {
|
||||
clearInterval(intervalID);
|
||||
new_node.remove();
|
||||
callback();
|
||||
};
|
||||
// new_node.close = () => {
|
||||
// clearInterval(intervalID);
|
||||
// new_node.remove();
|
||||
// callback();
|
||||
// };
|
||||
// 计时器
|
||||
let intervalID = window.setInterval(() => {
|
||||
if (mouse_enter) {
|
||||
@ -70,9 +71,12 @@ export default class Alert extends Utils {
|
||||
if (progressCount === 0) new_node.remove();
|
||||
}, timeout * 1000 / 100);
|
||||
new_node.querySelector('.wh-notify-close').addEventListener('click', new_node.close);
|
||||
new_node.loopId = intervalID;
|
||||
return new_node;
|
||||
}
|
||||
|
||||
callback: Function = () => null;
|
||||
|
||||
static initContainer() {
|
||||
this.container = document.createElement('div');
|
||||
this.container.id = 'wh-notify';
|
||||
@ -123,6 +127,8 @@ cursor: pointer;
|
||||
close() {
|
||||
this.notify.remove();
|
||||
this.notify = null;
|
||||
this.callback();
|
||||
clearInterval(this.intervalID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user