feat: search inputs trigger search on Enter

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
liuyun 2026-10-11 09:53:26 +08:00
parent 1699fee4a8
commit d9f1a4d17e
3 changed files with 14 additions and 2 deletions

View File

@ -58,6 +58,7 @@
:placeholder="prop.placeholder"
:disabled="isReadonly(key, prop)"
:style="widgetStyle(prop)"
@keyup.enter="onEnter"
/>
</el-form-item>
@ -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<FormInstance>()
function onEnter(): void {
if (props.enterToSubmit) emit('submit')
}
/** 按 mode 过滤 showOn 字段。 */
const visibleProperties = computed(() => {
const result: Record<string, JsonSchemaProperty> = {}

View File

@ -1,5 +1,5 @@
<template>
<ty-form :schema="visibleSchema" :model-value="modelValue" inline>
<ty-form :schema="visibleSchema" :model-value="modelValue" inline enter-to-submit @submit="emit('search')">
<el-form-item class="ty-search-form__actions">
<el-button v-if="collapsible" link type="primary" @click="expanded = !expanded">
{{ expanded ? '收起' : '展开' }}

File diff suppressed because one or more lines are too long