群聊创建失败提示弹窗问题

This commit is contained in:
2025-09-05 14:17:09 +08:00
parent 9f14b35847
commit 9dceb99a98
2 changed files with 425 additions and 393 deletions

View File

@@ -95,26 +95,15 @@ fun CreateGroupChatScreen() {
systemUiController.setNavigationBarColor(Color.Transparent) systemUiController.setNavigationBarColor(Color.Transparent)
} }
Column( Box(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
.background(AppColors.background) .background(AppColors.background)
) { ) {
// 错误提示 Column(
CreateGroupChatViewModel.errorMessage?.let { error ->
Box(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxSize()
.background(AppColors.error.copy(alpha = 0.1f))
.padding(16.dp)
) { ) {
Text(
text = error,
color = AppColors.error,
fontSize = 14.sp
)
}
}
StatusBarSpacer() StatusBarSpacer()
// 头部 // 头部
@@ -492,6 +481,38 @@ fun CreateGroupChatScreen() {
} }
} }
// 居中显示的错误提示弹窗
CreateGroupChatViewModel.errorMessage?.let { error ->
Box(
modifier = Modifier
.fillMaxSize()
.padding(24.dp)
) {
Column(
modifier = Modifier
.fillMaxWidth()
.align(Alignment.Center), // 在Box中居中对齐
horizontalAlignment = Alignment.CenterHorizontally, // 水平居中
verticalArrangement = Arrangement.Center // 垂直居中
) {
androidx.compose.material3.Card(
modifier = Modifier
.fillMaxWidth(0.8f),
shape = RoundedCornerShape(8.dp)
) {
Text(
text = error,
modifier = Modifier
.padding(16.dp)
.fillMaxWidth(),
color = Color.Red,
fontSize = 14.sp,
textAlign = androidx.compose.ui.text.style.TextAlign.Center
)
}
}
}
}
}
} }

View File

@@ -28,6 +28,7 @@ import com.tencent.imsdk.v2.V2TIMConversationResult
import com.tencent.imsdk.v2.V2TIMManager import com.tencent.imsdk.v2.V2TIMManager
import com.tencent.imsdk.v2.V2TIMMessage import com.tencent.imsdk.v2.V2TIMMessage
import com.tencent.imsdk.v2.V2TIMValueCallback import com.tencent.imsdk.v2.V2TIMValueCallback
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlin.coroutines.suspendCoroutine import kotlin.coroutines.suspendCoroutine
@@ -59,16 +60,26 @@ object CreateGroupChatViewModel : ViewModel() {
true true
} else { } else {
isLoading = false isLoading = false
errorMessage = "创建群聊失败: ${response.message()}" val errorMsg = "创建群聊失败: ${response.message()}"
showToast(errorMsg)
false false
} }
} catch (e: Exception) { } catch (e: Exception) {
isLoading = false isLoading = false
errorMessage = "创建群聊失败: ${e.message}" val errorMsg = "创建群聊失败: ${e.message}"
showToast(errorMsg)
false false
} }
} }
private fun showToast(message: String) {
errorMessage = message
viewModelScope.launch {
delay(3000)
errorMessage = null
}
}
// 清除错误信息 // 清除错误信息
fun clearError() { fun clearError() {
errorMessage = null errorMessage = null