Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
monorepo
/
venus
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
1
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 6cd9937c
authored
Oct 17, 2024
by
Vben
Committed by
GitHub
Oct 17, 2024
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat: add submitOnEnter configuration to form (#4670)
1 parent
f89f4f32
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
29 additions
and
1 deletions
docs/src/components/common-ui/vben-form.md
packages/@core/ui-kit/form-ui/src/components/form-actions.vue
packages/@core/ui-kit/form-ui/src/form-api.ts
packages/@core/ui-kit/form-ui/src/types.ts
packages/@core/ui-kit/form-ui/src/vben-use-form.vue
playground/src/views/examples/form/basic.vue
playground/src/views/examples/vxe-table/form.vue
docs/src/components/common-ui/vben-form.md
View file @
6cd9937
...
@@ -311,6 +311,7 @@ useVbenForm 返回的第二个参数,是一个对象,包含了一些表单
...
@@ -311,6 +311,7 @@ useVbenForm 返回的第二个参数,是一个对象,包含了一些表单
| collapsedRows | 折叠时保持的行数 |
`number`
|
`1`
|
| collapsedRows | 折叠时保持的行数 |
`number`
|
`1`
|
| commonConfig | 表单项的通用配置,每个配置都会传递到每个表单项,表单项可覆盖 |
`FormCommonConfig`
| - |
| commonConfig | 表单项的通用配置,每个配置都会传递到每个表单项,表单项可覆盖 |
`FormCommonConfig`
| - |
| schema | 表单项的每一项配置 |
`FormSchema`
| - |
| schema | 表单项的每一项配置 |
`FormSchema`
| - |
| submitOnEnter | 按下回车健时提交表单 |
`boolean`
| false |
### TS 类型说明
### TS 类型说明
...
...
packages/@core/ui-kit/form-ui/src/components/form-actions.vue
View file @
6cd9937
...
@@ -75,6 +75,11 @@ watch(
...
@@ -75,6 +75,11 @@ watch(
}
}
},
},
);
);
defineExpose
({
handleReset
,
handleSubmit
,
});
</
script
>
</
script
>
<
template
>
<
template
>
<div
<div
...
...
packages/@core/ui-kit/form-ui/src/form-api.ts
View file @
6cd9937
...
@@ -35,6 +35,7 @@ function getDefaultState(): VbenFormProps {
...
@@ -35,6 +35,7 @@ function getDefaultState(): VbenFormProps {
showCollapseButton
:
false
,
showCollapseButton
:
false
,
showDefaultActions
:
true
,
showDefaultActions
:
true
,
submitButtonOptions
:
{},
submitButtonOptions
:
{},
submitOnEnter
:
false
,
wrapperClass
:
'grid-cols-1'
,
wrapperClass
:
'grid-cols-1'
,
};
};
}
}
...
...
packages/@core/ui-kit/form-ui/src/types.ts
View file @
6cd9937
...
@@ -319,7 +319,6 @@ export interface VbenFormProps<
...
@@ -319,7 +319,6 @@ export interface VbenFormProps<
* 重置按钮参数
* 重置按钮参数
*/
*/
resetButtonOptions
?:
ActionButtonOptions
;
resetButtonOptions
?:
ActionButtonOptions
;
/**
/**
* 是否显示默认操作按钮
* 是否显示默认操作按钮
* @default true
* @default true
...
@@ -330,6 +329,12 @@ export interface VbenFormProps<
...
@@ -330,6 +329,12 @@ export interface VbenFormProps<
* 提交按钮参数
* 提交按钮参数
*/
*/
submitButtonOptions
?:
ActionButtonOptions
;
submitButtonOptions
?:
ActionButtonOptions
;
/**
* 是否在回车时提交表单
* @default false
*/
submitOnEnter
?:
boolean
;
}
}
export
type
ExtendedFormApi
=
{
export
type
ExtendedFormApi
=
{
...
...
packages/@core/ui-kit/form-ui/src/vben-use-form.vue
View file @
6cd9937
...
@@ -6,6 +6,8 @@ import type { ExtendedFormApi, VbenFormProps } from './types';
...
@@ -6,6 +6,8 @@ import type { ExtendedFormApi, VbenFormProps } from './types';
import
{
useForwardPriorityValues
}
from
'@vben-core/composables'
;
import
{
useForwardPriorityValues
}
from
'@vben-core/composables'
;
// import { isFunction } from '@vben-core/shared/utils';
// import { isFunction } from '@vben-core/shared/utils';
import
{
useTemplateRef
}
from
'vue'
;
import
FormActions
from
'./components/form-actions.vue'
;
import
FormActions
from
'./components/form-actions.vue'
;
import
{
import
{
COMPONENT_BIND_EVENT_MAP
,
COMPONENT_BIND_EVENT_MAP
,
...
@@ -21,6 +23,8 @@ interface Props extends VbenFormProps {
...
@@ -21,6 +23,8 @@ interface Props extends VbenFormProps {
const
props
=
defineProps
<
Props
>
();
const
props
=
defineProps
<
Props
>
();
const
formActionsRef
=
useTemplateRef
<
typeof
FormActions
>
(
'formActionsRef'
);
const
state
=
props
.
formApi
?.
useStore
?.();
const
state
=
props
.
formApi
?.
useStore
?.();
const
forward
=
useForwardPriorityValues
(
props
,
state
);
const
forward
=
useForwardPriorityValues
(
props
,
state
);
...
@@ -34,10 +38,18 @@ props.formApi?.mount?.(form);
...
@@ -34,10 +38,18 @@ props.formApi?.mount?.(form);
const
handleUpdateCollapsed
=
(
value
:
boolean
)
=>
{
const
handleUpdateCollapsed
=
(
value
:
boolean
)
=>
{
props
.
formApi
?.
setState
({
collapsed
:
!!
value
});
props
.
formApi
?.
setState
({
collapsed
:
!!
value
});
};
};
function
handleKeyDownEnter
()
{
if
(
!
state
.
value
.
submitOnEnter
||
!
formActionsRef
.
value
)
{
return
;
}
formActionsRef
.
value
?.
handleSubmit
?.();
}
</
script
>
</
script
>
<
template
>
<
template
>
<Form
<Form
@
keydown
.
enter
.
prevent=
"handleKeyDownEnter"
v-bind=
"forward"
v-bind=
"forward"
:collapsed=
"state.collapsed"
:collapsed=
"state.collapsed"
:component-bind-event-map=
"COMPONENT_BIND_EVENT_MAP"
:component-bind-event-map=
"COMPONENT_BIND_EVENT_MAP"
...
@@ -56,6 +68,7 @@ const handleUpdateCollapsed = (value: boolean) => {
...
@@ -56,6 +68,7 @@ const handleUpdateCollapsed = (value: boolean) => {
<slot
v-bind=
"slotProps"
>
<slot
v-bind=
"slotProps"
>
<FormActions
<FormActions
v-if=
"forward.showDefaultActions"
v-if=
"forward.showDefaultActions"
ref=
"formActionsRef"
:model-value=
"state.collapsed"
:model-value=
"state.collapsed"
@
update:model-value=
"handleUpdateCollapsed"
@
update:model-value=
"handleUpdateCollapsed"
>
>
...
...
playground/src/views/examples/form/basic.vue
View file @
6cd9937
...
@@ -16,6 +16,7 @@ const [BaseForm, baseFormApi] = useVbenForm({
...
@@ -16,6 +16,7 @@ const [BaseForm, baseFormApi] = useVbenForm({
class
:
'w-full'
,
class
:
'w-full'
,
},
},
},
},
// 提交函数
// 提交函数
handleSubmit
:
onSubmit
,
handleSubmit
:
onSubmit
,
// 垂直布局,label和input在不同行,值为vertical
// 垂直布局,label和input在不同行,值为vertical
...
...
playground/src/views/examples/vxe-table/form.vue
View file @
6cd9937
...
@@ -65,6 +65,8 @@ const formOptions: VbenFormProps = {
...
@@ -65,6 +65,8 @@ const formOptions: VbenFormProps = {
],
],
// 控制表单是否显示折叠按钮
// 控制表单是否显示折叠按钮
showCollapseButton
:
true
,
showCollapseButton
:
true
,
// 按下回车时是否提交表单
submitOnEnter
:
false
,
};
};
const
gridOptions
:
VxeGridProps
<
RowType
>
=
{
const
gridOptions
:
VxeGridProps
<
RowType
>
=
{
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment