feat: 优化统一规则逻辑

This commit is contained in:
2026-03-12 10:04:29 +08:00
parent d0f68e07b7
commit bf15918136
17 changed files with 859 additions and 600 deletions

View File

@@ -1,6 +1,7 @@
<script setup>
<script setup>
import { computed, ref } from 'vue'
import { storeToRefs } from 'pinia'
import { CATEGORY_CHIPS, getCategoryLabel } from '../config/transactionCategories.js'
import { useTransactionStore } from '../stores/transactions'
import { useUiStore } from '../stores/ui'
@@ -8,17 +9,7 @@ const transactionStore = useTransactionStore()
const uiStore = useUiStore()
const { groupedTransactions, filters, loading } = storeToRefs(transactionStore)
const deletingId = ref('')
const categoryChips = [
{ label: '全部', value: 'all', icon: 'ph-asterisk' },
{ label: '餐饮', value: 'Food', icon: 'ph-bowl-food' },
{ label: '通勤', value: 'Transport', icon: 'ph-taxi' },
{ label: '健康', value: 'Health', icon: 'ph-heartbeat' },
{ label: '买菜', value: 'Groceries', icon: 'ph-basket' },
{ label: '娱乐', value: 'Entertainment', icon: 'ph-game-controller' },
{ label: '收入', value: 'Income', icon: 'ph-wallet' },
{ label: '其他', value: 'Uncategorized', icon: 'ph-dots-three-outline' },
]
const categoryChips = CATEGORY_CHIPS
const setCategory = (value) => {
filters.value.category = value
@@ -29,7 +20,7 @@ const toggleTodayOnly = () => {
}
const formatAmount = (value) =>
`${value >= 0 ? '+' : '-'} ¥${Math.abs(value || 0).toFixed(2)}`
`${value >= 0 ? '+' : '-'} ${Math.abs(value || 0).toFixed(2)}`
const formatTime = (value) =>
new Intl.DateTimeFormat('zh-CN', { hour: '2-digit', minute: '2-digit' }).format(
@@ -53,8 +44,6 @@ const handleDelete = async (item) => {
}
const hasData = computed(() => groupedTransactions.value.length > 0)
transactionStore.ensureInitialized()
</script>
<template>
@@ -114,7 +103,7 @@ transactionStore.ensureInitialized()
<div>
<h4 class="text-sm font-bold text-stone-500">{{ group.label }}</h4>
<p class="text-[10px] text-stone-400">
支出 ¥{{ group.totalExpense.toFixed(2) }}
支出 {{ group.totalExpense.toFixed(2) }}
</p>
</div>
<span class="text-xs text-stone-300 font-bold">{{ group.dayKey }}</span>
@@ -145,10 +134,10 @@ transactionStore.ensureInitialized()
<p class="text-xs text-stone-400 mt-0.5">
{{ formatTime(item.date) }}
<span v-if="item.category" class="text-stone-300">
· {{ item.category }}
{{ getCategoryLabel(item.category) }}
</span>
<span v-if="item.note" class="text-stone-300">
· {{ item.note }}
{{ item.note }}
</span>
</p>
</div>