From e6b3477c7156ca3ca99fc701e14274054c71cee2 Mon Sep 17 00:00:00 2001 From: Liwanyi Date: Fri, 23 Sep 2022 18:23:09 +0800 Subject: [PATCH] =?UTF-8?q?TS=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/class/utils/Alert.ts | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/class/utils/Alert.ts b/src/class/utils/Alert.ts index cd1f190..82449de 100644 --- a/src/class/utils/Alert.ts +++ b/src/class/utils/Alert.ts @@ -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); } }