element导航菜单el-menu添加搜索功能

news2024/10/6 18:32:44

element导航菜单-侧栏,自带的功能没有搜索或者模糊查询。

找了找资料

找到一个比较可行的,记录一下:

//index.vue的代码
<div style="overflow:auto">
          <el-menu :default-active="$route.path"
                   :default-openeds="openeds"
                   :unique-opened="true"
                   active-text-color="rgb(185, 143, 37)"
                   text-color="#ADE0F6"
                   class="el-menu-vertical-demo"
                   background-color="#042939"
                   style="border:0;">
            <MenuTree :menuList="newMenuList"></MenuTree>
          </el-menu>
</div>

//newMenuList组件的代码
  <div class="menuTree">
    <template v-for="(item,index) in menuList">
      <el-submenu :index="item.id +''"
                  :key="index+''"
                  v-if="item.children && item.children.length>0">
        <template slot="title">
          <span @click.stop="routerClick(item)">{{item.label}}</span>
        </template>
        <MenuTree :menuList="item.children"></MenuTree>
      </el-submenu>
      <el-menu-item v-else
                    :index="item.id+''"
                    :key="index+''">
        <span @click="routerClick(item)">{{item.label}}</span>
      </el-menu-item>
    </template>
  </div>
<script>
import MenuTree from "./menuTree";
export default {
  name: 'leftAside',
  components: { MenuTree },
  props: ['transactionList'],
  data () {
    return {
      openeds: ["1", "2", "3", "4"],
      pathNumber: "",
      activeName: "first",
      filterText: "",
      menuList: [
        {
          id: 1,
          label: '主控',
          children: [
            {
              id: 2,
              label: '场地管理',
              children: [
                {
                  id: 3,
                  label: '数据中心',
                  children: [
                    {
                      id: 4,
                      label: '机房1',
                      children: [
                        {
                          id: 5,
                          label: '3D机房',
                          value: "jifang"
                        },
                        {
                          id: 6,
                          label: '2D机房',
                          value: "jifang"
                        },
                      ]
                    }
                  ]
                },
                {
                  id: 7,
                  label: '配电室',
                  children: [
                    {
                      id: 8,
                      label: '配电间1',
                    },
                    {
                      id: 9,
                      label: '配电间2',
                    },
                    {
                      id: 10,
                      label: '配电间3',
                    },
                  ]
                },
                {
                  id: 11,
                  label: '网络间',
                  children: [
                    {
                      id: 12,
                      label: '交换机1',
                      value: "jiaohuanji"
                    },
                    {
                      id: 13,
                      label: '交换机2',
                      value: "jiaohuanji"
                    },
                  ]
                }
              ]
            },
            {
              id: 15,
              label: '监测系统',
              children: [
                {
                  id: 16,
                  label: '变压器监测',
                  children: [
                    {
                      id: 17,
                      label: '变压器组1',
                    },
                    {
                      id: 18,
                      label: '变压器组2',
                    },
                    {
                      id: 19,
                      label: '变压器组3',
                    },
                  ]
                },
                {
                  id: 20,
                  label: '高压柜监测',
                  children: [
                    {
                      id: 21,
                      label: '高压柜组1',
                    },
                    {
                      id: 22,
                      label: '高压柜组2',
                    },
                    {
                      id: 23,
                      label: '高压柜组3',
                    },
                  ]
                },
                {
                  id: 24,
                  label: '母排监测',
                  children: [
                    {
                      id: 25,
                      label: '母排柜1',
                      value: "mupai"
                    },
                    {
                      id: 26,
                      label: '母排柜2',
                      children: [
                        {
                          id: 27,
                          label: 'M-2-01',
                          value: "mupai"
                        },
                        {
                          id: 28,
                          label: 'M-2-02',
                          value: "mupai"
                        }
                      ]
                    },
                    {
                      id: 29,
                      label: '母排柜3',
                      children: [
                        {
                          id: 30,
                          label: 'M-3-01',
                          value: "mupai"
                        }, {
                          id: 31,
                          label: 'M-3-02',
                          value: "mupai"
                        },
                      ]
                    },
                    {
                      id: 32,
                      label: '母排柜4',
                      children: [
                        {
                          id: 33,
                          label: 'M-4-01',
                          value: "mupai"
                        }, {
                          id: 34,
                          label: 'M-4-02',
                          value: "mupai"
                        },
                      ]
                    },
                    {
                      id: 35,
                      label: '母排柜5',
                      children: [
                        {
                          id: 36,
                          label: 'M-5-01',
                          value: "mupai"
                        }, {
                          id: 37,
                          label: 'M-5-02',
                          value: "mupai"
                        },
                      ]
                    },
                  ]
                },
                {
                  id: 38,
                  label: '空调监测',
                  children: [
                    {
                      id: 39,
                      label: '精密空调',
                      children: [
                        {
                          id: 40,
                          label: 'KT-W-05EVC',
                          value: "kongtiaoEVC"
                        },
                        {
                          id: 41,
                          label: 'KT-E-01EVC',
                          value: "kongtiaoEVC"
                        },
                        {
                          id: 42,
                          label: 'KT-E-03EVC',
                          value: "kongtiaoEVC"
                        },
                        {
                          id: 43,
                          label: 'KT-E-04EVC',
                          value: "kongtiaoEVC"
                        },
                        {
                          id: 44,
                          label: 'KT-E-05EVC',
                          value: "kongtiaoEVC"
                        },
                        {
                          id: 45,
                          label: 'KT-E-02EMS',
                          value: "kongtiaoEMS"
                        },
                        {
                          id: 46,
                          label: 'KT-E-06EMS',
                          value: "kongtiaoEMS"
                        },
                        {
                          id: 47,
                          label: 'KT-W-02EMS',
                          value: "kongtiaoEMS"
                        },
                        {
                          id: 48,
                          label: 'KT-W-04EMS',
                          value: "kongtiaoEMS"
                        },
                        {
                          id: 49,
                          label: 'KT-W-06EMS',
                          value: "kongtiaoEMS"
                        },
                      ]
                    },
                    {
                      id: 50,
                      label: '列间空调',
                      children: [
                        {
                          id: 51,
                          label: '英维克',
                          children: [
                            { id: 52, label: "LJKT-L2-02-EV", value: "kongtiaoEV" },
                            { id: 53, label: "LJKT-L2-04-EV", value: "kongtiaoEV" },
                            { id: 54, label: "LJKT-L2-06-EV", value: "kongtiaoEV" }
                          ]
                        },
                        {
                          id: 55,
                          label: '海信',
                          children: [
                            { id: 56, label: "LJKT-L4-01-HX", value: "kongtiaoHX" },
                            { id: 57, label: "LJKT-L4-02-HX", value: "kongtiaoHX" },
                            { id: 58, label: "LJKT-L4-03-HX", value: "kongtiaoHX" },
                            { id: 59, label: "LJKT-L4-04-HX", value: "kongtiaoHX" },
                            { id: 60, label: "LJKT-L4-05-HX", value: "kongtiaoHX" },
                            { id: 61, label: "LJKT-L4-06-HX", value: "kongtiaoHX" },
                          ]
                        },
                        {
                          id: 62,
                          label: '维谛',
                          children: [
                            { id: 63, label: "WD-A25-1", value: "kongtiaoWD" },
                            { id: 64, label: "WD-A25-2", value: "kongtiaoWD" },
                            { id: 65, label: "WD-A25-3", value: "kongtiaoWD" },
                            { id: 66, label: "WD-A25-4", value: "kongtiaoWD" },
                            { id: 67, label: "WD-A25-5", value: "kongtiaoWD" },
                            { id: 68, label: "WD-A25-6", value: "kongtiaoWD" },
                          ]
                        },
                      ]
                    },
                  ]
                },
                {
                  id: 69,
                  label: 'UPS监测',
                  children: [
                    {
                      id: 70,
                      label: 'UPS-400KVA-1',
                      value: "UPS"
                    },
                    {
                      id: 71,
                      label: 'UPS-400KVA-2',
                      value: "UPS"
                    },
                    {
                      id: 72,
                      label: 'UPS-400KVA-3',
                      value: "UPS"
                    },
                    {
                      id: 73,
                      label: 'UPS-400KVA-4',
                      value: "UPS",
                      children: [
                        { id: 74, label: '电池组-1', value: "dianchi" },
                        { id: 75, label: '电池组-2', value: "dianchi" },
                        { id: 76, label: '电池组-3', value: "dianchi" },
                        { id: 77, label: '电池组-4', value: "dianchi" },

                      ]
                    },
                    {
                      id: 78,
                      label: 'UPS-200KVA-1',
                      value: "UPS",
                      children: [
                        { id: 79, label: '电池组-1', value: "dianchi" },
                        { id: 80, label: '电池组-2', value: "dianchi" },
                        { id: 81, label: '电池组-3', value: "dianchi" },
                        { id: 82, label: '电池组-4', value: "dianchi" },
                      ]
                    },
                    {
                      id: 83,
                      label: 'UPS-200KVA-2',
                      value: "UPS",
                      children: [
                        { id: 84, label: '电池组-1', value: "dianchi" },
                        { id: 85, label: '电池组-2', value: "dianchi" },
                        { id: 86, label: '电池组-3', value: "dianchi" },
                        { id: 87, label: '电池组-4', value: "dianchi" },
                      ]
                    },
                    {
                      id: 88,
                      label: 'UPS-200KVA-3',
                      value: "UPS",
                      children: [
                        { id: 89, label: '电池组-1', value: "dianchi" },
                        { id: 90, label: '电池组-2', value: "dianchi" },
                        { id: 91, label: '电池组-3', value: "dianchi" },
                        { id: 92, label: '电池组-4', value: "dianchi" },
                      ]
                    },
                    {
                      id: 93,
                      label: 'UPS-200KVA-4',
                      value: "UPS",
                      children: [
                        { id: 94, label: '电池组-1', value: "dianchi" },
                        { id: 95, label: '电池组-2', value: "dianchi" },
                        { id: 96, label: '电池组-3', value: "dianchi" },
                        { id: 97, label: '电池组-4', value: "dianchi" },
                      ]
                    },
                    {
                      id: 98,
                      label: '智能电表ET903',
                      children: [
                        { id: 99, label: '200UPS输入柜', value: "dianbiao" },
                        { id: 100, label: '200UPS输出柜', value: "dianbiao" },
                        { id: 101, label: '400UPS输入', value: "dianbiao" },
                        { id: 102, label: '400UPS输入旁路', value: "dianbiao" },
                        { id: 103, label: '400UPS输出', value: "dianbiao" },
                        { id: 104, label: '空调柜', value: "dianbiao" },
                      ]
                    },
                  ]
                },
                {
                  id: 105,
                  label: '漏水监测',
                  children: [
                    { id: 106, label: '机房漏水传感器', value: "jinglou" },
                    { id: 107, label: 'UPS漏水传感器', value: "UPSlou" },
                  ]
                },
                {
                  id: 108,
                  label: '市电监测',
                  children: [
                    { id: 109, label: '市电监控1', },
                    { id: 110, label: '市电监控2', },
                  ]
                },
              ]
            }]
        }
      ],
      newMenuList: [],
      // 当前筛选名称
      nameUser: '',
      // 当前筛选id
      nameId: [],
      // nameId: '',
      // 接受条件结果数组
      arr: [],
      // 接受条件结果对象
      obj: {},
      // 接受条件结果children
      children: [],
      // 模糊查询数组
      fuzzyArr: [],
      fuzzyChildrenArr: [],
      fuzzyChildrenArr1: [],
      fuzzyChildrenArr2: [],
      fuzzyChildrenArr3: [],
      fuzzyFlag: true,
      // 字节点
      newNodeId: []
    }
  },

  mounted () {
    console.log(this.menuList);
    if (this.transactionList) {
      this.newMenuList = this.transactionList
    } else {
      this.newMenuList = this.menuList
    }
  },

  methods: {
    // 差一个模糊查询
    search (val) {
      // 初始化
      this.arr = []
      this.nameId = []
      this.obj = {}
      this.children = []
      this.fuzzyArr = []
      this.fuzzyChildrenArr = []
      this.fuzzyChildrenArr1 = []
      this.fuzzyChildrenArr2 = []
      this.fuzzyChildrenArr3 = []
      // 正布
      if (val) {
        this.nameUser = val
        // 获取id
        this.searchDg(this.menuList)
        // 遍历id查值
        if (this.nameId.length > 1) {
          for (var j = 0; j < this.nameId.length; j++) {
            this.arr.push(this.findPathByLeafId(this.nameId[j], this.menuList))
          }
          for (var q = 0; q < this.arr.length - 1; q++) {
            if (this.arr[q][this.arr[q].length - 2].id != this.arr[q + 1][this.arr[q + 1].length - 2].id) {
              this.fuzzyFlag = false
            } else {
              continue
            }
          }
          // 数组 arr 
          // 最里层的children
          for (var i = 0; i < this.arr.length - 1; i++) {
            if (this.arr[i][this.arr[i].length - 2].id == this.arr[i + 1][this.arr[i + 1].length - 2].id) {
              this.fuzzyChildrenArr1.push(this.arr[i][this.arr[i].length - 1])
            } else {
              this.fuzzyChildrenArr1.push(this.arr[i][this.arr[i].length - 1])
              this.fuzzyChildrenArr2.push(this.fuzzyChildrenArr1)
              this.fuzzyChildrenArr3.push(this.arr[i][this.arr[i].length - 2])
              this.fuzzyChildrenArr1 = []
            }
          }
          if (!this.fuzzyFlag) {
            if (i == this.arr.length - 1) {
              // 子
              this.fuzzyChildrenArr1.push(this.arr[i][this.arr[i].length - 1])
              this.fuzzyChildrenArr2.push(this.fuzzyChildrenArr1)
              // 父
              this.fuzzyChildrenArr3.push(this.arr[i][this.arr[i].length - 2])
              this.fuzzyChildrenArr1 = []
              // 重新赋值
              this.fuzzyChildrenArr = this.fuzzyChildrenArr2
            }
          } else {
            this.fuzzyChildrenArr = this.fuzzyChildrenArr1
          }
          // 判断是多组还是单组
          if (this.fuzzyFlag) {
            for (var i = this.arr[0].length - 2; i >= 0; i--) {
              this.obj = this.arr[0][i]
              if (i == this.arr[0].length - 2) {
                this.obj.children = this.fuzzyChildrenArr
              }
              else if (i !== this.arr[0].length - 1) {
                this.obj.children = [this.arr[0][i + 1]]
              }
            }
          } else {
            for (var w = 0; w < this.fuzzyChildrenArr3.length; w++) {
              this.fuzzyChildrenArr3[w].children = this.fuzzyChildrenArr[w]
            }

            for (var i = this.arr[0].length - 2; i >= 0; i--) {
              this.obj = this.arr[0][i]
              if (i == this.arr[0].length - 3) {
                this.obj.children = this.fuzzyChildrenArr3
              }
              else if (i !== this.arr[0].length - 1) {
                this.obj.children = [this.arr[0][i + 1]]
              }
            }
          }
          this.newMenuList = [this.obj]
        } else {
          this.arr = this.findPathByLeafId(this.nameId, this.menuList)
          // 单条
          for (var i = this.arr.length - 1; i >= 0; i--) {
            this.obj = this.arr[i]
            if (i !== this.arr.length - 1) {
              this.obj.children = [this.arr[i + 1]]
            }
          }
          this.newMenuList = [this.obj]
        }
      } else {
        this.newMenuList = this.menuList
      }
    },
    searchDg (data) {
      data.forEach(item => {
        if (item.label.includes(this.nameUser)) {
          this.nameId.push(item.id)
        } else {
          if (item.children) {
            this.searchDg(item.children)
          }
        }
      })
    },
    // 找出自己所在的位置的id和label  层级
    findPathByLeafId (leafId, nodes, path) {
      if (path === undefined) {
        path = [];
      }
      for (var i = 0; i < nodes.length; i++) {
        var tmpPath = path.concat();
        tmpPath.push({ id: nodes[i].id, label: nodes[i].label });
        if (leafId == nodes[i].id) {
          return tmpPath;
        }
        if (nodes[i].children) {
          var findResult = this.findPathByLeafId(leafId, nodes[i].children, tmpPath);
          if (findResult) {
            return findResult;
          }
        }
      }
    },
    // 查询子节点
  }
}
</script>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1467327.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

如何在 Tomcat 中为 Web 应用程序启用和配置缓存?

在Tomcat中为Web应用程序启用和配置缓存通常涉及到对Tomcat的连接器&#xff08;Connector&#xff09;进行配置&#xff0c;以及可能的话&#xff0c;配置Web应用程序本身以支持缓存。 1. 配置Tomcat连接器以启用缓存 Tomcat的连接器可以通过其配置来启用各种…

开源免费的NTFS for mac工具mounty

开源免费的NTFS for mac工具mounty 安装依赖 brew install gromgit/fuse/ntfs-3g-macbrew install --cask macfuse安装mounty 如果已经安装macFUSE和ntfs-3g-mac&#xff0c;可以直接点击下载的dmg安装包&#xff0c;安装升级。第一次启动mounty&#xff0c;你需要接受一系列…

Oracle迁移到mysql-导出mysql所有索引和主键

导出建库表索引等&#xff1a; [rootlnpg ~]# mysqldump -ugistar -pxxx -h192.168.207.143 --no-data -d lndb > lndb20230223-1.sql 只导出索引&#xff1a;参考&#xff1a;MYSQL导出现有库中的索引脚本_mysql 导出数据库所有表的主键和索引-CSDN博客 -- MYSQL导出现有…

国内排名比较好的ai软件有哪些?极力推荐这几款

随着人工智能技术的不断演进&#xff0c;越来越多的写作者开始借助AI写作软件来提升写作效率。在国内&#xff0c;有许多实用且易用的AI写作工具&#xff0c;让写作变得更加便捷和高效。以下是6款国内优秀的AI写作软件&#xff0c;让您的写作过程更加顺畅。 第一款&#xff1a;…

[附完整代码]群智能算法跑21种真实世界优化问题,并输出结果到excel||群智能算法跑CEC 2020真实世界优化问题,并输出结果到excel

1、简介 灰狼算法跑跑21种真实世界优化问题|足球训练队优化算法跑21种真实世界优化问题||牛顿拉夫逊算法跑21种真实世界优化问题||冠状豪猪CPO跑21种真实世界优化问题。 ‘FTTA’,‘BWO’, ‘CPO’, ‘FHO’, ‘GWO’, ‘HHO’, ‘NRBO’,‘SCA’,‘SGA’,WOA’跑21种真实世…

Python爬虫-报错requests.exceptions.SSLError: HTTPSConnectionPool

在学习python爬虫&#xff0c;在公司运行代码没有问题&#xff0c;但是下班回来把代码拉下来运行&#xff0c;却出现问题。 问题&#xff1a; requests.exceptions.SSLError: HTTPSConnectionPool(host‘campusgateway.51job.com’, port443): Max retries exceeded with url…

如何用jmeter请求application/octet-stream,image/jpeg

用postman调用时&#xff1a; 用jmeter&#xff1a; 注意上图不要勾选&#xff0c;不然会把所有的内容都以二进制传进去&#xff0c;我们不勾选只传二进制的图片内容&#xff0c;勾选了会把MIME类型、参数名称都转为二进制传进去。会报错。

MySQL-基本使用,数据类型,简单操作

1. 数据库概述 1.1 数据库(DatBase) 数据库&#xff0c;就是遵循一定数据格式的数据集合&#xff0c;可以认为他是对文件系统的改进。它解决了不同操作系统之间&#xff0c;数据格式的兼容性问题。也就是说&#xff0c;只要是同一个数据库的数据文件&#xff0c;即使从windows迁…

linux服务器tomcat日志中文出现问号乱码

目录 一、场景二、排查三、原因四、解决 一、场景 tomcat日志的中文出现问号乱码 乱码示例 ??[377995738417729536]????????? ac??????????????message:二、排查 1、使用locale命令查看服务器当前使用的语言包 发现只用的语言包为utf-8&#xff0…

Openstack云计算框架及前期服务搭建

openstack介绍 Openstack是一个开源的云计算管理平台项目&#xff0c;由几个主要的组件组合起来完成具体工作&#xff0c;支持几乎所有的云环境&#xff0c;项目目标是提供实施简单、可大规模扩展、丰富、标准统一的云计算管理平台 ----百度百科 Openstack是一个云操作系统&a…

Rust通用代码生成器莲花发布红莲尝鲜版二十一发布介绍视频,前端代码生成物大翻新

Rust通用代码生成器莲花发布红莲尝鲜版二十一发布介绍视频&#xff0c;前端代码生成物大翻新 Rust通用代码生成器发布了红莲尝鲜版二十一的最新介绍视频&#xff0c;前端代码生成物大翻新。视频请见&#xff1a; Rust通用代码生成器&#xff1a;莲花&#xff0c;红莲尝鲜版二…

【QT QML】软件打包,生成安装包

一、版本 Desktop 5.15.2 MinGW 64-bit二、打包 1. 编译Release版本 2. 在工程目录下找到Realse文件夹 3. 拷贝文件 ***-Desktop_Qt_5_15_2_MinGW_64_bit-Release - release - xxx.exe到一个新文件夹中 4. 开启相应打包工具&#xff08;根据自己的编译器和版本选择&#xff0…

爬取数位观察城市数据代码展示

import requests import json from Crypto.Cipher import AES # 开始解密 from Crypto.Util.Padding import unpad #去填充的逻辑 import base64 url https://app.swguancha.com/client/v1/cPublic/consumer/baseInfo data {current: 1,"dimensionTime": "20…

java课设之简易版客房管理系统(mvc三层架构)

&#xff08;一&#xff09;、系统概述&#xff1a; 客房管理系统是一个用于管理酒店客房信息的程序&#xff0c;主要功能包括客房信息录入、客房状态查询、客房订单管理&#xff0c;客房的预定功能。 &#xff08;二&#xff09;、功能说明&#xff1a; 1.登录&#xff1a;管理…

【openGL教程08】关于着色器(02)

LearnOpenGL - Shaders 一、说明 着色器是openGL渲染的重要内容&#xff0c;客户如果想自我实现渲染灵活性&#xff0c;可以用着色器进行编程&#xff0c;这种程序小脚本被传送到GPU的显卡内部&#xff0c;起到动态灵活的着色作用。 二、着色器简述 正如“Hello Triangle”一章…

UnityWebGL UGUI中文不显示问题

这是Unity编辑中效果 打包成webgl后的效果&#xff08;中文没有显示出来&#xff09; 解决方法 将Unity默认使用的Arial替换成中文字体。 1.找到电脑字体库&#xff08;win电脑字体库路径&#xff1a;C:\Windows\Fonts &#xff1b;Mac电脑搜索“字体册”&#xff09;。 2.将…

Web3之光:揭秘数字创新的未来

随着数字化时代的深入发展&#xff0c;Web3正以其独特的技术和理念&#xff0c;为我们打开数字创新的崭新视角。作为数字化时代的新兴力量&#xff0c;Web3将深刻影响着我们的生活、工作和社会。本文将揭秘Web3的奥秘&#xff0c;探讨其在数字创新领域的前景和潜力。 1. 重新定…

Go 如何按行读取(大)文件?尝试 bufio 包提供的几种方式

嗨&#xff0c;大家好&#xff01;我是波罗学。本文是系列文章 Go 技巧第十七篇&#xff0c;系列文章查看&#xff1a;Go 语言技巧。 本文将介绍 Go 如何按行读取文件&#xff0c;基于此会逐步延伸到如何按块读取文件。 引言 我们将要介绍的按行读取文件的方式其实是非常适合…

代码随想录刷题笔记-Day22

1. 修剪二叉搜索树 669. 修剪二叉搜索树https://leetcode.cn/problems/trim-a-binary-search-tree/ 给你二叉搜索树的根节点 root &#xff0c;同时给定最小边界low 和最大边界 high。通过修剪二叉搜索树&#xff0c;使得所有节点的值在[low, high]中。修剪树 不应该 改变保留…

MIT-BEVFusion系列九--CUDA-BEVFusion部署4 c++解析pytorch导出的tensor数据

目录 创建流打印 engine 信息打印结果内部流程 启动计时功能加载变换矩阵并更新数据&#xff08;重要&#xff09;内部实现 该系列文章与qwe一同创作&#xff0c;喜欢的话不妨点个赞。 在create_core方法结束后&#xff0c;我们的视角回到了main.cpp中。继续来看接下来的流程。…