From 7570e965cf55c03dbdd55eab98a9c74f1730f67d Mon Sep 17 00:00:00 2001 From: MrKBear Date: Mon, 21 Mar 2022 17:33:10 +0800 Subject: [PATCH] Add popup model --- source/Context/Popups.ts | 85 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 source/Context/Popups.ts diff --git a/source/Context/Popups.ts b/source/Context/Popups.ts new file mode 100644 index 0000000..30cc1fb --- /dev/null +++ b/source/Context/Popups.ts @@ -0,0 +1,85 @@ +import { ReactNode } from "react"; + +/** + * 弹窗类型 + */ +class Popup { + + /** + * 是否关闭 + */ + public isClose: boolean = false; + + /** + * 唯一标识符 + */ + public id: string; + + /** + * 控制器 + */ + public controller: PopupController; + + /** + * 渲染层级 + */ + public index: number = 0; + + /** + * react 节点 + */ + public reactNode: ReactNode; + + /** + * 渲染函数 + */ + public rendererFunction: undefined | ((p: Popup) => ReactNode); + + /** + * 渲染节点 + */ + public render(): ReactNode { + if (this.rendererFunction) { + this.reactNode = this.rendererFunction(this); + } + return this.reactNode; + }; + + public constructor(controller: PopupController, id: string) { + this.controller = controller; + this.id = id; + } +} + +/** + * 弹窗模型 + */ +class PopupController { + + /** + * ID 序列号 + */ + private idIndex = 0; + + /** + * 弹窗列表 + */ + public popups: Popup[] = []; + + public sortPopup() { + this.popups = this.popups.sort((a, b) => a.index - b.index); + } + + public newPopup(): Popup { + let newPopup = new Popup(this, `P-${this.idIndex ++}`); + this.popups.push(newPopup); + return newPopup; + } + + public closePopup(popup: Popup | string) { + + } + +} + +export { Popup, PopupController } \ No newline at end of file