1
- import { computed , ref , reactive } from 'vue' ;
1
+ import { computed , ref , reactive , watch } from 'vue' ;
2
2
import { getHours , getMinutes , getMonth , getYear } from 'date-fns' ;
3
3
4
4
import { getDate } from '@/utils/date-utils' ;
5
5
6
- import type { ICalendarData , InternalModuleValue , VueEmit } from '@/interfaces' ;
6
+ import type { ICalendarData , InternalModuleValue , TimeType , VueEmit } from '@/interfaces' ;
7
7
import type { PickerBasePropsType } from '@/props' ;
8
8
import { useDefaults } from '@/composables/defaults' ;
9
9
import { localToTz } from '@/utils/timezone' ;
@@ -14,13 +14,34 @@ export const useModel = (props: PickerBasePropsType, emit: VueEmit) => {
14
14
const today = getDate ( localToTz ( getDate ( ) , defaultedTz . value . timezone ) ) ;
15
15
const calendars = ref < ICalendarData [ ] > ( [ { month : getMonth ( today ) , year : getYear ( today ) } ] ) ;
16
16
17
+ const timeGetter = ( type : TimeType ) => {
18
+ const fn = {
19
+ hours : getHours ( today ) ,
20
+ minutes : getMinutes ( today ) ,
21
+ seconds : 0 ,
22
+ } ;
23
+
24
+ return defaultedRange . value . enabled ? [ fn [ type ] , fn [ type ] ] : fn [ type ] ;
25
+ } ;
17
26
// Time values
18
27
const time = reactive ( {
19
- hours : defaultedRange . value . enabled ? [ getHours ( today ) , getHours ( today ) ] : getHours ( today ) ,
20
- minutes : defaultedRange . value . enabled ? [ getMinutes ( today ) , getMinutes ( today ) ] : getMinutes ( today ) ,
21
- seconds : defaultedRange . value . enabled ? [ 0 , 0 ] : 0 ,
28
+ hours : timeGetter ( 'hours' ) ,
29
+ minutes : timeGetter ( 'minutes' ) ,
30
+ seconds : timeGetter ( 'seconds' ) ,
22
31
} ) ;
23
32
33
+ watch (
34
+ defaultedRange ,
35
+ ( newVal , oldVal ) => {
36
+ if ( newVal . enabled !== oldVal . enabled ) {
37
+ time . hours = timeGetter ( 'hours' ) ;
38
+ time . minutes = timeGetter ( 'minutes' ) ;
39
+ time . seconds = timeGetter ( 'seconds' ) ;
40
+ }
41
+ } ,
42
+ { deep : true } ,
43
+ ) ;
44
+
24
45
const modelValue = computed ( {
25
46
get : ( ) : InternalModuleValue => {
26
47
return props . internalModelValue ;
0 commit comments