import Log from "../Log"; import IWHNotify from "../../interface/IWHNotify"; import NotificationUtils from "./NotificationUtils"; import WuhuBase from "../WuhuBase"; import MathUtils from "./MathUtils"; export default class Alert extends WuhuBase { private static container: HTMLElement = null; private notify: MyHTMLElement = null; private intervalID = -1; private readonly callback: Function; public constructor(msg: string, options: IWHNotify = {}) { super(); let { timeout, callback, sysNotify, } = options; // 后台窗口、iframe内判断 if (!Alert.glob.isWindowActive.get() || (self !== top)) return null; // 通知的容器 if (Alert.container === null) Alert.initContainer(); this.callback = callback || (() => null); Alert.create(this, msg, timeout || 3); Log.info('创建新通知:', this); if (sysNotify) NotificationUtils.getInstance().push(msg, options); } private static create(that: Alert, msg, timeout): void { let mathUtils: MathUtils = MathUtils.getInstance(); // 通知的唯一id const uid = '' + mathUtils.getRandomInt(1000, 9999); // const uid = '' + performance.now(); // 每条通知 const element: MyHTMLElement = document.createElement('div'); element.id = `wh-notify-${ uid }`; element.classList.add('wh-notify-item'); element.innerHTML = `
${ msg }