@@ -28,8 +28,8 @@ export interface CronContext {
28
28
segmentMap : Map < string , UseCronSegmentReturn >
29
29
}
30
30
31
- function createCron ( len : number , seg : string = '*' ) {
32
- return new Array ( len ) . fill ( seg ) . join ( ' ' )
31
+ function createCron ( fields : Field [ ] ) {
32
+ return fields . map ( ( f ) => f . default ?? '*' ) . join ( ' ' )
33
33
}
34
34
35
35
function isDefined < T > ( obj : T | undefined ) : obj is T {
@@ -41,8 +41,8 @@ export class DefaultCronOptions {
41
41
42
42
format : CronFormat = 'crontab'
43
43
44
- initialValue ( len : number , seg : string = '*' ) {
45
- return createCron ( len , seg )
44
+ initialValue ( fields : Field [ ] ) {
45
+ return createCron ( fields )
46
46
}
47
47
48
48
fields ( format : CronFormat , locale : string ) : Field [ ] {
@@ -84,6 +84,7 @@ export class DefaultCronOptions {
84
84
{ id : 'month' , items : items . monthItems } ,
85
85
{
86
86
id : 'dayOfWeek' ,
87
+ default : format === 'quartz' ? '?' : undefined ,
87
88
items : items . dayOfWeekItems ,
88
89
onChange : isQuartz ? setNoSpecific ( 'day' ) : undefined ,
89
90
segmentFactories : isQuartz
@@ -140,7 +141,7 @@ export function useCron(options: CronOptions) {
140
141
const locale = options . locale ?? cronDefaults . locale
141
142
const format = options . format ?? cronDefaults . format
142
143
const { customLocale, fields = cronDefaults . fields ( format , locale ) } = options
143
- const initialValue = options . initialValue ?? cronDefaults . initialValue ( fields . length )
144
+ const initialValue = options . initialValue ?? cronDefaults . initialValue ( fields )
144
145
145
146
const l10n = createL10n ( locale , customLocale )
146
147
const periods = ( options . periods ?? cronDefaults . periods ( format ) ) . map ( ( p ) => {
@@ -176,7 +177,7 @@ export function useCron(options: CronOptions) {
176
177
177
178
const fromCron = ( value : string ) => {
178
179
if ( ! value ) {
179
- cron . value = createCron ( fields . length )
180
+ cron . value = createCron ( fields )
180
181
return
181
182
}
182
183
@@ -282,9 +283,13 @@ export function setupCron(
282
283
} ,
283
284
)
284
285
285
- watch ( cron . cron , ( value ) => {
286
- emit ( 'update:model-value' , value )
287
- } )
286
+ watch (
287
+ cron . cron ,
288
+ ( value ) => {
289
+ emit ( 'update:model-value' , value )
290
+ } ,
291
+ { immediate : props . modelValue === undefined } ,
292
+ )
288
293
289
294
watch ( cron . period . selected , ( value ) => {
290
295
emit ( 'update:period' , value . id )
0 commit comments