From c51c279c333c772e688b5159212c8af2746168cc Mon Sep 17 00:00:00 2001 From: QiuShuiBai <33334963+QiuShuiBai@users.noreply.github.com> Date: Mon, 4 Jan 2021 16:18:11 +0800 Subject: [PATCH] fix(time-picker): should only display now on the current date (#750) fix the bug that now is only displayed on the first date, let now be displayed on the current date --- src/components/time-picker/time-picker.vue | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/components/time-picker/time-picker.vue b/src/components/time-picker/time-picker.vue index 95a3f3b4..0219a825 100644 --- a/src/components/time-picker/time-picker.vue +++ b/src/components/time-picker/time-picker.vue @@ -229,12 +229,21 @@ day.children = partHours }) - if (this.showNow) { - days[0].children.unshift({ - value: NOW.value, - text: this.nowText, - children: [] - }) + const dayDiff = getDayDiff(this.minTime, this.now) + + if (this.showNow && dayDiff <= 0) { + const index = Math.abs(dayDiff) + const daysData = days[index] + // Make sure 'now' is between the 'min' and 'max' + if (daysData) { + // Because daysData.children is a reference to this.hours, avoid destroying this.hourse by using spread operator '...' + daysData.children = [...daysData.children] + daysData.children.unshift({ + value: NOW.value, + text: this.nowText, + children: [] + }) + } } return days -- GitLab