From 47a9db024a26400cc2859866fac254ee9c6d5edf Mon Sep 17 00:00:00 2001 From: marvzhang Date: Sun, 19 Jan 2020 12:30:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/Cron/index.vue | 147 +++++++++++-------------- 1 file changed, 62 insertions(+), 85 deletions(-) diff --git a/frontend/src/components/Cron/index.vue b/frontend/src/components/Cron/index.vue index 6959d1f5..80986e83 100644 --- a/frontend/src/components/Cron/index.vue +++ b/frontend/src/components/Cron/index.vue @@ -51,7 +51,7 @@ {{text.Minutes.interval[0]}} - + {{text.Minutes.interval[1]}} {{text.Minutes.interval[2]||''}} @@ -60,15 +60,15 @@ {{text.Minutes.specific}} - {{val-1}} + {{text.Minutes.cycle[0]}} - + {{text.Minutes.cycle[1]}} - + {{text.Minutes.cycle[2]}} @@ -91,7 +91,7 @@ {{text.Hours.specific}} - {{val-1}} + @@ -122,15 +122,15 @@ {{text.Day.specificDay}} - {{val}} + {{text.Day.cycle[0]}} - + {{text.Day.cycle[1]}} - + @@ -151,15 +151,15 @@ {{text.Month.specific}} - + {{text.Month.cycle[0]}} - + {{text.Month.cycle[1]}} - + {{text.Month.cycle[2]}} @@ -171,18 +171,10 @@ {{text.Week.every}} - - {{text.Week.specific}} - - - - - {{text.Week.specific}} - + @@ -212,7 +204,7 @@ export default { incrementIncrement: '5', rangeStart: '', rangeEnd: '', - specificSpecific: [] + specificSpecific: [0] }, minute: { cronEvery: '', @@ -220,7 +212,7 @@ export default { incrementIncrement: '5', rangeStart: '', rangeEnd: '', - specificSpecific: [] + specificSpecific: ['0'] }, hour: { cronEvery: '', @@ -228,7 +220,7 @@ export default { incrementIncrement: '5', rangeStart: '', rangeEnd: '', - specificSpecific: [] + specificSpecific: ['0'] }, day: { cronEvery: '', @@ -236,36 +228,28 @@ export default { incrementIncrement: '1', rangeStart: '', rangeEnd: '', - specificSpecific: [], + specificSpecific: ['1'], cronLastSpecificDomDay: 1, cronDaysBeforeEomMinus: '', cronDaysNearestWeekday: '' }, - week: { - cronEvery: '', - incrementStart: '1', - incrementIncrement: '1', - specificSpecific: [], - cronNthDayDay: 1, - cronNthDayNth: '1', - rangeStart: '', - rangeEnd: '' - }, month: { cronEvery: '', incrementStart: '3', incrementIncrement: '5', rangeStart: '', rangeEnd: '', - specificSpecific: [] + specificSpecific: ['1'] }, - year: { + week: { cronEvery: '', - incrementStart: '2017', + incrementStart: '1', incrementIncrement: '1', + specificSpecific: ['1'], + cronNthDayDay: 1, + cronNthDayNth: '1', rangeStart: '', - rangeEnd: '', - specificSpecific: [] + rangeEnd: '' }, output: { second: '', @@ -280,13 +264,11 @@ export default { }, watch: { data () { - if (!this.data) { - this.data = '* * * * *' - return - } - this.updateCron() + console.log('data', this.data) + this.updateCronFromData() }, cron () { + console.log('cron', this.cron) this.$emit('change', this.cron) } }, @@ -343,55 +325,23 @@ export default { let cronEvery = this.day.cronEvery switch (cronEvery.toString()) { case '1': - break - case '2': - case '4': - case '11': days = '*' break - case '3': + case '2': days = this.day.incrementStart + '/' + this.day.incrementIncrement break - case '5': + case '3': this.day.specificSpecific.map(val => { days += val + ',' }) days = days.slice(0, -1) break - case '6': - days = 'L' - break - case '7': - days = 'LW' - break - case '8': - days = this.day.cronLastSpecificDomDay + 'L' - break - case '9': - days = 'L-' + this.day.cronDaysBeforeEomMinus - break - case '10': - days = this.day.cronDaysNearestWeekday + 'W' + case '4': + days = this.day.rangeStart + '-' + this.day.rangeEnd break } return days }, - weeksText () { - let weeks = '' - let cronEvery = this.week.cronEvery - switch (cronEvery.toString()) { - case '1': - weeks = '*' - break - case '2': - this.week.specificSpecific.map(val => { - weeks += val + ',' - }) - weeks = weeks.slice(0, -1) - break - } - return weeks - }, monthsText () { let months = '' let cronEvery = this.month.cronEvery @@ -414,8 +364,29 @@ export default { } return months }, + weeksText () { + let weeks = '' + let cronEvery = this.week.cronEvery + switch (cronEvery.toString()) { + case '1': + weeks = '*' + break + case '3': + this.week.specificSpecific.map(val => { + weeks += val + ',' + }) + weeks = weeks.slice(0, -1) + break + case '4': + weeks = this.week.rangeStart + '-' + this.week.rangeEnd + break + } + return weeks + }, cron () { - return `${this.minutesText || '*'} ${this.hoursText || '*'} ${this.daysText || '*'} ${this.monthsText || '*'} ${this.weeksText || '*'}` + return [this.minutesText, this.hoursText, this.daysText, this.monthsText, this.weeksText] + .filter(v => !!v) + .join(' ') } }, methods: { @@ -430,7 +401,13 @@ export default { this.$emit('close') }, updateCronItem (key, value) { - if (value.match(/\//)) { + if (value === undefined) { + this[key].cronEvery = '0' + return + } + if (value.match(/^\*$/)) { + this[key].cronEvery = '1' + } else if (value.match(/\//)) { this[key].cronEvery = '2' this[key].incrementStart = value.split('/')[0] this[key].incrementIncrement = value.split('/')[1] @@ -442,10 +419,10 @@ export default { this[key].rangeStart = value.split('-')[0] this[key].rangeEnd = value.split('-')[1] } else { - this[key].cronEvery = '1' + this[key].cronEvery = '0' } }, - updateCron () { + updateCronFromData () { const arr = this.data.split(' ') const minute = arr[0] const hour = arr[1] @@ -461,6 +438,6 @@ export default { } }, mounted () { - this.updateCron() + this.updateCronFromData() } } From 60c3c056d00c68a15c338014bb1919f652aae572 Mon Sep 17 00:00:00 2001 From: marvzhang Date: Sun, 19 Jan 2020 12:31:21 +0800 Subject: [PATCH 2/2] remove verbose --- frontend/src/components/Cron/index.vue | 2 -- 1 file changed, 2 deletions(-) diff --git a/frontend/src/components/Cron/index.vue b/frontend/src/components/Cron/index.vue index 80986e83..d2a6313b 100644 --- a/frontend/src/components/Cron/index.vue +++ b/frontend/src/components/Cron/index.vue @@ -264,11 +264,9 @@ export default { }, watch: { data () { - console.log('data', this.data) this.updateCronFromData() }, cron () { - console.log('cron', this.cron) this.$emit('change', this.cron) } },