🚸 更新 dialog 组件,添加输入类型支持

This commit is contained in:
BTMuli
2026-05-19 18:46:12 +08:00
parent 4cd77ee74f
commit 482e736164
2 changed files with 16 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
/**
* dialog 组件封装,函数式调用
* @since Beta v0.9.1
* @since Beta v0.10.2
*/
import type { ComponentInternalInstance, VNode } from "vue";
@@ -35,6 +35,8 @@ export type DialogInputParams = DialogBaseParams & {
mode: "input";
/** 默认值 */
input?: string;
/** 输入类型 */
type?: string;
};
/**
@@ -123,11 +125,16 @@ async function showDialogInput(
}
}
/**
* Input Mode 封装
* @since Beta v0.10.2
* @param opts - 参数
* @returns 输入模式值
*/
async function showDialogInputFull(
opts: DialogBaseParams,
input?: string,
opts: Omit<DialogInputParams, "mode">,
): Promise<string | false | undefined> {
const params: DialogInputParams = { mode: "input", input, ...opts };
const params: DialogInputParams = { mode: "input", ...opts };
if (dialogInstance !== undefined) {
const boxVue = <DialogInstance>dialogInstance.component;
return await boxVue.exposeProxy.displayInputBox(params);

View File

@@ -17,6 +17,7 @@
<input
ref="inputRef"
v-model="inputDefault"
:type="inputType"
class="dialog-input-box"
@keydown.enter="handleConfirm"
/>
@@ -63,6 +64,7 @@ const dialogVal = ref<boolean | string | undefined>();
const inputDefault = ref<string>("");
const inputEl = useTemplateRef<HTMLInputElement>("inputRef");
const inputType = ref<string>("text");
const checkVal = computed<boolean | undefined>(() => {
if (typeof dialogVal.value === "string") return dialogVal.value !== "";
@@ -98,6 +100,7 @@ onMounted(async () => {
text: props.text,
input: props.input,
otcancel: props.otcancel,
type: props.type,
};
await displayInputBox(param);
} else {
@@ -142,6 +145,7 @@ async function displayInputBox(params: DialogInputParams): Promise<string | fals
cancelLabel: params.cancelLabel ?? defaultProp.cancelLabel,
};
inputDefault.value = params.input ?? "";
inputType.value = params.type ?? "text";
show.value = true;
return await new Promise<string | false | undefined>((resolve) => {
setTimeout(() => inputEl.value?.focus(), 100);
@@ -160,6 +164,7 @@ function handleConfirm(): void {
if (data.value.mode === "input") {
dialogVal.value = inputDefault.value;
inputDefault.value = "";
inputType.value = "text";
} else dialogVal.value = true;
show.value = false;
}