mirror of
https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git
synced 2025-08-14 00:25:46 +02:00
Починка adm7
This commit is contained in:
@@ -1,30 +1,30 @@
|
|||||||
import { ref, computed } from 'vue';
|
import { ref } from 'vue';
|
||||||
import type { Statistics, StatisticCard } from '@/types/statistics';
|
|
||||||
|
interface StatisticCard {
|
||||||
|
period: string;
|
||||||
|
label: string;
|
||||||
|
value: number | string;
|
||||||
|
}
|
||||||
|
|
||||||
export function useStatistics() {
|
export function useStatistics() {
|
||||||
const statistics = ref<Statistics | null>(null);
|
const statisticsCards = ref<StatisticCard[]>([]);
|
||||||
|
|
||||||
const statisticsCards = computed<StatisticCard[]>(() => {
|
|
||||||
if (!statistics.value) return [];
|
|
||||||
return [
|
|
||||||
{ period: 'total', label: 'Всего заявок', value: statistics.value.totalRequests },
|
|
||||||
{ period: 'resolved', label: 'Решено', value: statistics.value.resolvedRequests },
|
|
||||||
{ period: 'avgTime', label: 'Среднее время', value: statistics.value.averageResolutionTime }
|
|
||||||
];
|
|
||||||
});
|
|
||||||
|
|
||||||
const fetchStatistics = async () => {
|
const fetchStatistics = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/admin/statistics?period=week');
|
const response = await fetch('/api/admin/statistics?period=week');
|
||||||
if (!response.ok) throw new Error('Failed to fetch statistics');
|
if (!response.ok) throw new Error('Failed to fetch statistics');
|
||||||
statistics.value = await response.json();
|
const data = await response.json();
|
||||||
|
statisticsCards.value = [
|
||||||
|
{ period: 'total', label: 'Всего заявок', value: data.totalRequests },
|
||||||
|
{ period: 'resolved', label: 'Решено', value: data.resolvedRequests },
|
||||||
|
{ period: 'avgTime', label: 'Среднее время', value: data.averageResolutionTime }
|
||||||
|
];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching statistics:', error);
|
console.error('Error fetching statistics:', error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
statistics,
|
|
||||||
statisticsCards,
|
statisticsCards,
|
||||||
fetchStatistics
|
fetchStatistics
|
||||||
};
|
};
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
```vue
|
||||||
<template>
|
<template>
|
||||||
<div class="space-y-6">
|
<div class="space-y-6">
|
||||||
<div class="flex justify-between items-center">
|
<div class="flex justify-between items-center">
|
||||||
@@ -44,13 +45,13 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted } from 'vue';
|
import { onMounted } from 'vue';
|
||||||
import { useRequests } from '@/composables/useRequests';
|
import { useRequests } from '@/composables/useRequests';
|
||||||
import { useStatistics } from '@/composables/useStatistics';
|
import { useStatistics } from '@/composables/useStatistics';
|
||||||
import { getRequestTypeLabel, getStatusLabel } from '@/utils/labels';
|
import { getRequestTypeLabel, getStatusLabel } from '@/utils/labels';
|
||||||
|
|
||||||
const { requests, fetchRequests } = useRequests();
|
const { requests, fetchRequests } = useRequests();
|
||||||
const { statistics, statisticsCards, fetchStatistics } = useStatistics();
|
const { statisticsCards, fetchStatistics } = useStatistics();
|
||||||
|
|
||||||
const formatDate = (date: string) => {
|
const formatDate = (date: string) => {
|
||||||
return new Date(date).toLocaleString('ru-RU');
|
return new Date(date).toLocaleString('ru-RU');
|
||||||
@@ -60,4 +61,5 @@ onMounted(() => {
|
|||||||
fetchStatistics();
|
fetchStatistics();
|
||||||
fetchRequests();
|
fetchRequests();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
```
|
Reference in New Issue
Block a user