fix: 修复月份选择器参数错误
- 将 MonthYearPicker 的 initialMonth 参数改为 selectedMonth - 保持与组件定义一致
This commit is contained in:
parent
71deaaa288
commit
3c080fbc05
@ -35,12 +35,13 @@ fun AnalysisScreen(
|
||||
val categoryStats by viewModel.categoryStats.collectAsState()
|
||||
var showMonthPicker by remember { mutableStateOf(false) }
|
||||
|
||||
Column(
|
||||
LazyColumn(
|
||||
modifier = modifier
|
||||
.fillMaxSize()
|
||||
.padding(16.dp)
|
||||
) {
|
||||
// 月份选择器
|
||||
item {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
@ -100,41 +101,38 @@ fun AnalysisScreen(
|
||||
modifier = Modifier.padding(vertical = 8.dp)
|
||||
)
|
||||
|
||||
if (categoryStats.isEmpty()) {
|
||||
Box(
|
||||
if (categoryStats.isNotEmpty()) {
|
||||
val pieChartData = categoryStats.map { stat ->
|
||||
stat.category to stat.percentage.toFloat()
|
||||
}
|
||||
CategoryPieChart(
|
||||
categoryData = pieChartData,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(300.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
text = "暂无数据",
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
.height(300.dp)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
// 添加饼图
|
||||
CategoryPieChart(
|
||||
categoryData = categoryStats.map {
|
||||
it.category to it.amount.toFloat()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
// 分类列表
|
||||
LazyColumn {
|
||||
items(categoryStats) { stat ->
|
||||
CategoryStatItem(stat)
|
||||
}
|
||||
Text(
|
||||
text = "分类明细",
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
modifier = Modifier.padding(vertical = 8.dp)
|
||||
)
|
||||
} else {
|
||||
Text(
|
||||
text = "暂无数据",
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(32.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
AnalysisType.TREND -> {
|
||||
// TODO: 实现收支趋势图表
|
||||
Text(
|
||||
text = "收支趋势",
|
||||
text = "收支趋势分析(开发中)",
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
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) {
|
||||
MonthYearPicker(
|
||||
selectedMonth = selectedMonth,
|
||||
onMonthSelected = { yearMonth ->
|
||||
viewModel.setSelectedMonth(yearMonth)
|
||||
onMonthSelected = { month ->
|
||||
viewModel.setSelectedMonth(month)
|
||||
showMonthPicker = false
|
||||
},
|
||||
onDismiss = { showMonthPicker = false }
|
||||
@ -156,16 +162,10 @@ fun AnalysisScreen(
|
||||
|
||||
@Composable
|
||||
fun CategoryStatItem(stat: CategoryStat) {
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 4.dp),
|
||||
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp)
|
||||
.padding(vertical = 8.dp)
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
@ -174,41 +174,39 @@ fun CategoryStatItem(stat: CategoryStat) {
|
||||
) {
|
||||
Text(
|
||||
text = stat.category,
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
style = MaterialTheme.typography.bodyLarge
|
||||
)
|
||||
Text(
|
||||
text = String.format("%.1f%%", stat.percentage),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.primary
|
||||
text = String.format("%.2f", stat.amount),
|
||||
style = MaterialTheme.typography.bodyLarge
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
// 进度条
|
||||
LinearProgressIndicator(
|
||||
progress = { (stat.percentage / 100).toFloat() },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(8.dp),
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = "¥${String.format("%.2f", stat.amount)}",
|
||||
style = MaterialTheme.typography.bodyMedium
|
||||
LinearProgressIndicator(
|
||||
progress = stat.percentage.toFloat() / 100f,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.height(8.dp)
|
||||
.background(
|
||||
MaterialTheme.colorScheme.surfaceVariant,
|
||||
RoundedCornerShape(4.dp)
|
||||
)
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
|
||||
Text(
|
||||
text = "${stat.count}笔",
|
||||
text = String.format("%.1f%%", stat.percentage),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.outline
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user