Skip to content

Commit 1df4114

Browse files
authored
feat: add redis memory and command statistics components (#16)
* feat: add Redis memory and command statistics components * fix: label display * refactor: improve chart rendering logic and color handling * feat: integrate Ant Design Vue for improved UI components * refactor: replace Ant Design components with their Vue counterparts for consistency * feat: add Redis monitoring titles and descriptions for better clarity
1 parent d2ea452 commit 1df4114

File tree

7 files changed

+221
-23
lines changed

7 files changed

+221
-23
lines changed

apps/web-antd/src/bootstrap.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ import '@vben/styles';
99
import '@vben/styles/antd';
1010

1111
import { useTitle } from '@vueuse/core';
12+
import Antd from 'ant-design-vue';
1213

1314
import { $t, setupI18n } from '#/locales';
1415

1516
import { initComponentAdapter } from './adapter/component';
1617
import App from './app.vue';
1718
import { router } from './router';
1819

20+
import 'ant-design-vue/dist/reset.css';
21+
1922
async function bootstrap(namespace: string) {
2023
// 初始化组件适配器
2124
await initComponentAdapter();
@@ -49,6 +52,9 @@ async function bootstrap(namespace: string) {
4952
// 初始化 tippy
5053
initTippy(app);
5154

55+
// 全局加载 antdv
56+
app.use(Antd);
57+
5258
// 配置路由及路由守卫
5359
app.use(router);
5460

apps/web-antd/src/locales/langs/en-US/page.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,25 @@
4141
"mark": "Mark",
4242
"operation": "Operation",
4343
"updated_time": "Update time"
44+
},
45+
"monitor": {
46+
"redis": {
47+
"desc": {
48+
"title": "Basic Information"
49+
},
50+
"cards": {
51+
"commands": {
52+
"title": "Command Statistics"
53+
},
54+
"memory": {
55+
"title": "Memory Status"
56+
}
57+
},
58+
"stats": {
59+
"title": {
60+
"used_memory": "Used Memory"
61+
}
62+
}
63+
}
4464
}
4565
}

apps/web-antd/src/locales/langs/zh-CN/page.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,25 @@
4141
"mark": "备注",
4242
"operation": "操作",
4343
"updated_time": "更新时间"
44+
},
45+
"monitor": {
46+
"redis": {
47+
"desc": {
48+
"title": "基本信息"
49+
},
50+
"cards": {
51+
"commands": {
52+
"title": "命令统计"
53+
},
54+
"memory": {
55+
"title": "内存情况"
56+
}
57+
},
58+
"stats": {
59+
"title": {
60+
"used_memory": "已使用内存"
61+
}
62+
}
63+
}
4464
}
4565
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<script lang="ts" setup>
2+
import type { PropType } from 'vue';
3+
4+
import type { EchartsUIType } from '@vben/plugins/echarts';
5+
6+
import { onMounted, ref } from 'vue';
7+
8+
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
9+
10+
const props = defineProps({
11+
memory: {
12+
type: Array as PropType<Record<string, any>[]>,
13+
required: true,
14+
default: () => [] as Record<string, any>[],
15+
},
16+
});
17+
18+
const chartRef = ref<EchartsUIType>();
19+
const { renderEcharts } = useEcharts(chartRef);
20+
21+
onMounted(() => {
22+
renderEcharts({
23+
progress: {
24+
show: true,
25+
},
26+
series: [
27+
{
28+
type: 'gauge',
29+
data: props.memory,
30+
axisLine: {
31+
lineStyle: {
32+
width: 30,
33+
color: [
34+
[0.3, '#67e0e3'],
35+
[0.7, '#37a2da'],
36+
[1, '#fd666d'],
37+
],
38+
},
39+
},
40+
pointer: {
41+
itemStyle: {
42+
color: 'auto',
43+
},
44+
},
45+
},
46+
],
47+
detail: {
48+
valueAnimation: true,
49+
formatter: '{value} M',
50+
color: 'auto',
51+
},
52+
tooltip: {
53+
formatter: '{a} <br/>{b} : {c} M',
54+
},
55+
});
56+
});
57+
</script>
58+
59+
<template>
60+
<EchartsUI ref="chartRef" height="350px" />
61+
</template>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<script lang="ts" setup>
2+
import type { PropType } from 'vue';
3+
4+
import type { EchartsUIType } from '@vben/plugins/echarts';
5+
6+
import { computed, onMounted, ref, watch } from 'vue';
7+
8+
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
9+
import { usePreferences } from '@vben/preferences';
10+
11+
const props = defineProps({
12+
stats: {
13+
type: Array as PropType<Record<string, any>[]>,
14+
required: true,
15+
default: () => [] as Record<string, any>[],
16+
},
17+
});
18+
19+
const { isDark } = usePreferences();
20+
const chartRef = ref<EchartsUIType>();
21+
const { renderEcharts } = useEcharts(chartRef);
22+
23+
const labelColor = computed(() =>
24+
isDark.value ? 'rgba(255, 255, 255, 0.7)' : '#1F2329',
25+
);
26+
27+
const renderChart = () => {
28+
renderEcharts({
29+
series: [
30+
{
31+
type: 'pie',
32+
data: props.stats,
33+
label: {
34+
formatter: '{b}: {d}%',
35+
fontSize: 14,
36+
color: labelColor.value,
37+
},
38+
emphasis: {
39+
itemStyle: {
40+
shadowBlur: 10,
41+
shadowOffsetX: 0,
42+
shadowColor: 'rgba(0, 0, 0, 0.5)',
43+
},
44+
},
45+
},
46+
],
47+
tooltip: {
48+
trigger: 'item',
49+
formatter: '{a} <br/>{b}: {c} ({d}%)',
50+
},
51+
});
52+
};
53+
54+
onMounted(() => {
55+
renderChart();
56+
});
57+
58+
watch(
59+
[isDark, () => props.stats],
60+
() => {
61+
renderChart();
62+
},
63+
{ deep: false },
64+
);
65+
</script>
66+
67+
<template>
68+
<EchartsUI ref="chartRef" height="350px" />
69+
</template>
Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
<script lang="ts" setup>
22
import { computed, ref, watch } from 'vue';
33
4+
import { $t } from '@vben/locales';
5+
46
import { getRedisMonitor } from '#/api';
57
import ActiveSeries from '#/views/monitor/redis/components/active-series.vue';
68
import CommandsSeries from '#/views/monitor/redis/components/commands-series.vue';
79
810
const loading = ref<boolean>(false);
911
const redisInfo = ref<Record<string, any>>({});
1012
const redisStats = ref<Record<string, any>[]>([]);
11-
1213
const usedMemory = ref<number>(0);
1314
const redisUsedMemory = computed(() => [
1415
{
15-
name: '已使用内存',
16+
name: $t('page.monitor.redis.stats.title.used_memory'),
1617
value: usedMemory.value,
1718
},
1819
]);
@@ -23,8 +24,8 @@ const fetchRedisData = async () => {
2324
const res = await getRedisMonitor();
2425
redisInfo.value = res.info;
2526
redisStats.value = res.stats;
26-
} catch {
27-
// console.error(err);
27+
} catch (error) {
28+
console.error(error);
2829
} finally {
2930
loading.value = false;
3031
}
@@ -39,22 +40,36 @@ watch(redisInfo, (val) => {
3940
</script>
4041

4142
<template>
42-
<a-card title="基本信息" :loading="loading" class="info-card">
43-
<a-descriptions>
44-
<a-descriptions-item label="Test">123</a-descriptions-item>
45-
</a-descriptions>
46-
</a-card>
47-
<a-space style="padding-top: 22px" />
48-
<a-row :gutter="20">
49-
<a-col :span="12">
50-
<a-card title="命令统计" :loading="loading" class="info-card">
51-
<CommandsSeries :stats="redisStats" />
52-
</a-card>
53-
</a-col>
54-
<a-col :span="12">
55-
<a-card title="已使用内存" :loading="loading" class="info-card">
56-
<ActiveSeries :memory="redisUsedMemory" />
57-
</a-card>
58-
</a-col>
59-
</a-row>
43+
<div>
44+
<a-card
45+
:title="$t('page.monitor.redis.desc.title')"
46+
:loading="loading"
47+
class="info-card"
48+
>
49+
<a-descriptions>
50+
<a-descriptions-item label="Test">123</a-descriptions-item>
51+
</a-descriptions>
52+
</a-card>
53+
<a-space style="padding-top: 22px" />
54+
<a-row :gutter="20">
55+
<a-col :span="12">
56+
<a-card
57+
:title="$t('page.monitor.redis.cards.commands.title')"
58+
:loading="loading"
59+
class="info-card"
60+
>
61+
<CommandsSeries :stats="redisStats" />
62+
</a-card>
63+
</a-col>
64+
<a-col :span="12">
65+
<a-card
66+
:title="$t('page.monitor.redis.cards.memory.title')"
67+
:loading="loading"
68+
class="info-card"
69+
>
70+
<ActiveSeries :memory="redisUsedMemory" />
71+
</a-card>
72+
</a-col>
73+
</a-row>
74+
</div>
6075
</template>

packages/effects/plugins/src/echarts/echarts.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ import type {
1212
} from 'echarts/components';
1313
import type { ComposeOption } from 'echarts/core';
1414

15-
import { BarChart, LineChart, PieChart, RadarChart } from 'echarts/charts';
15+
import {
16+
BarChart,
17+
GaugeChart,
18+
LineChart,
19+
PieChart,
20+
RadarChart,
21+
} from 'echarts/charts';
1622
import {
1723
// 数据集组件
1824
DatasetComponent,
@@ -54,6 +60,7 @@ echarts.use([
5460
CanvasRenderer,
5561
LegendComponent,
5662
ToolboxComponent,
63+
GaugeChart,
5764
]);
5865

5966
export default echarts;

0 commit comments

Comments
 (0)