diff --git a/src/components/func/confirm.ts b/src/components/func/confirm.ts index fa099085..f429f535 100644 --- a/src/components/func/confirm.ts +++ b/src/components/func/confirm.ts @@ -1,7 +1,7 @@ /** - * @file component func confirm.ts + * @file component/func/confirm.ts * @description 封装自定义 confirm 组件,通过函数调用的方式,简化 confirm 的使用 - * @since Beta v0.3.4 + * @since Beta v0.3.9 */ import { h, render } from "vue"; @@ -35,10 +35,24 @@ const renderBox = (props: TGApp.Component.Confirm.Params): VNode => { let confirmInstance: VNode; -async function showConfirm(props: TGApp.Component.Confirm.ParamsConfirm): Promise; -async function showConfirm(props: TGApp.Component.Confirm.ParamsInput): Promise; -async function showConfirm(props: TGApp.Component.Confirm.Params): Promise; -async function showConfirm(props: TGApp.Component.Confirm.Params): Promise { +/** + * @function showConfirm + * @description 弹出 confirm + * @param {TGApp.Component.Confirm.Params} props confirm 的参数 + * @return {Promise} 点击确认返回 true,点击取消返回 false,点击外部返回 undefined + */ +async function showConfirm( + props: TGApp.Component.Confirm.ParamsConfirm, +): Promise; +async function showConfirm( + props: TGApp.Component.Confirm.ParamsInput, +): Promise; +async function showConfirm( + props: TGApp.Component.Confirm.Params, +): Promise; +async function showConfirm( + props: TGApp.Component.Confirm.Params, +): Promise { if (confirmInstance !== undefined) { const boxVue = confirmInstance.component; return await boxVue.exposeProxy.displayBox(props); diff --git a/src/components/func/confirm.vue b/src/components/func/confirm.vue index 2d9fa62b..b9612967 100644 --- a/src/components/func/confirm.vue +++ b/src/components/func/confirm.vue @@ -17,12 +17,12 @@ v-model="inputVal" class="confirm-input-box" ref="inputRef" - @keydown.enter="handleClick(true)" + @keydown.enter="handleConfirm" />
- - + +
@@ -54,7 +54,7 @@ const data = reactive({ const show = ref(false); const showOuter = ref(false); const showInner = ref(false); -const confirmVal = ref(false); +const confirmVal = ref(); const inputVal = ref(""); const inputRef = ref(); @@ -78,14 +78,16 @@ onMounted(async () => { await displayBox(props); }); -async function displayBox(params: TGApp.Component.Confirm.Params): Promise { +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) => { + return await new Promise((resolve) => { nextTick(() => { if (data.mode === "input") { // 等待确认框打开,聚焦输入框 @@ -103,27 +105,28 @@ async function displayBox(params: TGApp.Component.Confirm.Params): Promise