From 7dedcc4ea91d5bd972eb904608b0704f919024ba Mon Sep 17 00:00:00 2001 From: BTMuli Date: Fri, 13 Oct 2023 23:09:08 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E5=85=B6=E4=BD=99=E5=87=BD=E6=95=B0=E5=BC=8F=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/func/geetest.ts | 24 +++++++++++++++++++----- src/components/func/snackbar.ts | 24 +++++++++++++++++++----- src/components/func/snackbar.vue | 9 +-------- src/types/Component/Snackbar.d.ts | 14 +++++++++++--- 4 files changed, 50 insertions(+), 21 deletions(-) diff --git a/src/components/func/geetest.ts b/src/components/func/geetest.ts index e8f398e8..4961711d 100644 --- a/src/components/func/geetest.ts +++ b/src/components/func/geetest.ts @@ -4,12 +4,26 @@ * @since Beta v0.3.3 */ -import { h, render, type VNode } from "vue"; +import { h, render } from "vue"; +import type { ComponentInternalInstance, VNode } from "vue"; import geetest from "./geetest.vue"; const geetestId = "tg-func-geetest"; +/** + * @description 自定义 geetest 组件 + * @since Beta v0.3.3 + * @extends ComponentInternalInstance + * @property {Function} exposeProxy.displayBox 弹出 geetest 验证 + * @return GeetestInstance + */ +interface GeetestInstance extends ComponentInternalInstance { + exposeProxy: { + displayBox: () => boolean; + }; +} + const renderBox = (): VNode => { const container = document.createElement("div"); container.id = geetestId; @@ -21,14 +35,14 @@ const renderBox = (): VNode => { let geetestInstance: VNode; -const showGeetest = async (): Promise => { +async function showGeetest(): Promise { if (geetestInstance !== undefined) { - const boxVue = geetestInstance.component; - return boxVue?.exposeProxy?.displayBox(); + const boxVue = geetestInstance.component; + return boxVue.exposeProxy.displayBox(); } else { geetestInstance = renderBox(); return await showGeetest(); } -}; +} export default showGeetest; diff --git a/src/components/func/snackbar.ts b/src/components/func/snackbar.ts index 73198524..161e84d5 100644 --- a/src/components/func/snackbar.ts +++ b/src/components/func/snackbar.ts @@ -4,12 +4,26 @@ * @since Beta v0.3.3 */ -import { h, render, type VNode } from "vue"; +import type { ComponentInternalInstance, VNode } from "vue"; +import { h, render } from "vue"; import snackbar from "./snackbar.vue"; const snackbarId = "tg-func-snackbar"; +/** + * @description 自定义 snackbar 组件 + * @since Beta v0.3.3 + * @extends ComponentInternalInstance + * @property {Function} exposeProxy.displayBox 显示 snackbar + * @return SnackbarInstance + */ +interface SnackbarInstance extends ComponentInternalInstance { + exposeProxy: { + displayBox: typeof TGApp.Component.Snackbar.displayBox; + }; +} + const renderBox = (props: TGApp.Component.Snackbar.Params): VNode => { const container = document.createElement("div"); container.id = snackbarId; @@ -21,14 +35,14 @@ const renderBox = (props: TGApp.Component.Snackbar.Params): VNode => { let snackbarInstance: VNode; -const showSnackbar = (props: TGApp.Component.Snackbar.Params): void => { +function showSnackbar(props: TGApp.Component.Snackbar.Params): void { if (snackbarInstance !== undefined) { - const boxVue = snackbarInstance.component; - boxVue?.exposeProxy?.displayBox(props); + const boxVue = snackbarInstance.component; + boxVue.exposeProxy.displayBox(props); } else { snackbarInstance = renderBox(props); showSnackbar(props); } -}; +} export default showSnackbar; diff --git a/src/components/func/snackbar.vue b/src/components/func/snackbar.vue index c61b50ce..d25f4c79 100644 --- a/src/components/func/snackbar.vue +++ b/src/components/func/snackbar.vue @@ -8,16 +8,9 @@