feat: input-kv 组件允许自定义 keySchema 和 valueSchema Closes #6782 #6717

This commit is contained in:
wuduoyi 2023-05-08 12:05:36 +08:00
parent a80ecf054f
commit cc13593429
2 changed files with 103 additions and 9 deletions

View File

@ -77,6 +77,90 @@ key 只能是字符串,因此输入格式是 `input-text`,但 value 格式
}
```
## 自定义 value 的 schema
> 3.1.0 及以上版本
默认创建的 value schema 是
```json
{
"placeholder": "Value",
"type": "input-text",
"name": "value"
}
```
前面的配置可以改其中的 type 或 placeholder而这个新的 `valueSchema` 配置就能做到替换所有配置,比如
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-kv",
"name": "css",
"valueSchema": {
"type": "select",
"options": [
{
"label": "A",
"value": "a"
},
{
"label": "B",
"value": "b"
},
{
"label": "C",
"value": "c"
}
]
}
}
]
}
```
## 自定义 key schema
> 3.1.0 及以上版本
和前面的 value schema 类似,还可以自定义 key 的 schema
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-kv",
"name": "css",
"keySchema": {
"type": "select",
"options": [
{
"label": "A",
"value": "a"
},
{
"label": "B",
"value": "b"
},
{
"label": "C",
"value": "c"
}
]
}
}
]
}
```
## 关闭可拖拽排序
```schema: scope="body"

View File

@ -51,15 +51,25 @@ addSchemaFilter(function (schema: Schema, renderer, props?: any) {
return obj;
},
items: [
{
placeholder: schema.keyPlaceholder ?? 'Key',
type: 'input-text',
unique: true,
name: 'key',
required: true,
validateOnChange: true
},
schema.valueComponent
schema.keySchema
? {
...schema.keySchema,
unique: true,
name: 'key',
required: true,
validateOnChange: true
}
: {
placeholder: schema.keyPlaceholder ?? 'Key',
type: 'input-text',
unique: true,
name: 'key',
required: true,
validateOnChange: true
},
schema.valueSchema
? {...schema.valueSchema, name: 'value'}
: schema.valueComponent
? {
placeholder: schema.valuePlaceholder ?? 'Value',
component: schema.valueComponent,