Skip to content

Commit c278750

Browse files
author
fuyoo
committed
key-tree modify
1 parent db64018 commit c278750

File tree

6 files changed

+117
-19
lines changed

6 files changed

+117
-19
lines changed

src/assets/folder-close.png

8.07 KB
Loading

src/assets/folder-open.png

9.62 KB
Loading

src/assets/key.png

10.4 KB
Loading

src/pages/host/components/CoDatabase/CoDbs.vue

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,19 @@ const reload = async (v: number) => {
2929
console.log(route.query)
3030
</script>
3131
<template>
32-
<el-dropdown @command="reload">
33-
<span>
34-
<i class="i-material-symbols:database"></i> {{ $t('normal.0') + ' ' + db }}
35-
</span>
32+
<el-dropdown @command="reload" trigger="click" class="w-full">
33+
<q-btn outline unelevated dense no-caps push long color="primary" class="w-full mx-2">
34+
<div style="width: 100%;">
35+
<i class="i-material-symbols:database"></i>
36+
{{ $t('normal.0') + '.' + db }}
37+
</div>
38+
</q-btn>
3639
<template #dropdown>
3740
<el-dropdown-menu>
38-
<el-dropdown-item :key="item" v-for="item in Number(dbs)" :command="item - 1">{{ $t('normal.0') + (item - 1)
39-
}}</el-dropdown-item>
41+
<el-dropdown-item :key="item" v-for="item in Number(dbs)" :command="item - 1">
42+
<div class="w-40 text-center">
43+
{{ $t('normal.0') + '.' + (item - 1) }}</div>
44+
</el-dropdown-item>
4045
</el-dropdown-menu>
4146
</template>
4247
</el-dropdown>

src/pages/host/components/CoDatabase/CoKeys.vue

Lines changed: 89 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<script setup lang="ts">
22
import { useReqStore } from '@/stores/req';
3-
import { onMounted, reactive, ref } from 'vue';
3+
import { defineComponent, h, onMounted, reactive, ref } from 'vue';
44
import { RecycleScroller } from 'vue-virtual-scroller'
55
import "vue-virtual-scroller/dist/vue-virtual-scroller.css"
6-
import { ElTreeV2 } from 'element-plus'
6+
import { ElTreeV2, type TreeNode } from 'element-plus'
77
import "element-plus/dist/index.css"
88
const reqStore = useReqStore()
99
// this is do search
@@ -24,11 +24,14 @@ const v = ref([])
2424
2525
// here we do some no search logic.
2626
const noSearchKeys = async () => {
27+
// fetch data pass through rust side.
2728
const resp = await reqStore.reqWithHost<string>({
2829
path: '/cmd',
2930
data: JSON.stringify(['scan', keys.cursor, 'MATCH', '*', 'COUNT', '5000'])
3031
})
32+
// parse data
3133
const v = resp.data.split('\n')
34+
3235
let data = [] as Tree[]
3336
if (keys.cursor === '0') {
3437
data = v.splice(1).map(e => ({ type: 'key', label: e, icon: "key", id: ID() }))
@@ -40,14 +43,14 @@ const noSearchKeys = async () => {
4043
data.forEach((e) => {
4144
parseLevel(arr, e.label)
4245
})
43-
console.log(arr)
4446
keys.keys = arr
4547
}
4648
noSearchKeys()
4749
4850
// tree object
4951
interface Tree {
5052
label: string,
53+
value?: string,
5154
icon: string,
5255
type: 'key' | 'folder',
5356
id: string,
@@ -83,7 +86,7 @@ const parseLevel = (ori: Tree[], key: string, delimiter: string = ':') => {
8386
} else {
8487
// If key length is less than 2, it means it is a key.
8588
if (arr.length <= 1) {
86-
ori.push(createTreeNode(key, 'key'));
89+
ori.push(createTreeNode(arr[0], 'key', key));
8790
return;
8891
}
8992
// Otherwise create as a folder.
@@ -104,9 +107,9 @@ const parseLevel = (ori: Tree[], key: string, delimiter: string = ':') => {
104107
}
105108
};
106109
107-
const createTreeNode = (label: string, type: 'key' | 'folder'): Tree => {
110+
const createTreeNode = (label: string, type: 'key' | 'folder', value?: string): Tree => {
108111
try {
109-
return { label, icon: type === 'key' ? "key" : "folder", type, id: ID() };
112+
return { label, icon: type === 'key' ? "key" : "folder", type, id: ID(), value };
110113
} catch (error) {
111114
console.error('Error creating tree node:', error);
112115
throw error;
@@ -123,18 +126,28 @@ onMounted(() => {
123126
})
124127
treeHeight.value = (elTreeV2Ref.value.$el.getBoundingClientRect()).height
125128
})
129+
const print = (data: TreeNode) => {
130+
console.log(data)
131+
}
126132
</script>
127133
<template>
128-
<div class="flex flex-col h-full">
134+
<div class="flex flex-col h-full _mc">
129135
<div class="p-2 flex-1 flex justify-center items-center flex-row">
130136
<input type="text" class="flex-1 outline-none" v-model="search.match">
131137
</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="{
134140
value: 'id',
135141
label: 'label',
136142
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>
138151
<RecycleScroller v-else class="h-[calc(100vh-160px)] scroller mx-2" :items="keys.keys" :item-size="32"
139152
key-field="label" v-slot="{ item }">
140153
<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(() => {
150163
</template>
151164

152165
<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+
153232
.scroller {
154233
&::-webkit-scrollbar {
155234
width: 8px;

src/pages/host/components/CoDatabase/index.vue

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ console.log(route.fullPath)
1010
<template>
1111
<q-splitter v-model="spliter" unit="px" :limits="[200, 480]">
1212
<template v-slot:before>
13-
<div class="w-full h-10 flex items-center justify-center">
14-
<CoDbs></CoDbs>
13+
<div class="_ml">
14+
<div class="w-full h-10 flex items-center justify-center">
15+
<CoDbs></CoDbs>
16+
</div>
17+
<CoKeys></CoKeys>
1518
</div>
16-
<CoKeys></CoKeys>
1719
</template>
1820

1921
<template v-slot:after>
@@ -22,3 +24,15 @@ console.log(route.fullPath)
2224
</template>
2325
</q-splitter>
2426
</template>
27+
<style scoped lang="scss">
28+
._ml {
29+
user-select: none;
30+
-webkit-user-select: none;
31+
32+
* {
33+
user-select: none;
34+
-webkit-user-select: none;
35+
36+
}
37+
}
38+
</style>

0 commit comments

Comments
 (0)