fix: 修复收入预算计算和添加存款计划明细功能

问题1:修复收入预算实际金额计算
- 在 BudgetRepository.cs 中修复 SelectedCategories.Split 逻辑
- 添加 StringSplitOptions.RemoveEmptyEntries 和 StringSplitOptions.TrimEntries 参数
- 添加单元测试验证修复

问题2:添加存款计划明细按钮和弹窗
- 在 BudgetCard.vue 中添加 'show-detail' emit
- 为存款计划卡片(category === 2)添加明细按钮
- 在 SavingsBudgetContent.vue 中实现明细弹窗
- 弹窗显示:收入预算、支出预算、计划存款公式、存款结果

问题3:统一卡片样式
- 修复 BudgetChartAnalysis.vue 的卡片样式
- 使用 16px 圆角、增强阴影和边框
This commit is contained in:
SunCheng
2026-02-14 12:58:26 +08:00
parent a7954f55ad
commit 6f725dbb13
4 changed files with 356 additions and 8 deletions

View File

@@ -1,4 +1,4 @@
namespace WebApi.Test.Repository;
namespace WebApi.Test.Repository;
public class BudgetRepositoryTest : TransactionTestBase
{
@@ -64,4 +64,62 @@ public class BudgetRepositoryTest : TransactionTestBase
var b2_updated = all.First(b => b.Name == "B2");
b2_updated.SelectedCategories.Should().Be("美食");
}
[Fact]
public async Task GetCurrentAmountAsync_收入预算家庭年终奖金_Test()
{
// Arrange
// 创建收入交易记录,分类为"家庭年终奖金"
await _transactionRepository.AddAsync(CreateIncome(50000, classify: "家庭年终奖金", reason: "年终奖"));
await _transactionRepository.AddAsync(CreateIncome(30000, classify: "家庭年终奖金", reason: "绩效奖"));
// 创建其他收入交易,不应计入该预算
await _transactionRepository.AddAsync(CreateIncome(20000, classify: "工资", reason: "月工资"));
// 创建收入预算,包含"家庭年终奖金"分类
var budget = new BudgetRecord
{
Limit = 100000,
Category = BudgetCategory.Income,
SelectedCategories = "家庭年终奖金",
Name = "家庭年终奖金"
};
var startDate = DateTime.Now.AddDays(-1);
var endDate = DateTime.Now.AddDays(1);
// Act
var amount = await _repository.GetCurrentAmountAsync(budget, startDate, endDate);
// Assert
// 应该汇总两条"家庭年终奖金"交易50000 + 30000 = 80000
amount.Should().Be(80000);
}
[Fact]
public async Task GetCurrentAmountAsync_收入预算多个分类_Test()
{
// Arrange
await _transactionRepository.AddAsync(CreateIncome(50000, classify: "家庭年终奖金"));
await _transactionRepository.AddAsync(CreateIncome(20000, classify: "工资"));
// 创建收入预算,包含多个分类
var budget = new BudgetRecord
{
Limit = 80000,
Category = BudgetCategory.Income,
SelectedCategories = "家庭年终奖金,工资",
Name = "年收入"
};
var startDate = DateTime.Now.AddDays(-1);
var endDate = DateTime.Now.AddDays(1);
// Act
var amount = await _repository.GetCurrentAmountAsync(budget, startDate, endDate);
// Assert
// 应该汇总两个分类的交易50000 + 20000 = 70000
amount.Should().Be(70000);
}
}