fix: sync user status changes across team lifecycle

- Accept invitation: update local userStore status to in_team
- Start game: update userStore status to in_team
- End game: update userStore status to idle, simplify endGame logic
- Add $autoCancel:false to endGame session fetch

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
congsh
2026-04-18 10:59:10 +08:00
parent 8d3cce814a
commit 12b2cdbc02
3 changed files with 25 additions and 5 deletions
+7
View File
@@ -100,6 +100,13 @@ export async function respondInvitation(
// 更新用户状态为 in_team
await pb.collection('users').update(user.id, { status: 'in_team' })
// 同步更新本地 userStore
const { useUserStore } = await import('@/stores/user')
const userStore = useUserStore()
if (userStore.user) {
userStore.user.status = 'in_team'
}
}
// 更新邀请状态
+4 -5
View File
@@ -51,7 +51,9 @@ export async function updateTeamStatus(sessionId: string, status: TeamStatus): P
// 结束游戏(解散临时小组 + 重置成员状态)
export async function endGame(sessionId: string) {
const session = await pb.collection('team_sessions').getOne(sessionId) as any
const session = await pb.collection('team_sessions').getOne(sessionId, {
$autoCancel: false
}) as any
const members: string[] = session.members || []
// 解散临时小组
@@ -60,10 +62,7 @@ export async function endGame(sessionId: string) {
// 重置所有成员状态为 idle
for (const memberId of members) {
try {
const user = await pb.collection('users').getOne(memberId) as any
if (user && user.status === 'in_team') {
await pb.collection('users').update(memberId, { status: 'idle' })
}
await pb.collection('users').update(memberId, { status: 'idle' })
} catch (_) {}
}
}