Skip to content
本页目录

GapLeftTree

左侧树组件,使用 antdesign 的 tree 组件封装,自定义添加了操作按钮

说明

  • 当有 expandedKeys 时,defaultExpandAll 将失效;
  • 设置默认展开节点时请设置存在子节点的节点,不要设置叶子节点(即没有子节点的节点),否则节点展开会有问题;

基本用法

组件演示

示例
vue
<template>
  <div style="width: 400px; height: 100%">
    <GapLeftTree
      :tree-config-data="configData"
      style="padding: 50px"
      @customAdd="customAdd"
      @customHandle="customHandle"
      @node-select="nodeSelect"
    />
  </div>
</template>

<script setup lang="ts">
import GapLeftTree from '../package/gap-left-tree/index.vue'
import { treeConfig } from 'ctj-ui-next/lib/index'
import { ref } from 'vue'
let configData = ref<treeConfig>({
  isAdd: false,
  isAll: true,
  isSearch: true,
  placeholder: '请输入关键字',
  fieldNames: {
    title: 'name',
    key: 'id',
    children: 'children',
  },
  treeData: [
    {
      name: '一级',
      id: '01',
      children: [
        {
          name: '一级子级1',
          id: '0101',
          status: 0,
          children: [
            {
              name: '二级子级1',
              id: '010101',
            },
            {
              name: '二级子级2',
              id: '010102',
            },
          ],
        },
        {
          name: '一级子级2',
          id: '0102',
        },
      ],
    },
  ],
  handleBtn: [
    {
      code: 'edit',
      title: '编辑',
      visibleHandle: data => {
        if (data.status == 0) {
          return false
        } else {
          return true
        }
      },
    },
    {
      code: 'delete',
      title: '删除',
    },
  ],
})
//新增事件
const customAdd = () => {
  console.log('新增节点')
}
//节点右侧操作按钮事件
const customHandle = (code: string, record: any) => {
  console.log('code:', code, record)
}
//节点单击事件
const nodeSelect = (val: any, nodes) => {
  console.log('val:', val, nodes)
}
</script>
<style scoped lang="less"></style>
<template>
  <div style="width: 400px; height: 100%">
    <GapLeftTree
      :tree-config-data="configData"
      style="padding: 50px"
      @customAdd="customAdd"
      @customHandle="customHandle"
      @node-select="nodeSelect"
    />
  </div>
</template>

<script setup lang="ts">
import GapLeftTree from '../package/gap-left-tree/index.vue'
import { treeConfig } from 'ctj-ui-next/lib/index'
import { ref } from 'vue'
let configData = ref<treeConfig>({
  isAdd: false,
  isAll: true,
  isSearch: true,
  placeholder: '请输入关键字',
  fieldNames: {
    title: 'name',
    key: 'id',
    children: 'children',
  },
  treeData: [
    {
      name: '一级',
      id: '01',
      children: [
        {
          name: '一级子级1',
          id: '0101',
          status: 0,
          children: [
            {
              name: '二级子级1',
              id: '010101',
            },
            {
              name: '二级子级2',
              id: '010102',
            },
          ],
        },
        {
          name: '一级子级2',
          id: '0102',
        },
      ],
    },
  ],
  handleBtn: [
    {
      code: 'edit',
      title: '编辑',
      visibleHandle: data => {
        if (data.status == 0) {
          return false
        } else {
          return true
        }
      },
    },
    {
      code: 'delete',
      title: '删除',
    },
  ],
})
//新增事件
const customAdd = () => {
  console.log('新增节点')
}
//节点右侧操作按钮事件
const customHandle = (code: string, record: any) => {
  console.log('code:', code, record)
}
//节点单击事件
const nodeSelect = (val: any, nodes) => {
  console.log('val:', val, nodes)
}
</script>
<style scoped lang="less"></style>

属性 Props

参数说明类型是否必传默认值
treeConfigData配置项treeConfig参考treeConfig 说明

事件 Events

事件名说明回调参数参数说明
nodeSelect节点单击事件(selectedKeys, selectedNodes)selectedKeys 当前点击的节点 key / selectedNodes 当前点击的节点对象
customAdd新增 icon 事件--
customHandle节点右侧操作按钮事件(code, record)code 当前单击的按钮 code / record 当前单击的节点数据
nodeBeforeChange树节点切换限制函数Promise-

参数说明

treeConfig 说明

属性名说明类型是否必传默认值
treeData树形数据DataItem[][]
isSearch是否显示顶部输入框查询条件Booleantrue
placeholder顶部输入框提示语String请输入
isAll是否显示"全部"Booleantrue
isAdd是否显示"新增 icon"Booleantrue
handleBtn操作按钮treeBtnItem[]参考treeBtnItem 说明
fieldNames替换 treeNode 中 title,key,children 字段为 treeData 中对应的字段fieldName参考fieldName 说明
defaultDatas设置默认展开节点和默认单击节点defaultTreeDatas参考defaultTreeDatas 说明
height树组件高度string存在搜索时 calc(100vh - 172px),不存在搜索时 calc(100vh - 140px)
allTitle自定义“全部”titleString全部
expandAction目录展开逻辑,传false是单击节点不展开目录,只在点击左侧箭头图标时展开收起节点false/'cilck'/'dblclick''click'
allIsSelectable“全部”节点是否允许被选择booleanfalse

treeBtnItem 说明

属性名说明类型可选值
code按钮编码string''
title按钮名称string''
visibleHandle按钮是否显示Function

fieldName 说明

属性名说明类型可选值
key节点唯一标识字段String默认 key
title节点显示名称字段String默认 title
children子元素字段String默认 children

defaultTreeDatas 说明

属性名说明类型可选值
defaultSelectedNodes默认单击的节点DataItem不传是默认单击第一个节点的最末级叶子结点
defaultExpandKeys默认展开的节点 key 组成的数组any[]不传时默认展开第一个节点的最末级存在子节点的第一个节点

预算单位软件产品开发部