events
This commit is contained in:
@@ -22,6 +22,9 @@ import LoadingView from "@/components/LoadingView.vue";
|
|||||||
import BudgetTransactionView from "@/components/budgets/BudgetTransactionView.vue";
|
import BudgetTransactionView from "@/components/budgets/BudgetTransactionView.vue";
|
||||||
import {useUserStore} from "@/stores/userStore";
|
import {useUserStore} from "@/stores/userStore";
|
||||||
|
|
||||||
|
|
||||||
|
import { EventBus } from '@/utils/EventBus';
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
|
|
||||||
transaction: {
|
transaction: {
|
||||||
@@ -86,6 +89,7 @@ const fetchCategoriesAndTypes = async () => {
|
|||||||
categoryTypes.value = categoryTypesResponse.data;
|
categoryTypes.value = categoryTypesResponse.data;
|
||||||
transactionTypes.value = transactionTypesResponse.data;
|
transactionTypes.value = transactionTypesResponse.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
toast.add({severity: 'error', summary: 'Ошибка!', detail: error.response.data["message"], life: 3000});
|
||||||
console.error('Error fetching categories and types:', error);
|
console.error('Error fetching categories and types:', error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -171,6 +175,7 @@ const createTransaction = async () => {
|
|||||||
|
|
||||||
|
|
||||||
emit('create-transaction', editedTransaction.value);
|
emit('create-transaction', editedTransaction.value);
|
||||||
|
transactionsUpdatedEmit()
|
||||||
toast.add({severity: 'success', summary: 'Успешно!', detail: 'Транзакция создана!', life: 3000});
|
toast.add({severity: 'success', summary: 'Успешно!', detail: 'Транзакция создана!', life: 3000});
|
||||||
// computeResult(true)
|
// computeResult(true)
|
||||||
resetForm();
|
resetForm();
|
||||||
@@ -188,6 +193,13 @@ const createTransaction = async () => {
|
|||||||
}, 1000)
|
}, 1000)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const transactionsUpdatedEmit = () => {
|
||||||
|
EventBus.emit('transactions-updated', {
|
||||||
|
id: Date.now(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Обновление транзакции
|
// Обновление транзакции
|
||||||
const updateTransaction = async () => {
|
const updateTransaction = async () => {
|
||||||
if (checkForm()) {
|
if (checkForm()) {
|
||||||
@@ -198,6 +210,7 @@ const updateTransaction = async () => {
|
|||||||
// toast.add({severity: 'success', summary: 'Transaction updated!', detail: 'Транзакция обновлена!', life: 3000});
|
// toast.add({severity: 'success', summary: 'Transaction updated!', detail: 'Транзакция обновлена!', life: 3000});
|
||||||
emit('update-transaction', editedTransaction.value);
|
emit('update-transaction', editedTransaction.value);
|
||||||
emit('transaction-updated');
|
emit('transaction-updated');
|
||||||
|
transactionsUpdatedEmit()
|
||||||
toast.add({severity: 'success', summary: 'Успешно!', detail: 'Транзакция создана!', life: 3000});
|
toast.add({severity: 'success', summary: 'Успешно!', detail: 'Транзакция создана!', life: 3000});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.add({severity: 'error', summary: 'Ошибка!', detail: error.response.data["message"], life: 3000});
|
toast.add({severity: 'error', summary: 'Ошибка!', detail: error.response.data["message"], life: 3000});
|
||||||
@@ -220,6 +233,7 @@ const deleteTransaction = async () => {
|
|||||||
await deleteTransactionRequest(editedTransaction.value.id);
|
await deleteTransactionRequest(editedTransaction.value.id);
|
||||||
toast.add({severity: 'success', summary: 'Транзакция удалена!', detail: 'Транзакция удалена!', life: 3000});
|
toast.add({severity: 'success', summary: 'Транзакция удалена!', detail: 'Транзакция удалена!', life: 3000});
|
||||||
emit('delete-transaction', editedTransaction.value);
|
emit('delete-transaction', editedTransaction.value);
|
||||||
|
transactionsUpdatedEmit()
|
||||||
closeDrawer()
|
closeDrawer()
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {computed, onMounted, ref} from "vue";
|
import {computed, onMounted, onUnmounted, ref} from "vue";
|
||||||
import BudgetTransactionView from "@/components/budgets/BudgetTransactionView.vue";
|
import BudgetTransactionView from "@/components/budgets/BudgetTransactionView.vue";
|
||||||
import IconField from "primevue/iconfield";
|
import IconField from "primevue/iconfield";
|
||||||
import InputIcon from "primevue/inputicon";
|
import InputIcon from "primevue/inputicon";
|
||||||
import InputText from "primevue/inputtext";
|
import InputText from "primevue/inputtext";
|
||||||
|
|
||||||
import {getTransactions} from "@/services/transactionService";
|
import {getTransactions, getTransactionTypes} from "@/services/transactionService";
|
||||||
import {Transaction} from "@/models/Transaction";
|
import {Transaction} from "@/models/Transaction";
|
||||||
import ProgressSpinner from "primevue/progressspinner";
|
import ProgressSpinner from "primevue/progressspinner";
|
||||||
import {getUsers} from "@/services/userService";
|
import {getUsers} from "@/services/userService";
|
||||||
import Button from "primevue/button";
|
import Button from "primevue/button";
|
||||||
|
import { EventBus } from '@/utils/eventBus';
|
||||||
|
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
const searchText = ref("");
|
const searchText = ref("");
|
||||||
@@ -59,6 +60,8 @@ const switchUserFilter = async (user) => {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const tgname = computed(() => {
|
const tgname = computed(() => {
|
||||||
if (window.Telegram.WebApp) {
|
if (window.Telegram.WebApp) {
|
||||||
const tg = window.Telegram.WebApp;
|
const tg = window.Telegram.WebApp;
|
||||||
@@ -103,12 +106,21 @@ const selectedUserId = ref(null)
|
|||||||
const fetchUsers = async () => {
|
const fetchUsers = async () => {
|
||||||
users.value = await getUsers();
|
users.value = await getUsers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const selectedTransactionType = ref(null)
|
||||||
|
const types = ref([])
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
EventBus.on('transactions-updated', fetchTransactions);
|
||||||
await fetchTransactions(); // Первоначальная загрузка данных
|
await fetchTransactions(); // Первоначальная загрузка данных
|
||||||
await fetchUsers();
|
await fetchUsers();
|
||||||
|
await getTransactionTypes().then( it => types.value = it.data);
|
||||||
// window.addEventListener("scroll", handleScroll); // Добавляем обработчик прокрутки
|
// window.addEventListener("scroll", handleScroll); // Добавляем обработчик прокрутки
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onUnmounted( async () => {
|
||||||
|
EventBus.off('transactions-updated', fetchTransactions);
|
||||||
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -124,8 +136,14 @@ onMounted(async () => {
|
|||||||
<button v-for="user in users" @click="switchUserFilter(user)"
|
<button v-for="user in users" @click="switchUserFilter(user)"
|
||||||
class="rounded-xl border p-1 bg-white border-gray-300 mb-2 min-w-fit px-2"
|
class="rounded-xl border p-1 bg-white border-gray-300 mb-2 min-w-fit px-2"
|
||||||
:class="selectedUserId == user.id ? '!bg-blue-100' : ''">
|
:class="selectedUserId == user.id ? '!bg-blue-100' : ''">
|
||||||
|
|
||||||
<p><span class="text-sm font-bold">{{ user.firstName }}</span></p>
|
<p><span class="text-sm font-bold">{{ user.firstName }}</span></p>
|
||||||
</button>
|
</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>
|
||||||
<div class="flex flex-col gap-2">
|
<div class="flex flex-col gap-2">
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import { useRouter } from 'vue-router';
|
|||||||
|
|
||||||
// Создаем экземпляр axios
|
// Создаем экземпляр axios
|
||||||
const api = axios.create({
|
const api = axios.create({
|
||||||
baseURL: 'https://luminic.space/api/',
|
// baseURL: 'https://luminic.space/api/',
|
||||||
// baseURL: 'http://localhost:8082/api',
|
baseURL: 'http://localhost:8082/api',
|
||||||
});
|
});
|
||||||
|
|
||||||
// Устанавливаем токен из localStorage при каждом запуске
|
// Устанавливаем токен из localStorage при каждом запуске
|
||||||
|
|||||||
21
src/utils/EventBus.ts
Normal file
21
src/utils/EventBus.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { EventEmitter } from 'events';
|
||||||
|
|
||||||
|
interface Events {
|
||||||
|
'transaction-created': { id: number; data: string }; // Типизация событий
|
||||||
|
}
|
||||||
|
|
||||||
|
class TypedEventBus extends EventEmitter {
|
||||||
|
emit<K extends keyof Events>(event: K, payload: Events[K]): boolean {
|
||||||
|
return super.emit(event, payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
on<K extends keyof Events>(event: K, listener: (payload: Events[K]) => void): this {
|
||||||
|
return super.on(event, listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
off<K extends keyof Events>(event: K, listener: (payload: Events[K]) => void): this {
|
||||||
|
return super.off(event, listener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const EventBus = new TypedEventBus();
|
||||||
Reference in New Issue
Block a user