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


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

    1、先上DOM代码

    1. <div class="main">
    2. <div class="left">
    3. <el-tree
    4. ref="tree"
    5. class="tree"
    6. :data="labWorkOptions"
    7. :props="defaultProps"
    8. node-key="yiZhuMLID"
    9. :default-expanded-keys="currentNodekey"
    10. highlight-current
    11. @node-click="handleNodeClick"
    12. />
    13. div>
    14. <div class="center">
    15. // 封装的el-table(后面加上)
    16. <PublicTable
    17. ref="multipleTable"
    18. row-key="$multipleTable"
    19. class="table"
    20. :is-need-pagination="false"
    21. :table-data="centerTableData"
    22. :table-info="tableInfo"
    23. :need-select="true"
    24. :table-column="centerColumns"
    25. :events="centerEvents"
    26. :has-operation="false"
    27. />
    28. <div class="centerSearch">
    29. <el-input
    30. v-model="queryString"
    31. class=""
    32. size="small"
    33. clearable
    34. placeholder="请输入格式拼音/五笔首码搜索"
    35. @clear="onSearch"
    36. @keyup.enter.native="onSearch"
    37. />
    38. <el-button
    39. size="small"
    40. class="el-button-color"
    41. style="margin-right: 10px"
    42. icon="el-icon-search"
    43. @click="onSearch"
    44. >
    45. 查询
    46. el-button>
    47. div>
    48. div>
    49. <div class="right">
    50. <PublicTable
    51. ref="publicTable"
    52. class="table"
    53. :is-need-pagination="false"
    54. :table-data="rightData"
    55. :table-info="tableInfo"
    56. :table-column="rightColumns"
    57. :has-operation="false"
    58. />
    59. div>
    60. div>

    2、样式Style代码

    1. <style lang="scss" scoped>
    2. ::v-deep .el-table__body-wrapper {
    3. overflow: auto;
    4. }
    5. .title {
    6. font-size: 15px;
    7. font-weight: 600;
    8. padding: 0 8px;
    9. border-left: 3px solid #21c5c8;
    10. }
    11. .main {
    12. display: flex;
    13. width: 100%;
    14. height: 100%;
    15. .left {
    16. flex: 1;
    17. max-width: 25%;
    18. overflow: auto;
    19. ::v-deep .tree {
    20. height: 500px;
    21. }
    22. }
    23. .center {
    24. max-width: 29%;
    25. height: 500px;
    26. .centerSearch {
    27. display: flex;
    28. flex-direction: row;
    29. }
    30. .table {
    31. height: calc(500px - 15px);
    32. overflow: auto;
    33. }
    34. }
    35. .right {
    36. flex: 1;
    37. max-width: 50%;
    38. height: 500px;
    39. }
    40. }
    41. ::v-deep .handle-dialog {
    42. height: 100%;
    43. margin-top: 10px;
    44. }
    45. ::v-deep .el-table__header-wrapper .el-checkbox {
    46. display: none;
    47. }
    48. style>

    3、JS代码

    4、el-table的封装

    1. <script>
    2. // 自定义组件的内容
    3. const exSlot = {
    4. functional: true,
    5. props: {
    6. row: Object,
    7. render: Function,
    8. index: Number,
    9. column: {
    10. type: Object,
    11. default: null
    12. },
    13. defaultValue: [Number, String]
    14. },
    15. render: (h, ctx) => {
    16. const params = {
    17. row: ctx.props.row,
    18. index: ctx.props.index
    19. }
    20. const defaultValue = ctx.props.defaultValue
    21. params.column = ctx.props.column || {}
    22. return h(
    23. 'div',
    24. {
    25. class: [
    26. params.column.prop || '',
    27. params.column.class || params.column.className || ''
    28. ].join('')
    29. },
    30. [ctx.props.render(h, params) || defaultValue]
    31. )
    32. }
    33. }
    34. export default {
    35. name: 'PublicTable',
    36. components: {
    37. 'ex-slot': exSlot
    38. },
    39. props: {
    40. // key
    41. rowKey: {
    42. type: String,
    43. default: ''
    44. },
    45. // 超出行是否隐藏不换行
    46. showOverflowTooltip: {
    47. type: Boolean,
    48. default: true
    49. },
    50. // 是否需要多选
    51. needSelect: {
    52. type: Boolean,
    53. default: false
    54. },
    55. // 是否需要序号
    56. hasIndex: {
    57. type: Boolean,
    58. default: false
    59. },
    60. // 是否需要分页
    61. isNeedPagination: {
    62. type: Boolean,
    63. default: true
    64. },
    65. // 是否单页隐藏,默认为true
    66. isSinglePageHide: {
    67. type: Boolean,
    68. default: false
    69. },
    70. // 当前页页码,支持.sync修饰符
    71. currentPage: {
    72. type: Number,
    73. default: 1
    74. },
    75. // 页码显示数据量
    76. pagerCount: {
    77. type: Number,
    78. default: 7
    79. },
    80. // 每页数据条数, 支持.sync修饰符默认为每页10条
    81. pageSize: {
    82. type: Number,
    83. default: 20
    84. },
    85. // 数据总条数
    86. total: {
    87. type: Number,
    88. default: 0
    89. },
    90. // 每页多少数据
    91. pageSizes: {
    92. type: Array,
    93. required: false,
    94. default: () => [20, 40, 80, 100]
    95. },
    96. tableInfo: {
    97. type: Object,
    98. default: () => {}
    99. },
    100. // 获取数据时是否需要加载loading
    101. loading: {
    102. type: Boolean,
    103. default: false
    104. },
    105. tableData: {
    106. type: Array,
    107. default: () => []
    108. },
    109. // 表格展示数据
    110. tableColumn: {
    111. type: Array,
    112. default: () => []
    113. },
    114. // 是否需要操作列
    115. hasOperation: {
    116. type: Boolean,
    117. default: true
    118. },
    119. // 操作列
    120. btnButton: {
    121. type: Array,
    122. default: () => []
    123. },
    124. // 操作列宽度
    125. operationWidth: {
    126. type: String,
    127. default: '120px'
    128. },
    129. // 表格方法
    130. events: {
    131. type: Object,
    132. default: () => {}
    133. },
    134. templateSelectAll: {
    135. type: Boolean,
    136. default: false
    137. },
    138. // 合并单元格
    139. objectSpanMethod: {
    140. type: Function,
    141. default: () => {}
    142. },
    143. muBanAllToggleSelection: {
    144. type: Function,
    145. default: () => {}
    146. },
    147. selectAllTemplate: {
    148. type: Boolean,
    149. default: false
    150. }
    151. },
    152. data() {
    153. return {}
    154. },
    155. computed: {
    156. computedCurrentPage: {
    157. get() {
    158. return this.currentPage
    159. },
    160. set(val) {
    161. this.$emit('update:currentPage', val)
    162. }
    163. },
    164. computedPageSize: {
    165. get() {
    166. return this.pageSize
    167. },
    168. set(val) {
    169. this.$emit('update:pageSize', val)
    170. }
    171. },
    172. tableHeight() {
    173. return !this.isNeedPagination ? '100%' : 'calc(100% - 47px)'
    174. }
    175. },
    176. mounted() {},
    177. methods: {
    178. getTableRef() {
    179. return this.$refs.tableData
    180. },
    181. getRefPagination() {
    182. return this.$refs.pagination
    183. },
    184. // 页面切换事件 通过 @currentChange 绑定
    185. currentChange(val) {
    186. this.$emit('currentChange', val)
    187. },
    188. // 每页条数切换事件,通过@sizeChange 绑定
    189. sizeChange(val) {
    190. this.$emit('sizeChange', val)
    191. },
    192. handleSelectionChange(val) {
    193. this.$emit('selectionChange', val)
    194. }
    195. }
    196. }
    197. script>
    198. <style lang="scss" scoped>
    199. .table-box {
    200. flex: 1;
    201. overflow: hidden;
    202. width: 100%;
    203. height: 100%;
    204. }
    205. style>

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

    1. /**
    2. * table表格数据定位
    3. * @param {value} 查询的value唯一值
    4. * @param {tabKey} tableData数据中的key属性
    5. * @param {tableData} table表格数据源tableData
    6. * @param {tableRefs} table表格标签tableRefs
    7. * @returns
    8. */
    9. function tableLocateKey(value, tabKey, tableData, tableRefs) {
    10. let index = tableData.findIndex((i) => {
    11. return value === i[tabKey]
    12. })
    13. let vm = tableRefs.$el
    14. vm.querySelectorAll('.el-table__body tr')[index].scrollIntoView()
    15. //让定位到的这条数据产生高亮效果
    16. tableRefs.setCurrentRow(tableData[index])
    17. }

  • 相关阅读:
    [附源码]计算机毕业设计JAVAjsp电影院在线售票系统
    2024.3.9每日一题
    盘点苹果Mac电脑上好用的抠图修图设计软件
    用户组的概念(linux篇)
    基于CNN-RNN的医疗文本生成
    【PAT甲级 - C++题解】1014 Waiting in Line
    计算机毕业设计之java+springboot基于vue的网上图书商城系统
    溶于乙醇的碳量子点CQDs,发射波长420nm,535nm,565nm,505nm,675nm
    Vue项目中组件相互引用,组件不能正常注册,控制台警告处理
    QT小记:QT程序异常结束的可能原因
  • 原文地址:https://blog.csdn.net/Achong999/article/details/133741102