Files
xiaocai/client/src/App.vue
wangxiaogang 1abc55323d feat: 用户体验优化 — 首页加载/继续记账/登录恢复
## 首页加载优化
- 分级加载:首屏只请求 overview + recentTx(2个请求)
- 数据新鲜度:30秒内不重复请求
- 次要数据异步加载:budget + todayData
- 非关键数据后台加载:userInfo + notifications

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

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

## 群组账单逻辑修正
- 群组账单 = 所有群组成员的个人账单之和
- 修改查询:WHERE user_id IN (群组成员)
2026-06-07 17:49:46 +08:00

84 lines
2.1 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import { onLaunch } from '@dcloudio/uni-app'
import { wxLogin, demoLogin } from '@/api/auth'
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()
// #ifdef MP-WEIXIN
uni.login({
provider: 'weixin',
success: async (loginRes) => {
if (loginRes.code) {
const success = await loginWithRetry(() => wxLogin(loginRes.code))
if (success) {
groupStore.fetchGroups()
console.log('[Auth] Login success')
} else {
uni.showToast({ title: '登录失败,请重试', icon: 'none', duration: 3000 })
}
}
markReady()
}
})
// #endif
// #ifdef H5
const token = uni.getStorageSync('xc:token')
if (!token) {
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()
console.log('[Auth] H5 token exists')
}
// #endif
})
</script>
<style lang="scss">
@import './uni.scss';
// 全局盒模型
view, text, image, input, textarea, scroll-view, picker {
box-sizing: border-box;
}
page {
background-color: $bg;
font-family: 'Nunito', 'PingFang SC', sans-serif;
color: $text;
-webkit-font-smoothing: antialiased;
}
</style>