From d9f1a4d17ed26d2d97badf364c684f7c01458dd8 Mon Sep 17 00:00:00 2001 From: liuyun Date: Sun, 11 Oct 2026 09:53:26 +0800 Subject: [PATCH] feat: search inputs trigger search on Enter Co-Authored-By: Claude Opus 4.8 --- src/components/ty-form.vue | 12 ++++++++++++ src/components/ty-search-form.vue | 2 +- stats.html | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/components/ty-form.vue b/src/components/ty-form.vue index a6ac9d5..0addad4 100644 --- a/src/components/ty-form.vue +++ b/src/components/ty-form.vue @@ -58,6 +58,7 @@ :placeholder="prop.placeholder" :disabled="isReadonly(key, prop)" :style="widgetStyle(prop)" + @keyup.enter="onEnter" /> @@ -82,18 +83,29 @@ const props = withDefaults( inline?: boolean /** 表单模式(create/edit),用于 showOn 字段过滤。 */ mode?: 'create' | 'edit' + /** 输入框回车触发 submit 事件。 */ + enterToSubmit?: boolean /** 强制只读的字段名(如编辑模式下的 username)。 */ readonlyKeys?: string[] }>(), { inline: false, mode: undefined, + enterToSubmit: false, readonlyKeys: () => [], }, ) +const emit = defineEmits<{ + (e: 'submit'): void +}>() + const formRef = ref() +function onEnter(): void { + if (props.enterToSubmit) emit('submit') +} + /** 按 mode 过滤 showOn 字段。 */ const visibleProperties = computed(() => { const result: Record = {} diff --git a/src/components/ty-search-form.vue b/src/components/ty-search-form.vue index a820d17..e0b00d4 100644 --- a/src/components/ty-search-form.vue +++ b/src/components/ty-search-form.vue @@ -1,5 +1,5 @@