Skip to content

Commit 43ddaaf

Browse files
author
fuyoo
committed
add list view
1 parent 8a7d104 commit 43ddaaf

File tree

7 files changed

+127
-48
lines changed

7 files changed

+127
-48
lines changed

components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ declare module 'vue' {
1111
CoHostTab: typeof import('./src/components/CoHostTab.vue')['default']
1212
HelloWorld: typeof import('./src/components/HelloWorld.vue')['default']
1313
NButton: typeof import('naive-ui')['NButton']
14+
NDataTable: typeof import('naive-ui')['NDataTable']
1415
NDropdown: typeof import('naive-ui')['NDropdown']
1516
NInput: typeof import('naive-ui')['NInput']
1617
NMessageProvider: typeof import('naive-ui')['NMessageProvider']

src/css/quasar.variables.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// to match your app's branding.
1313
// Tip: Use the "Theme Builder" on Quasar's documentation website.
1414

15-
$primary: #1976d2;
15+
$primary: #18a058;
1616
$secondary: #26a69a;
1717
$accent: #9c27b0;
1818

src/hooks/life.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,9 @@ export const useResize = (sub?: number) => {
77
const onResize = () => {
88
clearTimeout(resizeTimer)
99
resizeTimer = setTimeout(() => {
10-
debugger
1110
const dom = document.querySelector('#app')
1211
height.value = (dom?.getBoundingClientRect()?.height || 0) - (sub || 0)
1312
width.value = dom?.getBoundingClientRect()?.width || 0
14-
console.log('height', height.value)
15-
console.log('width', width.value)
1613
}, 50)
1714
}
1815
// dynamic set tree height

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ onBeforeUnmount(() => {
6969
<template>
7070
<div class="b-b b-b-dashed b-b-#eee p-4 gap-2 flex">
7171
<b>{{ trans(route.params.key as string) }}</b>
72-
<q-badge><i class="i-iconamoon:type-bold mr-1"></i> {{ type.toUpperCase() }}</q-badge>
72+
<q-badge><i class="i-iconamoon:type-bold mr-1"></i> {{ type?.toUpperCase() }}</q-badge>
7373
<q-badge><i class="i-material-symbols:memory-alt mr-1"></i> {{ baseInfo.memory }}bytes</q-badge>
7474
<q-badge>
7575
<i class="i-material-symbols:nest-clock-farsight-analog-outline"></i>TTL

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

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ const menuOptions = ref<DropdownOption[]>([
111111
{
112112
label: '删除',
113113
key: 'delete',
114-
icon: () => h(NIcon, { default: () => h(Trash) }),
114+
icon: () => h(NIcon, null, { default: () => h(Trash) }),
115115
},
116116
])
117117
const x = ref(0)
@@ -143,40 +143,42 @@ const nodeProps = ({ option }: { option: Tree }) => {
143143
},
144144
}
145145
}
146-
const handleSelect = async (data: Record<string, any>) => {
146+
const handleSelect = async (act: string) => {
147147
showDropdownRef.value = false
148-
console.log(data)
149-
return
150-
if (data.type === 'key') {
151-
const { code } = await reqStore.reqWithHost<string>({
152-
path: '/cmd',
153-
data: ['del', data.value],
154-
})
155-
if (code === 0) {
156-
await queryOriginalData()
148+
const data = focusNodeData
149+
if (act === "delete") {
150+
151+
if (data?.type === 'key') {
152+
const { code } = await reqStore.reqWithHost<string>({
153+
path: '/cmd',
154+
data: ['del', data.value],
155+
})
156+
if (code === 0) {
157+
await queryOriginalData()
158+
}
159+
return
157160
}
158-
return
159-
}
160-
// delete all of children
161-
const keys = [] as string[]
162-
const findKeys = (data: Record<string, any>[]) => {
163-
for (const item of data || []) {
164-
if (item.type === 'key') {
165-
keys.push(item.value)
166-
} else {
167-
findKeys(item.children)
161+
// delete all of children
162+
const keys = [] as string[]
163+
const findKeys = (data: Record<string, any>[]) => {
164+
for (const item of data || []) {
165+
if (item.type === 'key') {
166+
keys.push(item.value)
167+
} else {
168+
findKeys(item.children)
169+
}
168170
}
169171
}
172+
findKeys(data?.children || [])
173+
// todo: need implement batch delete at 'rust' end. this implementation so ugly.
174+
for (const key of keys) {
175+
await reqStore.reqWithHost<string>({
176+
path: '/cmd',
177+
data: ['del', key],
178+
})
179+
}
180+
await queryOriginalData()
170181
}
171-
findKeys(data.children)
172-
// todo: need implement batch delete at 'rust' end. this implementation so ugly.
173-
for (const key of keys) {
174-
await reqStore.reqWithHost<string>({
175-
path: '/cmd',
176-
data: ['del', key],
177-
})
178-
}
179-
await queryOriginalData()
180182
}
181183
</script>
182184
<template>
@@ -209,6 +211,7 @@ const handleSelect = async (data: Record<string, any>) => {
209211
:style="{ height: height + 'px' }"
210212
key-field="id"
211213
children-field="children"
214+
class="whitespace-nowrap"
212215
/>
213216
<div class="flex flex-1 w-full justify-center items-center" v-show="original.cursor != '0'">
214217
<n-button size="small" type="primary" :loading="reqStore.reqLoading" @click="loadMoreFn"
@@ -224,6 +227,7 @@ const handleSelect = async (data: Record<string, any>) => {
224227
:x="x"
225228
:y="y"
226229
@select="handleSelect"
230+
@clickoutside="()=>showDropdownRef = false"
227231
/>
228232
</template>
229233

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,84 @@
1-
<script setup lang="ts">
1+
<script setup lang="tsx">
2+
import { ref, shallowRef } from 'vue'
3+
import { useRoute } from 'vue-router'
4+
import { useReqStore } from '@/stores/req.ts'
5+
import CoInfoHeader from '@/pages/host/components/CoInfoHeader/index.vue'
6+
import { ID } from '@/tools/keys.ts'
27
8+
const size = ref(0)
9+
const route = useRoute()
10+
const key = atob(route.params.key as string)
11+
console.log(key)
12+
const reqStore = useReqStore()
13+
const total = ref(0)
14+
const paginationReactive = reactive({
15+
page: 1,
16+
pageSize: 5,
17+
pageCount: 0,
18+
showSizePicker: true,
19+
pageSizes: [3, 5, 7],
20+
onChange: (page: number) => {
21+
paginationReactive.page = page
22+
},
23+
onUpdatePageSize: (pageSize: number) => {
24+
paginationReactive.pageSize = pageSize
25+
paginationReactive.page = 1
26+
}
27+
})
28+
const fetchLen = async () => {
29+
const resp = await reqStore.reqWithHost<string>({
30+
path: '/cmd',
31+
data: ['llen', key],
32+
})
33+
paginationReactive.pageCount = Number(resp.data)
34+
}
35+
fetchLen()
36+
37+
38+
const columns = [
39+
{
40+
title: 'index',
41+
key: 'no',
42+
render: (row: Record) => {
43+
return <div> { (paginationReactive.page - 1) * paginationReactive.pageSize + row.no +1 } </div>
44+
},
45+
},
46+
{ title: 'data', key: 'value' },
47+
]
48+
const records = shallowRef<Record[]>([])
49+
const fetchRecords = async () => {
50+
await fetchLen()
51+
const resp = await reqStore.reqWithHost({
52+
path: '/cmd',
53+
data: ['lrange', key, `${(paginationReactive.page - 1) * paginationReactive.pageSize}`, `${paginationReactive.page * paginationReactive.pageSize}`],
54+
})
55+
console.log( ['lrange', key, `${(paginationReactive.page - 1) * paginationReactive.pageSize}`, `${paginationReactive.page * paginationReactive.pageSize}`],
56+
)
57+
console.log(resp)
58+
records.value = resp.data.split('\n').map((item: string, i: number) => {
59+
return {
60+
title: item,
61+
value: item,
62+
no: i,
63+
key: ID(),
64+
}
65+
})
66+
}
67+
fetchRecords()
368
</script>
469

570
<template>
6-
<div></div>
71+
<div class="w-full h-full">
72+
<co-info-header v-model:size="size" type="string" />
73+
<n-data-table
74+
remote
75+
ref="table"
76+
:columns="columns"
77+
:data="records"
78+
:loading="reqStore.reqLoading"
79+
:pagination="paginationReactive"
80+
/>
81+
</div>
782
</template>
883

9-
<style scoped lang="scss">
10-
11-
</style>
84+
<style scoped lang="scss"></style>

src/pages/host/layout.vue

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
11
<script setup lang="ts">
2-
import { computed } from 'vue'
2+
import { computed, ref, shallowRef } from 'vue'
33
import { useRoute, useRouter } from 'vue-router'
44
import { useReqStore } from '@/stores/req.ts'
55
import { useI18n } from 'vue-i18n'
6+
67
const router = useRouter()
78
const route = useRoute()
89
const reqStore = useReqStore()
910
const { t } = useI18n()
1011
const changeTab = async (tab: string) => {
1112
await router.push({
1213
path: `/tab/${route.params.id}/main/${tab}`,
13-
query: route.query,
14+
query: route.query
1415
})
1516
console.log(route.path)
1617
}
1718
const tab = computed(() => {
1819
if (route.path.includes('database')) {
1920
return 'database'
20-
} else {
21+
}
22+
else {
2123
return 'info'
2224
}
2325
})
24-
const dbs = shallowRef([])
26+
const dbs = shallowRef<Record<string, any>[]>([])
2527
const fetchDbs = async () => {
2628
const resp = await reqStore.reqWithHost<string>({
2729
path: '/cmd',
28-
data: ['config', 'get', 'databases'],
30+
data: ['config', 'get', 'databases']
2931
})
3032
3133
dbs.value = new Array(Number(resp.data.split('\n')[1])).fill(0).map((_, i) => ({
3234
label: `${t('normal.0')}.${i}`,
33-
value: i,
35+
value: i
3436
}))
3537
}
3638
const selectedDb = ref(Number((route.query.db as string) || 0))
@@ -43,8 +45,8 @@ const reload = async (v: number) => {
4345
path: `/tab/${route.params.id}/main/database`,
4446
query: {
4547
...route.query,
46-
db: v,
47-
},
48+
db: v
49+
}
4850
})
4951
location.reload()
5052
}
@@ -117,6 +119,7 @@ const reload = async (v: number) => {
117119
118120
.active {
119121
position: relative;
122+
120123
&::after {
121124
content: '';
122125
position: absolute;
@@ -128,6 +131,7 @@ const reload = async (v: number) => {
128131
background: var(--q-primary);
129132
color: var(--q-primary);
130133
}
134+
131135
.c {
132136
color: var(--q-primary);
133137
}

0 commit comments

Comments
 (0)