Reset ViewModels on logout/account switch

This commit introduces a `ResetModel()` function to `AgentViewModel` and `MineAgentViewModel` to clear their state.

This function is now called in `ResourceCleanupManager` and `AppState` during logout or when switching accounts to ensure that data from the previous session is not retained.

Additionally, the search and group name input fields in `CreateGroupChatScreen` are now single-line.
This commit is contained in:
2025-09-01 15:36:22 +08:00
parent 5c12982908
commit 36d322ef8c
5 changed files with 39 additions and 16 deletions

View File

@@ -95,4 +95,14 @@ object AgentViewModel: ViewModel() {
}
}
/**
* 重置ViewModel状态用于登出或切换账号时清理数据
*/
fun ResetModel() {
agentItems = emptyList()
errorMessage = null
isRefreshing = false
isLoading = false
}
}

View File

@@ -139,5 +139,23 @@ object MineAgentViewModel : ViewModel() {
}
}
/**
* 重置ViewModel状态用于登出或切换账号时清理数据
*/
fun ResetModel() {
// 重置状态变量
refreshing = false
isLoading = false
hasNext = true
currentPage = 1
error = null
isFirstLoad = true
// 清除预加载的图片ID
preloadedImageIds.clear()
// 清空PagingData
_agentList.value = PagingData.empty()
}
}