diff --git a/Service/BudgetService.cs b/Service/BudgetService.cs index 7ee0b23..d3979c9 100644 --- a/Service/BudgetService.cs +++ b/Service/BudgetService.cs @@ -243,7 +243,7 @@ public class BudgetService( var hasGlobalBudget = relevant.Any(b => b.SelectedCategories == null || b.SelectedCategories.Length == 0); var allClassifies = hasGlobalBudget - ? new List() + ? [] : relevant .SelectMany(b => b.SelectedCategories) .Distinct() @@ -602,6 +602,12 @@ public class BudgetService( return null; } + allBudgets = allBudgets + // 排序顺序 1.硬性预算 2.月度->年度 3.实际金额倒叙 + .OrderBy(b => b.IsMandatoryExpense) + .ThenBy(b => b.Type) + .ThenByDescending(b => b.Limit); + var date = referenceDate ?? DateTime.Now; decimal incomeLimitAtPeriod = 0; @@ -724,12 +730,12 @@ public class BudgetService( """); - foreach (var item in noLimitIncomeItems) + foreach (var (Name, Amount) in noLimitIncomeItems) { description.Append($""" - {item.Name} - {item.Amount:N0} + {Name} + {Amount:N0} """); } @@ -753,14 +759,14 @@ public class BudgetService( """); - foreach (var item in expenseItems) + foreach (var (Name, Limit, Factor, Total) in expenseItems) { description.Append($""" - {item.Name} - {item.Limit:N0} - {item.Factor:0.##} - {item.Total:N0} + {Name} + {Limit:N0} + {Factor:0.##} + {Total:N0} """); } @@ -781,12 +787,12 @@ public class BudgetService( """); - foreach (var item in noLimitExpenseItems) + foreach (var (Name, Amount) in noLimitExpenseItems) { description.Append($""" - {item.Name} - {item.Amount:N0} + {Name} + {Amount:N0} """); } diff --git a/Web/src/components/Budget/BudgetChartAnalysis.vue b/Web/src/components/Budget/BudgetChartAnalysis.vue index 44ac709..3b218ed 100644 --- a/Web/src/components/Budget/BudgetChartAnalysis.vue +++ b/Web/src/components/Budget/BudgetChartAnalysis.vue @@ -331,6 +331,7 @@ const updateVarianceChart = (chart, budgets) => { const categories = data.map(item => item.name) const values = data.map(item => item.value) + const maxVal = Math.max(...values.map(v => Math.abs(v))) || 1 const textColor = getCssVar('--van-text-color') const splitLineColor = getCssVar('--chart-split') @@ -387,11 +388,25 @@ const updateVarianceChart = (chart, budgets) => { stack: 'Total', barWidth: 20, // Fixed bar width data: values.map((val, index) => { + // 如果柱子太短(小于15%),文字显示在外部,否则显示在内部 + const ratio = Math.abs(val) / maxVal + const isShort = ratio < 0.15 + let position + let color + + if (val >= 0) { + position = isShort ? 'right' : 'insideLeft' + } else { + position = isShort ? 'left' : 'insideRight' + } + + color = isShort ? textColor : '#fff' + return { value: val, label: { - position: val >= 0 ? 'insideLeft' : 'insideRight', - color: '#fff' + position: position, + color: color } } }), @@ -522,8 +537,8 @@ const updateBurndownChart = () => { data: dates, axisLabel: { color: axisLabelColor, - interval: Math.ceil(daysInMonth / 8) - 1, - rotate: 45 + interval: 'auto', + rotate: 0 }, splitLine: { show: false }, axisLine: { diff --git a/Web/src/components/Budget/BudgetEditPopup.vue b/Web/src/components/Budget/BudgetEditPopup.vue index 4363edc..fa8699d 100644 --- a/Web/src/components/Budget/BudgetEditPopup.vue +++ b/Web/src/components/Budget/BudgetEditPopup.vue @@ -30,16 +30,16 @@ - +