From 923aae692f77296cabec7a0edcdc4086d8db55d3 Mon Sep 17 00:00:00 2001 From: BTMuli Date: Mon, 28 Aug 2023 15:52:52 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=B1=20=E5=B0=9D=E8=AF=95=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E5=BC=8F=E7=BB=84=E4=BB=B6=20#34?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/func/snackbar.ts | 36 ++++++++++++ src/components/func/snackbar.vue | 94 +++++++++++++++++++++++++++++++ src/types/Component/Snackbar.d.ts | 24 ++++++++ 3 files changed, 154 insertions(+) create mode 100644 src/components/func/snackbar.ts create mode 100644 src/components/func/snackbar.vue create mode 100644 src/types/Component/Snackbar.d.ts diff --git a/src/components/func/snackbar.ts b/src/components/func/snackbar.ts new file mode 100644 index 00000000..71e3826c --- /dev/null +++ b/src/components/func/snackbar.ts @@ -0,0 +1,36 @@ +/** + * @file component func snackbar.ts + * @description 封装 vuetify 的 snackbar 组件,通过函数调用的方式,简化 snackbar 的使用 + * @author BTMuli + * @since Alpha v0.2.3 + */ + +// vue +import { h, render, type VNode } from "vue"; +// snackbar +import snackbar from "./snackbar.vue"; + +const snackbarId = "tg-func-snackbar"; + +const renderBox = (props: TGApp.Component.Snackbar.Params): VNode => { + const container = document.createElement("div"); + container.id = snackbarId; + const boxVNode: VNode = h(snackbar, props); + render(boxVNode, container); + document.body.appendChild(container); + return boxVNode; +}; + +let snackbarInstance: any; + +const snackbarBox = (props: TGApp.Component.Snackbar.Params): void => { + if (snackbarInstance) { + const boxVue = snackbarInstance.component; + boxVue.exposeProxy.displayBox(props); + } else { + snackbarInstance = renderBox(props); + snackbarBox(props); + } +}; + +export default snackbarBox; diff --git a/src/components/func/snackbar.vue b/src/components/func/snackbar.vue new file mode 100644 index 00000000..71a85be6 --- /dev/null +++ b/src/components/func/snackbar.vue @@ -0,0 +1,94 @@ + + + diff --git a/src/types/Component/Snackbar.d.ts b/src/types/Component/Snackbar.d.ts new file mode 100644 index 00000000..eb5d360f --- /dev/null +++ b/src/types/Component/Snackbar.d.ts @@ -0,0 +1,24 @@ +/** + * @file types Component Snackbar.d.ts + * @description Component Snackbar 类型声明文件 + * @author BTMuli + * @since Alpha v0.2.3 + */ + +declare namespace TGApp.Component.Snackbar { + /** + * @description Snackbar 参数 + * @interface Params + * @since Alpha v0.2.3 + * @property {string} text 文本 + * @property {string} color 颜色 + * @property {number} timeout 超时时间 + * @property {boolean} show 是否显示 + * @return Params + */ + export interface Params { + text: string; + color?: string; + timeout?: number; + } +}