@@ -28,8 +28,8 @@ export interface CronContext {
2828 segmentMap : Map < string , UseCronSegmentReturn >
2929}
3030
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 ( ' ' )
3333}
3434
3535function isDefined < T > ( obj : T | undefined ) : obj is T {
@@ -41,8 +41,8 @@ export class DefaultCronOptions {
4141
4242 format : CronFormat = 'crontab'
4343
44- initialValue ( len : number , seg : string = '*' ) {
45- return createCron ( len , seg )
44+ initialValue ( fields : Field [ ] ) {
45+ return createCron ( fields )
4646 }
4747
4848 fields ( format : CronFormat , locale : string ) : Field [ ] {
@@ -84,6 +84,7 @@ export class DefaultCronOptions {
8484 { id : 'month' , items : items . monthItems } ,
8585 {
8686 id : 'dayOfWeek' ,
87+ default : format === 'quartz' ? '?' : undefined ,
8788 items : items . dayOfWeekItems ,
8889 onChange : isQuartz ? setNoSpecific ( 'day' ) : undefined ,
8990 segmentFactories : isQuartz
@@ -140,7 +141,7 @@ export function useCron(options: CronOptions) {
140141 const locale = options . locale ?? cronDefaults . locale
141142 const format = options . format ?? cronDefaults . format
142143 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 )
144145
145146 const l10n = createL10n ( locale , customLocale )
146147 const periods = ( options . periods ?? cronDefaults . periods ( format ) ) . map ( ( p ) => {
@@ -176,7 +177,7 @@ export function useCron(options: CronOptions) {
176177
177178 const fromCron = ( value : string ) => {
178179 if ( ! value ) {
179- cron . value = createCron ( fields . length )
180+ cron . value = createCron ( fields )
180181 return
181182 }
182183
@@ -282,9 +283,13 @@ export function setupCron(
282283 } ,
283284 )
284285
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+ )
288293
289294 watch ( cron . period . selected , ( value ) => {
290295 emit ( 'update:period' , value . id )
0 commit comments