fix: 修复月份选择器参数错误

- 将 MonthYearPicker 的 initialMonth 参数改为 selectedMonth
- 保持与组件定义一致
This commit is contained in:
yovinchen 2024-11-28 10:51:01 +08:00
parent 71deaaa288
commit 3c080fbc05

View File

@ -35,12 +35,13 @@ fun AnalysisScreen(
val categoryStats by viewModel.categoryStats.collectAsState() val categoryStats by viewModel.categoryStats.collectAsState()
var showMonthPicker by remember { mutableStateOf(false) } var showMonthPicker by remember { mutableStateOf(false) }
Column( LazyColumn(
modifier = modifier modifier = modifier
.fillMaxSize() .fillMaxSize()
.padding(16.dp) .padding(16.dp)
) { ) {
// 月份选择器 // 月份选择器
item {
Row( Row(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween, horizontalArrangement = Arrangement.SpaceBetween,
@ -100,41 +101,38 @@ fun AnalysisScreen(
modifier = Modifier.padding(vertical = 8.dp) modifier = Modifier.padding(vertical = 8.dp)
) )
if (categoryStats.isEmpty()) { if (categoryStats.isNotEmpty()) {
Box( val pieChartData = categoryStats.map { stat ->
stat.category to stat.percentage.toFloat()
}
CategoryPieChart(
categoryData = pieChartData,
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.height(300.dp), .height(300.dp)
contentAlignment = Alignment.Center
) {
Text(
text = "暂无数据",
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurfaceVariant
) )
}
} else {
// 添加饼图
CategoryPieChart(
categoryData = categoryStats.map {
it.category to it.amount.toFloat()
}
)
}
Spacer(modifier = Modifier.height(16.dp)) Spacer(modifier = Modifier.height(16.dp))
// 分类列表 Text(
LazyColumn { text = "分类明细",
items(categoryStats) { stat -> style = MaterialTheme.typography.titleMedium,
CategoryStatItem(stat) modifier = Modifier.padding(vertical = 8.dp)
} )
} else {
Text(
text = "暂无数据",
style = MaterialTheme.typography.bodyLarge,
textAlign = TextAlign.Center,
modifier = Modifier
.fillMaxWidth()
.padding(32.dp)
)
} }
} }
AnalysisType.TREND -> { AnalysisType.TREND -> {
// TODO: 实现收支趋势图表
Text( Text(
text = "收支趋势", text = "收支趋势分析(开发中)",
style = MaterialTheme.typography.titleMedium, style = MaterialTheme.typography.titleMedium,
modifier = Modifier.padding(vertical = 8.dp) modifier = Modifier.padding(vertical = 8.dp)
) )
@ -142,11 +140,19 @@ fun AnalysisScreen(
} }
} }
// 分类统计列表
if (selectedType != AnalysisType.TREND && categoryStats.isNotEmpty()) {
items(categoryStats) { stat ->
CategoryStatItem(stat)
}
}
}
if (showMonthPicker) { if (showMonthPicker) {
MonthYearPicker( MonthYearPicker(
selectedMonth = selectedMonth, selectedMonth = selectedMonth,
onMonthSelected = { yearMonth -> onMonthSelected = { month ->
viewModel.setSelectedMonth(yearMonth) viewModel.setSelectedMonth(month)
showMonthPicker = false showMonthPicker = false
}, },
onDismiss = { showMonthPicker = false } onDismiss = { showMonthPicker = false }
@ -156,16 +162,10 @@ fun AnalysisScreen(
@Composable @Composable
fun CategoryStatItem(stat: CategoryStat) { fun CategoryStatItem(stat: CategoryStat) {
Card(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 4.dp),
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)
) {
Column( Column(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(16.dp) .padding(vertical = 8.dp)
) { ) {
Row( Row(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
@ -174,41 +174,39 @@ fun CategoryStatItem(stat: CategoryStat) {
) { ) {
Text( Text(
text = stat.category, text = stat.category,
style = MaterialTheme.typography.titleMedium style = MaterialTheme.typography.bodyLarge
) )
Text( Text(
text = String.format("%.1f%%", stat.percentage), text = String.format("%.2f", stat.amount),
style = MaterialTheme.typography.bodyMedium, style = MaterialTheme.typography.bodyLarge
color = MaterialTheme.colorScheme.primary
) )
} }
Spacer(modifier = Modifier.height(8.dp)) Spacer(modifier = Modifier.height(4.dp))
// 进度条
LinearProgressIndicator(
progress = { (stat.percentage / 100).toFloat() },
modifier = Modifier
.fillMaxWidth()
.height(8.dp),
)
Spacer(modifier = Modifier.height(8.dp))
Row( Row(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) { ) {
Text( LinearProgressIndicator(
text = "¥${String.format("%.2f", stat.amount)}", progress = stat.percentage.toFloat() / 100f,
style = MaterialTheme.typography.bodyMedium modifier = Modifier
.weight(1f)
.height(8.dp)
.background(
MaterialTheme.colorScheme.surfaceVariant,
RoundedCornerShape(4.dp)
) )
)
Spacer(modifier = Modifier.width(8.dp))
Text( Text(
text = "${stat.count}", text = String.format("%.1f%%", stat.percentage),
style = MaterialTheme.typography.bodyMedium, style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.outline color = MaterialTheme.colorScheme.onSurfaceVariant
) )
} }
} }
} }
}