<div class="hidden sm:grid mt-4 border border-wild-blue-50 rounded-lg overflow-hidden">
<!-- Table headers -->
<div class="grid bg-odd-blue-50 text-center font-medium divide-x divide-wild-blue-50"
:class="`grid-cols-${columns.length + 1}`"
>
<div class="p-4">Description</div>
<div
v-for="(col, index) in columns"
:key="index"
class="p-4"
>
{{ col.label }}
</div>
</div>
<!-- Table body -->
<div
v-for="(row, rowIndex) in rows"
:key="rowIndex"
class="grid text-center text-black divide-x divide-wild-blue-50"
:class="[
`grid-cols-${columns.length + 1}`,
rowIndex % 2 === 0 ? 'bg-odd-white' : 'bg-white'
]"
>
<div class="p-4 font-medium flex items-center justify-center" :class="rowColors[row.key]">
{{ row.label }}
</div>
<div
v-for="(col, colIndex) in columns"
:key="colIndex"
class="p-4 flex items-center justify-center"
:class="rowColors[row.key]"
>
{{ stats[row.key]?.[col.key] ?? 0 }}
</div>
</div>
</div>
<!-- Mobile cards -->
<div class="sm:hidden mt-4 space-y-4">
<div
v-for="(row, index) in rows"
:key="index"
class="border border-wild-blue-50 rounded-lg p-3 bg-odd-white-50"
>
<div class="font-medium text-lg mb-2" :class="rowColors[row.key]">
{{ row.label }}
</div>
<div
v-for="(col, colIndex) in columns"
:key="colIndex"
class="flex justify-between"
>
<span class="font-medium">{{ col.label }}:</span>
<span>{{ stats[row.key]?.[col.key] ?? 0 }}</span>
</div>
</div>
</div>
<template>
<div class="bg-background-gradient rounded-lg">
<!-- Widok Desktop / Większe ekrany -->
<div class="hidden sm:grid mt-4 border border-wild-blue-50 rounded-lg overflow-hidden">
<!-- Nagłówki tabeli - zawsze 3 kolumny -->
<div class="grid bg-odd-blue-50 text-center font-medium divide-x divide-wild-blue-50 grid-cols-3">
<div class="p-4">Description</div>
<!-- Pierwsza kolumna danych -->
<div class="p-4">
{{ columns[0]?.label ?? 'Column 1' }}
</div>
<!-- Druga kolumna danych -->
<div class="p-4">
{{ columns[1]?.label ?? 'Column 2' }}
</div>
</div>
<!-- Dane wierszy tabeli - zawsze 3 kolumny -->
<div
v-for="(row, rowIndex) in rows"
:key="rowIndex"
class="grid text-center text-black divide-x divide-wild-blue-50 grid-cols-3"
:class="[
rowIndex % 2 === 0 ? 'bg-odd-white' : 'bg-white'
]"
>
<!-- Komórka z opisem -->
<div class="p-4 font-medium flex items-center justify-center" :class="rowColors[row.key]">
{{ row.label }}
</div>
<!-- Komórka z danymi dla pierwszej kolumny -->
<div class="p-4 flex items-center justify-center" :class="rowColors[row.key]">
{{ stats[row.key]?.[columns[0]?.key] ?? 0 }}
</div>
<!-- Komórka z danymi dla drugiej kolumny -->
<div class="p-4 flex items-center justify-center" :class="rowColors[row.key]">
{{ stats[row.key]?.[columns[1]?.key] ?? 0 }}
</div>
</div>
</div>
<!-- Widok Mobile / Mniejsze ekrany -->
<div class="sm:hidden mt-4 space-y-4">
<div
v-for="(row, index) in rows"
:key="index"
class="border border-wild-blue-50 rounded-lg p-3"
:class="index % 2 === 0 ? 'bg-odd-white' : 'bg-white'"
>
<div class="font-medium text-lg mb-2" :class="rowColors[row.key]">
{{ row.label }}
</div>
<!-- Wyświetlamy tylko pierwsze dwie kolumny danych -->
<div
v-for="(col, colIndex) in columns.slice(0, 2)"
:key="colIndex"
class="flex justify-between"
:class="{ 'mb-1': colIndex < 1 }"
>
<span class="font-medium">{{ col.label }}:</span>
<span>{{ stats[row.key]?.[col.key] ?? 0 }}</span>
</div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { defineProps } from 'vue'
type Column = {
label: string
key: string
}
type Row = {
label: string
key: string
}
const props = defineProps<{
columns: Column[]
rows: Row[]
stats: Record<string, Record<string, number>>
}>()
const rowColors: Record<string, string> = {
newImageUrl: 'text-[#3B82F6]',
newSourceUrl: 'text-[#F59E0B]',
allProcessedRequests: 'text-[#10B981]',
}
</script>
<style scoped>
/* Dodaj tutaj ewentualne specyficzne style, jeśli są potrzebne */
/* Klasy takie jak bg-background-gradient, bg-odd-blue-50, etc. zakładają, że są zdefiniowane globalnie lub w Tailwind */
</style>
Teraz niezależnie od tego, ile obiektów znajduje się w tablicy props.columns, widok tabeli dla większych ekranów zawsze będzie miał 3 kolumny, a widok mobilny będzie wyświetlał opis i dane z pierwszych dwóch dostępnych kolumn.
// MyStatsDisplay.vue
<template>
<div class="p-8 bg-gray-100 min-h-screen">
<h1 class="text-3xl font-bold text-center mb-6 text-blue-800">Image Source Statistics</h1>
<!-- Użycie komponentu ImageSourceStatsTable -->
<ImageSourceStatsTable
:columns="imageColumns"
:rows="imageRows"
:stats="imageStatsData"
/>
<!-- Przykładowe dane źródłowe (można też pobrać z API) -->
<div class="mt-8 p-4 bg-white rounded-lg shadow">
<h2 class="text-xl font-semibold mb-3">Source Data Used:</h2>
<pre class="bg-gray-900 text-white p-3 rounded text-sm overflow-x-auto">
{{ JSON.stringify({ columns: imageColumns, rows: imageRows, stats: imageStatsData }, null, 2) }}
</pre>
</div>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
// Zaimportuj komponent ImageSourceStatsTable (dostosuj ścieżkę, jeśli jest inna)
import ImageSourceStatsTable from './ImageSourceStatsTable.vue'; // Zakładając, że oba pliki są w tym samym folderze
// Struktura kolumn przekazywana do komponentu
const imageColumns = ref([
{ label: 'AVG Last Sec', key: 'avgLastSec' },
{ label: 'AVG / 1000 Requests', key: 'avgPer1000' }
]);
// Struktura wierszy przekazywana do komponentu
const imageRows = ref([
{ label: 'New Image', key: 'newImages' },
{ label: 'New Source', key: 'newSources' },
{ label: 'Processed Prompt', key: 'processedPrompts' },
{ label: 'All Images', key: 'allImages' },
{ label: 'All Sources', key: 'allSources' }
]);
// Struktura statystyk przekazywana do komponentu
// Używamy tutaj przykładowych danych liczbowych.
// W realnej aplikacji, te dane pochodziłyby prawdopodobnie z propsów rodzica,
// z Vuex/Pinia store lub z odpowiedzi API.
const imageStatsData = ref({
newImages: {
avgLastSec: 15.5, // Odpowiada stats.newImageStats
avgPer1000: 120, // Odpowiada stats.newImageStats1000
},
newSources: {
avgLastSec: 8.2, // Odpowiada stats.newSourceStats
avgPer1000: 95, // Odpowiada stats.newSourceStats1000
},
processedPrompts: {
avgLastSec: 25.0, // Odpowiada stats.processedPromptStats
avgPer1000: 210, // Odpowiada stats.processedPromptStats1000
},
allImages: {
avgLastSec: 30.1, // Odpowiada stats.allImageStats
avgPer1000: 250, // Odpowiada stats.allImageStats1000
},
allSources: {
avgLastSec: 10.0, // Odpowiada stats.allSourceStats
avgPer1000: 110, // Odpowiada stats.allSourceStats1000
}
});
// Uwaga: Obiekt `rowColors` jest zdefiniowany wewnątrz komponentu `ImageSourceStatsTable`.
// Jeśli chcesz dostosować kolory z poziomu rodzica, musiałbyś przekazać je jako prop
// lub zmodyfikować komponent `ImageSourceStatsTable`, aby je przyjmował.
</script>
<style>
/* Podstawowe style Tailwind są już zawarte w komponentach Vue */
/* Możesz dodać dodatkowe globalne style tutaj, jeśli są potrzebne */
/* Poniższe style są tylko dla demonstracji */
/* Wymaga skonfigurowanego Tailwind CSS w projekcie */
/*
.p-8 { padding: 2rem; }
.bg-gray-100 { background-color: #f3f4f6; }
.min-h-screen { min-height: 100vh; }
.text-3xl { font-size: 1.875rem; line-height: 2.375rem; }
.font-bold { font-weight: 700; }
.text-center { text-align: center; }
.mb-6 { margin-bottom: 1.5rem; }
.text-blue-800 { color: #2563eb; }
.mt-8 { margin-top: 2rem; }
.p-4 { padding: 1rem; }
.bg-white { background-color: #ffffff; }
.rounded-lg { border-radius: 0.5rem; }
.shadow { box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06); }
.text-xl { font-size: 1.25rem; line-height: 1.75rem; }
.font-semibold { font-weight: 600; }
.mb-3 { margin-bottom: 0.75rem; }
.bg-gray-900 { background-color: #111827; }
.text-white { color: #ffffff; }
.overflow-x-auto { overflow-x: auto; }
*/
</style>
Pamiętaj, że ten przykład zakłada, że masz skonfigurowane środowisko Vue.js z obsługą składni <script setup> i (opcjonalnie) Tailwind CSS dla klas stylistycznych użytych w komponentach.