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 593916d6
authored
Dec 16, 2024
by
Netfan
Committed by
GitHub
Dec 16, 2024
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat: form `colon` support (#5156)
1 parent
38805a0e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
11 deletions
docs/src/components/common-ui/vben-form.md
packages/@core/ui-kit/form-ui/src/form-render/form-field.vue
packages/@core/ui-kit/form-ui/src/form-render/form.vue
packages/@core/ui-kit/form-ui/src/types.ts
playground/src/views/examples/form/basic.vue
docs/src/components/common-ui/vben-form.md
View file @
593916d
...
...
@@ -313,14 +313,14 @@ useVbenForm 返回的第二个参数,是一个对象,包含了一些表单
| resetButtonOptions | 重置按钮组件参数 |
`ActionButtonOptions`
| - |
| submitButtonOptions | 提交按钮组件参数 |
`ActionButtonOptions`
| - |
| showDefaultActions | 是否显示默认操作按钮 |
`boolean`
|
`true`
|
| collapsed | 是否折叠,在
`
是否展开,在showCollapseButton=
true`
时生效 |
`boolean`
|
`false`
|
| collapsed | 是否折叠,在
`
showCollapseButton`
为
`
true`
时生效 |
`boolean`
|
`false`
|
| collapseTriggerResize | 折叠时,触发
`resize`
事件 |
`boolean`
|
`false`
|
| collapsedRows | 折叠时保持的行数 |
`number`
|
`1`
|
| fieldMappingTime | 用于将表单内时间区域
的应设
成 2 个字段 |
`[string, [string, string], string?][]`
| - |
| fieldMappingTime | 用于将表单内时间区域
组件的数组值映射
成 2 个字段 |
`[string, [string, string], string?][]`
| - |
| commonConfig | 表单项的通用配置,每个配置都会传递到每个表单项,表单项可覆盖 |
`FormCommonConfig`
| - |
| schema | 表单项的每一项配置 |
`FormSchema`
| - |
| schema | 表单项的每一项配置 |
`FormSchema
[]
`
| - |
| submitOnEnter | 按下回车健时提交表单 |
`boolean`
| false |
| submitOnChange | 字段值改变时提交表单 |
`boolean`
| false |
| submitOnChange | 字段值改变时提交表单
(内部防抖,这个属性一般用于表格的搜索表单)
|
`boolean`
| false |
### TS 类型说明
...
...
@@ -362,6 +362,10 @@ export interface FormCommonConfig {
*/
controlClass
?:
string
;
/**
* 在表单项的Label后显示一个冒号
*/
colon
?:
boolean
;
/**
* 所有表单项的禁用状态
* @default false
*/
...
...
@@ -420,7 +424,7 @@ export interface FormSchema<
dependencies
?:
FormItemDependencies
;
/** 描述 */
description
?:
string
;
/** 字段名 */
/** 字段名
,也作为自定义插槽的名称
*/
fieldName
:
string
;
/** 帮助信息 */
help
?:
string
;
...
...
@@ -443,7 +447,7 @@ export interface FormSchema<
```
ts
dependencies
:
{
//
只有当 name 字段的值变化时,才会触发联动
//
触发字段。只有这些字段值变动时,联动才会触发
triggerFields
:
[
'name'
],
// 动态判断当前字段是否需要显示,不显示则直接销毁
if
(
values
,
formApi
){},
...
...
@@ -464,11 +468,11 @@ dependencies: {
### 表单校验
表单
联动
需要通过 schema 内的
`rules`
属性进行配置。
表单
校验
需要通过 schema 内的
`rules`
属性进行配置。
rules的值可以是
一个字符串
,也可以是一个zod的schema。
rules的值可以是
字符串(预定义的校验规则名称)
,也可以是一个zod的schema。
####
字符串
####
预定义的校验规则
```
ts
// 表示字段必填,默认会根据适配器的required进行国际化
...
...
@@ -494,11 +498,16 @@ import { z } from '#/adapter/form';
rules
:
z
.
string
().
min
(
1
,
{
message
:
'请输入字符串'
});
}
// 可选
,并且携带默认值
// 可选
(可以是undefined),并且携带默认值。注意zod的optional不包括空字符串''
{
rules
:
z
.
string
().
default
(
'默认值'
).
optional
(),
}
// 可以是空字符串、undefined或者一个邮箱地址
{
rules
:
z
.
union
(
z
.
string
().
email
().
optional
(),
z
.
literal
(
""
))
}
// 复杂校验
{
z
.
string
().
min
(
1
,
{
message
:
"请输入"
})
...
...
packages/@core/ui-kit/form-ui/src/form-render/form-field.vue
View file @
593916d
...
...
@@ -26,6 +26,7 @@ import { isEventObjectLike } from './helper';
interface
Props
extends
FormSchema
{}
const
{
colon
,
commonComponentProps
,
component
,
componentProps
,
...
...
@@ -300,7 +301,10 @@ function autofocus() {
:required="shouldRequired
&&
!hideRequiredMark"
:style="labelStyle"
>
{{
label
}}
<template
v-if=
"label"
>
<span>
{{
label
}}
</span>
<span
v-if=
"colon"
class=
"ml-[2px]"
>
:
</span>
</
template
>
</FormLabel>
<div
:class=
"cn('relative flex w-full items-center', wrapperClass)"
>
<FormControl
:class=
"cn(controlClass)"
>
...
...
packages/@core/ui-kit/form-ui/src/form-render/form.vue
View file @
593916d
...
...
@@ -86,6 +86,7 @@ const computedSchema = computed(
formFieldProps
:
Record
<
string
,
any
>
;
}
&
Omit
<
FormSchema
,
'formFieldProps'
>
)[]
=>
{
const
{
colon
=
false
,
componentProps
=
{},
controlClass
=
''
,
disabled
,
...
...
@@ -110,6 +111,7 @@ const computedSchema = computed(
:
false
;
return
{
colon
,
disabled
,
disabledOnChangeListener
,
disabledOnInputListener
,
...
...
packages/@core/ui-kit/form-ui/src/types.ts
View file @
593916d
...
...
@@ -137,6 +137,10 @@ type ComponentProps =
export
interface
FormCommonConfig
{
/**
* 在Label后显示一个冒号
*/
colon
?:
boolean
;
/**
* 所有表单项的props
*/
componentProps
?:
ComponentProps
;
...
...
playground/src/views/examples/form/basic.vue
View file @
593916d
...
...
@@ -16,6 +16,8 @@ const activeTab = ref('basic');
const
[
BaseForm
,
baseFormApi
]
=
useVbenForm
({
// 所有表单项共用,可单独在表单内覆盖
commonConfig
:
{
// 在label后显示一个冒号
colon
:
true
,
// 所有表单项
componentProps
:
{
class
:
'w-full'
,
...
...
@@ -40,6 +42,7 @@ const [BaseForm, baseFormApi] = useVbenForm({
fieldName
:
'username'
,
// 界面显示的label
label
:
'字符串'
,
rules
:
'required'
,
},
{
// 组件需要在 #/adapter.ts内注册,并加上类型
...
...
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