我是靠谱客的博主 失眠白昼,这篇文章主要介绍vue本地搜索-递归查询列表-封装树结构列表,现在分享给大家,希望可以做个参考。

vue本地搜索-递归查询列表-封装树结构列表

tableSearch.vue-界面

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<template> <div class="container"> <div> <SearchTree style="flex: 1" :dataList="treeData" :isEdit="false" :isSearch="true" :isDrag="true" v-show="!isShowInfo" @treeSearch="treeSearch" :treeProps="{ label: 'settingtypename', children: 'seatTypeList', }" ></SearchTree> </div> <div> <!-- row-key="myID" 更换唯一标识 避免index或id有相同的,产生冲突 --> <el-table stripe :data="tableData" style="width: 100%; margin-bottom: 20px" row-key="myID" ></el-table> </div> </div> </template> <script> import SearchTree from "./SearchTree"; export default { components: { SearchTree, }, data() { return { isShowwInfo: false, tableDataMergeInfo: [], }; }, created() { var tableDataMerge = []; var oneSeatPlan = {}; oneSeatPlan = this.tableDataResult; tableDataMerge.push(oneSeatPlan); this.recursion(tableDataMerge); this.tableDataMergeInfo = tableDataMerge; this.tableData = this.tableDataMergeInfo; }, methods: { // 递归添加字段 recursion(arr) { arr.forEach((el) => { let myID = Math.random().toString(36).substr(2); this.$set(el, "myID", myID); if (el.children && el.children.length) { this.recursion(el.children); } }); }, // 递归搜索数据 recursion2(arr, filterWords) { arr.forEach((el) => { if (el.seattingtypename.includes(filterWords)) { this.midellTreeArr.push(el); return; } if (el.seatTypeList && el.seatTypeList.length) { this.recursion2(el.seatTypeList, filterWords); } }); this.treeData = this.midellTreeArr; }, treeSearch(val) { if (!val) { this.treeData = this.initTreeData; return; } let filterData = [...this.initTreeData]; this.midellTreeArr = []; console.log(this.initTreeData); this.recursion2(filterData, val); }, }, }; </script> <style scoped lang="less"> // 树结构菜单 .search-tree-warp { border-top: none; box-sizing: border-box; position: relative; margin-top: 2vw; margin-right: 2vw; height: 53vh; flex: 1; } </style>

SearchTree.vue-组件

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
<template> <div class="search-tree-warp"> <slot></slot> <div class="search-tree-title" v-if="title">{{ title }}</div> <el-input v-if="isSearch" class="tree-search-input" placeholder="请搜索相关内容" size="mini" suffix-icon="el-icon-search" clearable v-model="treeSearch" ></el-input> <el-tree :data="dataList" :props="treeProps" :filter-node-method="treeFilter" :allow-drag="allowDrag" :allow-drop="allowDrop" :default-expanded-keys="myTreeExpandData" highlight-current node-key="id" @node-drag-start="handleDragStart" @node-click="handleNodeClick" accordion draggable ref="tree" :class="isSearch ? 'tree-heigth' : ''" v-on="$listeners" > <span class="train-class-tree" slot-scope="{ node, data }" @drop="handleDrop($event, node, data)" > <i class="tree-round"></i> <i class="tree-my-icon" v-if="data.icon" :class="data.icon"></i> <span>{{ node.label }}</span> <div class="tree-btn-warp" v-if="isEdit"> <span @click="editTree(data, node)" class="el-icon-edit" v-if="node.level != 1 || rootEdit" ></span> <span @click="addTree(data, node)" class="el-icon-plus"></span> <i @click.stop="delTree(data, node)" class="el-icon-minus" v-if="node.level != 1|| rootEdit" ></i> </div> </span> </el-tree> </div> </template> <script> export default { name: "SearchTree", props: { isSearch: { type: Boolean, default: false, }, treeProps: { type: Object, default: function () { return { label: "label", children: "children", }; }, }, isEdit: { type: Boolean, default: true, }, isRootEdit: { type: Boolean, default: true, }, rootEdit:{ type: Boolean, default: false, }, dataList: { type: Array, default: function () { return []; }, }, myTreeExpandData: { type: Array, default: function () { return ["0"]; }, }, title: { type: String, default: "", }, isDrop: { type: Boolean, default: false, }, isDrag: { type: Boolean, default: false, }, isDragRoot: { type: Boolean, default: true, }, }, data() { return { treeSearch: "", }; }, watch: { treeSearch(val) { this.$emit("treeSearch", val); }, }, methods: { /** * 自定义按钮 */ editTree(data, node) { // this.myTreeExpandData = []; // this.myTreeExpandData.push(data.id); let subData = Object.assign({}, data); this.$emit("editTree", subData); }, addTree(data, node) { this.$emit("addTree", data); }, delTree(data, node) { this.$confirm("是否要删除?", "提示", { confirmButtonText: "确定", cancelButtonText: "取消", type: "warning", }).then(() => { this.$emit("delTree", data, node); }); }, // tree treeFilter(value, data) { if (!value) return true; return data[this.treeProps.label].indexOf(value) !== -1; }, allowDrag(node, ev) { // ev.dataTransfer.setData("itemData", str); if (this.isDragRoot) { // 默认只能最底层节点拖拽 return this.isDrag && node.childNodes.length === 0; } else { return this.isDrag; } }, allowDrop(draggingNode, dropNode, type) { return this.isDrop; }, handleNodeClick(obj, dom, com) { dom.expanded = true; this.$emit("clickTree", obj, dom, com); }, handleDragStart(node, ev) { /* console.log(node) console.log(ev) */ let str = JSON.stringify(node.data); ev.dataTransfer.setData("itemData", str); }, handleDrop(ev, node, dropData) { if (!this.isDrop) { this.$message({ message: "此处不能被放置", type: "error", }); return; } // console.log(789,) let droped = false; if ( this.$refs.tree.getCurrentNode() && this.$refs.tree.getCurrentNode().id == dropData.id ) { droped = true; } this.$refs.tree.setCurrentNode(dropData); let strData = ev.dataTransfer.getData("itemData"); let dragData = JSON.parse(strData); this.$emit("drop", dragData, node, dropData,droped); }, handleDragOver(node, dropNode, ev) { ev.preventDefault(); }, }, }; </script> <!-- Add "scoped" attribute to limit CSS to this component only --> <style lang="scss"> .search-tree-warp { border-top: none; box-sizing: border-box; position: relative; margin-top: 2vw; margin-right: 2vw; flex: 1; .search-tree-title { font-size: 14px; color: #fff; border-radius: 8px; text-align: center; margin-bottom: 20px; } /*搜索框*/ .tree-search-input { margin: 0vw 0.39rem; margin-bottom: 1vw; width: calc(100% - 0.39rem - 8px); box-sizing: border-box; > input { background-color: #104769; border: solid 0.05vw #2685b3; font-size: 0.14rem; color: #fff; &::-webkit-input-placeholder { color: #82c5e8; } } } .is-current { > .el-tree-node__content { background-image: linear-gradient( 90deg, rgba(38, 133, 179, 0), rgba(38, 133, 179, 1), rgba(38, 133, 179, 0) ) !important; } } .el-tree { width: 100%; // position: absolute; height: 100% !important; overflow: auto; background: transparent; .el-tree-node__expand-icon { margin-right: 5px; } &::-webkit-scrollbar-button { display: none; // background-image: url(); } &::-webkit-scrollbar-track { border-radius: 10px; background-color: #184660; } .el-tree-node { .el-icon-caret-right { padding: 0px; margin-left: 0.39rem; } .el-tree-node__content { background-color: transparent !important; padding: 20px; &:hover { background-image: linear-gradient( 90deg, rgba(38, 133, 179, 0), rgba(38, 133, 179, 1), rgba(38, 133, 179, 0) ); } } } .el-tree-node__expand-icon { color: #39baf8; margin-right: 0.1rem; } .el-tree-node__expand-icon.is-leaf { color: transparent !important; } div[role="group"] { //非根节点 .tree-round { display: none; } .tree-my-icon { margin-right: 0.1rem; display: inline-block; } .tree-btn-warp { display: inline-block; } } } .tree-heigth { height: calc(100% - 3vw - 60px) !important; } .train-class-tree { font-size: 0.14rem; color: #daf0fc; display: flex; align-items: center; cursor: pointer; padding: 0.12rem 0px; /* 席位类别树形结构按钮包裹盒子 */ .tree-btn-warp { margin-left: 0.1rem; span { color: #39baf8; } i { color: #d9374e; } span, i { padding: 0px 0.05rem; } } > .tree-round { margin-right: 0.1rem; } .tree-round { display: block; width: 0.1rem; height: 0.1rem; background: #42cfaf; border: 0.04rem solid #1c4f56; border-radius: 50%; } } } </style>

效果图

1.1-搜索子级携带父级

在这里插入图片描述

1.2

在这里插入图片描述

2.1-搜索菜单组件

在这里插入图片描述

2.2

在这里插入图片描述

最后

以上就是失眠白昼最近收集整理的关于vue本地搜索-递归查询列表-封装树结构列表的全部内容,更多相关vue本地搜索-递归查询列表-封装树结构列表内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(108)

评论列表共有 0 条评论

立即
投稿
返回
顶部