mirror of https://github.com/halo-dev/halo-admin
8386e14301
#### What type of PR is this? /kind feature /milestone 2.0 #### What this PR does / why we need it: 为 FormKit 添加 Repeater 输入类型,用于让用户动态操作一个对象数组。 使用方式可以查阅:https://github.com/ruibaby/halo-console/tree/feat/formkit-repeater/docs/custom-formkit-input#repeater #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/2529 #### Screenshots: <img width="635" alt="image" src="https://user-images.githubusercontent.com/21301288/201640327-5eb0489a-2193-445d-9dfe-7405ae75a297.png"> #### Special notes for your reviewer: /cc @halo-dev/sig-halo-console 测试方式: 1. 按照 https://github.com/ruibaby/halo-console/tree/feat/formkit-repeater/docs/custom-formkit-input#repeater 文档,在主题或者插件中使用 FormKit Schema 的形式定义设置表单,然后对表单进行保存等设置,检查是否符合预期。 2. 或者使用 https://github.com/halo-sigs/theme-earth/tree/refactor/setting-spec 主题进行测试,这个分支已经对社交媒体和侧边栏进行了适配。可以在主题设置中测试社交媒体和侧边栏配置,检查在主题端的效果。 #### Does this PR introduce a user-facing change? ```release-note 为 FormKit 添加 Repeater 输入类型。 ``` |
||
---|---|---|
.. | ||
README.md |
README.md
自定义 FormKit 输入组件
原由
目前在 Console 端的所有表单都使用了 FormKit,但 FormKit 内置的 Input 组件并不满足所有的需求,因此需要自定义一些 Input 组件。此外,为了插件和主题能够更加方便的使用系统内的一些数据,所以同样需要自定义一些带数据的选择组件。
使用方式
目前已提供以下类型:
code
: 代码编辑器- 参数
- language: 目前支持
yaml
,html
,css
,javascript
,json
- height: 编辑器高度,如:
100px
- language: 目前支持
- 参数
attachment
: 附件选择repeater
: 定义一个对象集合,可以让使用者可视化的操作集合。menuCheckbox
:选择一组菜单menuRadio
:选择一个菜单menuItemSelect
:选择菜单项postSelect
:选择文章singlePageSelect
:选择自定义页面categorySelect
:选择分类categoryCheckbox
:选择多个分类tagSelect
:选择标签tagCheckbox
:选择多个标签
在 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"
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
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"
}
]