Skip to content

Commit db64018

Browse files
author
fuyoo
committed
feat: add database choose function.
1 parent 9a235ed commit db64018

File tree

7 files changed

+88
-20
lines changed

7 files changed

+88
-20
lines changed

src/i18n/en-US/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ export default {
2828
tabName: ['Status', 'Data'],
2929
},
3030
hostInfo: ['Memory', 'Server', 'Stats', 'Details', 'Key Anylaysis'],
31+
normal: ['Database'],
3132
}

src/i18n/zh-CN/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ export default {
2626
tabName: ['状态', '数据'],
2727
},
2828
hostInfo: ['内存', '服务端', '状态', '详情', 'Key情况'],
29+
normal: ['数据库'],
2930
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<script setup lang="ts">
2+
import { useReqStore } from "@/stores/req";
3+
import { ElDropdown, ElDropdownMenu, ElDropdownItem, ElButton } from "element-plus"
4+
import { ref } from "vue";
5+
import { useRoute, useRouter } from "vue-router";
6+
const reqStore = useReqStore()
7+
const router = useRouter()
8+
const route = useRoute()
9+
const dbs = ref("16")
10+
const db = ref(route.query.db as string || "0")
11+
const fetchDbs = async () => {
12+
const resp = await reqStore.reqWithHost<string>({
13+
path: '/cmd',
14+
data: ['config', 'get', 'databases']
15+
})
16+
dbs.value = resp.data.split("\n")[1];
17+
}
18+
fetchDbs()
19+
const reload = async (v: number) => {
20+
console.log(v)
21+
await router.replace({
22+
query: {
23+
...route.query,
24+
db: v,
25+
}
26+
})
27+
location.reload()
28+
}
29+
console.log(route.query)
30+
</script>
31+
<template>
32+
<el-dropdown @command="reload">
33+
<span>
34+
<i class="i-material-symbols:database"></i> {{ $t('normal.0') + ' ' + db }}
35+
</span>
36+
<template #dropdown>
37+
<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>
40+
</el-dropdown-menu>
41+
</template>
42+
</el-dropdown>
43+
</template>
44+
<style scoped lang="scss"></style>

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
import { useReqStore } from '@/stores/req';
3-
import { reactive, ref } from 'vue';
3+
import { onMounted, reactive, ref } from 'vue';
44
import { RecycleScroller } from 'vue-virtual-scroller'
55
import "vue-virtual-scroller/dist/vue-virtual-scroller.css"
66
import { ElTreeV2 } from 'element-plus'
@@ -26,7 +26,6 @@ const v = ref([])
2626
const noSearchKeys = async () => {
2727
const resp = await reqStore.reqWithHost<string>({
2828
path: '/cmd',
29-
db: '0',
3029
data: JSON.stringify(['scan', keys.cursor, 'MATCH', '*', 'COUNT', '5000'])
3130
})
3231
const v = resp.data.split('\n')
@@ -115,22 +114,28 @@ const createTreeNode = (label: string, type: 'key' | 'folder'): Tree => {
115114
};
116115
// todo: configurable name space enable.
117116
const nameSpaceEnable = ref(true)
118-
117+
const elTreeV2Ref = ref()
118+
const treeHeight = ref(0)
119+
// dynamic set tree height
120+
onMounted(() => {
121+
window.addEventListener('resize', () => {
122+
treeHeight.value = (elTreeV2Ref.value.$el.getBoundingClientRect()).height
123+
})
124+
treeHeight.value = (elTreeV2Ref.value.$el.getBoundingClientRect()).height
125+
})
119126
</script>
120127
<template>
121128
<div class="flex flex-col h-full">
122129
<div class="p-2 flex-1 flex justify-center items-center flex-row">
123130
<input type="text" class="flex-1 outline-none" v-model="search.match">
124131
</div>
125-
<q-scroll-area v-if="nameSpaceEnable" class="h-[calc(100vh-120px)]">
126-
<!-- <q-tree dense :nodes="keys.keys" node-key="id" no-transition /> -->
127-
<el-tree-v2 style="height: calc(100vh - 120px)" :data="keys.keys" :props="{
132+
<el-tree-v2 :height="treeHeight" v-if="nameSpaceEnable" class="h-[calc(100vh-160px)]" ref="elTreeV2Ref"
133+
:data="keys.keys" :props="{
128134
value: 'id',
129135
label: 'label',
130136
children: 'children',
131137
}" />
132-
</q-scroll-area>
133-
<RecycleScroller v-else class="h-[calc(100vh-120px)] scroller mx-2" :items="keys.keys" :item-size="32"
138+
<RecycleScroller v-else class="h-[calc(100vh-160px)] scroller mx-2" :items="keys.keys" :item-size="32"
134139
key-field="label" v-slot="{ item }">
135140
<div class="flex items-center mx-2 px-2 justify-start white-space-nowrap w-full cursor-pointer hover:bg-gray-100"
136141
style="flex-wrap: nowrap; word-break: keep-all; overflow: hidden; text-overflow: ellipsis;">

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
<script lang="ts" setup>
22
import { ref } from 'vue';
3-
4-
const spliter = ref(200)
3+
import { useRoute } from 'vue-router';
54
import CoKeys from './CoKeys.vue';
5+
import CoDbs from './CoDbs.vue';
6+
const route = useRoute();
7+
const spliter = ref(200)
8+
console.log(route.fullPath)
69
</script>
710
<template>
811
<q-splitter v-model="spliter" unit="px" :limits="[200, 480]">
912
<template v-slot:before>
13+
<div class="w-full h-10 flex items-center justify-center">
14+
<CoDbs></CoDbs>
15+
</div>
1016
<CoKeys></CoKeys>
1117
</template>
1218

1319
<template v-slot:after>
14-
<q-scroll-area class="h-[calc(100vh-50px)]">
20+
<q-scroll-area class="h-[calc(100vh-90px)]">
1521
</q-scroll-area>
1622
</template>
1723
</q-splitter>

src/pages/host/index.vue

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
<script setup lang="ts">
22
import CoHostInfo from './components/CoHostInfo.vue'
33
import { ref } from 'vue'
4-
import { useReqStore } from '@/stores/req'
54
import CoDatabase from './components/CoDatabase/index.vue'
6-
const navTab = ref('status')
7-
const dbsize = ref(16)
8-
const tabs = ref(new Set<number>())
5+
import { useRoute, useRouter } from 'vue-router'
6+
const router = useRouter()
7+
const route = useRoute()
8+
const navTab = ref(route.query.tab as string || 'status')
9+
const changeTab = (tab: string) => {
10+
navTab.value = tab
11+
router.replace({
12+
query: {
13+
tab: navTab.value
14+
}
15+
})
16+
}
917
</script>
1018
<template>
1119
<div>
1220
<q-toolbar class="text-primary b-b b-b-solid b-b-#eee">
13-
<q-btn flat round dense @click="navTab = 'status'" class="mr-2">
21+
<q-btn flat round dense @click="changeTab('status')" class="mr-2">
1422
<i class="i-hugeicons:cpu-settings text-5"></i>
1523
</q-btn>
16-
<q-btn flat round dense @click="navTab = 'data'" class="mr-2">
24+
<q-btn flat round dense @click="changeTab('data')" class="mr-2">
1725
<i class="i-material-symbols:database text-5"></i>
1826
</q-btn>
1927
</q-toolbar>

src/stores/req.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { defineStore } from 'pinia'
22

33
import { db, type ConnectionHost } from '@/db'
44
import { invoke } from '@tauri-apps/api/core'
5-
import { Notify } from 'quasar'
5+
import { Notify, is } from 'quasar'
66
import { useRoute } from 'vue-router'
77
export interface CommonRequestParams {
88
connectionInfo: ConnectionHost
@@ -39,7 +39,7 @@ const request = async <T>({
3939
}
4040
return body
4141
}
42-
42+
const _T = (v: any) => Object.prototype.toString.call(v).slice(8, -1)
4343
export const useReqStore = defineStore('req', () => {
4444
// at here, we should get host from route params.
4545
const route = useRoute()
@@ -50,13 +50,16 @@ export const useReqStore = defineStore('req', () => {
5050
notify?: boolean
5151
}): Promise<BackendResponse<R>> => {
5252
const host = await db.hosts.get({ id: parseInt(route.params.id as string) })
53+
if (route.query.db && host) {
54+
host.node[0].db = route.query.db as string
55+
}
5356
if (option.db && host) {
5457
host.node[0].db = option.db
5558
}
5659
return request({
5760
connectionInfo: host!,
5861
path: option.path,
59-
data: option.data,
62+
data: _T(option.data) != 'String' ? JSON.stringify(option.data) : option.data,
6063
notify: option.notify,
6164
})
6265
}

0 commit comments

Comments
 (0)