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; + } +}