Browse Source

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

pull/3283/head
zhangdaiscott 3 years ago
parent
commit
2a5ec11660
  1. 37
      ant-design-vue-jeecg/src/components/jeecg/JEasyCron/EasyCron.vue
  2. 14
      ant-design-vue-jeecg/src/components/jeecg/JEasyCron/tabs/week.vue

37
ant-design-vue-jeecg/src/components/jeecg/JEasyCron/EasyCron.vue

@ -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),

14
ant-design-vue-jeecg/src/components/jeecg/JEasyCron/tabs/week.vue

@ -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 {

Loading…
Cancel
Save