Line data Source code
1 4 : <template>
2 5 : <div class="grid grid-cols-2 gap-2">
3 30 : <template v-for="col in deviceColumns" :key="col.field">
4 : <div class="font-medium">
5 : {{ col.header }}
6 : </div>
7 : <div>
8 : {{ formatValue(props.device[col.field], col.field) }}
9 : </div>
10 : </template>
11 : </div>
12 : </template>
13 :
14 : <script setup lang="ts">
15 : import type { DeviceStats } from '@comfyorg/api-client/types'
16 : import { formatSize } from '@/utils/formatUtil'
17 :
18 5 : const props = defineProps<{
19 : device: DeviceStats
20 : }>()
21 :
22 5 : const deviceColumns: { field: keyof DeviceStats; header: string }[] = [
23 : { field: 'name', header: 'Name' },
24 : { field: 'type', header: 'Type' },
25 : { field: 'vram_total', header: 'VRAM Total' },
26 : { field: 'vram_free', header: 'VRAM Free' },
27 : { field: 'torch_vram_total', header: 'Torch VRAM Total' },
28 : { field: 'torch_vram_free', header: 'Torch VRAM Free' }
29 : ]
30 :
31 5 : const formatValue = (value: string | number, field: string) => {
32 30 : if (
33 : ['vram_total', 'vram_free', 'torch_vram_total', 'torch_vram_free'].includes(
34 : field
35 : )
36 : ) {
37 20 : const num = Number(value)
38 20 : if (Number.isFinite(num)) {
39 18 : return formatSize(num)
40 : }
41 2 : return value
42 : }
43 10 : return value
44 : }
45 : </script>
|