fix: 清理死代码 + 修复群组模式预算支出计算

- 清理 store 中未使用的 loading 状态(stats/budget/category/user)
- 清理 stats store 冗余类型重导出和 catch 重置逻辑
- 清理 transaction store 未使用的 currentPage
- 清理 api/group 未使用的 GroupDetail/GroupMember/getGroupDetail
- 删除无引用的 api/index.ts barrel 导出文件
- 删除后端未调用的 GET /groups/:id 群组详情路由
- 合并 stats 页面重复的 loadTabData 函数
- 修复预算页群组模式下只算个人支出(不传 group_id)
This commit is contained in:
wangxiaogang
2026-06-04 21:04:59 +08:00
parent e764ae996e
commit 114263e4b2
10 changed files with 56 additions and 182 deletions

View File

@@ -77,8 +77,8 @@
import { ref, onMounted } from 'vue'
import { onShow } from '@dcloudio/uni-app'
import { useBudgetStore } from '@/stores/budget'
import { useStatsStore } from '@/stores/stats'
import { useGroupStore } from '@/stores/group'
import { getOverview } from '@/api/stats'
import { waitForReady } from '@/utils/app-ready'
import { formatAmount, getCurrentMonth } from '@/utils/format'
import { statusBarHeight } from '@/utils/system'
@@ -87,7 +87,6 @@ import Numpad from '@/components/Numpad/Numpad.vue'
import Icon from '@/components/Icon/Icon.vue'
const budgetStore = useBudgetStore()
const statsStore = useStatsStore()
const groupStore = useGroupStore()
const currentMonth = getCurrentMonth()
@@ -106,7 +105,6 @@ function formatPreset(val: number) {
function syncBudgetData() {
budget.value = budgetStore.budget
monthExpense.value = statsStore.overview.expense
// 群组模式用 myAmount个人预算个人模式用 amount
budgetAmount.value = budget.value
? (groupStore.isGroupMode ? (budget.value.myAmount || 0) : budget.value.amount)
@@ -116,13 +114,19 @@ function syncBudgetData() {
}
}
/** 获取个人支出(不传 group_id始终只算自己的消费 */
async function fetchMyExpense() {
const data = await getOverview({ month: currentMonth, group_id: null })
monthExpense.value = Number(data?.expense) || 0
}
onMounted(async () => {
await waitForReady()
loading.value = true
try {
await Promise.all([
budgetStore.fetchBudget(currentMonth),
statsStore.fetchOverview(currentMonth)
fetchMyExpense()
])
syncBudgetData()
} catch (e) {
@@ -139,7 +143,7 @@ onShow(async () => {
try {
await Promise.all([
budgetStore.fetchBudget(currentMonth),
statsStore.fetchOverview(currentMonth)
fetchMyExpense()
])
syncBudgetData()
} catch {}

View File

@@ -236,7 +236,7 @@ onShow(() => {
// Only re-fetch category/trend on tab switch; re-fetch all on month change
watch(currentMonth, () => loadData())
watch(tabType, () => loadTabData())
watch(tabType, () => loadData(true))
async function loadData(silent = false) {
const seq = ++loadSeq
@@ -260,26 +260,6 @@ async function loadData(silent = false) {
}
}
// Re-fetch all data when tab switches
async function loadTabData() {
const seq = ++loadSeq
loadError.value = false
try {
await Promise.all([
statsStore.fetchOverview(currentMonth.value),
statsStore.fetchCategoryStats(currentMonth.value, tabType.value),
statsStore.fetchTrend(currentMonth.value, tabType.value),
fetchMaxSingle(),
fetchPrevMonthData()
])
if (seq !== loadSeq) return
} catch (e) {
if (seq !== loadSeq) return
console.error('Stats tab load error:', e)
loadError.value = true
}
}
async function fetchMaxSingle() {
try {
const [y, m] = currentMonth.value.split('-').map(Number)