|
@@ -1,33 +1,92 @@
|
|
|
<script lang="ts" setup>
|
|
<script lang="ts" setup>
|
|
|
|
|
+import type { BasicTreeOptionResult } from '#/api/model';
|
|
|
|
|
+
|
|
|
import { onMounted, reactive } from 'vue';
|
|
import { onMounted, reactive } from 'vue';
|
|
|
|
|
|
|
|
-import { BcNav, BcPage, JsonViewer, VbenScrollbar } from '@vben/common-ui';
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ BcNav,
|
|
|
|
|
+ BcPage,
|
|
|
|
|
+ confirm,
|
|
|
|
|
+ JsonViewer,
|
|
|
|
|
+ VbenScrollbar,
|
|
|
|
|
+} from '@vben/common-ui';
|
|
|
|
|
+
|
|
|
|
|
+import { Button } from 'ant-design-vue';
|
|
|
|
|
|
|
|
import { CacheApi } from '#/api';
|
|
import { CacheApi } from '#/api';
|
|
|
|
|
+import { BcTree } from '#/components/bc-tree';
|
|
|
|
|
|
|
|
const props = reactive({
|
|
const props = reactive({
|
|
|
defaultLayout: [20, 80, 0],
|
|
defaultLayout: [20, 80, 0],
|
|
|
title: '缓存Key',
|
|
title: '缓存Key',
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
-const state = reactive<{ jsonValue: any; navList: any[] }>({
|
|
|
|
|
|
|
+const state = reactive<{
|
|
|
|
|
+ cacheKey: string;
|
|
|
|
|
+ isTree: boolean;
|
|
|
|
|
+ jsonValue: any;
|
|
|
|
|
+ navList: any[];
|
|
|
|
|
+ treeData: BasicTreeOptionResult[];
|
|
|
|
|
+}>({
|
|
|
navList: [],
|
|
navList: [],
|
|
|
jsonValue: {},
|
|
jsonValue: {},
|
|
|
|
|
+ cacheKey: '',
|
|
|
|
|
+ treeData: [],
|
|
|
|
|
+ isTree: true,
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
const fetch = async () => {
|
|
const fetch = async () => {
|
|
|
const data = await CacheApi.getList();
|
|
const data = await CacheApi.getList();
|
|
|
|
|
+ state.treeData = [];
|
|
|
|
|
+ data.forEach((element) => {
|
|
|
|
|
+ const keyNames = element.split(':');
|
|
|
|
|
+ const pName = keyNames[0] as string;
|
|
|
|
|
+ const filterItem = state.treeData.filter((x: any) => x.value === pName);
|
|
|
|
|
+ if (filterItem.length === 0) {
|
|
|
|
|
+ state.treeData.push({
|
|
|
|
|
+ value: keyNames.length > 1 ? pName : element,
|
|
|
|
|
+ label: pName,
|
|
|
|
|
+ children: [],
|
|
|
|
|
+ parentId: 0,
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ if (keyNames.length > 1) {
|
|
|
|
|
+ const pNode = (state.treeData.find((x: any) => x.value === pName) || {
|
|
|
|
|
+ children: [],
|
|
|
|
|
+ }) as BasicTreeOptionResult;
|
|
|
|
|
+ pNode.children.push({
|
|
|
|
|
+ value: element,
|
|
|
|
|
+ label: element.slice(pName.length + 1),
|
|
|
|
|
+ children: [],
|
|
|
|
|
+ parentId: 0,
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
state.navList = data.map((item) => {
|
|
state.navList = data.map((item) => {
|
|
|
return { title: item };
|
|
return { title: item };
|
|
|
});
|
|
});
|
|
|
- if (state.navList.length > 0) {
|
|
|
|
|
|
|
+ if (state.navList.length > 0 && !state.isTree) {
|
|
|
await handleChange(state.navList[0]);
|
|
await handleChange(state.navList[0]);
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const handleChange = async (item: Record<string, any>) => {
|
|
const handleChange = async (item: Record<string, any>) => {
|
|
|
|
|
+ state.cacheKey = item.title;
|
|
|
state.jsonValue = await CacheApi.getDetail(item.title);
|
|
state.jsonValue = await CacheApi.getDetail(item.title);
|
|
|
};
|
|
};
|
|
|
|
|
+const handleDelete = () => {
|
|
|
|
|
+ if (state.cacheKey) {
|
|
|
|
|
+ confirm(`确证要删除缓存[${state.cacheKey}]`).then(async () => {
|
|
|
|
|
+ await CacheApi.deleteDetail(state.cacheKey);
|
|
|
|
|
+ await fetch();
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+const handleTreeChange = async (keys: any[]) => {
|
|
|
|
|
+ await handleChange({ title: keys[0] });
|
|
|
|
|
+};
|
|
|
onMounted(async () => {
|
|
onMounted(async () => {
|
|
|
await fetch();
|
|
await fetch();
|
|
|
});
|
|
});
|
|
@@ -35,7 +94,7 @@ onMounted(async () => {
|
|
|
<template>
|
|
<template>
|
|
|
<BcPage auto-content-height v-bind="props">
|
|
<BcPage auto-content-height v-bind="props">
|
|
|
<template #left="{ isCollapsed, expand }">
|
|
<template #left="{ isCollapsed, expand }">
|
|
|
- <VbenScrollbar class="h-full">
|
|
|
|
|
|
|
+ <VbenScrollbar class="h-full" v-if="!state.isTree">
|
|
|
<BcNav
|
|
<BcNav
|
|
|
:is-collapsed="isCollapsed"
|
|
:is-collapsed="isCollapsed"
|
|
|
@collapse="expand"
|
|
@collapse="expand"
|
|
@@ -43,9 +102,36 @@ onMounted(async () => {
|
|
|
@change="handleChange"
|
|
@change="handleChange"
|
|
|
/>
|
|
/>
|
|
|
</VbenScrollbar>
|
|
</VbenScrollbar>
|
|
|
|
|
+ <BcTree
|
|
|
|
|
+ v-else
|
|
|
|
|
+ title="缓存列表"
|
|
|
|
|
+ :tree-data="state.treeData"
|
|
|
|
|
+ @change="handleTreeChange"
|
|
|
|
|
+ />
|
|
|
</template>
|
|
</template>
|
|
|
- <div class="m-4">
|
|
|
|
|
- <JsonViewer :value="state.jsonValue" />
|
|
|
|
|
|
|
+ <div class="h-full">
|
|
|
|
|
+ <div class="h-[45px] border-b">
|
|
|
|
|
+ <div class="ml-4 mr-4 flex h-full items-center justify-between">
|
|
|
|
|
+ <div>缓存数据【{{ state.cacheKey }}】</div>
|
|
|
|
|
+ <Button
|
|
|
|
|
+ type="primary"
|
|
|
|
|
+ size="small"
|
|
|
|
|
+ v-access:code="'cache:delete'"
|
|
|
|
|
+ @click="() => handleDelete()"
|
|
|
|
|
+ >
|
|
|
|
|
+ 删除
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div class="h-[calc(100%-45px)]">
|
|
|
|
|
+ <VbenScrollbar class="h-full">
|
|
|
|
|
+ <JsonViewer
|
|
|
|
|
+ :value="state.jsonValue"
|
|
|
|
|
+ preview-mode
|
|
|
|
|
+ :show-array-index="false"
|
|
|
|
|
+ />
|
|
|
|
|
+ </VbenScrollbar>
|
|
|
|
|
+ </div>
|
|
|
</div>
|
|
</div>
|
|
|
</BcPage>
|
|
</BcPage>
|
|
|
</template>
|
|
</template>
|