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

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()
// 头部 // 头部
@@ -216,40 +205,40 @@ fun CreateGroupChatScreen() {
} }
} }
// // 搜索栏 // // 搜索栏
// Box( // Box(
// modifier = Modifier // modifier = Modifier
// .fillMaxWidth() // .fillMaxWidth()
// .padding(horizontal = 16.dp, vertical = 8.dp) // .padding(horizontal = 16.dp, vertical = 8.dp)
// .background( // .background(
// color = AppColors.inputBackground, // color = AppColors.inputBackground,
// shape = RoundedCornerShape(8.dp) // shape = RoundedCornerShape(8.dp)
// ) // )
// .padding(horizontal = 12.dp, vertical = 8.dp) // .padding(horizontal = 12.dp, vertical = 8.dp)
// ) { // ) {
// Row( // Row(
// verticalAlignment = Alignment.CenterVertically // verticalAlignment = Alignment.CenterVertically
// ) { // ) {
// Image( // Image(
// painter = painterResource(id = R.drawable.rider_pro_nav_search), // painter = painterResource(id = R.drawable.rider_pro_nav_search),
// contentDescription = stringResource(R.string.search), // contentDescription = stringResource(R.string.search),
// modifier = Modifier.size(16.dp), // modifier = Modifier.size(16.dp),
// colorFilter = ColorFilter.tint(AppColors.secondaryText) // colorFilter = ColorFilter.tint(AppColors.secondaryText)
// ) // )
// Spacer(modifier = Modifier.width(8.dp)) // Spacer(modifier = Modifier.width(8.dp))
// if (searchText.text.isEmpty()) { // if (searchText.text.isEmpty()) {
// Text( // Text(
// text = stringResource(R.string.search), // text = stringResource(R.string.search),
// color = AppColors.secondaryText, // color = AppColors.secondaryText,
// fontSize = 14.sp // fontSize = 14.sp
// ) // )
// } // }
// innerTextField() // innerTextField()
// } // }
// } // }
// ) // )
// } // }
// 群聊名称输入:同一圆角灰色矩形容器 // 群聊名称输入:同一圆角灰色矩形容器
Box( Box(
@@ -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