From 55761e81b5c9328d8e4ef6470c4d9f8bc12e5e7a Mon Sep 17 00:00:00 2001 From: BTMuli Date: Tue, 29 Aug 2023 18:23:14 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20=E4=BC=98=E5=8C=96=E7=BB=84?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/func/confirm.ts | 4 +- src/components/func/confirm.vue | 51 ++++++++++------------ src/components/func/snackbar.ts | 4 +- src/components/func/snackbar.vue | 74 ++++++++++++++++++++------------ src/types/Component/Confirm.d.ts | 2 +- 5 files changed, 74 insertions(+), 61 deletions(-) diff --git a/src/components/func/confirm.ts b/src/components/func/confirm.ts index d0a9b1f3..de41fd53 100644 --- a/src/components/func/confirm.ts +++ b/src/components/func/confirm.ts @@ -21,12 +21,12 @@ const renderBox = (props: TGApp.Component.Confirm.Params): VNode => { return boxVNode; }; -let confirmInstance: any; +let confirmInstance: VNode; const showConfirm = async (props: TGApp.Component.Confirm.Params): Promise => { if (confirmInstance) { const boxVue = confirmInstance.component; - return boxVue.exposeProxy.displayBox(props); + return boxVue?.exposeProxy?.displayBox(props); } else { confirmInstance = renderBox(props); return await showConfirm(props); diff --git a/src/components/func/confirm.vue b/src/components/func/confirm.vue index 09ba587b..558b37e2 100644 --- a/src/components/func/confirm.vue +++ b/src/components/func/confirm.vue @@ -4,7 +4,7 @@
- {{ data.title ?? "" }} + {{ data.title }}
{{ data.text }} @@ -37,7 +37,7 @@ import { onMounted, reactive, ref, watch } from "vue"; interface ConfirmProps { title: string; - text?: string; + text: string; mode: "confirm" | "input"; otcancel?: boolean; } @@ -49,11 +49,9 @@ const props = withDefaults(defineProps(), { }); // 组件参数 -const data = reactive({ +const data = reactive({ title: "", - text: "", mode: "confirm", - otcancel: false, }); const show = ref(false); const showOuter = ref(false); @@ -61,34 +59,31 @@ const showInner = ref(false); const confirmVal = ref(false); const inputVal = ref(""); -watch( - () => show.value, - () => { - if (show.value) { - showOuter.value = true; - setTimeout(() => { - showInner.value = true; - }, 100); - } else { - setTimeout(() => { - showInner.value = false; - }, 100); - setTimeout(() => { - showOuter.value = false; - }, 300); - } - }, -); +watch(show, () => { + if (show.value) { + showOuter.value = true; + setTimeout(() => { + showInner.value = true; + }, 100); + } else { + setTimeout(() => { + showInner.value = false; + }, 100); + setTimeout(() => { + showOuter.value = false; + }, 300); + } +}); onMounted(async () => { await displayBox(props); }); -async function displayBox(props: TGApp.Component.Confirm.Params): Promise { - data.title = props.title; - data.text = props.text ?? ""; - data.mode = props.mode ?? "confirm"; - data.otcancel = props.otcancel ?? true; +async function displayBox(params: TGApp.Component.Confirm.Params): Promise { + data.title = params.title; + data.text = params.text ?? ""; + data.mode = params.mode ?? "confirm"; + data.otcancel = params.otcancel ?? true; show.value = true; // 等待确认框关闭,返回关闭后的confirmVal return await new Promise((resolve) => { diff --git a/src/components/func/snackbar.ts b/src/components/func/snackbar.ts index e4be1a5f..d9e2f527 100644 --- a/src/components/func/snackbar.ts +++ b/src/components/func/snackbar.ts @@ -21,12 +21,12 @@ const renderBox = (props: TGApp.Component.Snackbar.Params): VNode => { return boxVNode; }; -let snackbarInstance: any; +let snackbarInstance: VNode; const showSnackbar = (props: TGApp.Component.Snackbar.Params): void => { if (snackbarInstance) { const boxVue = snackbarInstance.component; - boxVue.exposeProxy.displayBox(props); + boxVue?.exposeProxy?.displayBox(props); } else { snackbarInstance = renderBox(props); showSnackbar(props); diff --git a/src/components/func/snackbar.vue b/src/components/func/snackbar.vue index 71a85be6..29a17e23 100644 --- a/src/components/func/snackbar.vue +++ b/src/components/func/snackbar.vue @@ -8,16 +8,34 @@ diff --git a/src/types/Component/Confirm.d.ts b/src/types/Component/Confirm.d.ts index a6bad5e1..c44d9582 100644 --- a/src/types/Component/Confirm.d.ts +++ b/src/types/Component/Confirm.d.ts @@ -19,7 +19,7 @@ declare namespace TGApp.Component.Confirm { export interface Params { title: string; text?: string; - mode?: "confirm" | "input"; + mode: "confirm" | "input"; otcancel?: boolean; } }