当前位置: 首页 > news >正文

el-tree目录和el-table实现搜索定位高亮方法

需求:el-tree目录实现搜索查询el-table表格项,双击表格项根据yiZhuMLID||muLuID定位el-tree目录,并且高亮展示在可视化区域内,再重新根据el-tree目录的yiZhuMLID搜索刷新el-table表格,定位且高亮展示相对应的yiZhuMLID的需求

1、先上DOM代码

    <div class="main"><div class="left"><el-treeref="tree"class="tree":data="labWorkOptions":props="defaultProps"node-key="yiZhuMLID":default-expanded-keys="currentNodekey"highlight-current@node-click="handleNodeClick"/></div><div class="center">// 封装的el-table(后面加上)<PublicTableref="multipleTable"row-key="$multipleTable"class="table":is-need-pagination="false":table-data="centerTableData":table-info="tableInfo":need-select="true":table-column="centerColumns":events="centerEvents":has-operation="false"/><div class="centerSearch"><el-inputv-model="queryString"class=""size="small"clearableplaceholder="请输入格式拼音/五笔首码搜索"@clear="onSearch"@keyup.enter.native="onSearch"/><el-buttonsize="small"class="el-button-color"style="margin-right: 10px"icon="el-icon-search"@click="onSearch">查询</el-button></div></div><div class="right"><PublicTableref="publicTable"class="table":is-need-pagination="false":table-data="rightData":table-info="tableInfo":table-column="rightColumns":has-operation="false"/></div></div>

2、样式Style代码

<style lang="scss" scoped>
::v-deep .el-table__body-wrapper {overflow: auto;
}
.title {font-size: 15px;font-weight: 600;padding: 0 8px;border-left: 3px solid #21c5c8;
}
.main {display: flex;width: 100%;height: 100%;.left {flex: 1;max-width: 25%;overflow: auto;::v-deep .tree {height: 500px;}}.center {max-width: 29%;height: 500px;.centerSearch {display: flex;flex-direction: row;}.table {height: calc(500px - 15px);overflow: auto;}}.right {flex: 1;max-width: 50%;height: 500px;}
}
::v-deep .handle-dialog {height: 100%;margin-top: 10px;
}
::v-deep .el-table__header-wrapper .el-checkbox {display: none;
}
</style>

3、JS代码

<script>
import {getHYXMMXWHByIdItem,getItemByPinyinWubi
} from '@/api/menZhenAPI/huaYanjiChu/huaYanXMMLMXWH'
export default {name: 'HuaYanMNKDDialog',props: {labWorkOptions: {type: Array,default: () => []},value: {type: Boolean,default: false},data: {type: Object,default: () => ({})},rightTableData: {type: Array,default: () => []}},data() {return {currentNodekey: [],formData: {},yiZhuMLID: '',queryString: '',leftTableData: [],centerTableData: [],tableData: [],defaultProps: {children: 'children',label: 'yiZhuMLMC'},addData: [],tableInfo: {},rightData: [],leftEvents: {'row-click': (row) => {this.getHuaYanXMById(row)}},centerEvents: {select: (selection, row) => {console.log('selection', selection)console.log('row', row)const flag = this.rightData.findIndex((item) => item.huaYanID === row.huaYanID)if (flag === -1) {if (row.lianDongHao !== null) {this.centerTableData.forEach((item) => {if (item.lianDongHao === row.lianDongHao) {this.rightData.push({muLuID: item.muLuId,huaYanID: item.huaYanID,huaYanXMMC: item.huaYanXMMC,paiXu: item.paiXu,lianDongHao: item.lianDongHao,zhuCiXiang: null})console.log('item', item)console.log('this.rightData', this.rightData)}})} else {this.rightData.push({muLuID: row.muLuId,huaYanID: row.huaYanID,huaYanXMMC: row.huaYanXMMC,paiXu: row.paiXu,lianDongHao: row.lianDongHao,zhuCiXiang: null})console.log(this.rightData)}} else {if (row.lianDongHao === null) {this.rightData.splice(flag, 1)} else {this.centerTableData.forEach((item) => {if (item.lianDongHao === row.lianDongHao) {const index = this.rightData.findIndex((item) => item.huaYanID === row.huaYanID)this.rightData.splice(index, 1)}})}this.$refs.multipleTable.getTableRef().clearSelection()}this.chenckByHuaYanID()},// 这是主要方法其他地方的函数方法可以尽量不看'row-dblclick': (row) => {const currentKey = row.yiZhuMLID || row.muLuIDthis.$nextTick(() => {// tree节点的id// this.currentNodekey = row.yiZhuMLID || row.muLuIDthis.currentNodekey = []for (let i = 0; i < this.$refs.tree.store._getAllNodes().length; i++) {if (currentKey === this.$refs.tree.store._getAllNodes()[i].data.yiZhuMLID) {this.$refs.tree.setCurrentKey(currentKey)this.currentNodekey.push(currentKey)}}getHYXMMXWHByIdItem(currentKey).then((res) => {if (res.data) {console.log(row)this.centerTableData = res.datathis.chenckByHuaYanID()// 获取数据后定位setTimeout(() => {this.$tools.tableLocateKey(row.huaYanID,'huaYanID',this.centerTableData,this.$refs['multipleTable'].$refs.tableData)}, 200)// 让高亮元素出现在视图区域document.querySelector('.el-tree--highlight-current .el-tree-node.is-current>.el-tree-node__content').scrollIntoView()}})})}},leftColumns: [{label: '化验项目名称',prop: 'mingCheng',minWidth: '120px'}],centerColumns: [{label: '请选择化验项目',prop: 'huaYanXMMC',minWidth: '120px'}],rightColumns: [{prop: 'huaYanXMMC',label: '化验项目名称',minWidth: '150px'},{prop: '',label: '类别',minWidth: '50px'},{prop: '',label: '医保类别',minWidth: '80px'},{prop: '',label: '目录名称',minWidth: '80px'},{prop: '',label: '状态标志',minWidth: '80px'},{prop: '',label: '医嘱备注',minWidth: '80px'},{prop: '',label: '首次录入时间',minWidth: '120px'},{prop: '',label: '医嘱用户',minWidth: '80px'}],operations: [{text: '删除',type: 'text',class: 'el-text-color-del',callback: (row) => {this.delHandleCancelFormClick(row)}}]}},computed: {visible: {get() {return this.value},set(value) {this.$emit('update:value', false)}}},watch: {visible(val) {if (val) {this.rightData = Object.assign([], this.rightTableData)this.queryString = ''} else {this.centerTableData = []}}},created() {},methods: {onSearch() {getItemByPinyinWubi({key: this.queryString,zhenLiaoLX: this.data.zhenLiaoLX}).then((res) => {if (res) {this.centerTableData = res.data.map((item) => {return {huaYanID: item['huaYanID'],huaYanXMMC: item['huaYanMC'],yiZhuMLID: item['yiZhuMLID'],yiZhuMLMC: item['yiZhuMLMC']}})this.queryString = ''}})},}
}
</script>

4、el-table的封装

<template><div class="table-box"><el-tableref="tableData"v-loading="loading"style="width: 100%":row-key="rowKey":data="tableData":height="tableHeight"highlight-current-rowv-bind="tableInfo":span-method="objectSpanMethod"v-on="events"@selection-change="handleSelectionChange"><slot name="expand" /><el-table-column v-if="selectAllTemplate" min-width="140" label="全选模板列表"><template slot-scope="{ row }"><div><el-checkboxv-model="row.all"@change="muBanAllToggleSelection($event, tableData, row)">{{ row.muBanMC }}</el-checkbox></div></template></el-table-column><!-- 多选 --><el-table-columnv-if="needSelect"type="selection"reserve-selectionwidth="55"align="center"/><el-table-column v-if="hasIndex" label="序号" width="50" type="index" /><template v-for="(item, index) in tableColumn"><!-- 此列需要自定义 --><el-table-columnv-if="item.isSlot":key="'%' + index":show-overflow-tooltip="showOverflowTooltip"v-bind="item":render-header="item.renderHeader"v-on="events"><template slot-scope="{ row, $index }"><ex-slotv-if="item.render":render="item.render":row="row":index="$index":column="item":class="item.prop":default-value="item.defaultValue"/><slot v-else :name="item.prop" :row="row" /></template></el-table-column><!-- 正常列 --><el-table-columnv-else:key="'%' + index":show-overflow-tooltip="showOverflowTooltip"v-bind="item"v-on="events"/></template><el-table-column v-if="hasOperation" fixed="right" label="操作" :min-width="operationWidth"><!-- <template v-if="!btnButton || btnButton.length === 0" slot-scope="scope"><slot name="operation" :row="scope.row" :index="scope.$index" /></template> --><template v-if="btnButton.length" slot-scope="{ row, column, $index }"><el-buttonv-for="(value, i) in btnButton":key="'$' + i"size="small":type="value.type":icon="value.icon":class="value.class"@click="value.callback(row, column, $index)">{{ value.text }}</el-button></template></el-table-column></el-table><!-- 分页 --><divv-if="isNeedPagination"style="display: flex; justify-content: flex-end; align-item: centerl; padding-top: 15px"><el-paginationref="pagination":page-sizes="pageSizes":page-size.sync="computedPageSize":hide-on-single-page="isSinglePageHide"layout="total, sizes, prev, pager, next, jumper":current-page.sync="computedCurrentPage":total="total":pager-count="pagerCount"@current-change="currentChange"@size-change="sizeChange"/></div></div>
</template>
<script>
// 自定义组件的内容
const exSlot = {functional: true,props: {row: Object,render: Function,index: Number,column: {type: Object,default: null},defaultValue: [Number, String]},render: (h, ctx) => {const params = {row: ctx.props.row,index: ctx.props.index}const defaultValue = ctx.props.defaultValueparams.column = ctx.props.column || {}return h('div',{class: [params.column.prop || '',params.column.class || params.column.className || ''].join('')},[ctx.props.render(h, params) || defaultValue])}
}
export default {name: 'PublicTable',components: {'ex-slot': exSlot},props: {// keyrowKey: {type: String,default: ''},// 超出行是否隐藏不换行showOverflowTooltip: {type: Boolean,default: true},// 是否需要多选needSelect: {type: Boolean,default: false},// 是否需要序号hasIndex: {type: Boolean,default: false},// 是否需要分页isNeedPagination: {type: Boolean,default: true},// 是否单页隐藏,默认为trueisSinglePageHide: {type: Boolean,default: false},// 当前页页码,支持.sync修饰符currentPage: {type: Number,default: 1},// 页码显示数据量pagerCount: {type: Number,default: 7},// 每页数据条数, 支持.sync修饰符默认为每页10条pageSize: {type: Number,default: 20},// 数据总条数total: {type: Number,default: 0},// 每页多少数据pageSizes: {type: Array,required: false,default: () => [20, 40, 80, 100]},tableInfo: {type: Object,default: () => {}},// 获取数据时是否需要加载loadingloading: {type: Boolean,default: false},tableData: {type: Array,default: () => []},// 表格展示数据tableColumn: {type: Array,default: () => []},// 是否需要操作列hasOperation: {type: Boolean,default: true},// 操作列btnButton: {type: Array,default: () => []},// 操作列宽度operationWidth: {type: String,default: '120px'},// 表格方法events: {type: Object,default: () => {}},templateSelectAll: {type: Boolean,default: false},// 合并单元格objectSpanMethod: {type: Function,default: () => {}},muBanAllToggleSelection: {type: Function,default: () => {}},selectAllTemplate: {type: Boolean,default: false}},data() {return {}},computed: {computedCurrentPage: {get() {return this.currentPage},set(val) {this.$emit('update:currentPage', val)}},computedPageSize: {get() {return this.pageSize},set(val) {this.$emit('update:pageSize', val)}},tableHeight() {return !this.isNeedPagination ? '100%' : 'calc(100% - 47px)'}},mounted() {},methods: {getTableRef() {return this.$refs.tableData},getRefPagination() {return this.$refs.pagination},// 页面切换事件  通过 @currentChange 绑定currentChange(val) {this.$emit('currentChange', val)},// 每页条数切换事件,通过@sizeChange 绑定sizeChange(val) {this.$emit('sizeChange', val)},handleSelectionChange(val) {this.$emit('selectionChange', val)}}
}
</script>
<style lang="scss" scoped>
.table-box {flex: 1;overflow: hidden;width: 100%;height: 100%;
}
</style>

5、el-table定位数据高亮的方法

/*** table表格数据定位* @param {value} 查询的value唯一值* @param {tabKey} tableData数据中的key属性* @param {tableData} table表格数据源tableData* @param {tableRefs} table表格标签tableRefs* @returns*/
function tableLocateKey(value, tabKey, tableData, tableRefs) {let index = tableData.findIndex((i) => {return value === i[tabKey]})let vm = tableRefs.$elvm.querySelectorAll('.el-table__body tr')[index].scrollIntoView()//让定位到的这条数据产生高亮效果tableRefs.setCurrentRow(tableData[index])
}

相关文章:

el-tree目录和el-table实现搜索定位高亮方法

需求&#xff1a;el-tree目录实现搜索查询el-table表格项&#xff0c;双击表格项根据yiZhuMLID||muLuID定位el-tree目录&#xff0c;并且高亮展示在可视化区域内&#xff0c;再重新根据el-tree目录的yiZhuMLID搜索刷新el-table表格&#xff0c;定位且高亮展示相对应的yiZhuMLID…...

linux常用指令

基础命令 cd&#xff1a;用于切换目录。例如&#xff0c;要从当前目录切换到/home/user目录&#xff0c;可以使用命令“cd /home/user”。ls&#xff1a;用于列出目录内容。例如&#xff0c;要列出当前目录的内容&#xff0c;可以使用命令“ls”。mkdir&#xff1a;用于创建目…...

C语言,指针的一些运算

若创建一个数组&#xff1a;int arr[10] 0; 用指针变量来储存数组首元素的地址&#xff1a;int* p arr,这里arr是数组名&#xff0c;表示首元素地址。 若p p 1或者p之后p本来指向数组首元素地址&#xff0c;就变成了指向第二个元素的地址&#xff0c;p n即指向第n 1个地…...

iPhone 如何强制重启

参考iPhone的官方使用手册 传送门 尤其当 iPhone 未响应&#xff0c;也无法将其关机再开机&#xff0c;此方法最有效&#xff1a; 按住调高音量按钮&#xff0c;然后快速松开。按住调低音量按钮&#xff0c;然后快速松开。按住侧边按钮。当 Apple 标志出现时&#xff0c;松开侧…...

数据结构--单链表操作

1.单链表的创建&#xff08;带头结点&#xff09; #include<stdlib.h> #define ElemType int typedef struct {//定义一个结点ElemType data;struct STU* next; }STU,*LinkList; bool InitList(LinkList& L) {L (STU*)malloc(sizeof(STU));//创建头结点if (L NUL…...

AlmaLinux (兼容centos)安装Geant4与ROOT

AlmaLinux 介绍 AlmaLinux OS 是一个开源、社区驱动的 Linux 操作系统&#xff0c;它填补了因 CentOS 稳定版本停止维护而留下的空白&#xff0c;同时更加强大。 安装 AlmaLinux 这个我用的是 windows 子系统进行安装 首先打开微软商店&#xff0c;然后搜索AlmaLinux&#…...

FPGA面试题(2)

一.同步复位和异步复位 同步复位&#xff1a;当clk有效时&#xff0c;复位才有效。优点&#xff1a;有利于时序分析&#xff0c;防止毛刺现象出现。缺点&#xff1a;复位信号必须大于时钟周期&#xff0c;大部分逻辑器件中D触发器都只有异步复位端口&#xff0c;需要在寄存器数…...

【C++ Primer Plus学习记录】指针——使用new来创建动态数组

目录 1.使用new创建动态数组 2.使用动态数组&#xff08;如何使用指针访问数组元素&#xff09; 如果程序只需要一个值&#xff0c;则可能会声明一个简单变量&#xff0c;因为对于管理一个小型数据对象来说&#xff0c;这样做比使用new和指针更简单。通常&#xff0c;对于大型…...

移动app广告变现,对接广告联盟还是选择第三方聚合广告平台?

作为互联网广告的载体&#xff0c;APP天生就比线下传统广告位更具优势&#xff0c;不受地域限制可以辐射到地球上的每一个角落&#xff0c;可以让广告获得更广的覆盖面。通过丰富的广告形式&#xff0c;精准的目标用户画像&#xff0c;也可以更好地实现品牌广告或效果广告的投放…...

ARM 按键控制 LED灯,蜂鸣器,风扇

main.c: #include "uart.h" #include "key_it.h" int main() {all_led_init();uart4_init();//串口初始化//中断初始化key_it_config();key3_it_config();buzzer_init();fan_init();while(1){//保证主程序不结束}return 0; }src/key_it.c: #include"…...

VirtualBox Ubuntu扩展虚拟机磁盘空间

关于Orical VM VirtualBox虚拟机安装了ubuntu linux系统&#xff0c;由于需要&#xff0c;磁盘空间不足&#xff0c;需要扩展磁盘空间&#xff0c;最终找到了一个非常简单的方法&#xff0c;上干货。 1、关闭虚拟机 2、运用VBoxManage命令扩展vdi文件的空间 打开windows的命…...

C#开发的OpenRA游戏之电力系统之二

C#开发的OpenRA游戏之电力系统之二 继续前面的电力系统分析,在OpenRA游戏里,每一个建筑物都会有一个电力描述字段,说明这个建筑物是消耗电力,还是产生电力的。如果这个建筑物是产生电力的,那么这个字段就会是正值,如果这个建筑物是消耗电力的,就会是负值。因此所有电厂…...

Java架构师基础框架设计

目录 1 导学2 理解软件框架3 框架设计里面的框架和设计模式的关系4 基础框架中常见的基本功能4.1 事务处理4.2 微服务网络调用4.3 缓存实现4.4 分布式id4.5 任务调度4.6 工作流5 基础框架的几种基本的使用方式5.1 继承方式5.2 注解或注解加AOP的方式5.3 将基础框架的功能直接当…...

tortoise创建本地仓库

1.安装git和tortoise 推荐 TortoiseGit的安装与配置方法 以及 Git TortoiseGit 配置步骤以及本地版本管理 这里记录一下我遇到的问题 1.右键没有创建本地版本库 2 .创建了但是克隆不了 后续专有 一般选专有网络 注意自行谨慎选择 自行负责...

【FreeRTOS】【STM32】03 FreeRTOSConfig.h头文件简介与修改

基于[野火]《FreeRTOS%20内核实现与应用开发实战—基于STM32》.pdf FreeRTOSConfig.h头文件是FreeRTOS各项功能的打开与关闭 FreeRTOSConfig.h头文件简介 之前也说过了&#xff0c;FreeRTOSConfig.h文件可以添加在工程中任意文件夹&#xff0c;只需要在路径中添加好了就行。…...

VScode商店无法访问

下面的方法也许对你没用&#xff0c;也许也有用&#xff0c;但是尝试一下不会有任何副作用。 步骤一&#xff1a; 步骤二&#xff1a;在Proxy代理设置中复制输入 http://127.0.0.1:8080 步骤三&#xff1a;关闭软件&#xff0c;再打开VScode&#xff0c;把http://127.0.0.1:8…...

【UnityUGUI】复合控件详解,你还记得多少

&#x1f468;‍&#x1f4bb;个人主页&#xff1a;元宇宙-秩沅 &#x1f468;‍&#x1f4bb; hallo 欢迎 点赞&#x1f44d; 收藏⭐ 留言&#x1f4dd; 加关注✅! &#x1f468;‍&#x1f4bb; 本文由 秩沅 原创 &#x1f468;‍&#x1f4bb; 收录于专栏&#xff1a;UI_…...

ubuntu下使用gcc编译c程序: “error: stray ‘\357’ in program“

现象&#xff1a; ubuntu下使用gcc编译c程序: “error: stray ‘\357’ in program“ 尝试查找原因&#xff1a;打开从windos直接粘贴c程序到ubuntu的c代码&#xff0c;发现多了 <200b>&#xff1a; 方案&#xff1a;尝试在vim编辑器删除&#xff0c;多出来的字符后编译…...

LeetCode 143.重排链表

题目链接 力扣&#xff08;LeetCode&#xff09;官网 - 全球极客挚爱的技术成长平台 题目解析 分析题目后我们可以直接进行模拟实现。 具体用到的就是我们之前的知识的结合&#xff0c;首先使用快慢指针找到链表的中间结点。然后将后半段链表给翻转一下&#xff0c;然后再让这…...

不做决策的“RPA机器人”,不是合格的“数字化劳动力”

01 RPA机器人向“数字劳动力”的转变 随着 RPA 技术被广泛应用各行业的不同场景中&#xff0c;再结合以深度学习为代表的 AI 人工智能技术的新一轮发展&#xff0c;RPA 机器人目前已经从仅能处理“单一、重复和标准化的流程”向智能流程自动化的方向发展&#xff0c;从而具备处…...

应用升级/灾备测试时使用guarantee 闪回点迅速回退

1.场景 应用要升级,当升级失败时,数据库回退到升级前. 要测试系统,测试完成后,数据库要回退到测试前。 相对于RMAN恢复需要很长时间&#xff0c; 数据库闪回只需要几分钟。 2.技术实现 数据库设置 2个db_recovery参数 创建guarantee闪回点&#xff0c;不需要开启数据库闪回。…...

linux arm系统烧录

1、打开瑞芯微程序 2、按住linux arm 的 recover按键 插入电源 3、当瑞芯微检测到有设备 4、松开recover按键 5、选择升级固件 6、点击固件选择本地刷机的linux arm 镜像 7、点击升级 &#xff08;忘了有没有这步了 估计有&#xff09; 刷机程序 和 镜像 就不提供了。要刷的时…...

质量体系的重要

质量体系是为确保产品、服务或过程质量满足规定要求&#xff0c;由相互关联的要素构成的有机整体。其核心内容可归纳为以下五个方面&#xff1a; &#x1f3db;️ 一、组织架构与职责 质量体系明确组织内各部门、岗位的职责与权限&#xff0c;形成层级清晰的管理网络&#xf…...

镜像里切换为普通用户

如果你登录远程虚拟机默认就是 root 用户&#xff0c;但你不希望用 root 权限运行 ns-3&#xff08;这是对的&#xff0c;ns3 工具会拒绝 root&#xff09;&#xff0c;你可以按以下方法创建一个 非 root 用户账号 并切换到它运行 ns-3。 一次性解决方案&#xff1a;创建非 roo…...

ServerTrust 并非唯一

NSURLAuthenticationMethodServerTrust 只是 authenticationMethod 的冰山一角 要理解 NSURLAuthenticationMethodServerTrust, 首先要明白它只是 authenticationMethod 的选项之一, 并非唯一 1 先厘清概念 点说明authenticationMethodURLAuthenticationChallenge.protectionS…...

【Java_EE】Spring MVC

目录 Spring Web MVC ​编辑注解 RestController RequestMapping RequestParam RequestParam RequestBody PathVariable RequestPart 参数传递 注意事项 ​编辑参数重命名 RequestParam ​编辑​编辑传递集合 RequestParam 传递JSON数据 ​编辑RequestBody ​…...

【Oracle】分区表

个人主页&#xff1a;Guiat 归属专栏&#xff1a;Oracle 文章目录 1. 分区表基础概述1.1 分区表的概念与优势1.2 分区类型概览1.3 分区表的工作原理 2. 范围分区 (RANGE Partitioning)2.1 基础范围分区2.1.1 按日期范围分区2.1.2 按数值范围分区 2.2 间隔分区 (INTERVAL Partit…...

深度学习习题2

1.如果增加神经网络的宽度&#xff0c;精确度会增加到一个特定阈值后&#xff0c;便开始降低。造成这一现象的可能原因是什么&#xff1f; A、即使增加卷积核的数量&#xff0c;只有少部分的核会被用作预测 B、当卷积核数量增加时&#xff0c;神经网络的预测能力会降低 C、当卷…...

A2A JS SDK 完整教程:快速入门指南

目录 什么是 A2A JS SDK?A2A JS 安装与设置A2A JS 核心概念创建你的第一个 A2A JS 代理A2A JS 服务端开发A2A JS 客户端使用A2A JS 高级特性A2A JS 最佳实践A2A JS 故障排除 什么是 A2A JS SDK? A2A JS SDK 是一个专为 JavaScript/TypeScript 开发者设计的强大库&#xff…...

Rust 开发环境搭建

环境搭建 1、开发工具RustRover 或者vs code 2、Cygwin64 安装 https://cygwin.com/install.html 在工具终端执行&#xff1a; rustup toolchain install stable-x86_64-pc-windows-gnu rustup default stable-x86_64-pc-windows-gnu ​ 2、Hello World fn main() { println…...