From d662b0d23387334e425b8952106c8c1347ec4619 Mon Sep 17 00:00:00 2001 From: Eiinu Date: Sun, 7 Jan 2024 23:46:07 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix(date-picker):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=A7=92=E6=95=B0=E6=8D=AE=E6=9B=B4=E6=96=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/packages/__VUE/datepicker/index.taro.vue | 5 ++++- src/packages/__VUE/datepicker/index.vue | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/packages/__VUE/datepicker/index.taro.vue b/src/packages/__VUE/datepicker/index.taro.vue index 167edac13c..23f1bc0d8d 100644 --- a/src/packages/__VUE/datepicker/index.taro.vue +++ b/src/packages/__VUE/datepicker/index.taro.vue @@ -148,7 +148,7 @@ export default create({ hour = 23; minute = 59; } - const seconds = minute; + let seconds = minute; if (value.getFullYear() === year) { month = boundary.getMonth() + 1; if (value.getMonth() + 1 === month) { @@ -157,6 +157,9 @@ export default create({ hour = boundary.getHours(); if (value.getHours() === hour) { minute = boundary.getMinutes(); + if (value.getMinutes() === minute) { + seconds = boundary.getSeconds(); + } } } } diff --git a/src/packages/__VUE/datepicker/index.vue b/src/packages/__VUE/datepicker/index.vue index 0a6f3d69a4..fe2646a690 100644 --- a/src/packages/__VUE/datepicker/index.vue +++ b/src/packages/__VUE/datepicker/index.vue @@ -148,7 +148,7 @@ export default create({ hour = 23; minute = 59; } - const seconds = minute; + let seconds = minute; if (value.getFullYear() === year) { month = boundary.getMonth() + 1; if (value.getMonth() + 1 === month) { @@ -157,6 +157,9 @@ export default create({ hour = boundary.getHours(); if (value.getHours() === hour) { minute = boundary.getMinutes(); + if (value.getMinutes() === minute) { + seconds = boundary.getSeconds(); + } } } } From 05e17c8dabc4805b67d1a9a07570de7891d27ba2 Mon Sep 17 00:00:00 2001 From: eiinu Date: Tue, 9 Jan 2024 15:24:12 +0800 Subject: [PATCH 2/3] fix: update --- src/packages/__VUE/datepicker/index.taro.vue | 58 ++++++++++---------- src/packages/__VUE/datepicker/index.vue | 56 +++++++++---------- 2 files changed, 55 insertions(+), 59 deletions(-) diff --git a/src/packages/__VUE/datepicker/index.taro.vue b/src/packages/__VUE/datepicker/index.taro.vue index 23f1bc0d8d..6c76ea9a1a 100644 --- a/src/packages/__VUE/datepicker/index.taro.vue +++ b/src/packages/__VUE/datepicker/index.taro.vue @@ -224,37 +224,35 @@ export default create({ selectedValue: (string | number)[]; selectedOptions: PickerOption[]; }) => { - if (['date', 'datetime', 'datehour', 'month-day', 'year-month', 'hour-minute'].includes(props.type)) { - let formatDate: (number | string)[] = []; - selectedValue.forEach((item) => { - formatDate.push(item); - }); - if (props.type == 'month-day' && formatDate.length < 3) { - formatDate.unshift(new Date(state.currentDate || props.minDate || props.maxDate).getFullYear()); - } - if (props.type == 'year-month' && formatDate.length < 3) { - formatDate.push(new Date(state.currentDate || props.minDate || props.maxDate).getDate()); - } + let formatDate: (number | string)[] = []; + selectedValue.forEach((item) => { + formatDate.push(item); + }); + if (props.type == 'month-day' && formatDate.length < 3) { + formatDate.unshift(new Date(state.currentDate || props.minDate || props.maxDate).getFullYear()); + } + if (props.type == 'year-month' && formatDate.length < 3) { + formatDate.push(new Date(state.currentDate || props.minDate || props.maxDate).getDate()); + } - const year = Number(formatDate[0]); - const month = Number(formatDate[1]) - 1; - const day = Math.min(Number(formatDate[2]), getMonthEndDay(Number(formatDate[0]), Number(formatDate[1]))); - let date: Date | null = null; - if (props.type === 'date' || props.type === 'month-day' || props.type === 'year-month') { - date = new Date(year, month, day); - } else if (props.type === 'datetime') { - date = new Date(year, month, day, Number(formatDate[3]), Number(formatDate[4])); - } else if (props.type === 'datehour') { - date = new Date(year, month, day, Number(formatDate[3])); - } else if (props.type === 'hour-minute') { - date = new Date(state.currentDate); - const year = date.getFullYear(); - const month = date.getMonth(); - const day = date.getDate(); - date = new Date(year, month, day, Number(formatDate[0]), Number(formatDate[1])); - } - state.currentDate = formatValue(date as Date); + const year = Number(formatDate[0]); + const month = Number(formatDate[1]) - 1; + const day = Math.min(Number(formatDate[2]), getMonthEndDay(Number(formatDate[0]), Number(formatDate[1]))); + let date: Date | null = null; + if (props.type === 'date' || props.type === 'month-day' || props.type === 'year-month') { + date = new Date(year, month, day); + } else if (props.type === 'datetime') { + date = new Date(year, month, day, Number(formatDate[3]), Number(formatDate[4])); + } else if (props.type === 'datehour') { + date = new Date(year, month, day, Number(formatDate[3])); + } else if (props.type === 'hour-minute' || props.type === 'time') { + date = new Date(state.currentDate); + const year = date.getFullYear(); + const month = date.getMonth(); + const day = date.getDate(); + date = new Date(year, month, day, Number(formatDate[0]), Number(formatDate[1]), Number(formatDate[2] || 0)); } + state.currentDate = formatValue(date as Date); emit('change', { columnIndex, selectedValue, selectedOptions }); }; @@ -285,7 +283,7 @@ export default create({ min++; } - if (min <= +val) { + if (min <= Number(val)) { index++; } } diff --git a/src/packages/__VUE/datepicker/index.vue b/src/packages/__VUE/datepicker/index.vue index fe2646a690..670d05793a 100644 --- a/src/packages/__VUE/datepicker/index.vue +++ b/src/packages/__VUE/datepicker/index.vue @@ -224,37 +224,35 @@ export default create({ selectedValue: (string | number)[]; selectedOptions: PickerOption[]; }) => { - if (['date', 'datetime', 'datehour', 'month-day', 'year-month', 'hour-minute'].includes(props.type)) { - let formatDate: (number | string)[] = []; - selectedValue.forEach((item) => { - formatDate.push(item); - }); - if (props.type == 'month-day' && formatDate.length < 3) { - formatDate.unshift(new Date(state.currentDate || props.minDate || props.maxDate).getFullYear()); - } - if (props.type == 'year-month' && formatDate.length < 3) { - formatDate.push(new Date(state.currentDate || props.minDate || props.maxDate).getDate()); - } + let formatDate: (number | string)[] = []; + selectedValue.forEach((item) => { + formatDate.push(item); + }); + if (props.type == 'month-day' && formatDate.length < 3) { + formatDate.unshift(new Date(state.currentDate || props.minDate || props.maxDate).getFullYear()); + } + if (props.type == 'year-month' && formatDate.length < 3) { + formatDate.push(new Date(state.currentDate || props.minDate || props.maxDate).getDate()); + } - const year = Number(formatDate[0]); - const month = Number(formatDate[1]) - 1; - const day = Math.min(Number(formatDate[2]), getMonthEndDay(Number(formatDate[0]), Number(formatDate[1]))); - let date: Date | null = null; - if (props.type === 'date' || props.type === 'month-day' || props.type === 'year-month') { - date = new Date(year, month, day); - } else if (props.type === 'datetime') { - date = new Date(year, month, day, Number(formatDate[3]), Number(formatDate[4])); - } else if (props.type === 'datehour') { - date = new Date(year, month, day, Number(formatDate[3])); - } else if (props.type === 'hour-minute') { - date = new Date(state.currentDate); - const year = date.getFullYear(); - const month = date.getMonth(); - const day = date.getDate(); - date = new Date(year, month, day, Number(formatDate[0]), Number(formatDate[1])); - } - state.currentDate = formatValue(date as Date); + const year = Number(formatDate[0]); + const month = Number(formatDate[1]) - 1; + const day = Math.min(Number(formatDate[2]), getMonthEndDay(Number(formatDate[0]), Number(formatDate[1]))); + let date: Date | null = null; + if (props.type === 'date' || props.type === 'month-day' || props.type === 'year-month') { + date = new Date(year, month, day); + } else if (props.type === 'datetime') { + date = new Date(year, month, day, Number(formatDate[3]), Number(formatDate[4])); + } else if (props.type === 'datehour') { + date = new Date(year, month, day, Number(formatDate[3])); + } else if (props.type === 'hour-minute' || props.type === 'time') { + date = new Date(state.currentDate); + const year = date.getFullYear(); + const month = date.getMonth(); + const day = date.getDate(); + date = new Date(year, month, day, Number(formatDate[0]), Number(formatDate[1]), Number(formatDate[2] || 0)); } + state.currentDate = formatValue(date as Date); emit('change', { columnIndex, selectedValue, selectedOptions }); }; From 6705ca07e3d73eeda145f6af126b5924c5302f8a Mon Sep 17 00:00:00 2001 From: eiinu Date: Wed, 10 Jan 2024 15:18:52 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=81=94=E5=8A=A8?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/packages/__VUE/datepicker/index.taro.vue | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/packages/__VUE/datepicker/index.taro.vue b/src/packages/__VUE/datepicker/index.taro.vue index 6c76ea9a1a..7880c80fd8 100644 --- a/src/packages/__VUE/datepicker/index.taro.vue +++ b/src/packages/__VUE/datepicker/index.taro.vue @@ -28,6 +28,7 @@ import { PickerOption } from '../picker/types'; import { createComponent } from '@/packages/utils/create'; import { Formatter, Filter } from './type'; import { padZero, isDate as isDateU } from '@/packages/utils/util'; +import { nextTick } from '@tarojs/taro'; const { create } = createComponent('date-picker'); const currentYear = new Date().getFullYear(); @@ -377,6 +378,9 @@ export default create({ const isSameValue = JSON.stringify(newValues) === JSON.stringify(props.modelValue); if (!isSameValue) { emit('update:modelValue', newValues); + nextTick(() => { + state.selectedValue = getSelectedValue(newValues); + }); } } );