amis2/docs/zh-CN/components/form/input-tree.md

1592 lines
48 KiB
Markdown
Raw Normal View History

2020-07-28 10:03:53 +08:00
---
2021-06-03 22:09:30 +08:00
title: InputTree 树形选择框
2020-07-29 16:20:21 +08:00
description:
2020-07-28 10:03:53 +08:00
type: 0
group: null
2021-06-03 22:09:30 +08:00
menuName: InpputTree 树形选择框
2020-07-29 16:20:21 +08:00
icon:
2020-07-28 10:03:53 +08:00
order: 59
---
## 基本使用
配置的`options`中,可以通过`children`字段进行嵌套展示,实现树形选择器
```schema: scope="body"
2020-07-28 10:03:53 +08:00
{
"type": "form",
"api": "/api/mock2/form/saveForm",
2021-06-03 22:09:30 +08:00
"body": [
2020-07-28 10:03:53 +08:00
{
2021-06-03 22:09:30 +08:00
"type": "input-tree",
2020-07-28 10:03:53 +08:00
"name": "tree",
"label": "Tree",
"options": [
{
"label": "Folder A",
"value": 1,
"children": [
{
"label": "file A",
"value": 2
},
{
"label": "Folder B",
"value": 3,
"children": [
{
"label": "file b1",
"value": 3.1
},
{
"label": "file b2",
"value": 3.2
}
]
2020-07-28 10:03:53 +08:00
}
]
},
{
"label": "file C",
"value": 4
},
{
"label": "file D",
"value": 5
}
]
}
]
}
```
## 选择器样式
配置`"type": "tree-select"`可以实现选择器样式
```schema: scope="body"
2020-07-28 10:03:53 +08:00
{
"type": "form",
"api": "/api/mock2/form/saveForm",
2021-06-03 22:09:30 +08:00
"body": [
2020-07-28 10:03:53 +08:00
{
"type": "tree-select",
"name": "tree",
"label": "Tree",
"options": [
{
"label": "Folder A",
"value": 1,
"children": [
{
"label": "file A",
"value": 2
},
{
"label": "file B",
"value": 3
}
]
},
{
"label": "file C",
"value": 4
},
{
"label": "file D",
"value": 5
}
]
}
]
}
```
## 是否显示展开线
> 1.1.6 版本
通过 `showOutline` 来控制是否显示展开线。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
2021-06-03 22:09:30 +08:00
"body": [
{
2021-06-03 22:09:30 +08:00
"type": "input-tree",
"name": "tree",
"label": "Tree",
"showOutline": true,
"options": [
{
"label": "Folder A",
"value": 1,
"children": [
{
"label": "file A",
"value": 2
},
{
"label": "Folder B",
"value": 3,
"children": [
{
"label": "file b1",
"value": 3.1
},
{
"label": "file b2",
"value": 3.2
}
]
}
]
},
{
"label": "file C",
"value": 4
},
{
"label": "file D",
"value": 5
}
]
}
]
}
```
2020-07-28 10:03:53 +08:00
## 选中父节点是否自动选中子节点
> since 1.9.0
`autoCheckChildren`默认为 true选中父节点会自动选中子节点可以设置`"autoCheckChildren": false`,不自动选中子节点
2020-07-28 10:03:53 +08:00
```schema: scope="body"
2020-07-28 10:03:53 +08:00
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
2021-06-03 22:09:30 +08:00
"body": [
2020-07-28 10:03:53 +08:00
{
2021-06-03 22:09:30 +08:00
"type": "input-tree",
2020-07-28 10:03:53 +08:00
"name": "tree1",
"label": "默认自动选中子节点",
"multiple": true,
"options": [
{
"label": "A",
"value": "a"
},
{
"label": "B",
"value": "b",
"children": [
{
"label": "B-1",
"value": "b-1"
},
{
"label": "B-2",
"value": "b-2"
},
{
"label": "B-3",
"value": "b-3"
}
]
},
{
"label": "C",
"value": "c"
}
]
},
{
"type": "divider"
},
{
2021-06-03 22:09:30 +08:00
"type": "input-tree",
2020-07-28 10:03:53 +08:00
"name": "tree2",
"label": "不自动选中子节点",
"multiple": true,
"autoCheckChildren": false,
2020-07-28 10:03:53 +08:00
"options": [
{
"label": "A",
"value": "a"
},
{
"label": "B",
"value": "b",
"children": [
{
"label": "B-1",
"value": "b-1"
},
{
"label": "B-2",
"value": "b-2"
},
{
"label": "B-3",
"value": "b-3"
}
]
},
{
"label": "C",
"value": "c"
}
]
}
]
}
```
## 选中父节点自动选中子节点,数据是否包含父子节点的值
2020-07-28 10:03:53 +08:00
`cascade`默认为 false子节点禁止反选值不包含子节点值配置`"cascade": true`子节点可以反选值包含父子节点值1.9.0 之前的版本 cascade 配置为 true 的效果为:选中父节点不默认选中子节点)
2020-07-28 10:03:53 +08:00
```schema: scope="body"
2020-07-28 10:03:53 +08:00
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
2021-06-03 22:09:30 +08:00
"body": [
2020-07-28 10:03:53 +08:00
{
2021-06-03 22:09:30 +08:00
"type": "input-tree",
2020-07-28 10:03:53 +08:00
"name": "tree1",
"label": "默认子节点禁止反选,值不包含子节点值",
"multiple": true,
"options": [
{
"label": "A",
"value": "a"
},
{
"label": "B",
"value": "b",
"children": [
{
"label": "B-1",
"value": "b-1"
},
{
"label": "B-2",
"value": "b-2"
},
{
"label": "B-3",
"value": "b-3"
}
]
},
{
"label": "C",
"value": "c"
}
]
},
{
"type": "divider"
},
{
"type": "input-tree",
"name": "tree2",
"label": "子节点可以反选,值包含父子节点值",
"multiple": true,
"cascade": true,
"options": [
{
"label": "A",
"value": "a"
},
{
"label": "B",
"value": "b",
"children": [
{
"label": "B-1",
"value": "b-1"
},
{
"label": "B-2",
"value": "b-2"
},
{
"label": "B-3",
"value": "b-3"
}
]
},
{
"label": "C",
"value": "c"
}
]
}
]
}
```
`withChildren`默认为 false子节点禁止反选值包含父子节点值配置`withChildren": true`,子节点禁止反选,值包含父子节点值
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-tree",
"name": "tree1",
"label": "默认不包含子节点的值",
2020-07-28 10:03:53 +08:00
"multiple": true,
"options": [
{
"label": "A",
"value": "a"
},
{
"label": "B",
"value": "b",
"children": [
{
"label": "B-1",
"value": "b-1"
},
{
"label": "B-2",
"value": "b-2"
},
{
"label": "B-3",
"value": "b-3"
}
]
},
{
"label": "C",
"value": "c"
}
]
},
{
"type": "divider"
},
{
2021-06-03 22:09:30 +08:00
"type": "input-tree",
2020-07-28 10:03:53 +08:00
"name": "tree2",
"label": "自动带上子节点的值",
"multiple": true,
"withChildren": true,
"options": [
{
"label": "A",
"value": "a"
},
{
"label": "B",
"value": "b",
"children": [
{
"label": "B-1",
"value": "b-1"
},
{
"label": "B-2",
"value": "b-2"
},
{
"label": "B-3",
"value": "b-3"
}
]
},
{
"label": "C",
"value": "c"
}
]
}
]
}
```
也可以设置`onlyChildren`,实现只包含子节点的值
```schema: scope="body"
2020-07-28 10:03:53 +08:00
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
2021-06-03 22:09:30 +08:00
"body": [
2020-07-28 10:03:53 +08:00
{
2021-06-03 22:09:30 +08:00
"type": "input-tree",
2020-07-28 10:03:53 +08:00
"name": "tree1",
"label": "默认不包含子节点的值",
2020-07-28 10:03:53 +08:00
"multiple": true,
"options": [
{
"label": "A",
"value": "a"
},
{
"label": "B",
"value": "b",
"children": [
{
"label": "B-1",
"value": "b-1"
},
{
"label": "B-2",
"value": "b-2"
},
{
"label": "B-3",
"value": "b-3"
}
]
},
{
"label": "C",
"value": "c"
}
]
},
{
"type": "divider"
},
{
2021-06-03 22:09:30 +08:00
"type": "input-tree",
2020-07-28 10:03:53 +08:00
"name": "tree2",
"label": "只包含子节点的值",
"multiple": true,
"onlyChildren": true,
"options": [
{
"label": "A",
"value": "a"
},
{
"label": "B",
"value": "b",
"children": [
{
"label": "B-1",
"value": "b-1"
},
{
"label": "B-2",
"value": "b-2"
},
{
"label": "B-3",
"value": "b-3"
}
]
},
{
"label": "C",
"value": "c"
}
]
}
]
}
```
## 只允许选择叶子节点
> 1.10.0 及以上版本
在单选时,可通过 `onlyLeaf` 可以配置只允许选择叶子节点
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-tree",
"name": "tree",
"label": "Tree",
"onlyLeaf": true,
"searchable": true,
"options": [
{
"label": "Folder A",
"value": 1,
"children": [
{
"label": "file A",
"value": 2
},
{
"label": "file B",
"value": 3
}
]
},
{
"label": "file C",
"value": 4
},
{
"label": "file D",
"value": 5
},
{
"label": "Folder E",
"value": "61",
"children": [
{
"label": "Folder G",
"value": "62",
"children": [
{
"label": "file H",
"value": 6
},
{
"label": "file I",
"value": 7
}
]
}
]
}
]
}
]
}
```
2020-07-28 10:03:53 +08:00
## 默认展开
默认是展开所有子节点的,如果不想默认展开,则配置`"initiallyOpen": false`
```schema: scope="body"
2020-07-28 10:03:53 +08:00
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
2021-06-03 22:09:30 +08:00
"body": [
2020-07-28 10:03:53 +08:00
{
2021-06-03 22:09:30 +08:00
"type": "input-tree",
2020-07-28 10:03:53 +08:00
"name": "tree1",
"label": "默认不自动带上子节点的值",
"initiallyOpen": false,
"options": [
{
"label": "A",
"value": "a"
},
{
"label": "B",
"value": "b",
"children": [
{
"label": "B-1",
"value": "b-1"
},
{
"label": "B-2",
"value": "b-2"
},
{
"label": "B-3",
"value": "b-3"
}
]
},
{
"label": "C",
"value": "c"
}
]
}
]
}
```
如果层级较多,也可以配置`unfoldedLevel`指定展开的层级数,默认展开第 1 层
2020-07-28 10:03:53 +08:00
下例中设置`"unfoldedLevel": 2`,表示展开第 2 层
2020-07-28 10:03:53 +08:00
```schema: scope="body"
2020-07-28 10:03:53 +08:00
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
2021-06-03 22:09:30 +08:00
"body": [
2020-07-28 10:03:53 +08:00
{
2021-06-03 22:09:30 +08:00
"type": "input-tree",
2020-07-28 10:03:53 +08:00
"name": "tree1",
"label": "默认不自动带上子节点的值",
"initiallyOpen": false,
"unfoldedLevel": 2,
2020-07-28 10:03:53 +08:00
"options": [
{
"label": "A",
"value": "a"
},
{
"label": "B",
"value": "b",
"children": [
{
"label": "B-1",
"value": "b-1"
},
{
"label": "B-2",
"value": "b-2",
"children": [
{
"label": "B-2-1",
"value": "b-2-1"
},
{
"label": "B-2-2",
"value": "b-2-2"
},
{
"label": "B-2-3",
"value": "b-2-3"
}
]
},
{
"label": "B-3",
"value": "b-3"
}
]
},
{
"label": "C",
"value": "c"
}
]
}
]
}
```
## 可编辑
配置 `creatable`、`removable` 和 `editable` 可以实现树可编辑。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
2021-06-03 22:09:30 +08:00
"body": [
{
2021-06-03 22:09:30 +08:00
"type": "input-tree",
"name": "tree",
"label": "Tree",
"creatable": true,
"removable": true,
"editable": true,
"options": [
{
"label": "Folder A",
"value": 1,
"children": [
{
"label": "file A",
"value": 2
},
{
"label": "file B",
"value": 3
}
]
},
{
"label": "file C",
"value": 4
},
{
"label": "file D",
"value": 5
}
]
}
]
}
```
## 控制哪些项可编辑
配置 `creatable`、`removable` 和 `editable` 可以实现树可编辑,同时如果需要关闭部分节点的编辑权限,可以在节点上配置`creatable`、`removable` 和 `editable`
`rootCreatable` 可以用来关闭顶层是否可以创建。如果想要控制顶层可编辑,请配置 `hideRoot`,用节点来控制。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-tree",
"name": "tree",
"label": "Tree",
"creatable": true,
"removable": true,
"editable": true,
"rootCreatable": false,
"options": [
{
"label": "Folder A",
"value": 1,
"creatable": false,
"removable": false,
"editable": false,
"children": [
{
"label": "file A",
"value": 2
},
{
"label": "file B",
"value": 3
}
]
},
{
"label": "file C",
"value": 4,
"removable": false
},
{
"label": "file D",
"value": 5,
"editable": false
}
]
}
]
}
```
## 控制添加/编辑的表单
配置 `addControls` 可以控制添加时需要填写哪些信息,同样还有 `editControls` 来配置编辑节点的表单
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-tree",
"name": "tree",
"label": "Tree",
"creatable": true,
"addControls": [
{
"label": "节点名称",
"type": "input-text",
"required": true,
"name": "label"
},
{
"label": "节点值",
"type": "input-text",
"required": true,
"name": "value"
}
],
"options": [
{
"label": "Folder A",
"value": 1,
"children": [
{
"label": "file A",
"value": 2
},
{
"label": "file B",
"value": 3
}
]
},
{
"label": "file C",
"value": 4
},
{
"label": "file D",
"value": 5
}
]
}
]
}
```
## 懒加载
> since 1.1.6
需要懒加载的选项请配置 `defer` 为 true然后配置 `deferApi` 即可完成懒加载。如果不配置 `deferApi` 会使用 `source` 接口。
`deferApi` 中可以用到当前选项中的任何字段,比如以下这个例子是把 label 传给了 defer 接口
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
2021-06-03 22:09:30 +08:00
"body": [
{
2021-06-03 22:09:30 +08:00
"type": "input-tree",
"name": "tree",
"label": "Tree",
"deferApi": "/api/mock2/form/deferOptions?label=${label}&waitSeconds=2",
"options": [
{
"label": "Folder A",
"value": 1,
"collapsed": true,
"children": [
{
"label": "file A",
"value": 2
},
{
"label": "file B",
"value": 3
}
]
},
{
"label": "这下面是懒加载的",
"value": 4,
"defer": true
},
{
"label": "file D",
"value": 5
}
]
}
]
}
```
## 节点路径模式
> since 1.2.4
2022-03-01 23:12:49 +08:00
配置`enableNodePath: true`后, 可以将`value`格式转换成节点路径模式,`pathSeparator`设置路径分隔符,建议将该属性的值和拼接符`delimiter`区分开。节点路径模式下,`value`中所有节点的父节点都会自动加载数据并回显。不同配置属性的节点路径模式`value`如下:
```
a
/ \
b d
/
c
----------------------------------------------
multiple joinValues extractValue value
----------------------------------------------
false true - 'a/b/c'
false false false {label: 'A/B/C', value: 'a/b/c'}
true true - 'a/b/c,a/d'
true false true ['a/b/c', 'a/d']
true false false [{label: 'A/B/C', value: 'a/b/c'},{label: 'A/D', value: 'a/d'}]
```
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-tree",
"name": "tree",
"label": "Tree",
"deferApi": "/api/mock2/form/deferOptions?label=${label}&waitSeconds=2",
"value": "1/2,4/lazy-1/lazy-1-3,4/lazy-1/lazy-1-5",
"enableNodePath": true,
"pathSeparator": '/',
"multiple": true,
"options": [
{
"label": "Folder A",
"value": 1,
"collapsed": true,
"children": [
{
"label": "file A",
"value": 2
},
{
"label": "file B",
"value": 3
}
]
},
{
"label": "这下面是懒加载的",
"value": 4,
"defer": true
},
{
"label": "file D",
"value": 5
}
]
}
]
}
```
## 自定义选项渲染
2023-02-27 21:39:28 +08:00
> `2.8.0` 及以上版本
使用`menuTpl`属性,自定义下拉选项的渲染内容。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-tree",
"name": "tree",
"label": "Tree",
"menuTpl": "<div class='flex justify-between'><span>${label}</span><span class='bg-gray-200 rounded p-1 text-xs text-center w-14'>${tag}</span></div>",
"iconField": "icon",
"options": [
{
"label": "采购单",
"value": "order",
"tag": "数据模型",
"icon": "fa fa-database",
"children": [
{
"label": "ID",
"value": "id",
"tag": "数字",
"icon": "fa fa-check",
},
{
"label": "采购人",
"value": "name",
"tag": "字符串",
"icon": "fa fa-check",
},
{
"label": "采购时间",
"value": "time",
"tag": "日期时间",
"icon": "fa fa-check",
}
]
}
]
}
]
}
```
## 选项搜索
2023-02-27 21:39:28 +08:00
> `2.8.0` 及以上版本
开启`"searchable": true`后,支持搜索当前数据源内的选项
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-tree",
"name": "tree",
"label": "Tree",
"deferApi": "/api/mock2/form/deferOptions?label=${label}&waitSeconds=2",
"searchable": true,
"searchConfig": {
"sticky": true
},
"options": [
{
"label": "Folder A",
"value": 1,
"collapsed": true,
"children": [
{
"label": "file A",
"value": 2
},
{
"label": "file B",
"value": 3
}
]
},
{
"label": "这下面是懒加载的",
"value": 4,
"defer": true
},
{
"label": "file D",
"value": 5
}
]
}
]
}
```
### searchApi
> `3.6.0` 及以上版本
**发送**
默认 GET携带 term 变量,值为搜索框输入的文字,可从上下文中取数据设置进去。
**响应**
格式要求如下:
```json
{
"status": 0,
"msg": "",
"data": {
"options": [
{
"label": "描述",
"value": "值" // ,
// "children": [] // 可以嵌套
},
{
"label": "描述2",
"value": "值2"
}
],
"value": "值" // 默认值,可以获取列表的同时设置默认值。
}
}
```
适用于需选择的数据/信息源较多时,用户可直观的知道自己所选择的数据/信息的场景。未配置 searchApi 是前端检索,配置之后就只能通过后端检索。
2020-07-28 10:03:53 +08:00
## 属性表
当做选择器表单项使用时,除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
| ---------------------- | -------------------------------------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------- |
| options | `Array<object>`或`Array<string>` | | [选项组](./options#%E9%9D%99%E6%80%81%E9%80%89%E9%A1%B9%E7%BB%84-options) |
| source | `string`或 [API](../../../../docs/types/api) | | [动态选项组](./options#%E5%8A%A8%E6%80%81%E9%80%89%E9%A1%B9%E7%BB%84-source) |
| autoComplete | [API](../../../../docs/types/api) | | [自动提示补全](./options#%E8%87%AA%E5%8A%A8%E8%A1%A5%E5%85%A8-autocomplete) |
| multiple | `boolean` | `false` | 是否多选 |
| delimiter | `string` | `false` | [拼接符](./options#%E6%8B%BC%E6%8E%A5%E7%AC%A6-delimiter) |
| labelField | `string` | `"label"` | [选项标签字段](./options#%E9%80%89%E9%A1%B9%E6%A0%87%E7%AD%BE%E5%AD%97%E6%AE%B5-labelfield) |
| valueField | `string` | `"value"` | [选项值字段](./options#%E9%80%89%E9%A1%B9%E5%80%BC%E5%AD%97%E6%AE%B5-valuefield) |
| iconField | `string` | `"icon"` | 图标值字段 |
| deferField | `string` | `"defer"` | 懒加载字段 | `3.6.0` |
| joinValues | `boolean` | `true` | [拼接值](./options#%E6%8B%BC%E6%8E%A5%E5%80%BC-joinvalues) |
| extractValue | `boolean` | `false` | [提取值](./options#%E6%8F%90%E5%8F%96%E5%A4%9A%E9%80%89%E5%80%BC-extractvalue) |
| creatable | `boolean` | `false` | [新增选项](./options#%E5%89%8D%E7%AB%AF%E6%96%B0%E5%A2%9E-creatable) |
| addControls | Array<[表单项](./formitem)> | | [自定义新增表单项](./options#%E8%87%AA%E5%AE%9A%E4%B9%89%E6%96%B0%E5%A2%9E%E8%A1%A8%E5%8D%95%E9%A1%B9-addcontrols) |
| addApi | [API](../../../docs/types/api) | | [配置新增选项接口](./options#%E9%85%8D%E7%BD%AE%E6%96%B0%E5%A2%9E%E6%8E%A5%E5%8F%A3-addapi) |
| editable | `boolean` | `false` | [编辑选项](./options#%E5%89%8D%E7%AB%AF%E7%BC%96%E8%BE%91-editable) |
| editControls | Array<[表单项](./formitem)> | | [自定义编辑表单项](./options#%E8%87%AA%E5%AE%9A%E4%B9%89%E7%BC%96%E8%BE%91%E8%A1%A8%E5%8D%95%E9%A1%B9-editcontrols) |
| editApi | [API](../../../docs/types/api) | | [配置编辑选项接口](./options#%E9%85%8D%E7%BD%AE%E7%BC%96%E8%BE%91%E6%8E%A5%E5%8F%A3-editapi) |
| removable | `boolean` | `false` | [删除选项](./options#%E5%88%A0%E9%99%A4%E9%80%89%E9%A1%B9) |
| deleteApi | [API](../../../docs/types/api) | | [配置删除选项接口](./options#%E9%85%8D%E7%BD%AE%E5%88%A0%E9%99%A4%E6%8E%A5%E5%8F%A3-deleteapi) |
2023-02-27 21:39:28 +08:00
| searchable | `boolean` | `false` | 是否可检索 | `2.8.0`前仅`tree-select`支持 |
| hideRoot | `boolean` | `true` | 如果想要显示个顶级节点,请设置为 `false` |
| rootLabel | `boolean` | `"顶级"` | 当 `hideRoot` 不为 `false` 时有用,用来设置顶级节点的文字。 |
| showIcon | `boolean` | `true` | 是否显示图标 |
| showRadio | `boolean` | `false` | 是否显示单选按钮,`multiple` 为 `false` 是有效。 |
| showOutline | `boolean` | `false` | 是否显示树层级展开线 |
| initiallyOpen | `boolean` | `true` | 设置是否默认展开所有层级。 |
| unfoldedLevel | `number` | `1` | 设置默认展开的级数,只有`initiallyOpen`不是`true`时生效。 |
| autoCheckChildren | `boolean` | `true` | 当选中父节点时级联选择子节点。 |
| cascade | `boolean` | `false` | autoCheckChildren 为 true 时生效;默认行为:子节点禁用,值只包含父节点值;设置为 true 时,子节点可反选,值包含父子节点值。 |
| withChildren | `boolean` | `false` | cascade 为 false 时生效,选中父节点时,值里面将包含父子节点的值,否则只会保留父节点的值。 |
| onlyChildren | `boolean` | `false` | autoCheckChildren 为 true 时生效,不受 cascade 影响onlyChildren 为 trueui 行为级联选中子节点,子节点可反选,值只包含子节点的值。 |
| onlyLeaf | `boolean` | `false` | 只允许选择叶子节点 |
| rootCreatable | `boolean` | `false` | 是否可以创建顶级节点 |
| rootCreateTip | `string` | `"添加一级节点"` | 创建顶级节点的悬浮提示 |
| minLength | `number` | | 最少选中的节点数 |
| maxLength | `number` | | 最多选中的节点数 |
| treeContainerClassName | `string` | | tree 最外层容器类名 |
| enableNodePath | `boolean` | `false` | 是否开启节点路径模式 |
| pathSeparator | `string` | `/` | 节点路径的分隔符,`enableNodePath`为`true`时生效 |
| highlightTxt | `string` | | 标签中需要高亮的字符,支持变量 |
merge: feat-virtual-list into master (#5829) * feat: select transfer 除树形模式外,增加虚拟列表能力 (#5612) * feat: select transfer 除树形模式外,增加虚拟列表能力 * 修改分组模式问题 * 更新快照 * transfer 虚拟列表单测补充 * select 虚拟列表单测补充 * 更新 select 快照 * chore: merge master into feat-virtual-list branch (#5716) * chore: combo组件items扩充编辑器的拖拽点位 (#5693) * feat: combo组件items支持编辑器的拖拽 * feat: combo组件items支持编辑器的拖拽 * feat: combo组件items支持编辑器的拖拽 * feat: combo组件items支持编辑器的拖拽 * fix: 数字输入框-属性配置-placeholder置灰+边框与form-input统一 amis-saas-4938 (#5666) Co-authored-by: limengyang03 <limengyang03@baidu.com> * feat:Remark组件支持自定义图标 (#5694) * feat:Remark组件支持自定义图标 * 去掉多余内容 Co-authored-by: xujiahao01 <xujiahao01@baidu.com> * fix: 修复 amis本地跑不起来 问题 * fix: https://github.com/baidu/amis/issues/4681 * feat: 使用cross-env 设置NODE_ENV 变量 * perf: 删除重复声明项 * revert: 恢复删除的SchemaRedirect Co-authored-by: 吴多益 <wuduoyi@baidu.com> * feat: ui 组件 form 支持 autoSubmit (#5695) * feat: ui 组件 form 支持 autoSubmit * 下发 onSubmit 否则只能用 handleSubmit 这个会绕过 form 的检测,无法通知到上层 * chore: sdk embed 方法添加 callback 在 callback 中可确保 scoped 方法是可用的 (#5698) * publish beta * chore: sdk embed 方法添加 callback 在 callback 中可确保 scoped 方法是可用的 * fix: filter 过滤器 isTrue/isFalse 问题修复 (#5676) * fix: filter 过滤器 isTrue 问题修复 * 修改 * 修改 * 修改 * chore: InputArray新增默认值示例, 调整Combo组件scaffold逻辑 (#5701) * chore: InputNumber严格判断大数模式,避免错误抛出string类型值 (#5703) * fix: 修复查看代码报 require is not defined 错误 (#5704) * publish beta * fix: 修复查看代码报 require is not defined 错误 * feat: 补充 ConfirmBox ui 控件, 并将 PickerContainer 改成 ConfirmBox 实现 (#5708) * publish beta * feat: 添加 ui ConfirmBox * feat: 补充 confirmBox ui 控件, 并将 pickerContainer 改成 confirmBox 实现 * PickerContainer title 逻辑不变动 * 暴露 InputTableColumnProps * 调整 ts 定义 * 升级 react-hook-form * inputTable 补充数组本身的验证 * Combo 也支持内部数组的验证 * 调整内部验证 * 调整目录 * chore: 优化 locale, theme hoc, 存在 context 直接复用 (#5702) * publish beta * chore: 优化 locale, theme hoc, 存在 context 直接复用 * chore: 日期范围类组件单元测试补充 (#5705) * dateRange * datetimeRange * timeRange * monthRange * quarter and year * 修改 * 修改 * fix: 评分组件 count 支持变量获取 (#5681) * fix: 评分组件 count 支持变量获取 * tokenize 修改为 filter Co-authored-by: zhou999 <zhousq809@163.com> Co-authored-by: PE_Sicca <46698676+swjtulmy@users.noreply.github.com> Co-authored-by: limengyang03 <limengyang03@baidu.com> Co-authored-by: 徐佳豪 <1440054388@qq.com> Co-authored-by: xujiahao01 <xujiahao01@baidu.com> Co-authored-by: h7ml <h7ml@qq.com> Co-authored-by: 吴多益 <wuduoyi@baidu.com> Co-authored-by: liaoxuezhi <2betop.cn@gmail.com> Co-authored-by: sansiro <sansiro@sansiro.me> * feat: tree 增加虚拟列表 (#5696) * feat: Tree 使用 VirtualList 渲染, 提升大数据时的性能 * fix: 适配编辑和新建 * chore: 增加 Tree 测试用例 * chore: 更新 Tree 测试用例 * feat: Tree虚拟列表,调整props名称 * chore: 清理 Tree 相关的无用代码 * feat: select transfer 树形模式增加虚拟滚动支持, treeSelect 虚拟滚动参数 (#5799) * 其他 transfer 支持虚拟列表属性 * feat: select transfer 树形模式增加虚拟滚动支持, treeSelect 虚拟滚动参数 * add * fix: tree 多级时,通过递归parent来判断展开收起,递归partial判断父元素的Partial状态 (#5807) * fix: 调整 tree 组件中,判断父子关系的方法 (#5814) * Revert "chore: merge master into feat-virtual-list branch (#5716)" (#5825) This reverts commit c9895812989c31d3471d50c2adaf7110478ad0a0. * chore: 更新 tree 虚拟滚动相关快照 和一些优化 Co-authored-by: RUNZE LU <36724300+lurunze1226@users.noreply.github.com> Co-authored-by: zhou999 <zhousq809@163.com> Co-authored-by: PE_Sicca <46698676+swjtulmy@users.noreply.github.com> Co-authored-by: limengyang03 <limengyang03@baidu.com> Co-authored-by: 徐佳豪 <1440054388@qq.com> Co-authored-by: xujiahao01 <xujiahao01@baidu.com> Co-authored-by: h7ml <h7ml@qq.com> Co-authored-by: 吴多益 <wuduoyi@baidu.com> Co-authored-by: liaoxuezhi <2betop.cn@gmail.com> Co-authored-by: meerkat <kit_hack@outlook.com>
2022-11-28 18:07:45 +08:00
| itemHeight | `number` | `32` | 每个选项的高度,用于虚拟渲染 |
| virtualThreshold | `number` | `100` | 在选项数量超过多少时开启虚拟渲染 |
2023-02-27 21:39:28 +08:00
| menuTpl | `string` | | 选项自定义渲染 HTML 片段 | `2.8.0` |
| enableDefaultIcon | `boolean` | `true` | 是否为选项添加默认的前缀 Icon父节点默认为`folder`,叶节点默认为`file` | `2.8.0` |
| heightAuto | `boolean` | `false` | 默认高度会有个 maxHeight即超过一定高度就会内部滚动如果希望自动增长请设置此属性 | `3.0.0` |
## 事件表
2023-05-28 22:26:48 +08:00
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
2022-05-31 15:05:54 +08:00
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| ------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------- |
| change | `value: any`表单项的值,值格式取决于具体配置<br/>`items: object[]`选项集合3.6.0 及以上版本)<br/>`item: object`选中的节点6.2.0 及以上版本)单选时才有值<br/> `selectedItems: object[]` 当前选中的项单选多选都值且值格式始终是数组6.4.0 及以上版本) <br /> `[name]: string` 组件的值 | 选中值变化时触发 |
| addConfirm (3.6.4 及以上版本) | `[name]: string` 组件的值<br/>`item: object` 新增的节点信息<br/>`items: object[]`选项集合 | 新增节点提交时触发 |
| editConfirm (3.6.4 及以上版本) | `[name]: object` 组件的值<br/>`item: object` 编辑的节点信息<br/>`items: object[]`选项集合 | 编辑节点提交时触发 |
| deleteConfirm (3.6.4 及以上版本) | `[name]: string` 组件的值<br/>`item: object` 删除的节点信息<br/>`items: object[]`选项集合 | 删除节点提交时触发 |
| deferLoadFinished (3.6.4 及以上版本) | `[name]: object` 组件的值<br/>`result: object` deferApi 懒加载远程请求成功后返回的数据 <br/>`items: object[]`选项集合 | 懒加载接口远程请求成功时触发 |
| add不推荐 | `[name]: object` 新增的节点信息<br/>`items: object[]`选项集合(< 2.3.2 及以下版本 `options` | 新增节点提交时触发 |
| edit不推荐 | `[name]: object` 编辑的节点信息<br/>`items: object[]`选项集合(< 2.3.2 及以下版本 `options` | 编辑节点提交时触发 |
| delete不推荐 | `[name]: object` 删除的节点信息<br/>`items: object[]`选项集合(< 2.3.2 及以下版本 `options` | 删除节点提交时触发 |
| loadFinished不推荐 | `[name]: object` deferApi 懒加载远程请求成功后返回的数据 | 懒加载接口远程请求成功时触发 |
### change
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-tree",
"name": "tree",
"label": "Tree",
"onEvent": {
"change": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.tree|json}"
}
}
]
}
},
"options": [
{
"label": "Folder A",
"value": 1,
"children": [
{
"label": "file A",
"value": 2
},
{
"label": "file B",
"value": 3
}
]
},
{
"label": "file C",
"value": 4
},
{
"label": "file D",
"value": 5
}
]
}
]
}
```
### addConfirm
配置 `creatable`后,可监听确认新增操作。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-tree",
"name": "tree",
"label": "Tree",
"creatable": true,
"removable": true,
"editable": true,
"addApi": "/api/mock2/form/saveForm",
"onEvent": {
"addConfirm": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.item|json}"
}
}
]
}
},
"options": [
{
"label": "Folder A",
"value": 1,
"children": [
{
"label": "file A",
"value": 2
},
{
"label": "file B",
"value": 3
}
]
},
{
"label": "file C",
"value": 4
},
{
"label": "file D",
"value": 5
}
]
}
]
}
```
### editConfirm
配置 `editable`后,可监听确认编辑操作。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-tree",
"name": "tree",
"label": "Tree",
"creatable": true,
"removable": true,
"editable": true,
"onEvent": {
"editConfirm": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.item|json}"
}
}
]
}
},
"options": [
{
"label": "Folder A",
"value": 1,
"children": [
{
"label": "file A",
"value": 2
},
{
"label": "file B",
"value": 3
}
]
},
{
"label": "file C",
"value": 4
},
{
"label": "file D",
"value": 5
}
]
}
]
}
```
### deleteConfirm
配置 `removable`后,可监听确认删除操作。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-tree",
"name": "tree",
"label": "Tree",
"creatable": true,
"removable": true,
"editable": true,
"onEvent": {
"deleteConfirm": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.item|json}"
}
}
]
}
},
"options": [
{
"label": "Folder A",
"value": 1,
"children": [
{
"label": "file A",
"value": 2
},
{
"label": "file B",
"value": 3
}
]
},
{
"label": "file C",
"value": 4
},
{
"label": "file D",
"value": 5
}
]
}
]
}
```
### deferLoadFinished
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-tree",
"name": "tree",
"label": "Tree",
"deferApi": "/api/mock2/form/deferOptions?label=${label}&waitSeconds=2",
"onEvent": {
"deferLoadFinished": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.result|json}"
}
}
]
}
},
"options": [
{
"label": "Folder A",
"value": 1,
"collapsed": true,
"children": [
{
"label": "file A",
"value": 2
},
{
"label": "file B",
"value": 3
}
]
},
{
"label": "这下面是懒加载的",
"value": 4,
"defer": true
},
{
"label": "file D",
"value": 5
}
]
}
]
}
```
## 动作表
2022-05-31 15:05:54 +08:00
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | -------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| expand | openLevel: `number` | 展开指定层级 |
| collapse | - | 收起 |
| add | `item: Option, parentValue?: any` | item 新增的数据项parentValue 父级数据项的 value如果配置了 valueField以 valueField 的字段值为准) |
| edit | `item: Option, originValue: any` | item 编辑后的数据项originValue 编辑前数据项的 value如果配置了 valueField以 valueField 的字段值为准) |
| delete | value: ` any` | 删除数据项的 value如果配置了 valueField以 valueField 的字段值为准) |
| reload | - | 刷新 |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| setValue | `value: string` \| `string[]` 更新的值 | 更新数据,开启`multiple`支持设置多项,开启`joinValues`时,多值用`,`分隔,否则多值用数组 |
### clear
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-tree",
"name": "tree",
"label": "Tree",
"options": [
{
"label": "Folder A",
"value": 1,
"children": [
{
"label": "file A",
"value": 2
},
{
"label": "Folder B",
"value": 3,
"children": [
{
"label": "file b1",
"value": 3.1
},
{
"label": "file b2",
"value": 3.2
}
]
}
]
},
{
"label": "file C",
"value": 4
},
{
"label": "file D",
"value": 5
}
],
"value": 5,
"id": "clear_text"
},
{
"type": "button",
"label": "清空",
"onEvent": {
"click": {
"actions": [
{
"actionType": "clear",
"componentId": "clear_text"
}
]
}
}
}
]
}
```
### reset
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-tree",
"name": "tree",
"label": "Tree",
"options": [
{
"label": "Folder A",
"value": 1,
"children": [
{
"label": "file A",
"value": 2
},
{
"label": "Folder B",
"value": 3,
"children": [
{
"label": "file b1",
"value": 3.1
},
{
"label": "file b2",
"value": 3.2
}
]
}
]
},
{
"label": "file C",
"value": 4
},
{
"label": "file D",
"value": 5
}
],
"value": 5,
"id": "reset_text"
},
{
"type": "button",
"label": "重置",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reset",
"componentId": "reset_text"
}
]
}
}
}
]
}
```