feat: onShow静默刷新 + 群组预算双显 + TransactionItem优化

onShow 静默刷新(首次有loading,后续静默):
- budget: 添加 initialLoaded 守卫,避免首次双重请求
- profile: 添加 onShow 刷新概览/预算/账单/群组
- group-manage: 添加 onShow 刷新群组列表
- category-manage: 添加 onShow 刷新分类列表
- add: 添加 onShow 刷新分类(可能新增了分类)

群组模式预算双显:
- 服务端 GET /budget 群组模式额外返回 myAmount(本人预算)
- 客户端 Budget 类型添加 myAmount 字段
- 预算页群组模式:群组总预算卡片(只读)+ 我的预算卡片(可编辑)
- 个人模式保持原样

TransactionItem 群组模式优化:
- 主图标始终显示分类图标(不再显示创建者头像)
- 他人记录在昵称旁显示小头像(28rpx圆形)
This commit is contained in:
2026-06-04 17:45:37 +08:00
parent e110cd5c5d
commit 8bd4af9b9a
8 changed files with 125 additions and 44 deletions

View File

@@ -15,7 +15,7 @@ router.get('/', async (req: AuthRequest, res: Response) => {
const group_id = req.query.group_id as string | undefined
if (group_id && group_id !== 'null') {
// 群组视图:所有成员的预算总和
// 群组视图:所有成员的预算总和 + 当前用户个人预算
const [memberCheck] = await pool.query(
'SELECT id FROM group_members WHERE group_id = ? AND user_id = ?',
[group_id, req.userId]
@@ -24,15 +24,20 @@ router.get('/', async (req: AuthRequest, res: Response) => {
return res.status(403).json({ code: 40300, message: '无权访问此群组' })
}
const [rows] = await pool.query(
const [groupRows] = await pool.query(
`SELECT COALESCE(SUM(amount), 0) as amount, month
FROM budgets
WHERE user_id IN (SELECT user_id FROM group_members WHERE group_id = ?) AND month = ?
GROUP BY month`,
[group_id, month]
)
const budget = (rows as any[])[0] || { amount: 0, month }
res.json({ code: 0, data: budget })
const [myRows] = await pool.query(
'SELECT COALESCE(amount, 0) as amount FROM budgets WHERE user_id = ? AND month = ?',
[req.userId, month]
)
const groupBudget = (groupRows as any[])[0] || { amount: 0, month }
const myAmount = (myRows as any[])[0]?.amount || 0
res.json({ code: 0, data: { amount: groupBudget.amount, myAmount, month } })
} else {
// 个人视图
const [rows] = await pool.query(
@@ -40,6 +45,9 @@ router.get('/', async (req: AuthRequest, res: Response) => {
[req.userId, month]
)
const budget = (rows as any[])[0] || null
if (budget) {
budget.myAmount = budget.amount
}
res.json({ code: 0, data: budget })
}
} catch (err) {