Element tree control integrates a drop-down menu with icons (tree+dropdown+input)

Element tree control integrates a drop-down menu with icons (tree+dropdown+input)

This article mainly describes: Custom tree control <el-tree>

Requirements:

The tree controls provided by the Element UI official website include basic, selectable, custom node content, node filtering, and draggable node tree structures as follows:

insert image description here

The effect I want is a tree that supports search effects. When the mouse is hovered, the add and modify icons will be displayed. When the icon is clicked, the corresponding page will pop up; and a custom icon will be added in front of each folder.

Result:

insert image description here

Implementation steps:

1. Use slots

<el-col :span="4" :xs="24">
   <!--Directory search function-->
  <div class="head-container">
    <el-input
      v-model="dirNameCn"
      placeholder="Please enter the directory name"
      clearable
      size="small"
      prefix-icon="el-icon-search"
      style="margin-bottom: 20px"
    />
  </div>
  <!--Tree display-->
  <div class="head-container">
    <el-tree
      :data="dirTreeOptions"
      :props="defaultProps"
      :expand-on-click-node="false"
      :filter-node-method="filterNode"
      ref="tree"
      default-expand-all
      @node-click="handleNodeClick"
      icon-class="el-icon-folder-opened"
      node-key="id"
      :check-on-click-node="true"
    >
      <!--Hidden new icons-->
      <span class="custom-tree-node" slot-scope="{ node, data }" @mouseenter="mouseenter(data)" @mouseleave="mouseleave(data)">
        <span>{{ node.label }}</span>
        <div>
          <i v-show="data.show" class="el-icon-circle-plus" style="color: #00afff" @click="addDial(node, data)"/>
          <!--Hidden drop-down selection-->
          <el-dropdown trigger="click" placement="right" @command="(command) => {handleCommand(command)}">
            <i v-show="data.show" class="el-icon-more" style="color: #D3D3D3"/>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="a">Rename</el-dropdown-item>
              <el-dropdown-item command="b">Delete</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </span>
    </el-tree>
  </div>
</el-col>

2. JS corresponding to the component

Note: The tree data is queried from the backend and saved in dirTreeOptions

<script>
  export default {
    name: 'reqmdoctree',
    data() {
      return {
        // The content of the left search box dirNameCn: '',
       	// Directory tree options dirTreeOptions: undefined,
        defaultProps: {
          children: "children",
          label: "label"
        },
        //Whether there is a child node in the tree menu yesChild: undefined,
        // Control the newly added prompt information box on the left show: 0,
        // Query requirement document information parameters queryParams: {
          docNo: undefined, // Document number docNameEn: undefined, // Document English name dirNo: undefined, // Directory number current: 1, // Current page size: 20 // How many items are displayed per page },
        treeId: undefined,
      }
    },
    methods: {
      /** Query the drop-down tree structure of the required directory*/
      getTreeselect() {
        treeselect().then(response => {
          this.dirTreeOptions = response.data
        })
      },
      // Search value is filter function filterNode(value, data) {
        if (!value) return true
        return data.label.indexOf(value) !== -1
      },
      // callback function when the node is clicked handleNodeClick(data) {
        // console.log(data)
        this.treeId = data.id
        this.yesChild = data.children
        this.queryParams.dirNo = data.id
        this.getList()
      },
      //Events of three points in the tree handleCommand(command) {
        if (command == 'a') {
          selectReqNo(this.treeId).then(response => {
            this.uuid = response.msg
            getObjTree(response.msg).then(response => {
              this.form = response.data
              this.open = true
              this.title = 'Modify the requirements document directory configuration table'
            })
          })
        }
        if (command == 'b') {
          if (this.yesChild != undefined) {
            this.$notify.error({
              title: 'Warning',
              message: 'There are other folders in this directory'
            })
          } else {
            selectReqNo(this.treeId).then(response => {
              this.uuid = response.msg
              this.$confirm('Are you sure you want to delete the data item with ID ' + this.uuid + '?', 'Warning', {
                confirmButtonText: 'Confirm',
                cancelButtonText: 'Cancel',
                type: 'warning'
              }).then(()=>{
                return delObjTree(this.uuid)
              }).then(data => {
                this.getTreeselect()
                this.msgSuccess('Deleted successfully')
              }).catch(function() {
              })
            })
          }
        }
      },
      // Create a new directory/file on the left addDial(node, data) {
        // console.log(node, '---', data)
        this.reset()
        this.form.dirParentId = data.id
        this.open = true
        this.title = 'Add requirement document directory configuration table'
      },
      // Display icon when mouse hovers on the left mouseenter(data){
        this.$set(data, 'show', true)
      },
      // The icon will not be displayed when the left mouse leaves mouseleave(data){
        this.$set(data, 'show', false)
      },
      //Open the new resource pop-up window here......
    }
  }
</script>

illustrate:

Reference documents: element UI, tree control integrated drop-down selection

This is the end of this article about Element tree control integrating drop-down menu with icons (tree+dropdown+input). For more content related to Element drop-down menu with icons, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Solution to incomplete text display in el-tree
  • Interview must ask questions about Set implementation class: TreeSet
  • C++ implementation of KDTree with complete code
  • JDK collection source code analysis TreeMap (Part 2)
  • JDK collection source code analysis TreeMap (I)
  • Parsing ConcurrentHashMap: Red-black tree proxy class (TreeBin)
  • About the value transfer problem between antd tree and parent-child components (react summary)
  • C# TreeNode case study

<<:  MySQL index leftmost principle example code

>>:  Detailed explanation of Linux environment variable configuration strategy

Recommend

Docker volumes file mapping method

background When working on the blockchain log mod...

Complete Tutorial on Deploying Java Web Project on Linux Server

Most of this article refers to other tutorials on...

Vue uses three methods to refresh the page

When we are writing projects, we often encounter ...

VMware Workstation Installation (Linux Kernel) Kylin Graphic Tutorial

This article shares with you how to install Kylin...

Detailed explanation of CSS3 text shadow text-shadow property

Text shadow text-shadow property effects: 1. Lowe...

Sample code for implementing neon button animation effects with CSS3.0

Today I will share with you a neon button animati...

Summary of clipboard.js usage

Table of contents (1) Introduction: (2) The ways ...

Detailed analysis of MySQL 8.0 memory consumption

Table of contents 1. innodb_buffer_pool_size 2. i...

Detailed tutorial on how to quickly install Zookeeper in Docker

Docker Quickly Install Zookeeper I haven't us...

Implementation of nginx worker process loop

After the worker process is started, it will firs...

How to check if a table exists in MySQL and then delete it in batches

1. I searched for a long time on the Internet but...

A brief analysis of different ways to configure static IP addresses in RHEL8

While working on a Linux server, assigning static...

What does href=# mean in a link?

Links to the current page. ------------------- Com...

Mysql 5.7.19 free installation version encountered pitfalls (collection)

1. Download the 64-bit zip file from the official...