StatusCard.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <script setup>
  2. import { computed } from 'vue';
  3. import { useI18n } from 'vue-i18n';
  4. import { AreaChartOutlined } from '@ant-design/icons-vue';
  5. import { CPUFormatter, SizeFormatter } from '@/utils';
  6. const { t } = useI18n();
  7. const props = defineProps({
  8. status: { type: Object, required: true },
  9. isMobile: { type: Boolean, default: false },
  10. });
  11. // AD-Vue's default 120px dashboard renders the percent text at ~36px
  12. // which dwarfs the rest of the card. 70 (60 on mobile) plus the
  13. // :deep(.ant-progress-text) override below keep the gauges compact.
  14. const gaugeSize = computed(() => (props.isMobile ? 60 : 70));
  15. // AD-Vue's default unfinished trail (rgba(0,0,0,0.06) /
  16. // rgba(255,255,255,0.08)) is invisible against the light card; a
  17. // neutral mid-gray reads on both themes.
  18. const trailColor = 'rgba(128, 128, 128, 0.25)';
  19. </script>
  20. <template>
  21. <a-card hoverable>
  22. <a-row :gutter="[0, isMobile ? 16 : 0]">
  23. <!-- CPU + Memory -->
  24. <a-col :xs="24" :md="12">
  25. <a-row>
  26. <a-col :span="12" class="text-center">
  27. <a-progress type="dashboard" status="normal" :stroke-color="status.cpu.color"
  28. :trail-color="trailColor" :percent="status.cpu.percent" :width="gaugeSize" />
  29. <div>
  30. <b>{{ t('pages.index.cpu') }}:</b> {{ CPUFormatter.cpuCoreFormat(status.cpuCores) }}
  31. <a-tooltip>
  32. <template #title>
  33. <div><b>{{ t('pages.index.logicalProcessors') }}:</b> {{ status.logicalPro }}</div>
  34. <div><b>{{ t('pages.index.frequency') }}:</b> {{ CPUFormatter.cpuSpeedFormat(status.cpuSpeedMhz) }}
  35. </div>
  36. </template>
  37. <AreaChartOutlined />
  38. </a-tooltip>
  39. </div>
  40. </a-col>
  41. <a-col :span="12" class="text-center">
  42. <a-progress type="dashboard" status="normal" :stroke-color="status.mem.color"
  43. :trail-color="trailColor" :percent="status.mem.percent" :width="gaugeSize" />
  44. <div>
  45. <b>{{ t('pages.index.memory') }}:</b> {{ SizeFormatter.sizeFormat(status.mem.current) }} /
  46. {{ SizeFormatter.sizeFormat(status.mem.total) }}
  47. </div>
  48. </a-col>
  49. </a-row>
  50. </a-col>
  51. <!-- Swap + Disk -->
  52. <a-col :xs="24" :md="12">
  53. <a-row>
  54. <a-col :span="12" class="text-center">
  55. <a-progress type="dashboard" status="normal" :stroke-color="status.swap.color"
  56. :trail-color="trailColor" :percent="status.swap.percent" :width="gaugeSize" />
  57. <div>
  58. <b>{{ t('pages.index.swap') }}:</b> {{ SizeFormatter.sizeFormat(status.swap.current) }} /
  59. {{ SizeFormatter.sizeFormat(status.swap.total) }}
  60. </div>
  61. </a-col>
  62. <a-col :span="12" class="text-center">
  63. <a-progress type="dashboard" status="normal" :stroke-color="status.disk.color"
  64. :trail-color="trailColor" :percent="status.disk.percent" :width="gaugeSize" />
  65. <div>
  66. <b>{{ t('pages.index.storage') }}:</b> {{ SizeFormatter.sizeFormat(status.disk.current) }} /
  67. {{ SizeFormatter.sizeFormat(status.disk.total) }}
  68. </div>
  69. </a-col>
  70. </a-row>
  71. </a-col>
  72. </a-row>
  73. </a-card>
  74. </template>
  75. <style scoped>
  76. .text-center {
  77. text-align: center;
  78. }
  79. /* Pin the percent number to a label-sized 14px — AD-Vue scales it
  80. * from the SVG's intrinsic size, so :width alone leaves it too big. */
  81. :deep(.ant-progress-text) {
  82. font-size: 14px !important;
  83. font-weight: 500;
  84. }
  85. </style>