Skip to content

Commit 43eb2fb

Browse files
author
fuyoo
committed
fix ui
1 parent 8ccb0bf commit 43eb2fb

File tree

6 files changed

+88
-61
lines changed

6 files changed

+88
-61
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<script setup lang="ts">
2+
import { ElCard } from 'element-plus'
3+
import { useReqStore } from '@/stores/req.ts'
4+
import { storeToRefs } from 'pinia'
5+
6+
const prop = defineProps<{ value?: string }>()
7+
const reqStore = useReqStore()
8+
const fetchInfo = async () => {
9+
console.log(prop.value)
10+
const resp = await reqStore.reqWithHost({
11+
path: '/cmd',
12+
data: ['type',prop.value]
13+
})
14+
console.log(resp)
15+
const r2 = await reqStore.reqWithHost({
16+
path: '/cmd',
17+
data: ['memory','usage',prop.value]
18+
})
19+
console.log(r2)
20+
}
21+
fetchInfo()
22+
</script>
23+
24+
<template>
25+
<div class="mx-2">
26+
<el-card shadow="never"> </el-card>
27+
<b>{{ value }}</b>
28+
</div>
29+
</template>
30+
31+
<style scoped lang="scss"></style>

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

Lines changed: 0 additions & 17 deletions
This file was deleted.

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

Lines changed: 29 additions & 27 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 { onMounted, reactive, ref } from 'vue'
3+
import { onMounted, reactive, ref, shallowRef } from 'vue'
44
import 'vue-virtual-scroller/dist/vue-virtual-scroller.css'
55
import { ElTreeV2, type TreeNode,ElButton } from 'element-plus'
66
import 'element-plus/dist/index.css'
@@ -119,14 +119,15 @@ const createTreeNode = (label: string, type: 'key' | 'folder', value?: string):
119119
}
120120
// todo: configurable name space enable.
121121
const nameSpaceEnable = ref(true)
122-
const elTreeV2Ref = ref()
123-
const treeHeight = ref(0)
122+
const treeBoxRef = shallowRef()
123+
const elTreeV2Ref = shallowRef()
124+
const treeHeight = shallowRef(560)
124125
// dynamic set tree height
125126
onMounted(() => {
126127
window.addEventListener('resize', () => {
127-
treeHeight.value = elTreeV2Ref.value.$el.getBoundingClientRect().height
128+
treeHeight.value = treeBoxRef.value.getBoundingClientRect().height - 30
128129
})
129-
treeHeight.value = elTreeV2Ref.value.$el.getBoundingClientRect().height
130+
treeHeight.value = treeBoxRef.value.getBoundingClientRect().height - 30
130131
})
131132
132133
const onNodeClick = (data: Record<string, any>,node: TreeNode,e: MouseEvent) => {
@@ -143,34 +144,35 @@ const loadMoreFn = () => {
143144
}
144145
</script>
145146
<template>
146-
<div class="flex flex-col h-full _mc">
147-
<div class="p-2 flex-1 flex justify-center items-center flex-row">
147+
<div class="_mc flex flex-col flex-1 justify-start items-start">
148+
<div class="p-2 flex justify-center items-start flex-row">
148149
<input type="text" class="flex-1 outline-none" v-model="search.match" />
149150
</div>
150-
<el-tree-v2
151-
@node-click="onNodeClick"
152-
:item-size="30"
153-
:height="treeHeight"
154-
v-if="nameSpaceEnable"
155-
class="h-[calc(100vh-160px)]"
156-
ref="elTreeV2Ref"
157-
:data="noSearchKeyData"
158-
:props="{
151+
<div class="flex-1 w-full" ref="treeBoxRef">
152+
<el-tree-v2
153+
@node-click="onNodeClick"
154+
:item-size="30"
155+
:height="treeHeight"
156+
v-if="nameSpaceEnable"
157+
ref="elTreeV2Ref"
158+
:data="noSearchKeyData"
159+
:props="{
159160
value: 'id',
160161
label: 'label',
161162
children: 'children',
162163
}"
163-
>
164-
<template #default="{ data }">
165-
<div
166-
class="w-full text-nowrap text-ellipsis cursor-default overflow-hidden"
167-
:title="data.value"
168-
>
169-
<span> {{ data.label }}</span>
170-
</div>
171-
</template>
172-
</el-tree-v2>
173-
<div class="flex justify-center items-center flex-1">
164+
>
165+
<template #default="{ data }">
166+
<div
167+
class="w-full text-nowrap text-ellipsis cursor-default overflow-hidden"
168+
:title="data.value"
169+
>
170+
<span> {{ data.label }}</span>
171+
</div>
172+
</template>
173+
</el-tree-v2>
174+
</div>
175+
<div class="flex justify-center items-center">
174176
<el-button size="small" class="w-full h-full" v-show="noSearchCursor !== '0'" text :loading="reqStore.reqLoading" @click="loadMoreFn">加载更多</el-button>
175177
</div>
176178
</div>

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<script lang="ts" setup>
2-
import { onBeforeUnmount, ref } from 'vue'
2+
import { computed, onBeforeUnmount, ref } from 'vue'
33
import CoKeys from './CoKeys.vue'
44
import CoDbs from './CoDbs.vue'
5-
import CoInformation from './CoInformation.vue'
6-
const key = ref('')
5+
import CoInformation from './CoInfomation/index.vue'
6+
import { ElEmpty } from 'element-plus'
7+
import { useI18n } from 'vue-i18n'
8+
const { t } = useI18n()
9+
const key = ref('type:hash')
710
const canMove = ref(false)
811
let startX = 0
912
const width = ref(200)
@@ -39,33 +42,37 @@ onBeforeUnmount(() => {
3942
window.removeEventListener('mouseup', mouseupFn)
4043
window.removeEventListener('mouseleave', mouseleaveFn)
4144
})
45+
const keyInfo = computed(() => {
46+
if (key.value) {
47+
return CoInformation
48+
}
49+
return ElEmpty
50+
})
4251
</script>
4352
<template>
44-
<div class="flex h-full" :class="{ moving: canMove }">
45-
<div class="_ml l b-r b-r-dashed b-r-#eee relative" :style="{ width: `${width}px` }">
53+
<div class="flex" :class="{ moving: canMove }">
54+
<div class="l flex flex-col items-start h-full b-r b-r-dashed b-r-#eee relative" :style="{ width: `${width}px` }">
4655
<div class="w-full h-10 flex items-center justify-center">
4756
<CoDbs></CoDbs>
4857
</div>
4958
<CoKeys v-model="key"></CoKeys>
5059
<div
5160
@mousedown="mousedownFn"
52-
class="opacity-0 flex justify-center items-center move w-5 h-5 bg-#ddd shadow-lg absolute top-50% mt--2 right--2 rounded"
61+
class="opacity-0 flex justify-center items-center
62+
move w-5 h-5 bg-#ddd shadow-lg absolute top-50% mt--2 right--2 rounded"
5363
>
5464
<span class="i-uil:arrows-resize-h"></span>
5565
</div>
5666
</div>
57-
<div class="r flex-1">
58-
<q-scroll-area class="h-[calc(100vh-90px)]">
59-
<co-information :value="key"></co-information>
67+
<div class="r flex-1 h-full">
68+
<q-scroll-area class="h-full">
69+
<component :is="keyInfo" :description="t('normal.1')" :value="key"></component>
6070
</q-scroll-area>
6171
</div>
6272
</div>
6373
</template>
6474
<style scoped lang="scss">
65-
._ml *{
66-
-webkit-user-select: none;
67-
user-select: none;
68-
}
75+
6976
.moving {
7077
cursor: col-resize;
7178
&:hover .move {

src/pages/host/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const changeTab = (tab: string) => {
3333
</q-tab-panel>
3434
<q-tab-panel name="data" class="q-pa-none">
3535
<q-scroll-area class="h-[calc(100vh-50px)]">
36-
<co-database></co-database>
36+
<co-database class="absolute top-0 left-0 bottom-0 right-0"></co-database>
3737
</q-scroll-area>
3838
</q-tab-panel>
3939
</q-tab-panels>

src/stores/req.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,15 @@ export const useReqStore = defineStore('req', () => {
4545
const reqLoading = ref(false)
4646
// at here, we should get host from route params.
4747
const route = useRoute()
48+
// define a timer to throttle the loading status
49+
let timer:any;
4850
const reqWithHost = async <R>(option: {
4951
path: string
5052
data?: any
5153
db?: string
5254
notify?: boolean
5355
}): Promise<BackendResponse<R>> => {
56+
clearTimeout(timer)
5457
reqLoading.value = true
5558
const host = await db.hosts.get({ id: parseInt(route.params.id as string) })
5659
if (route.query.db && host) {
@@ -66,11 +69,12 @@ export const useReqStore = defineStore('req', () => {
6669
data: _T(option.data) != 'String' ? JSON.stringify(option.data) : option.data,
6770
notify: option.notify,
6871
})
69-
reqLoading.value = false
70-
console.log(reqLoading.value)
72+
// throttle timer
73+
timer = setTimeout(()=>reqLoading.value=false,100)
7174
return resp
7275
} catch (e) {
73-
reqLoading.value = false
76+
// throttle timer
77+
timer = setTimeout(()=>reqLoading.value=false,100)
7478
throw e
7579
}
7680
}

0 commit comments

Comments
 (0)