Skip to content

Commit

Permalink
feat(tree): actionItem added show attribute close #314
Browse files Browse the repository at this point in the history
  • Loading branch information
anncwb committed Mar 2, 2021
1 parent b6bb816 commit 8b62fa0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- 新增部门管理示例界面
- 新增 WebSocket 示例和服务脚本
- BasicTree 组件新增 `renderIcon` 属性用于控制层级图标显示
- BasicTree->actionItem 新增 show 属性,用于动态控制按钮显示

### ⚡ Performance Improvements

Expand Down
12 changes: 10 additions & 2 deletions src/components/Tree/src/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// import { DownOutlined } from '@ant-design/icons-vue';
import { omit, get } from 'lodash-es';
import { isFunction } from '/@/utils/is';
import { isBoolean, isFunction } from '/@/utils/is';
import { extendSlots } from '/@/utils/helper/tsxHelper';
import { useTree } from './useTree';
Expand Down Expand Up @@ -116,6 +116,14 @@
const { actionList } = props;
if (!actionList || actionList.length === 0) return;
return actionList.map((item, index) => {
if (isFunction(item.show)) {
return item.show?.(node);
}
if (isBoolean(item.show)) {
return item.show;
}
return (
<span key={index} class={`${prefixCls}__action`}>
{item.render(node)}
Expand Down Expand Up @@ -147,7 +155,7 @@
>
{get(item, titleField)}
</span>
<span class={`${prefixCls}__actions`}> {renderAction(item)}</span>
<span class={`${prefixCls}__actions`}> {renderAction({ ...item, level })}</span>
</span>
),
default: () =>
Expand Down
3 changes: 2 additions & 1 deletion src/components/Tree/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { TreeDataItem } from 'ant-design-vue/es/tree/Tree';
export interface ActionItem {
render: (record: any) => any;
render: (record: Recordable) => any;
show?: boolean | ((record: Recordable) => boolean);
}

export interface TreeItem extends TreeDataItem {
Expand Down
1 change: 1 addition & 0 deletions src/views/demo/tree/EditTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
}
const actionList: ActionItem[] = [
{
// show:()=>boolean;
render: (node) => {
return h(PlusOutlined, {
class: 'ml-2',
Expand Down

0 comments on commit 8b62fa0

Please sign in to comment.