mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-03 12:38:53 +08:00
ad9c8d73b2
* feat: Editor 支持插件弹出面板 (#11055) * feat: Editor 支持插件弹出面板 (#11059) * chore: 暴露 RendererThumb * feat: resultBox item项支持点击事件 (#11060) * feat: resultBox item项支持点击事件 * feat: resultBox item项支持点击事件 * feat: resultBox item项点击事件增加testid * feat: resultBox item项点击事件更新jest快照 --------- Co-authored-by: hezhihang <hezhihang@baidu.com> * chore: 调整 Page 渲染器导出方便外部覆盖 * chore: ConfirmBox 支持配置 onEntered 和 onExit 事件 * chore: checkboxes radios 选项 children 必须是数组且有长度才切到分组展示 * feat: 折叠面板,无标题时显示折叠箭头。组件存在于表单中,面板新增切换展示方式按钮 (#11067) * feat: 折叠面板,无标题时显示折叠箭头。组件存在于表单中,面板新增切换展示方式按钮 * feat: 调整面板组件默认值 * feat: 调整无标题时,折叠箭头样式。调整面板配置 * 更新jest快照 * feat: page侧栏支持左右位置 (#11090) Co-authored-by: hezhihang <hezhihang@baidu.com> * chore: checkboxes radios 选项 children 必须是数组且有长度才切到分组展示 * feat: AvailableRenderersPanel 支持外围扩展 * feat: AvailableRenderersPanel 支持外围扩展 * feat: editor 插件 scaffoldForm 支持异步获取 * chore: add cross-env * chore: 避免 Table 数据更新死循环 * chore: 调整 ts 定义 * feat: 给配置面板加些标记方便外围扩充 * chore: checkboxes radios 选项 children 必须是数组且有长度才切到分组展示 * chore: Options 相关逻辑支持外部扩展 * feat: mapping支持接口变量是records,提供外围扩充函数 (#11105) * feat: mapping支持接口变量是records 的情况 * feat: 提供外围扩充函数 * feat: 修改函数名 * feat: 补充props 类型定义 * chore: 调整用例 * feat: 自定义样式扩展 (#11140) Co-authored-by: hezhihang <hezhihang@baidu.com> * feat: tabs支持删除动作,外观样式支持主题 * typo error * chore: 支持更多的场景 * feat: 穿梭选择器增加点击选项事件 * feat: 锚点导航调整为sticky布局 (#11143) * feat: 锚点导航调整为sticky布局 * bugfix * 更新快照 * 更新单测 * 更新单测 * bugfix * 优化样式 --------- Co-authored-by: qinhaoyan <30946345+qinhaoyan@users.noreply.github.com> * 动作面板支持外部注册 (#11149) * 动作面板支持外部注册 * 修复someTree报错 * chore: debug 面板调整 (#11152) * feat:事件动作面板支持查看调用链 * feat: 新增autoCheckChildren和onlyChildren属性配置面板,更改穿梭框事件点击位置 * feat: 预留外围扩充函数 * fix: 调整文案和属性名 * 修复初始化弹窗问题 * fix:自定义样式根节点不生效、样式修改时schema更新不正确,tabs动作仅支持hash删除 (#11145) Co-authored-by: hezhihang <hezhihang@baidu.com> * feat: 日期\日期范围组件可配禁止输入 (#11197) * feat:验证器手机和电话号支持国家代号,数字框新增显示上下按钮,修改自定义样式实现。 (#11198) * fix: 穿梭器面板中onlyChildren属性默认开启 * feat: 验证器中手机号和电话号支持国家代号 * feat: 数字框编辑器新增显示上下按钮开关,修改自定义样式实现 * 修复插件重复注册&输入序号支持表达式 * 移除无用代码 * feat: tree支持节点行为配置、点击事件、虚拟列表高度、工具栏、操作栏等功能 * feat: 虚拟列表支持高度自适应 * feat: 虚拟列表支持高度自适应 * feat: 虚拟列表支持高度自适应 * feat: 虚拟列表支持高度自适应 * feat: 表格列新增textOverflow属性 * feat: 新增文本未超出,不呼出功能 * feat: 修改dom计算的位置 * feat: 增加限制条件 * feat: 删除sonTarget属性 * feat: 合并renderTextOver * feat: 留出外围扩充位置 * feat: 步骤条新增iconPositon属性,修复简单模式下箭头布局错乱 (#11250) * feat: 替换按钮配置面板自定义样式 * feat: 步骤条新增iconPositon属性,修复简单模式下箭头布局错乱 --------- Co-authored-by: hzh11012 <43038692+hzh11012@users.noreply.github.com> Co-authored-by: hezhihang <hezhihang@baidu.com> Co-authored-by: F-jianchao <161407305+F-jianchao@users.noreply.github.com> Co-authored-by: hsm-lv <80095014+hsm-lv@users.noreply.github.com> Co-authored-by: fujianchao <fujianchao@baidu.com> Co-authored-by: qkiroc <30946345+qkiroc@users.noreply.github.com> Co-authored-by: qinhaoyan <30946345+qinhaoyan@users.noreply.github.com> Co-authored-by: z418577198 <418577198@qq.com> Co-authored-by: lvxiaojiao <lvxiaojiao@baidu.com> Co-authored-by: zhangzhijun03 <zhangzhijun03@baidu.com> Co-authored-by: Allen <yupeng.fe@qq.com>
25 KiB
Executable File
25 KiB
Executable File
title | description | type | group | menuName | icon | order |
---|---|---|---|---|---|---|
TreeSelect 树形选择器 | 0 | null | TreeSelect 树形选择器 | 60 |
基本使用
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "tree-select",
"name": "tree",
"label": "Tree",
"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",
"children": [
{
"label": "Folder G",
"children": [
{
"label": "file H",
"value": 6
},
{
"label": "file I",
"value": 7
}
]
}
]
}
]
}
]
}
仅展示选中节点文本信息
设置hideNodePathLabel: true
,可以隐藏选择框中已选择节点的祖先节点(ancestor)的labelField
字段值,仅展示当前选中节点的labelField
字段值。
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "tree-select",
"name": "tree1",
"label": "展示已选择节点的祖先节点的文本信息",
"value": "1,6,7",
"multiple": 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",
"children": [
{
"label": "Folder G",
"children": [
{
"label": "file H",
"value": 6
},
{
"label": "file I",
"value": 7
}
]
}
]
}
]
},
{
"type": "divider"
},
{
"type": "tree-select",
"name": "tree2",
"label": "仅展示已选择节点的文本信息",
"value": "1,6,7",
"multiple": true,
"hideNodePathLabel": 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",
"children": [
{
"label": "Folder G",
"children": [
{
"label": "file H",
"value": 6
},
{
"label": "file I",
"value": 7
}
]
}
]
}
]
}
]
}
只允许选择叶子节点
1.8.0 及以上版本
在单选时,可通过 onlyLeaf
可以配置只允许选择叶子节点
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "tree-select",
"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
}
]
}
]
}
]
}
]
}
如何让某些节点无法点?
只需要对应的节点没有 value 就行,比如下面例子的目录节点都无法点,只能点文件节点
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "tree-select",
"name": "tree",
"label": "Tree",
"searchable": true,
"options": [
{
"label": "Folder A",
"children": [
{
"label": "file A",
"value": 2
},
{
"label": "file B",
"value": 3
}
]
},
{
"label": "Folder E",
"children": [
{
"label": "Folder G",
"children": [
{
"label": "file H",
"value": 6
},
{
"label": "file I",
"value": 7
}
]
}
]
}
]
}
]
}
搜索选项
2.7.1
及以上版本
配置autoComplete
接口可以实现从远程数据搜索目标结果,搜索的关键字段为term
,注意搜索的逻辑需要在服务端实现。
{
"type":"form",
"api":"/api/mock2/form/saveForm",
"body":[
{
"type":"tree-select",
"name":"tree",
"label":"Tree",
"autoComplete":"/api/mock2/tree/search?term=$term",
"source":"/api/mock2/tree/search"
}
]
}
自定义选项渲染
2.8.0
及以上版本
使用menuTpl
属性,自定义下拉选项的渲染内容。
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "tree-select",
"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-24'>${tag}</span></div>",
"iconField": "icon",
"searchable": true,
"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",
},
{
"label": "供应商",
"value": "vendor",
"tag": "数据模型(N:1)",
"icon": "fa fa-database",
"children": [
{
"label": "供应商ID",
"value": "vendor_id",
"tag": "数字",
"icon": "fa fa-check",
},
{
"label": "供应商名称",
"value": "vendor_name",
"tag": "字符串",
"icon": "fa fa-check",
}
]
}
]
}
]
}
]
}
属性表
下列属性为tree-select
独占属性, 更多属性用法,参考InputTree 树形选择框
属性名 | 类型 | 默认值 | 说明 | 版本 |
---|---|---|---|---|
hideNodePathLabel | boolean |
false |
是否隐藏选择框中已选择节点的路径 label 信息 | |
onlyLeaf | boolean |
false |
只允许选择叶子节点 | |
searchable | boolean |
false |
是否可检索,仅在 type 为 tree-select 的时候生效 |
事件表
当前组件会对外派发以下事件,可以通过onEvent
来监听这些事件,并通过actions
来配置执行的动作,在actions
中可以通过${事件参数名}
或${event.data.[事件参数名]}
来获取事件产生的数据,详细请查看事件动作。
[name]
表示当前组件绑定的名称,即name
属性,如果没有配置name
属性,则通过value
取值。
事件名称 | 事件参数 | 说明 |
---|---|---|
change | [name]: string 组件的值 item: object 选中的节点(6.2.0 及以上版本)items: object[] 选项集合(3.6.0 及以上版本) |
选中值变化时触发 |
blur | [name]: string 组件的值 ``item: object 选中的节点(6.2.0 及以上版本)<br/>items: object[] 选项集合(3.6.4 及以上版本) |
输入框失去焦点时触发 |
focus | [name]: string 组件的值 item: object 选中的节点(6.2.0 及以上版本)items: object[] 选项集合(3.6.4 及以上版本) |
输入框获取焦点时触发 |
addConfirm (3.6.4 及以上版本) | [name]: string 组件的值item: object 新增的节点信息items: object[] 选项集合 |
新增节点提交时触发 |
editConfirm (3.6.4 及以上版本) | [name]: object 组件的值item: object 编辑的节点信息items: object[] 选项集合 |
编辑节点提交时触发 |
deleteConfirm (3.6.4 及以上版本) | [name]: string 组件的值item: object 删除的节点信息items: object[] 选项集合 |
删除节点提交时触发 |
deferLoadFinished (3.6.4 及以上版本) | [name]: object 组件的值result: object deferApi 懒加载远程请求成功后返回的数据 items: object[] 选项集合 |
懒加载接口远程请求成功时触发 |
itemClick (6.9.0 以上版本) | value: any 表单项的值,值格式取决于具体配置item: object 点击的节点信息 |
节点点击时触发 |
add(不推荐) | [name]: object 新增的节点信息items: object[] 选项集合(< 2.3.2 及以下版本 为options ) |
新增节点提交时触发 |
edit(不推荐) | [name]: object 编辑的节点信息items: object[] 选项集合(< 2.3.2 及以下版本 为options ) |
编辑节点提交时触发 |
delete(不推荐) | [name]: object 删除的节点信息items: object[] 选项集合(< 2.3.2 及以下版本 为options ) |
删除节点提交时触发 |
loadFinished(不推荐) | [name]: object deferApi 懒加载远程请求成功后返回的数据 |
懒加载接口远程请求成功时触发 |
change
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "tree-select",
"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
}
]
}
]
}
focus
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "tree-select",
"name": "tree",
"label": "Tree",
"onEvent": {
"focus": {
"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
}
]
}
]
}
blur
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "tree-select",
"name": "tree",
"label": "Tree",
"onEvent": {
"blur": {
"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
后,可监听确认新增操作。
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "tree-select",
"name": "tree",
"label": "Tree",
"creatable": true,
"removable": true,
"editable": true,
"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
后,可监听确认编辑操作。
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "tree-select",
"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
后,可监听确认删除操作。
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "tree-select",
"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
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "tree-select",
"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
}
]
}
]
}
itemClick
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-tree",
"name": "tree",
"label": "Tree",
"nodeBehavior": [],
"onEvent": {
"itemClick": {
"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
}
]
}
]
}
动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定actionType: 动作名称
、componentId: 该组件id
来触发这些动作,动作配置可以通过args: {动作配置项名称: xxx}
来配置具体的参数,详细请查看事件动作。
动作名称 | 动作配置 | 说明 |
---|---|---|
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
{
"type": "form",
"debug": true,
"body": [
{
"type": "tree-select",
"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
的值,否则使用初始值。
{
"type": "form",
"debug": true,
"body": [
{
"type": "tree-select",
"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"
}
]
}
}
}
]
}