fix
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
:finished="true"
|
||||
:show-delete="true"
|
||||
@click="viewDetail"
|
||||
@delete="handleDateTransactionDelete"
|
||||
/>
|
||||
</PopupContainer>
|
||||
|
||||
@@ -44,7 +45,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted, nextTick } from "vue";
|
||||
import { ref, onMounted, nextTick, onBeforeUnmount } from "vue";
|
||||
import { showToast } from "vant";
|
||||
import request from "@/api/request";
|
||||
import { getTransactionDetail, getTransactionsByDate } from "@/api/transactionRecord";
|
||||
@@ -214,6 +215,15 @@ const onDetailSave = async (saveData) => {
|
||||
fetchDailyStatistics(now.getFullYear(), now.getMonth() + 1);
|
||||
};
|
||||
|
||||
// 处理删除事件:从当前日期交易列表中移除,并刷新当日和当月统计
|
||||
const handleDateTransactionDelete = async (transactionId) => {
|
||||
dateTransactions.value = dateTransactions.value.filter(t => t.id !== transactionId)
|
||||
|
||||
// 刷新当前日期以及当月的统计数据
|
||||
const now = selectedDate.value || new Date();
|
||||
fetchDailyStatistics(now.getFullYear(), now.getMonth() + 1);
|
||||
};
|
||||
|
||||
// 智能分类保存回调
|
||||
const onSmartClassifySave = async () => {
|
||||
// 保存完成后重新加载数据
|
||||
@@ -248,6 +258,36 @@ const formatterCalendar = (day) => {
|
||||
// 初始加载当前月份数据
|
||||
const now = new Date();
|
||||
fetchDailyStatistics(now.getFullYear(), now.getMonth() + 1);
|
||||
|
||||
// 全局删除事件监听,确保日历页面数据一致
|
||||
const onGlobalTransactionDeleted = (e) => {
|
||||
if (selectedDate.value) {
|
||||
fetchDateTransactions(selectedDate.value)
|
||||
}
|
||||
const now = selectedDate.value || new Date()
|
||||
fetchDailyStatistics(now.getFullYear(), now.getMonth() + 1)
|
||||
}
|
||||
|
||||
window.addEventListener && window.addEventListener('transaction-deleted', onGlobalTransactionDeleted)
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener && window.removeEventListener('transaction-deleted', onGlobalTransactionDeleted)
|
||||
})
|
||||
|
||||
// 当有交易被新增/修改/批量更新时刷新
|
||||
const onGlobalTransactionsChanged = (e) => {
|
||||
if (selectedDate.value) {
|
||||
fetchDateTransactions(selectedDate.value)
|
||||
}
|
||||
const now = selectedDate.value || new Date()
|
||||
fetchDailyStatistics(now.getFullYear(), now.getMonth() + 1)
|
||||
}
|
||||
|
||||
window.addEventListener && window.addEventListener('transactions-changed', onGlobalTransactionsChanged)
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener && window.removeEventListener('transactions-changed', onGlobalTransactionsChanged)
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Reference in New Issue
Block a user