【issues/I4IFWX】定时任务表达式,”星期“一栏错误]

pull/3283/head
zhangdaiscott 2021-12-06 00:04:58 +08:00
parent 509be1e382
commit 2a5ec11660
2 changed files with 43 additions and 8 deletions

View File

@ -144,8 +144,12 @@ export default {
const v = this.cronValue_c const v = this.cronValue_c
if (this.hideYear || this.hideSecond) return v if (this.hideYear || this.hideSecond) return v
const vs = v.split(' ') const vs = v.split(' ')
return vs.slice(0, vs.length - 1).join(' ') if (vs.length >= 6) {
// 转成 Quartz 的规则
vs[5] = this.convertWeekToQuartz(vs[5])
} }
return vs.slice(0, vs.length - 1).join(' ')
},
}, },
watch: { watch: {
cronValue(newVal, oldVal) { cronValue(newVal, oldVal) {
@ -226,6 +230,37 @@ export default {
if (values.length > i) this.year = values[i] if (values.length > i) this.year = values[i]
this.assignInput() this.assignInput()
}, },
// Quartz 的规则:
// 1 = 周日2 = 周一3 = 周二4 = 周三5 = 周四6 = 周五7 = 周六
convertWeekToQuartz(week) {
let convert = (v) => {
if (v === '0') {
return '1'
}
if (v === '1') {
return '0'
}
return (Number.parseInt(v) - 1).toString()
}
// 匹配示例 1-7 or 1/7
let patten1 = /^([0-7])([-/])([0-7])$/
// 匹配示例 1,4,7
let patten2 = /^([0-7])(,[0-7])+$/
if (/^[0-7]$/.test(week)) {
return convert(week)
} else if (patten1.test(week)) {
return week.replace(patten1, ($0, before, separator, after) => {
if (separator === '/') {
return convert(before) + separator + after
} else {
return convert(before) + separator + convert(after)
}
})
} else if (patten2.test(week)) {
return week.split(',').map(v => convert(v)).join(',')
}
return week
},
calTriggerList: simpleDebounce(function () { calTriggerList: simpleDebounce(function () {
this.calTriggerListInner() this.calTriggerListInner()
}, 500), }, 500),

View File

@ -51,14 +51,14 @@ import mixin from './mixin'
import { replaceWeekName, WEEK_MAP_EN } from './const.js' import { replaceWeekName, WEEK_MAP_EN } from './const.js'
const WEEK_MAP = { const WEEK_MAP = {
'': 1, '': 2,
'': 2, '': 3,
'': 3, '': 4,
'': 4, '': 5,
'': 5, '': 6,
'': 6, '': 7,
// 按照国人习惯,将周日放到每周的最后一天 // 按照国人习惯,将周日放到每周的最后一天
'': 7, '': 1,
} }
export default { export default {