2022-10-18 03:32:09 +00:00
|
|
|
|
# 自定义 FormKit 输入组件
|
|
|
|
|
|
|
|
|
|
## 原由
|
|
|
|
|
|
2022-11-01 02:56:16 +00:00
|
|
|
|
目前在 Console 端的所有表单都使用了 FormKit,但 FormKit 内置的 Input 组件并不满足所有的需求,因此需要自定义一些 Input 组件。此外,为了插件和主题能够更加方便的使用系统内的一些数据,所以同样需要自定义一些带数据的选择组件。
|
2022-10-18 03:32:09 +00:00
|
|
|
|
|
|
|
|
|
## 使用方式
|
|
|
|
|
|
|
|
|
|
目前已提供以下类型:
|
|
|
|
|
|
2022-11-01 02:56:16 +00:00
|
|
|
|
- `code`: 代码编辑器
|
|
|
|
|
- 参数
|
|
|
|
|
1. language: 目前支持 `yaml`, `html`, `css`, `javascript`, `json`
|
|
|
|
|
2. height: 编辑器高度,如:`100px`
|
2022-11-01 03:06:18 +00:00
|
|
|
|
- `attachment`: 附件选择
|
2023-04-24 07:45:44 +00:00
|
|
|
|
- 参数
|
|
|
|
|
1. accepts:允许上传的文件类型,如:`image/*`
|
2022-11-15 07:48:17 +00:00
|
|
|
|
- `repeater`: 定义一个对象集合,可以让使用者可视化的操作集合。
|
2023-05-25 14:38:19 +00:00
|
|
|
|
- 参数
|
|
|
|
|
1. min: 最小数量,默认为 `0`
|
|
|
|
|
2. max: 最大数量,默认为 `Infinity`,即无限制。
|
refactor: refactor the repeater component using the schema approach (#4702)
#### What type of PR is this?
/kind improvement
#### What this PR does / why we need it:
对 Formkit Repeater 组件使用 schema 的方式进行重构,重构后的 Repeater 组件将支持条件判断,按照下述方式定义即可。
```
const formSchema = [
{
$formkit: "repeater",
name: "testing",
min: 1,
max: 2,
addLabel: "添加",
children: [
{
$formkit: "select",
name: "things",
id: "things",
label: "Things",
placeholder: "Select",
options: ["Something", "Else"],
},
{
$formkit: "number",
if: "$value.things === Something",
name: "show_1",
id: "show_something_1",
label: "Show something",
},
{
$formkit: "number",
if: "$value.things === Something",
name: "show_2",
id: "show_something_2",
label: "Also show something",
},
],
},
];
```
同时额外增加了对 `addLabel`、`addButton`、`upControl`、`downControl`、`insertControl`、`removeControl` 属性的支持。
#### How to test it?
- 测试原有使用 `Repeater` 组件可否正常使用。
- 对 `Repeater` 条件判断功能进行测试。
- 查看保存的数据格式是否正确
#### Which issue(s) this PR fixes:
Fixes #4603
#### Does this PR introduce a user-facing change?
```release-note
重构 Repeater 组件,使其支持条件判断
```
2023-10-12 08:08:33 +00:00
|
|
|
|
3. addLabel: 添加按钮的文本,默认为 `添加`
|
|
|
|
|
4. addButton: 是否显示添加按钮,默认为 `true`
|
|
|
|
|
5. upControl: 是否显示上移按钮,默认为 `true`
|
|
|
|
|
6. downControl: 是否显示下移按钮,默认为 `true`
|
|
|
|
|
7. insertControl: 是否显示插入按钮,默认为 `true`
|
|
|
|
|
8. removeControl: 是否显示删除按钮,默认为 `true`
|
2022-10-18 03:32:09 +00:00
|
|
|
|
- `menuCheckbox`:选择一组菜单
|
|
|
|
|
- `menuRadio`:选择一个菜单
|
|
|
|
|
- `menuItemSelect`:选择菜单项
|
|
|
|
|
- `postSelect`:选择文章
|
|
|
|
|
- `singlePageSelect`:选择自定义页面
|
|
|
|
|
- `categorySelect`:选择分类
|
2023-01-16 08:02:13 +00:00
|
|
|
|
- 参数
|
|
|
|
|
1. multiple: 是否多选,默认为 `false`
|
2022-10-18 03:32:09 +00:00
|
|
|
|
- `categoryCheckbox`:选择多个分类
|
|
|
|
|
- `tagSelect`:选择标签
|
2023-01-16 02:58:13 +00:00
|
|
|
|
- 参数
|
|
|
|
|
1. multiple: 是否多选,默认为 `false`
|
2022-10-18 03:32:09 +00:00
|
|
|
|
- `tagCheckbox`:选择多个标签
|
2024-03-26 08:00:07 +00:00
|
|
|
|
- `verificationForm`: 远程验证一组数据是否符合某个规则
|
|
|
|
|
- 参数
|
|
|
|
|
1. action: 对目标数据进行验证的接口地址
|
|
|
|
|
2. label: 验证按钮文本
|
|
|
|
|
3. buttonAttrs: 验证按钮的额外属性
|
2022-10-18 03:32:09 +00:00
|
|
|
|
|
|
|
|
|
在 Vue 单组件中使用:
|
|
|
|
|
|
|
|
|
|
```vue
|
|
|
|
|
<script lang="ts" setup>
|
refactor: refactor the repeater component using the schema approach (#4702)
#### What type of PR is this?
/kind improvement
#### What this PR does / why we need it:
对 Formkit Repeater 组件使用 schema 的方式进行重构,重构后的 Repeater 组件将支持条件判断,按照下述方式定义即可。
```
const formSchema = [
{
$formkit: "repeater",
name: "testing",
min: 1,
max: 2,
addLabel: "添加",
children: [
{
$formkit: "select",
name: "things",
id: "things",
label: "Things",
placeholder: "Select",
options: ["Something", "Else"],
},
{
$formkit: "number",
if: "$value.things === Something",
name: "show_1",
id: "show_something_1",
label: "Show something",
},
{
$formkit: "number",
if: "$value.things === Something",
name: "show_2",
id: "show_something_2",
label: "Also show something",
},
],
},
];
```
同时额外增加了对 `addLabel`、`addButton`、`upControl`、`downControl`、`insertControl`、`removeControl` 属性的支持。
#### How to test it?
- 测试原有使用 `Repeater` 组件可否正常使用。
- 对 `Repeater` 条件判断功能进行测试。
- 查看保存的数据格式是否正确
#### Which issue(s) this PR fixes:
Fixes #4603
#### Does this PR introduce a user-facing change?
```release-note
重构 Repeater 组件,使其支持条件判断
```
2023-10-12 08:08:33 +00:00
|
|
|
|
const postName = ref("");
|
2022-10-18 03:32:09 +00:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<FormKit
|
|
|
|
|
v-model="postName"
|
|
|
|
|
placeholder="请选择文章"
|
|
|
|
|
label="文章"
|
|
|
|
|
type="postSelect"
|
|
|
|
|
validation="required"
|
|
|
|
|
/>
|
|
|
|
|
</template>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
在 FormKit Schema 中使用(插件 / 主题设置表单定义):
|
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
- $formkit: menuRadio
|
|
|
|
|
name: menus
|
|
|
|
|
label: 底部菜单组
|
|
|
|
|
```
|
2022-11-15 07:48:17 +00:00
|
|
|
|
|
|
|
|
|
### Repeater
|
|
|
|
|
|
|
|
|
|
Repeater 是一个集合类型的输入组件,可以让使用者可视化的操作集合。
|
|
|
|
|
|
|
|
|
|
在 Vue SFC 中以组件形式使用:
|
|
|
|
|
|
|
|
|
|
```vue
|
|
|
|
|
<script lang="ts" setup>
|
refactor: refactor the repeater component using the schema approach (#4702)
#### What type of PR is this?
/kind improvement
#### What this PR does / why we need it:
对 Formkit Repeater 组件使用 schema 的方式进行重构,重构后的 Repeater 组件将支持条件判断,按照下述方式定义即可。
```
const formSchema = [
{
$formkit: "repeater",
name: "testing",
min: 1,
max: 2,
addLabel: "添加",
children: [
{
$formkit: "select",
name: "things",
id: "things",
label: "Things",
placeholder: "Select",
options: ["Something", "Else"],
},
{
$formkit: "number",
if: "$value.things === Something",
name: "show_1",
id: "show_something_1",
label: "Show something",
},
{
$formkit: "number",
if: "$value.things === Something",
name: "show_2",
id: "show_something_2",
label: "Also show something",
},
],
},
];
```
同时额外增加了对 `addLabel`、`addButton`、`upControl`、`downControl`、`insertControl`、`removeControl` 属性的支持。
#### How to test it?
- 测试原有使用 `Repeater` 组件可否正常使用。
- 对 `Repeater` 条件判断功能进行测试。
- 查看保存的数据格式是否正确
#### Which issue(s) this PR fixes:
Fixes #4603
#### Does this PR introduce a user-facing change?
```release-note
重构 Repeater 组件,使其支持条件判断
```
2023-10-12 08:08:33 +00:00
|
|
|
|
const users = ref([]);
|
2022-11-15 07:48:17 +00:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<FormKit
|
|
|
|
|
v-model="users"
|
refactor: refactor the repeater component using the schema approach (#4702)
#### What type of PR is this?
/kind improvement
#### What this PR does / why we need it:
对 Formkit Repeater 组件使用 schema 的方式进行重构,重构后的 Repeater 组件将支持条件判断,按照下述方式定义即可。
```
const formSchema = [
{
$formkit: "repeater",
name: "testing",
min: 1,
max: 2,
addLabel: "添加",
children: [
{
$formkit: "select",
name: "things",
id: "things",
label: "Things",
placeholder: "Select",
options: ["Something", "Else"],
},
{
$formkit: "number",
if: "$value.things === Something",
name: "show_1",
id: "show_something_1",
label: "Show something",
},
{
$formkit: "number",
if: "$value.things === Something",
name: "show_2",
id: "show_something_2",
label: "Also show something",
},
],
},
];
```
同时额外增加了对 `addLabel`、`addButton`、`upControl`、`downControl`、`insertControl`、`removeControl` 属性的支持。
#### How to test it?
- 测试原有使用 `Repeater` 组件可否正常使用。
- 对 `Repeater` 条件判断功能进行测试。
- 查看保存的数据格式是否正确
#### Which issue(s) this PR fixes:
Fixes #4603
#### Does this PR introduce a user-facing change?
```release-note
重构 Repeater 组件,使其支持条件判断
```
2023-10-12 08:08:33 +00:00
|
|
|
|
:min="1"
|
|
|
|
|
:max="3"
|
|
|
|
|
addLabel="Add User"
|
2022-11-15 07:48:17 +00:00
|
|
|
|
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 中使用:
|
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
- $formkit: repeater
|
|
|
|
|
name: users
|
|
|
|
|
label: Users
|
refactor: refactor the repeater component using the schema approach (#4702)
#### What type of PR is this?
/kind improvement
#### What this PR does / why we need it:
对 Formkit Repeater 组件使用 schema 的方式进行重构,重构后的 Repeater 组件将支持条件判断,按照下述方式定义即可。
```
const formSchema = [
{
$formkit: "repeater",
name: "testing",
min: 1,
max: 2,
addLabel: "添加",
children: [
{
$formkit: "select",
name: "things",
id: "things",
label: "Things",
placeholder: "Select",
options: ["Something", "Else"],
},
{
$formkit: "number",
if: "$value.things === Something",
name: "show_1",
id: "show_something_1",
label: "Show something",
},
{
$formkit: "number",
if: "$value.things === Something",
name: "show_2",
id: "show_something_2",
label: "Also show something",
},
],
},
];
```
同时额外增加了对 `addLabel`、`addButton`、`upControl`、`downControl`、`insertControl`、`removeControl` 属性的支持。
#### How to test it?
- 测试原有使用 `Repeater` 组件可否正常使用。
- 对 `Repeater` 条件判断功能进行测试。
- 查看保存的数据格式是否正确
#### Which issue(s) this PR fixes:
Fixes #4603
#### Does this PR introduce a user-facing change?
```release-note
重构 Repeater 组件,使其支持条件判断
```
2023-10-12 08:08:33 +00:00
|
|
|
|
addLabel: Add User
|
|
|
|
|
min: 1
|
|
|
|
|
max: 3
|
2022-11-15 07:48:17 +00:00
|
|
|
|
items:
|
|
|
|
|
- $formkit: text
|
|
|
|
|
name: full_name
|
|
|
|
|
label: Full Name
|
|
|
|
|
validation: required
|
|
|
|
|
- $formkit: email
|
|
|
|
|
name: email
|
|
|
|
|
label: Email
|
|
|
|
|
validation: required|email
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
最终得到的数据类似于:
|
|
|
|
|
|
|
|
|
|
```json
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
"full_name": "Jack",
|
|
|
|
|
"email": "jack@example.com"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"full_name": "John",
|
|
|
|
|
"email": "john@example.com"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
```
|