From 32d7c748353cf5a245353c9e0853fce7a5bda91f Mon Sep 17 00:00:00 2001 From: Akino Date: Thu, 10 Apr 2025 03:46:42 +0000 Subject: [PATCH] enhance: remove unused log and improve loading style --- api/nginx/status.go | 1 - app/src/composables/useNginxPerformance.ts | 6 ++-- app/src/composables/usePerformanceMetrics.ts | 20 +++++------ app/src/composables/useSSE.ts | 16 ++++----- app/src/views/dashboard/NginxDashBoard.vue | 36 +++++++++---------- .../components/ConnectionMetricsCard.vue | 16 ++++----- .../components/PerformanceStatisticsCard.vue | 12 +++---- .../components/PerformanceTablesCard.vue | 18 +++++----- .../components/ProcessDistributionCard.vue | 4 +-- .../components/ResourceUsageCard.vue | 8 ++--- 10 files changed, 68 insertions(+), 69 deletions(-) diff --git a/api/nginx/status.go b/api/nginx/status.go index 0e70ca5c..19d4adcf 100644 --- a/api/nginx/status.go +++ b/api/nginx/status.go @@ -313,7 +313,6 @@ func getNginxProcessInfo() (map[string]interface{}, error) { // 转换为 MB memoryUsage := float64(mem.RSS) / 1024 / 1024 totalMemory += memoryUsage - logger.Debug("Master进程内存使用(MB):", memoryUsage) } break diff --git a/app/src/composables/useNginxPerformance.ts b/app/src/composables/useNginxPerformance.ts index b5b12581..53d5a8ec 100644 --- a/app/src/composables/useNginxPerformance.ts +++ b/app/src/composables/useNginxPerformance.ts @@ -8,17 +8,17 @@ export function useNginxPerformance() { const error = ref('') const lastUpdateTime = ref(new Date()) - // 更新刷新时间 + // Update refresh time function updateLastUpdateTime() { lastUpdateTime.value = new Date() } - // 格式化上次更新时间 + // Format the last update time const formattedUpdateTime = computed(() => { return lastUpdateTime.value.toLocaleTimeString() }) - // 获取Nginx状态数据 + // Get Nginx status data async function fetchInitialData() { loading.value = true error.value = '' diff --git a/app/src/composables/usePerformanceMetrics.ts b/app/src/composables/usePerformanceMetrics.ts index 0a05ca97..c10ae275 100644 --- a/app/src/composables/usePerformanceMetrics.ts +++ b/app/src/composables/usePerformanceMetrics.ts @@ -3,7 +3,7 @@ import type { Ref } from 'vue' import { computed } from 'vue' export function usePerformanceMetrics(nginxInfo: Ref) { - // 格式化数值为可读性更好的形式 + // Format numbers to a more readable form function formatNumber(num: number): string { if (num >= 1000000) { return `${(num / 1000000).toFixed(2)}M` @@ -14,7 +14,7 @@ export function usePerformanceMetrics(nginxInfo: Ref { if (!nginxInfo.value) { return 0 @@ -23,7 +23,7 @@ export function usePerformanceMetrics(nginxInfo: Ref { if (!nginxInfo.value) { return 0 @@ -31,7 +31,7 @@ export function usePerformanceMetrics(nginxInfo: Ref { if (!nginxInfo.value || nginxInfo.value.handled === 0) { return 0 @@ -39,7 +39,7 @@ export function usePerformanceMetrics(nginxInfo: Ref { if (!nginxInfo.value) { return 0 @@ -47,7 +47,7 @@ export function usePerformanceMetrics(nginxInfo: Ref { if (!nginxInfo.value) { return [] @@ -61,7 +61,7 @@ export function usePerformanceMetrics(nginxInfo: Ref { if (!nginxInfo.value) { return 0 @@ -74,7 +74,7 @@ export function usePerformanceMetrics(nginxInfo: Ref { if (!nginxInfo.value) { return [] @@ -119,7 +119,7 @@ export function usePerformanceMetrics(nginxInfo: Ref { if (!nginxInfo.value) { return [] @@ -159,7 +159,7 @@ export function usePerformanceMetrics(nginxInfo: Ref { if (!nginxInfo.value) { return [] diff --git a/app/src/composables/useSSE.ts b/app/src/composables/useSSE.ts index befc567f..9ad9a0dd 100644 --- a/app/src/composables/useSSE.ts +++ b/app/src/composables/useSSE.ts @@ -12,14 +12,14 @@ export interface SSEOptions { } /** - * SSE 连接 Composable - * 提供创建、管理和自动清理 SSE 连接的能力 + * SSE Composable + * Provide the ability to create, manage, and automatically clean up SSE connections */ export function useSSE() { const sseInstance = shallowRef() /** - * 连接 SSE 服务 + * Connect to SSE service */ function connect(options: SSEOptions) { disconnect() @@ -39,7 +39,7 @@ export function useSSE() { }, }) - // 处理消息 + // Handle messages sse.onmessage = (e: SSEvent) => { if (!e.data) { return @@ -54,11 +54,11 @@ export function useSSE() { } } - // 处理错误并重连 + // Handle errors and reconnect sse.onerror = () => { onError?.() - // 重连逻辑 + // Reconnect logic setTimeout(() => { connect(options) }, reconnectInterval) @@ -69,7 +69,7 @@ export function useSSE() { } /** - * 断开 SSE 连接 + * Disconnect SSE connection */ function disconnect() { if (sseInstance.value) { @@ -78,7 +78,7 @@ export function useSSE() { } } - // 组件卸载时自动断开连接 + // Automatically disconnect when the component is unmounted onUnmounted(() => { disconnect() }) diff --git a/app/src/views/dashboard/NginxDashBoard.vue b/app/src/views/dashboard/NginxDashBoard.vue index 55646cc5..650e61c4 100644 --- a/app/src/views/dashboard/NginxDashBoard.vue +++ b/app/src/views/dashboard/NginxDashBoard.vue @@ -12,12 +12,12 @@ import PerformanceTablesCard from './components/PerformanceTablesCard.vue' import ProcessDistributionCard from './components/ProcessDistributionCard.vue' import ResourceUsageCard from './components/ResourceUsageCard.vue' -// 全局状态 +// Global state const global = useGlobalStore() const { nginxStatus: status } = storeToRefs(global) const { token } = storeToRefs(useUserStore()) -// 使用性能数据composable +// Use performance data composable const { loading, nginxInfo, @@ -27,10 +27,10 @@ const { fetchInitialData, } = useNginxPerformance() -// SSE 连接 +// SSE connection const { connect, disconnect } = useSSE() -// 连接SSE +// Connect SSE function connectSSE() { disconnect() loading.value = true @@ -52,7 +52,7 @@ function connectSSE() { onError: () => { error.value = $gettext('Connection error, trying to reconnect...') - // 如果连接失败,尝试使用传统方式获取数据 + // If the connection fails, try to get data using the traditional method setTimeout(() => { fetchInitialData() }, 5000) @@ -60,12 +60,12 @@ function connectSSE() { }) } -// 手动刷新数据 +// Manually refresh data function refreshData() { fetchInitialData().then(connectSSE) } -// 组件挂载时初始化连接 +// Initialize connection when the component is mounted onMounted(() => { fetchInitialData().then(connectSSE) }) @@ -73,7 +73,7 @@ onMounted(() => {