From e6c5e98ef9b57dc8d45121468d38b6c784507bfe Mon Sep 17 00:00:00 2001 From: BTMuli Date: Tue, 29 Aug 2023 14:44:26 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=B1=20=E5=88=9D=E6=AD=A5=E5=B0=9D?= =?UTF-8?q?=E8=AF=95=E6=94=B9=E9=80=A0=20confirm=EF=BC=8C=E5=9B=9E?= =?UTF-8?q?=E8=B0=83=E6=B2=A1=E5=86=99=E5=A5=BD=20#34?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/func/confirm.ts | 36 +++++ src/components/func/confirm.vue | 220 +++++++++++++++++++++++++++++++ src/types/Component/Confirm.d.ts | 30 +++++ 3 files changed, 286 insertions(+) create mode 100644 src/components/func/confirm.ts create mode 100644 src/components/func/confirm.vue create mode 100644 src/types/Component/Confirm.d.ts diff --git a/src/components/func/confirm.ts b/src/components/func/confirm.ts new file mode 100644 index 00000000..1f6b194c --- /dev/null +++ b/src/components/func/confirm.ts @@ -0,0 +1,36 @@ +/** + * @file component func confirm.ts + * @description 封装自定义 confirm 组件,通过函数调用的方式,简化 confirm 的使用 + * @author BTMuli + * @since Alpha v0.2.3 + */ + +// vue +import { h, render, type VNode } from "vue"; +// confirm +import confirm from "./confirm.vue"; + +const confirmId = "tg-func-confirm"; + +const renderBox = (props: TGApp.Component.Confirm.Params): VNode => { + const container = document.createElement("div"); + container.id = confirmId; + const boxVNode: VNode = h(confirm, props); + render(boxVNode, container); + document.body.appendChild(container); + return boxVNode; +}; + +let confirmInstance: any; + +const showConfirm = (props: TGApp.Component.Confirm.Params): void => { + if (confirmInstance) { + const boxVue = confirmInstance.component; + boxVue.exposeProxy.displayBox(props); + } else { + confirmInstance = renderBox(props); + showConfirm(props); + } +}; + +export default showConfirm; diff --git a/src/components/func/confirm.vue b/src/components/func/confirm.vue new file mode 100644 index 00000000..228173ec --- /dev/null +++ b/src/components/func/confirm.vue @@ -0,0 +1,220 @@ + + + + + diff --git a/src/types/Component/Confirm.d.ts b/src/types/Component/Confirm.d.ts new file mode 100644 index 00000000..702eee6b --- /dev/null +++ b/src/types/Component/Confirm.d.ts @@ -0,0 +1,30 @@ +/** + * @file types Component Confirm.d.ts + * @description Component Confirm 类型声明文件 + * @author BTMuli + * @since Alpha v0.2.3 + */ + +declare namespace TGApp.Component.Confirm { + /** + * @description Confirm 参数 + * @interface Params + * @since Alpha v0.2.3 + * @property {string} title 标题 + * @property {string} text 文本 + * @property {string} mode 模式 // normal: 正常(默认),input: 输入框 + * @property {boolean} otcancel 点击外部取消 // true: 取消(默认),false: 不取消 + * @property {function} onConfirm 确认回调 + * @property {function} onCancel 取消回调 + * @property {function} onInput 输入回调 + * @return Params + */ + export interface Params { + title: string; + text?: string; + mode?: "confirm" | "input"; + otcancel?: boolean; + onConfirm?: (value?: string | boolean) => void; + onCancel?: () => void; + } +}