fix: v1.4 Bug 修复与体验优化

- 修复所有日期相关逻辑使用 UTC 导致时区偏移问题
- 首页今日数据改用 stats API 聚合查询,消除 100 条上限
- 账单分页加载添加请求序号,防止并发覆盖
- 统计页 maxSingle 改为按金额排序
- 统计页 tab 切换时刷新月对比数据
- 首页 onShow 跳过首次加载,避免双重请求
- 今日卡片同时展示支出/收入,骨架屏对齐
- 账单页统一左滑删除,去掉长按
- 后端 transaction 支持 sortBy 参数
- 后端 stats overview 支持 startDate/endDate 查询
This commit is contained in:
2026-05-29 17:33:24 +08:00
parent 418d5b24f9
commit 4737f160b7
7 changed files with 94 additions and 45 deletions

View File

@@ -7,11 +7,28 @@ const router = Router()
router.get('/overview', async (req: AuthRequest, res: Response) => {
try {
const { month } = req.query
const m = (month as string) || getCurrentMonth()
const range = getMonthRange(m)
if (!range) return res.status(400).json({ code: 40001, message: '月份格式无效' })
const { startDate, endDate } = range
const { month, startDate: qStart, endDate: qEnd } = req.query
let startDate: string
let endDate: string
let elapsedDays = 1
if (qStart && qEnd) {
// 按日期范围查询(用于今日等场景)
startDate = qStart as string
endDate = qEnd as string
elapsedDays = 1
} else {
const m = (month as string) || getCurrentMonth()
const range = getMonthRange(m)
if (!range) return res.status(400).json({ code: 40001, message: '月份格式无效' })
startDate = range.startDate
endDate = range.endDate
const now = new Date()
const [year, mon] = m.split('-').map(Number)
const isCurrentMonth = year === now.getFullYear() && mon === now.getMonth() + 1
elapsedDays = isCurrentMonth ? now.getDate() : new Date(year, mon, 0).getDate()
}
const [rows] = await pool.query(
`SELECT
@@ -22,11 +39,6 @@ router.get('/overview', async (req: AuthRequest, res: Response) => {
[req.userId, startDate, endDate]
)
const row = (rows as any[])[0]
const now = new Date()
const [year, mon] = m.split('-').map(Number)
const isCurrentMonth = year === now.getFullYear() && mon === now.getMonth() + 1
const elapsedDays = isCurrentMonth ? now.getDate() : new Date(year, mon, 0).getDate()
const daily = elapsedDays > 0 ? Math.round(row.expense / elapsedDays) : 0
res.json({