feat: 用户体验优化 — 首页加载/继续记账/登录恢复

## 首页加载优化
- 分级加载:首屏只请求 overview + recentTx(2个请求)
- 数据新鲜度:30秒内不重复请求
- 次要数据异步加载:budget + todayData
- 非关键数据后台加载:userInfo + notifications

## 继续记账功能
- SaveSuccess 组件新增「继续记一笔」按钮
- 新增模式显示继续按钮,编辑模式自动返回
- 继续记账时保留分类和日期,清空金额和备注

## 登录失败恢复
- 登录重试机制:最多3次,间隔1秒
- 失败后显示提示而非静默等待

## 群组账单逻辑修正
- 群组账单 = 所有群组成员的个人账单之和
- 修改查询:WHERE user_id IN (群组成员)
This commit is contained in:
wangxiaogang
2026-06-07 17:49:46 +08:00
parent bd7af8e512
commit 1abc55323d
11 changed files with 183 additions and 87 deletions

View File

@@ -5,6 +5,24 @@ import { useGroupStore } from '@/stores/group'
import { saveLoginResult } from '@/utils/request'
import { markReady } from '@/utils/app-ready'
/** 登录重试最多3次 */
async function loginWithRetry(loginFn: () => Promise<any>, retries = 3): Promise<boolean> {
for (let i = 0; i < retries; i++) {
try {
const data = await loginFn()
saveLoginResult(data)
return true
} catch (e) {
console.error(`[Auth] Login attempt ${i + 1} failed:`, e)
if (i < retries - 1) {
// 等待1秒后重试
await new Promise(resolve => setTimeout(resolve, 1000))
}
}
}
return false
}
onLaunch(() => {
const groupStore = useGroupStore()
groupStore.init()
@@ -14,12 +32,12 @@ onLaunch(() => {
provider: 'weixin',
success: async (loginRes) => {
if (loginRes.code) {
try {
saveLoginResult(await wxLogin(loginRes.code))
const success = await loginWithRetry(() => wxLogin(loginRes.code))
if (success) {
groupStore.fetchGroups()
console.log('[Auth] Login success')
} catch (e) {
console.error('[Auth] Login failed:', e)
} else {
uni.showToast({ title: '登录失败,请重试', icon: 'none', duration: 3000 })
}
}
markReady()
@@ -30,13 +48,15 @@ onLaunch(() => {
// #ifdef H5
const token = uni.getStorageSync('xc:token')
if (!token) {
demoLogin().then((data) => {
saveLoginResult(data)
groupStore.fetchGroups()
console.log('[Auth] H5 demo login success')
}).catch((e) => {
console.error('[Auth] H5 demo login failed:', e)
}).finally(() => { markReady() })
loginWithRetry(demoLogin).then((success) => {
if (success) {
groupStore.fetchGroups()
console.log('[Auth] H5 demo login success')
} else {
uni.showToast({ title: '登录失败,请刷新页面', icon: 'none', duration: 3000 })
}
markReady()
})
} else {
groupStore.fetchGroups()
markReady()