From dfa4a8284fbd699465cffd8f6160434c777c4a75 Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Wed, 16 Jul 2025 10:51:04 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82?= =?UTF-8?q?=20date=20picker=20error=20=E0=B8=9A=E0=B8=99=20ios=20(?= =?UTF-8?q?=E0=B9=80=E0=B8=94=E0=B8=B7=E0=B8=AD=E0=B8=99/=E0=B8=9B?= =?UTF-8?q?=E0=B8=B5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ToolBar.vue | 34 +++++++++++++++++++++++++++------- src/stores/mixin.ts | 27 +++++++++++++-------------- src/views/HistoryView.vue | 6 ++++++ 3 files changed, 46 insertions(+), 21 deletions(-) diff --git a/src/components/ToolBar.vue b/src/components/ToolBar.vue index bdf7922..2430ed6 100644 --- a/src/components/ToolBar.vue +++ b/src/components/ToolBar.vue @@ -32,7 +32,8 @@ const filterYear = ref( const titleName = ref('เพิ่มรายการลงเวลากรณีพิเศษ') //หัว popup const dateMonth = ref({ month: new Date().getMonth(), - year: stores.year ? stores.year : new Date().getFullYear(), + year: + stores.year && !isNaN(stores.year) ? stores.year : new Date().getFullYear(), }) const modalPopup = ref(false) // modal เพิ่มรายการลงเวลากรณีพิเศษ @@ -42,8 +43,16 @@ const modalPopup = ref(false) // modal เพิ่มรายกา */ function filterYearFn(type: string) { const year = type === 'year' ? filterYear.value : dateMonth.value.year + const month = dateMonth.value.month + + // ตรวจสอบค่าก่อนส่ง + if (isNaN(Number(year)) || isNaN(Number(month))) { + console.warn('Invalid year or month value:', { year, month }) + return + } + //ส่งค่า ปีงบประมาณ กลับ - emit('update:year', year, dateMonth.value.month) + emit('update:year', Number(year), Number(month)) } /** @@ -66,8 +75,19 @@ function onClickClose() { * @returns เดือนและปีในภาษาไทย */ const monthYearThai = (val: DataDateMonthObject) => { - if (val == null) return '' - else return monthYear2Thai(val.month, val.year) + if (!val || !val.year || val.month === undefined || val.month === null) { + return '' + } + + // ตรวจสอบว่าค่าเป็น number ที่ถูกต้อง + const year = Number(val.year) + const month = Number(val.month) + + if (isNaN(year) || isNaN(month) || year < 1900 || month < 0 || month > 11) { + return '' + } + + return monthYear2Thai(month, year) } /** @@ -130,7 +150,7 @@ watch( month-picker :transitions="false" :enableTimePicker="false" - @update:modelValue="filterYearFn('mount')" + @update:modelValue="filterYearFn('month')" >