From 8e475b39a1dfa6189c41bb9d0b69a5d59d73af21 Mon Sep 17 00:00:00 2001 From: mxie <15623530290@163.com> Date: Sat, 8 Sep 2018 12:04:08 +0800 Subject: [PATCH] fix: fix the selectTime 'am' and 'pm' --- src/calendar.vue | 6 ++++++ src/panel/time.js | 3 ++- src/utils/index.js | 8 ++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/calendar.vue b/src/calendar.vue index 51b0a2f..f2608b4 100644 --- a/src/calendar.vue +++ b/src/calendar.vue @@ -63,6 +63,7 @@ :time-picker-options="timePickerOptions" :value="value" :disabled-time="isDisabledTime" + :time-type="timeType" @select="selectTime" /> @@ -162,6 +163,11 @@ export default { this.calendarMonth = now.getMonth() } }, + timeType () { + const h = /h+/.test(this.$parent.format) ? '12' : '24' + const a = /A/.test(this.$parent.format) ? 'A' : 'a' + return [h, a] + }, timeHeader () { if (this.type === 'time') { return this.$parent.format diff --git a/src/panel/time.js b/src/panel/time.js index b381d96..07ec6e8 100644 --- a/src/panel/time.js +++ b/src/panel/time.js @@ -15,6 +15,7 @@ export default { validator: val => val >= 0 && val <= 60 }, value: null, + timeType: Array, disabledTime: Function }, computed: { @@ -64,7 +65,7 @@ export default { } result.push({ value, - label: formatTime(value) + label: formatTime(value, ...this.timeType) }) } } diff --git a/src/utils/index.js b/src/utils/index.js index 2257d7c..f745f13 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -38,14 +38,18 @@ export function parseTime (time) { return null } -export function formatTime (time, type = '24') { +export function formatTime (time, type = '24', a = 'a') { let hours = time.hours hours = (type === '24') ? hours : (hours % 12 || 12) hours = hours < 10 ? '0' + hours : hours let minutes = time.minutes < 10 ? '0' + time.minutes : time.minutes let result = hours + ':' + minutes if (type === '12') { - result += time.hours >= 12 ? ' pm' : ' am' + let suffix = time.hours >= 12 ? 'pm' : 'am' + if (a === 'A') { + suffix = suffix.toUpperCase() + } + result = `${result} ${suffix}` } return result }