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

How to allow external network access to mysql and modify mysql account password

The root account of mysql, I usually use localhos...

Analysis of MySQL duplicate index and redundant index examples

This article uses examples to describe MySQL dupl...

How to let DOSBox automatically execute commands after startup

Using DOSBox, you can simulate DOS under Windows ...

Detailed explanation of the use of Linux lseek function

Note: If there are any errors in the article, ple...

MySQL solution for creating horizontal histogram

Preface Histogram is a basic statistical informat...

Detailed explanation of custom swiper component in JavaScript

Table of contents Effect display Component Settin...

Commonly used English fonts for web page creation

Arial Arial is a sans-serif TrueType font distribu...

How to run tomcat source code in maven mode

Preface Recently, I was analyzing the startup pro...

Solution to Mysql binlog log file being too large

Table of contents 1. Related binlog configuration...

Various ways to modify the background image color using CSS3

CSS3 can change the color of pictures. From now o...

Install Docker environment in Linux environment (no pitfalls)

Table of contents Installation Prerequisites Step...