mirror of https://github.com/halo-dev/halo
a2810156da
#### What type of PR is this? /kind feature /area ui /area core /milestone 2.14.x #### What this PR does / why we need it: 为邮件的 `通知设置` 添加验证的功能。 同时为 formkit 增加了一个新的组件 (verificationForm),用于支持验证,它的定义方式如下: ``` - $formkit: verificationForm action: "http://localhost:8090/verify/user" label: 用户验证 children: - $formkit: text label: "用户名" name: username validation: required - $formkit: password label: "密码" name: password validation: required ``` verificationForm 支持 `action` 属性,当前端数据验证通过时,会将其下所包含的子节点数据发送至 action 所代表的接口上。 按上述示例,则验证数据会提交至 `http://localhost:8090/verify/user` 进行验证。验证的数据为 `{name: xxx, password: xxx}` 需要注意的是,verificationForm 只用于包装需要验证的数据,不会破坏原始数据的格式。因此上述数据在提交保存后仍旧为 `{name: xxx, password: xxx}` 而不会变成 `{verificationForm1: {name: xxx, password: xxx}}` #### How to test it? 1. 测试邮箱中的 `通知设置` 新增的验证按钮是否可以正常验证邮箱。 2. 查看数据是否正常回显 #### Which issue(s) this PR fixes: Fixes #4714 #### Does this PR introduce a user-facing change? ```release-note 在邮件通知设置中增加了发送测试的功能。 ``` |
||
---|---|---|
.. | ||
README.md |
README.md
自定义 FormKit 输入组件
原由
目前在 Console 端的所有表单都使用了 FormKit,但 FormKit 内置的 Input 组件并不满足所有的需求,因此需要自定义一些 Input 组件。此外,为了插件和主题能够更加方便的使用系统内的一些数据,所以同样需要自定义一些带数据的选择组件。
使用方式
目前已提供以下类型:
code
: 代码编辑器- 参数
- language: 目前支持
yaml
,html
,css
,javascript
,json
- height: 编辑器高度,如:
100px
- language: 目前支持
- 参数
attachment
: 附件选择- 参数
- accepts:允许上传的文件类型,如:
image/*
- accepts:允许上传的文件类型,如:
- 参数
repeater
: 定义一个对象集合,可以让使用者可视化的操作集合。- 参数
- min: 最小数量,默认为
0
- max: 最大数量,默认为
Infinity
,即无限制。 - addLabel: 添加按钮的文本,默认为
添加
- addButton: 是否显示添加按钮,默认为
true
- upControl: 是否显示上移按钮,默认为
true
- downControl: 是否显示下移按钮,默认为
true
- insertControl: 是否显示插入按钮,默认为
true
- removeControl: 是否显示删除按钮,默认为
true
- min: 最小数量,默认为
- 参数
menuCheckbox
:选择一组菜单menuRadio
:选择一个菜单menuItemSelect
:选择菜单项postSelect
:选择文章singlePageSelect
:选择自定义页面categorySelect
:选择分类- 参数
- multiple: 是否多选,默认为
false
- multiple: 是否多选,默认为
- 参数
categoryCheckbox
:选择多个分类tagSelect
:选择标签- 参数
- multiple: 是否多选,默认为
false
- multiple: 是否多选,默认为
- 参数
tagCheckbox
:选择多个标签verificationForm
: 远程验证一组数据是否符合某个规则- 参数
- action: 对目标数据进行验证的接口地址
- label: 验证按钮文本
- buttonAttrs: 验证按钮的额外属性
- 参数
在 Vue 单组件中使用:
<script lang="ts" setup>
const postName = ref("");
</script>
<template>
<FormKit
v-model="postName"
placeholder="请选择文章"
label="文章"
type="postSelect"
validation="required"
/>
</template>
在 FormKit Schema 中使用(插件 / 主题设置表单定义):
- $formkit: menuRadio
name: menus
label: 底部菜单组
Repeater
Repeater 是一个集合类型的输入组件,可以让使用者可视化的操作集合。
在 Vue SFC 中以组件形式使用:
<script lang="ts" setup>
const users = ref([]);
</script>
<template>
<FormKit
v-model="users"
:min="1"
:max="3"
addLabel="Add User"
type="repeater"
label="Users"
>
<FormKit
type="text"
label="Full Name"
name="full_name"
validation="required"
/>
<FormKit
type="email"
label="Email"
name="email"
validation="required|email"
/>
</FormKit>
</template>
在 FormKit Schema 中使用:
- $formkit: repeater
name: users
label: Users
addLabel: Add User
min: 1
max: 3
items:
- $formkit: text
name: full_name
label: Full Name
validation: required
- $formkit: email
name: email
label: Email
validation: required|email
最终得到的数据类似于:
[
{
"full_name": "Jack",
"email": "jack@example.com"
},
{
"full_name": "John",
"email": "john@example.com"
}
]