1
1
<script setup lang="ts">
2
2
import { useReqStore } from ' @/stores/req' ;
3
- import { onMounted , reactive , ref } from ' vue' ;
3
+ import { defineComponent , h , onMounted , reactive , ref } from ' vue' ;
4
4
import { RecycleScroller } from ' vue-virtual-scroller'
5
5
import " vue-virtual-scroller/dist/vue-virtual-scroller.css"
6
- import { ElTreeV2 } from ' element-plus'
6
+ import { ElTreeV2 , type TreeNode } from ' element-plus'
7
7
import " element-plus/dist/index.css"
8
8
const reqStore = useReqStore ()
9
9
// this is do search
@@ -24,11 +24,14 @@ const v = ref([])
24
24
25
25
// here we do some no search logic.
26
26
const noSearchKeys = async () => {
27
+ // fetch data pass through rust side.
27
28
const resp = await reqStore .reqWithHost <string >({
28
29
path: ' /cmd' ,
29
30
data: JSON .stringify ([' scan' , keys .cursor , ' MATCH' , ' *' , ' COUNT' , ' 5000' ])
30
31
})
32
+ // parse data
31
33
const v = resp .data .split (' \n ' )
34
+
32
35
let data = [] as Tree []
33
36
if (keys .cursor === ' 0' ) {
34
37
data = v .splice (1 ).map (e => ({ type: ' key' , label: e , icon: " key" , id: ID () }))
@@ -40,14 +43,14 @@ const noSearchKeys = async () => {
40
43
data .forEach ((e ) => {
41
44
parseLevel (arr , e .label )
42
45
})
43
- console .log (arr )
44
46
keys .keys = arr
45
47
}
46
48
noSearchKeys ()
47
49
48
50
// tree object
49
51
interface Tree {
50
52
label: string ,
53
+ value? : string ,
51
54
icon: string ,
52
55
type: ' key' | ' folder' ,
53
56
id: string ,
@@ -83,7 +86,7 @@ const parseLevel = (ori: Tree[], key: string, delimiter: string = ':') => {
83
86
} else {
84
87
// If key length is less than 2, it means it is a key.
85
88
if (arr .length <= 1 ) {
86
- ori .push (createTreeNode (key , ' key' ));
89
+ ori .push (createTreeNode (arr [ 0 ] , ' key' , key ));
87
90
return ;
88
91
}
89
92
// Otherwise create as a folder.
@@ -104,9 +107,9 @@ const parseLevel = (ori: Tree[], key: string, delimiter: string = ':') => {
104
107
}
105
108
};
106
109
107
- const createTreeNode = (label : string , type : ' key' | ' folder' ): Tree => {
110
+ const createTreeNode = (label : string , type : ' key' | ' folder' , value ? : string ): Tree => {
108
111
try {
109
- return { label , icon: type === ' key' ? " key" : " folder" , type , id: ID () };
112
+ return { label , icon: type === ' key' ? " key" : " folder" , type , id: ID (), value };
110
113
} catch (error ) {
111
114
console .error (' Error creating tree node:' , error );
112
115
throw error ;
@@ -123,18 +126,28 @@ onMounted(() => {
123
126
})
124
127
treeHeight .value = (elTreeV2Ref .value .$el .getBoundingClientRect ()).height
125
128
})
129
+ const print = (data : TreeNode ) => {
130
+ console .log (data )
131
+ }
126
132
</script >
127
133
<template >
128
- <div class =" flex flex-col h-full" >
134
+ <div class =" flex flex-col h-full _mc " >
129
135
<div class =" p-2 flex-1 flex justify-center items-center flex-row" >
130
136
<input type =" text" class =" flex-1 outline-none" v-model =" search.match" >
131
137
</div >
132
- <el-tree-v2 :height =" treeHeight" v-if =" nameSpaceEnable" class =" h-[calc(100vh-160px)]" ref = " elTreeV2Ref "
133
- :data =" keys.keys" :props =" {
138
+ <el-tree-v2 :item-size = " 30 " : height =" treeHeight" v-if =" nameSpaceEnable" class =" h-[calc(100vh-160px)]"
139
+ ref = " elTreeV2Ref " :data =" keys.keys" :props =" {
134
140
value: 'id',
135
141
label: 'label',
136
142
children: 'children',
137
- }" />
143
+ }" >
144
+ <template #default =" { node , data } " >
145
+ <div class =" w-full text-nowrap text-ellipsis cursor-default overflow-hidden" :title =" data.value" >
146
+ <span >
147
+ {{ data.label }}{{ print(node) }}</span >
148
+ </div >
149
+ </template >
150
+ </el-tree-v2 >
138
151
<RecycleScroller v-else class =" h-[calc(100vh-160px)] scroller mx-2" :items =" keys.keys" :item-size =" 32"
139
152
key-field =" label" v-slot =" { item }" >
140
153
<div class =" flex items-center mx-2 px-2 justify-start white-space-nowrap w-full cursor-pointer hover:bg-gray-100"
@@ -150,6 +163,72 @@ onMounted(() => {
150
163
</template >
151
164
152
165
<style lang="scss" scoped>
166
+ ._mc {
167
+ & ::v-deep (.el-tree-node ) {
168
+ padding-right : 10px ;
169
+ padding-left : 20px ;
170
+
171
+ * {
172
+ line-height : 1 ;
173
+ }
174
+
175
+ .el-tree-node__expand-icon {
176
+ background : url (' @/assets/folder-close.png' ) no-repeat center center ;
177
+ background-size : 14px 14px ;
178
+ position : relative ;
179
+
180
+ & ::after {
181
+ content : ' ' ;
182
+ position : absolute ;
183
+ top : -50% ;
184
+ left : -8px ;
185
+ height : 100% ;
186
+ width : 10px ;
187
+ border-left : 1px dashed #aaa ;
188
+ border-bottom : 1px dashed #aaa ;
189
+ }
190
+
191
+ svg {
192
+ display : none ;
193
+ }
194
+ }
195
+
196
+ .el-tree-node__expand-icon.expanded {
197
+ background : url (' @/assets/folder-open.png' ) no-repeat center center ;
198
+ background-size : 14px 14px ;
199
+ transform : rotate (0 );
200
+
201
+ & ::after {
202
+ top : -50% ;
203
+ height : 100% ;
204
+ width : 10px ;
205
+ border-left : 1px dashed #aaa ;
206
+ border-bottom : 1px dashed #aaa ;
207
+ }
208
+ }
209
+
210
+ .el-tree-node__expand-icon.is-leaf {
211
+ background : url (' @/assets/key.png' ) no-repeat center center ;
212
+ background-size : 14px 14px ;
213
+ visibility : visible ;
214
+
215
+ & ::after {
216
+ top : -50% ;
217
+ height : 100% ;
218
+ width : 10px ;
219
+ border-left : 1px dashed #aaa ;
220
+ border-bottom : 1px dashed #aaa ;
221
+ }
222
+ }
223
+
224
+ // width: calc(100% - 20px) !important;
225
+ .el-tree-node__content {
226
+ border-radius : 4px ;
227
+ font-size : 16px ;
228
+ }
229
+ }
230
+ }
231
+
153
232
.scroller {
154
233
& ::-webkit-scrollbar {
155
234
width : 8px ;
0 commit comments