This commit is contained in:
Baobhan Sith
2025-04-28 21:17:05 +08:00
parent 8d9612977e
commit 6246497807
2 changed files with 18 additions and 10 deletions
@@ -2,11 +2,11 @@
import { ref, reactive, watch, computed, onMounted } from 'vue';
import { storeToRefs } from 'pinia';
import { useI18n } from 'vue-i18n';
import apiClient from '../utils/apiClient'; // 修正导入路径和名称
import apiClient from '../utils/apiClient';
import { useConnectionsStore, ConnectionInfo } from '../stores/connections.store';
import { useProxiesStore } from '../stores/proxies.store'; // 引入代理 Store
import { useTagsStore } from '../stores/tags.store'; // 引入标签 Store
import TagInput from './TagInput.vue'; // 导入新的 TagInput 组件
import { useProxiesStore } from '../stores/proxies.store';
import { useTagsStore } from '../stores/tags.store';
import TagInput from './TagInput.vue';
// 定义组件发出的事件
const emit = defineEmits(['close', 'connection-added', 'connection-updated']);
@@ -167,13 +167,23 @@ const formatKbToGb = (kb?: number): string => {
return `${gb.toFixed(1)} ${t('statusMonitor.gigaBytes')}`;
};
// Helper function to format MB to GB if needed
const formatMemorySize = (mb?: number): string => {
if (mb === undefined || mb === null || isNaN(mb)) return t('statusMonitor.notAvailable');
if (mb < 1024) {
const value = Number.isInteger(mb) ? mb : mb.toFixed(1);
return `${value} ${t('statusMonitor.megaBytes')}`;
} else {
const gb = mb / 1024;
return `${gb.toFixed(1)} ${t('statusMonitor.gigaBytes')}`;
}
};
const memDisplay = computed(() => {
const data = props.serverStatus;
if (!data || data.memUsed === undefined || data.memTotal === undefined) return t('statusMonitor.notAvailable');
const percent = data.memPercent !== undefined ? `(${(data.memPercent).toFixed(1)}%)` : ''; // Keep 1 decimal for percent
const usedMb = Number.isInteger(data.memUsed) ? data.memUsed : data.memUsed.toFixed(1);
const totalMb = Number.isInteger(data.memTotal) ? data.memTotal : data.memTotal.toFixed(1);
return `${usedMb} / ${totalMb} ${t('statusMonitor.megaBytes')} ${percent}`; // Removed extra space before MB
return `${formatMemorySize(data.memUsed)} / ${formatMemorySize(data.memTotal)} ${percent}`;
});
const diskDisplay = computed(() => {
@@ -195,9 +205,7 @@ const swapDisplay = computed(() => {
}
const percent = `(${(percentVal).toFixed(1)}%)`; // Keep 1 decimal for percent
const usedMb = Number.isInteger(used) ? used : used.toFixed(1);
const totalMb = Number.isInteger(total) ? total : total.toFixed(1);
return `${usedMb} / ${totalMb} ${t('statusMonitor.megaBytes')} ${percent}`; // Removed extra space before MB
return `${formatMemorySize(used)} / ${formatMemorySize(total)} ${percent}`;
});
</script>