tags and new analytics new in budget

This commit is contained in:
xds
2025-02-24 00:06:08 +03:00
parent 2fe692f87a
commit 374265a1a1
2 changed files with 32 additions and 21 deletions

View File

@@ -10,9 +10,10 @@ import {Transaction} from "@/models/Transaction";
import ProgressSpinner from "primevue/progressspinner";
import {getUsers} from "@/services/userService";
import Button from "primevue/button";
import { EventBus } from '@/utils/EventBus.ts';
import {EventBus} from '@/utils/EventBus.ts';
import {useSpaceStore} from "@/stores/spaceStore";
import router from "@/router";
import {useDrawerStore} from "@/stores/drawerStore";
const loading = ref(false);
const searchText = ref("");
@@ -21,6 +22,8 @@ const limit = 20; // Количество транзакций на одну з
const offset = ref(0); // Начальное смещение
const allLoaded = ref(false); // Флаг для отслеживания окончания данных
const drawerStore = useDrawerStore()
// Функция для получения транзакций с параметрами limit и offset
const fetchTransactions = async (reload) => {
@@ -28,7 +31,7 @@ const fetchTransactions = async (reload) => {
loading.value = true;
try {
const response = await getTransactions( 'INSTANT', null, null, selectedUserId.value ? selectedUserId.value : null, null, reload ? offset.value : limit, reload ? 0 : offset.value);
const response = await getTransactions('INSTANT', null, null, selectedUserId.value ? selectedUserId.value : null, null, reload ? offset.value : limit, reload ? 0 : offset.value);
const newTransactions = response.data;
// Проверка на конец данных
@@ -39,7 +42,7 @@ const fetchTransactions = async (reload) => {
// Добавляем новые транзакции к текущему списку
reload ? transactions.value = newTransactions : transactions.value.push(...newTransactions)
!reload ? offset.value += limit : offset.value
!reload ? offset.value += limit : offset.value
} catch (error) {
console.error("Error fetching transactions:", error);
}
@@ -62,7 +65,6 @@ const switchUserFilter = async (user) => {
}
const tgname = computed(() => {
if (window.Telegram.WebApp) {
const tg = window.Telegram.WebApp;
@@ -109,38 +111,47 @@ const fetchUsers = async () => {
}
const selectedTransactionType = ref(null)
const spaceStore = useSpaceStore()
const spaceStore = useSpaceStore()
const selectedSpace = computed(() => spaceStore.space)
watch( selectedSpace, async (newValue, oldValue) => {
watch(selectedSpace, async (newValue, oldValue) => {
if (newValue != oldValue) {
await fetchTransactions(false)
}
})
const types = ref([])
onMounted(async () => {
EventBus.on('transactions-updated', fetchTransactions,true);
if (selectedSpace.value){
EventBus.on('transactions-updated', fetchTransactions, true);
if (selectedSpace.value) {
await fetchTransactions(false); // Первоначальная загрузка данных
}
// await fetchUsers();
await getTransactionTypes().then( it => types.value = it.data);
await getTransactionTypes().then(it => types.value = it.data);
// window.addEventListener("scroll", handleScroll); // Добавляем обработчик прокрутки
});
onUnmounted( async () => {
onUnmounted(async () => {
EventBus.off('transactions-updated', fetchTransactions);
})
</script>
<template>
<div class="px-4 bg-gray-100 h-full">
<h2 class="text-4xl mb-6 font-bold">Список транзакций </h2>
<div class="flex flex-col gap-4 p-4 bg-gray-100 h-full ">
<div class="flex flex-row gap-4 items-center">
<h2 class="text-4xl font-bold">Список транзакций </h2>
<Button label="+ Создать" @click="{
drawerStore.setCategoryType('EXPENSE');
drawerStore.setTransactionType('INSTANT');
drawerStore.visible = true
}" size="small"/>
</div>
<div v-if="!selectedSpace" class="flex w-full h-full items-center justify-center">
<p>Сперва нужно выбрать Пространство.
<button class="text-blue-500 hover:underline" @click="router.push('/spaces').then((res) => router.go(0))">Перейти</button>
<button class="text-blue-500 hover:underline" @click="router.push('/spaces').then((res) => router.go(0))">
Перейти
</button>
</p>
</div>
<div v-else class="flex flex-col gap-2">
@@ -158,9 +169,9 @@ onUnmounted( async () => {
</button>
<!-- <button v-for="type in types" class="rounded-xl border p-1 bg-white border-gray-300 mb-2 min-w-fit px-2">-->
<!-- <p><span class="text-sm font-bold">{{ type.name }}</span></p>-->
<!-- </button>-->
<!-- <button v-for="type in types" class="rounded-xl border p-1 bg-white border-gray-300 mb-2 min-w-fit px-2">-->
<!-- <p><span class="text-sm font-bold">{{ type.name }}</span></p>-->
<!-- </button>-->
</div>
<div class="flex flex-col gap-2">