fix:优化匹配规则
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { computed, onMounted, onBeforeUnmount } from 'vue';
|
||||
import OverviewCard from '../../../components/cards/OverviewCard.vue';
|
||||
import QuickActionButton from '../../../components/actions/QuickActionButton.vue';
|
||||
import TransactionItem from '../../../components/transactions/TransactionItem.vue';
|
||||
@@ -8,6 +8,8 @@ import { useAuthStore } from '../../../stores/auth';
|
||||
import { useTransactionsQuery } from '../../../composables/useTransactions';
|
||||
import { useBudgetsQuery } from '../../../composables/useBudgets';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { App, type AppState } from '@capacitor/app';
|
||||
import type { PluginListenerHandle } from '@capacitor/core';
|
||||
|
||||
const authStore = useAuthStore();
|
||||
const router = useRouter();
|
||||
@@ -67,6 +69,25 @@ const budgetAlerts = computed(() =>
|
||||
(budget) => budget.amount > 0 && (budget.usage / budget.amount >= budget.threshold || budget.usage >= budget.amount)
|
||||
)
|
||||
);
|
||||
|
||||
let appStateListener: PluginListenerHandle | null = null;
|
||||
|
||||
onMounted(async () => {
|
||||
// Ensure we fetch latest on mount/foreground
|
||||
await Promise.all([transactionsQuery.refetch(), budgetsQuery.refetch()]);
|
||||
appStateListener = await App.addListener('appStateChange', async ({ isActive }: AppState) => {
|
||||
if (isActive) {
|
||||
await Promise.all([transactionsQuery.refetch(), budgetsQuery.refetch()]);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (appStateListener) {
|
||||
void appStateListener.remove();
|
||||
appStateListener = null;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -136,7 +157,7 @@ const budgetAlerts = computed(() =>
|
||||
<h2 class="text-xl font-semibold text-gray-900">近期交易</h2>
|
||||
<RouterLink to="/transactions" class="text-sm text-indigo-500">查看全部</RouterLink>
|
||||
</div>
|
||||
<div class="space-y-4 mt-4 pb-10">
|
||||
<div class="space-y-6 mt-4 pb-10">
|
||||
<div v-if="isInitialLoading" class="text-sm text-gray-400 text-center py-10">
|
||||
数据加载中...
|
||||
</div>
|
||||
|
||||
@@ -101,6 +101,9 @@ const submit = async () => {
|
||||
};
|
||||
|
||||
const removeTransaction = async (id: string) => {
|
||||
// 防误触:增加确认
|
||||
const ok = window.confirm('确认删除该交易吗?');
|
||||
if (!ok) return;
|
||||
try {
|
||||
await deleteTransaction.mutateAsync(id);
|
||||
showFeedback('交易已删除');
|
||||
@@ -178,24 +181,26 @@ const refreshTransactions = async () => {
|
||||
暂无交易记录,点击「新增」开始记账。
|
||||
</div>
|
||||
<div v-else>
|
||||
<div
|
||||
v-for="transaction in filteredTransactions"
|
||||
:key="transaction.id"
|
||||
class="relative group"
|
||||
>
|
||||
<RouterLink
|
||||
class="block"
|
||||
:to="{ name: 'transaction-detail', params: { id: transaction.id } }"
|
||||
<div class="space-y-4">
|
||||
<div
|
||||
v-for="transaction in filteredTransactions"
|
||||
:key="transaction.id"
|
||||
class="relative group"
|
||||
>
|
||||
<TransactionItem :transaction="transaction" />
|
||||
</RouterLink>
|
||||
<button
|
||||
class="absolute top-4 right-4 opacity-0 group-hover:opacity-100 transition-opacity text-gray-400 hover:text-red-500 z-10"
|
||||
@click.stop="removeTransaction(transaction.id)"
|
||||
aria-label="删除"
|
||||
>
|
||||
<LucideIcon name="trash-2" :size="18" />
|
||||
</button>
|
||||
<RouterLink
|
||||
class="block"
|
||||
:to="{ name: 'transaction-detail', params: { id: transaction.id } }"
|
||||
>
|
||||
<TransactionItem :transaction="transaction" />
|
||||
</RouterLink>
|
||||
<button
|
||||
class="absolute top-4 right-4 opacity-0 group-hover:opacity-100 transition-opacity text-gray-400 hover:text-red-500 z-10"
|
||||
@click.stop="removeTransaction(transaction.id)"
|
||||
aria-label="删除"
|
||||
>
|
||||
<LucideIcon name="trash-2" :size="18" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user