From 4ca6cf3c61735cf5e3e8c1b8f5782d6a2b86974a Mon Sep 17 00:00:00 2001 From: weizong song Date: Mon, 27 Jul 2026 14:20:57 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=84=E7=AE=97=E9=80=89=E6=8B=A9=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=B9=B4=E4=BB=BD=E8=A7=84=E5=88=99=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/BudgetSourcePickerField.vue | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/components/BudgetSourcePickerField.vue b/src/components/BudgetSourcePickerField.vue index e479eb3..e1caa79 100644 --- a/src/components/BudgetSourcePickerField.vue +++ b/src/components/BudgetSourcePickerField.vue @@ -606,9 +606,9 @@ export default { } if (!this.yearId && this.yearOptions.length > 0) { - // 尝试根据当前 value 反查 year_id(可选),否则默认第一项 + // 尝试根据当前 value 反查 year_id;未命中时优先回退到当前自然年,再回退到第一项 const fromValue = await this.tryResolveYearIdByValue(); - this.yearId = fromValue || this.yearOptions[0].value; + this.yearId = fromValue || this.getCurrentYearOptionValue() || this.yearOptions[0].value; } if (this.yearId) { @@ -629,6 +629,13 @@ export default { this.yearLoading = false; } }, + getCurrentYearOptionValue() { + const currentYear = new Date().getFullYear(); + const matched = (this.yearOptions || []).find( + (y) => String(y.year) === String(currentYear) + ); + return matched ? matched.value : null; + }, async tryResolveYearIdByValue() { if (!this.hasValue) return null; const idFromValue = this.budgetDataId || (this.budgetItems[0] && this.budgetItems[0].budget_data_id); @@ -1135,7 +1142,10 @@ export default { // 尝试获取年份ID if (!this.yearId) { const fromValue = await this.tryResolveYearIdByValue(); - this.yearId = fromValue || (this.yearOptions.length > 0 ? this.yearOptions[0].value : null); + this.yearId = + fromValue || + this.getCurrentYearOptionValue() || + (this.yearOptions.length > 0 ? this.yearOptions[0].value : null); } // 如果没有年份ID,无法生成显示文本