This commit is contained in:
parent
fad98a3bd0
commit
400a11fc7e
|
|
@ -64,17 +64,6 @@
|
||||||
class="time-input"
|
class="time-input"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="time-input-item" v-if="showSecond">
|
|
||||||
<label>秒</label>
|
|
||||||
<el-input-number
|
|
||||||
v-model="timeValues.second"
|
|
||||||
:min="0"
|
|
||||||
:max="59"
|
|
||||||
:controls="false"
|
|
||||||
size="default"
|
|
||||||
class="time-input"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -137,7 +126,6 @@ const periodOptions = [
|
||||||
{ label: '每天', value: 'day' },
|
{ label: '每天', value: 'day' },
|
||||||
{ label: '每小时', value: 'hour' },
|
{ label: '每小时', value: 'hour' },
|
||||||
{ label: '每分钟', value: 'minute' },
|
{ label: '每分钟', value: 'minute' },
|
||||||
{ label: '每秒', value: 'second' },
|
|
||||||
]
|
]
|
||||||
|
|
||||||
// 星期选项
|
// 星期选项
|
||||||
|
|
@ -152,34 +140,30 @@ const weekOptions = [
|
||||||
]
|
]
|
||||||
|
|
||||||
// 选中的周期
|
// 选中的周期
|
||||||
const selectedPeriod = ref('second')
|
const selectedPeriod = ref('minute')
|
||||||
// 选中的星期(用于每周)
|
// 选中的星期(用于每周)
|
||||||
const selectedWeek = ref(1)
|
const selectedWeek = ref(1)
|
||||||
|
|
||||||
// 时间值
|
// 时间值
|
||||||
const timeValues = ref({
|
const timeValues = ref({
|
||||||
second: 0,
|
|
||||||
minute: 0,
|
minute: 0,
|
||||||
hour: 0,
|
hour: 0,
|
||||||
day: 1,
|
day: 1,
|
||||||
month: 1,
|
month: 1,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Cron表达式对象
|
// Cron表达式对象(5位标准格式:分钟 小时 日 月 星期)
|
||||||
const crontabValueObj = ref({
|
const crontabValueObj = ref({
|
||||||
second: '*',
|
|
||||||
min: '*',
|
min: '*',
|
||||||
hour: '*',
|
hour: '*',
|
||||||
day: '*',
|
day: '*',
|
||||||
month: '*',
|
month: '*',
|
||||||
week: '?',
|
week: '?',
|
||||||
year: '',
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// 执行描述
|
// 执行描述
|
||||||
const executionDesc = computed(() => {
|
const executionDesc = computed(() => {
|
||||||
const periodMap = {
|
const periodMap = {
|
||||||
second: '每秒执行',
|
|
||||||
minute: '每分钟执行',
|
minute: '每分钟执行',
|
||||||
hour: '每小时执行',
|
hour: '每小时执行',
|
||||||
day: '每天执行',
|
day: '每天执行',
|
||||||
|
|
@ -187,16 +171,12 @@ const executionDesc = computed(() => {
|
||||||
month: '每月执行',
|
month: '每月执行',
|
||||||
year: '每年执行',
|
year: '每年执行',
|
||||||
}
|
}
|
||||||
return periodMap[selectedPeriod.value] || '每秒执行'
|
return periodMap[selectedPeriod.value] || '每分钟执行'
|
||||||
})
|
})
|
||||||
|
|
||||||
// 显示控制
|
// 显示控制
|
||||||
const showTimeInputs = computed(() => {
|
const showTimeInputs = computed(() => {
|
||||||
return selectedPeriod.value !== 'second'
|
return selectedPeriod.value !== 'minute'
|
||||||
})
|
|
||||||
|
|
||||||
const showSecond = computed(() => {
|
|
||||||
return ['minute', 'hour', 'day', 'week', 'month', 'year'].includes(selectedPeriod.value)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const showMinute = computed(() => {
|
const showMinute = computed(() => {
|
||||||
|
|
@ -219,23 +199,10 @@ const showWeek = computed(() => {
|
||||||
return selectedPeriod.value === 'week'
|
return selectedPeriod.value === 'week'
|
||||||
})
|
})
|
||||||
|
|
||||||
// Cron表达式字符串
|
// Cron表达式字符串(6位格式:秒 分钟 小时 日 月 星期,秒固定为0)
|
||||||
const crontabValueString = computed(() => {
|
const crontabValueString = computed(() => {
|
||||||
const obj = crontabValueObj.value
|
const obj = crontabValueObj.value
|
||||||
return (
|
return '0 ' + obj.min + ' ' + obj.hour + ' ' + obj.day + ' ' + obj.month + ' ' + obj.week
|
||||||
obj.second +
|
|
||||||
' ' +
|
|
||||||
obj.min +
|
|
||||||
' ' +
|
|
||||||
obj.hour +
|
|
||||||
' ' +
|
|
||||||
obj.day +
|
|
||||||
' ' +
|
|
||||||
obj.month +
|
|
||||||
' ' +
|
|
||||||
obj.week +
|
|
||||||
(obj.year === '' ? '' : ' ' + obj.year)
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// 监听时间值变化,更新Cron表达式
|
// 监听时间值变化,更新Cron表达式
|
||||||
|
|
@ -247,91 +214,67 @@ watch(
|
||||||
{ deep: true },
|
{ deep: true },
|
||||||
)
|
)
|
||||||
|
|
||||||
// 更新Cron表达式
|
// 更新Cron表达式(生成6位格式:秒固定为0,分钟 小时 日 月 星期)
|
||||||
function updateCronExpression() {
|
function updateCronExpression() {
|
||||||
switch (selectedPeriod.value) {
|
switch (selectedPeriod.value) {
|
||||||
case 'second':
|
|
||||||
// 每秒:* * * * * ? *
|
|
||||||
crontabValueObj.value = {
|
|
||||||
second: '*',
|
|
||||||
min: '*',
|
|
||||||
hour: '*',
|
|
||||||
day: '*',
|
|
||||||
month: '*',
|
|
||||||
week: '?',
|
|
||||||
year: '',
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 'minute':
|
case 'minute':
|
||||||
// 每分钟:指定秒 * * * * ? *
|
// 每分钟:* * * * ?
|
||||||
crontabValueObj.value = {
|
crontabValueObj.value = {
|
||||||
second: String(timeValues.value.second),
|
|
||||||
min: '*',
|
min: '*',
|
||||||
hour: '*',
|
hour: '*',
|
||||||
day: '*',
|
day: '*',
|
||||||
month: '*',
|
month: '*',
|
||||||
week: '?',
|
week: '?',
|
||||||
year: '',
|
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'hour':
|
case 'hour':
|
||||||
// 每小时:指定秒 指定分钟 * * * ? *
|
// 每小时:指定分钟 * * * ?
|
||||||
crontabValueObj.value = {
|
crontabValueObj.value = {
|
||||||
second: String(timeValues.value.second),
|
|
||||||
min: String(timeValues.value.minute),
|
min: String(timeValues.value.minute),
|
||||||
hour: '*',
|
hour: '*',
|
||||||
day: '*',
|
day: '*',
|
||||||
month: '*',
|
month: '*',
|
||||||
week: '?',
|
week: '?',
|
||||||
year: '',
|
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'day':
|
case 'day':
|
||||||
// 每天:指定秒 指定分钟 指定小时 * * ? *
|
// 每天:指定分钟 指定小时 * * ?
|
||||||
crontabValueObj.value = {
|
crontabValueObj.value = {
|
||||||
second: String(timeValues.value.second),
|
|
||||||
min: String(timeValues.value.minute),
|
min: String(timeValues.value.minute),
|
||||||
hour: String(timeValues.value.hour),
|
hour: String(timeValues.value.hour),
|
||||||
day: '*',
|
day: '*',
|
||||||
month: '*',
|
month: '*',
|
||||||
week: '?',
|
week: '?',
|
||||||
year: '',
|
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'week':
|
case 'week':
|
||||||
// 每周:指定秒 指定分钟 指定小时 ? * 指定星期 *
|
// 每周:指定分钟 指定小时 ? * 指定星期
|
||||||
crontabValueObj.value = {
|
crontabValueObj.value = {
|
||||||
second: String(timeValues.value.second),
|
|
||||||
min: String(timeValues.value.minute),
|
min: String(timeValues.value.minute),
|
||||||
hour: String(timeValues.value.hour),
|
hour: String(timeValues.value.hour),
|
||||||
day: '?',
|
day: '?',
|
||||||
month: '*',
|
month: '*',
|
||||||
week: String(selectedWeek.value),
|
week: String(selectedWeek.value),
|
||||||
year: '',
|
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'month':
|
case 'month':
|
||||||
// 每月:指定秒 指定分钟 指定小时 指定日期 * ? *
|
// 每月:指定分钟 指定小时 指定日期 * ?
|
||||||
crontabValueObj.value = {
|
crontabValueObj.value = {
|
||||||
second: String(timeValues.value.second),
|
|
||||||
min: String(timeValues.value.minute),
|
min: String(timeValues.value.minute),
|
||||||
hour: String(timeValues.value.hour),
|
hour: String(timeValues.value.hour),
|
||||||
day: String(timeValues.value.day),
|
day: String(timeValues.value.day),
|
||||||
month: '*',
|
month: '*',
|
||||||
week: '?',
|
week: '?',
|
||||||
year: '',
|
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'year':
|
case 'year':
|
||||||
// 每年:指定秒 指定分钟 指定小时 指定日期 指定月份 ? *
|
// 每年:指定分钟 指定小时 指定日期 指定月份 ?
|
||||||
crontabValueObj.value = {
|
crontabValueObj.value = {
|
||||||
second: String(timeValues.value.second),
|
|
||||||
min: String(timeValues.value.minute),
|
min: String(timeValues.value.minute),
|
||||||
hour: String(timeValues.value.hour),
|
hour: String(timeValues.value.hour),
|
||||||
day: String(timeValues.value.day),
|
day: String(timeValues.value.day),
|
||||||
month: String(timeValues.value.month),
|
month: String(timeValues.value.month),
|
||||||
week: '?',
|
week: '?',
|
||||||
year: '',
|
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
@ -349,21 +292,37 @@ function handleWeekChange(week) {
|
||||||
updateCronExpression()
|
updateCronExpression()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析表达式
|
// 解析表达式(支持5位和6位格式,生成时统一为6位格式:0 分钟 小时 日 月 星期)
|
||||||
function resolveExp() {
|
function resolveExp() {
|
||||||
if (props.expression) {
|
if (props.expression) {
|
||||||
const arr = props.expression.split(/\s+/)
|
const arr = props.expression.split(/\s+/)
|
||||||
if (arr.length >= 6) {
|
let obj = {}
|
||||||
// 6位以上是合法表达式
|
|
||||||
const obj = {
|
// 判断是5位还是6位表达式
|
||||||
second: arr[0],
|
if (arr.length === 5) {
|
||||||
|
// 5位格式:分钟 小时 日 月 星期(兼容旧数据)
|
||||||
|
obj = {
|
||||||
|
min: arr[0],
|
||||||
|
hour: arr[1],
|
||||||
|
day: arr[2],
|
||||||
|
month: arr[3],
|
||||||
|
week: arr[4],
|
||||||
|
}
|
||||||
|
} else if (arr.length >= 6) {
|
||||||
|
// 6位或7位格式:秒 分钟 小时 日 月 星期 [年]
|
||||||
|
// 秒字段(arr[0])固定为0,忽略它,使用分钟作为第一位
|
||||||
|
obj = {
|
||||||
min: arr[1],
|
min: arr[1],
|
||||||
hour: arr[2],
|
hour: arr[2],
|
||||||
day: arr[3],
|
day: arr[3],
|
||||||
month: arr[4],
|
month: arr[4],
|
||||||
week: arr[5],
|
week: arr[5],
|
||||||
year: arr[6] ? arr[6] : '',
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
clearCron()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
crontabValueObj.value = { ...obj }
|
crontabValueObj.value = { ...obj }
|
||||||
|
|
||||||
// 根据表达式反推周期选择
|
// 根据表达式反推周期选择
|
||||||
|
|
@ -373,16 +332,6 @@ function resolveExp() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
obj.second === '*' &&
|
|
||||||
obj.min === '*' &&
|
|
||||||
obj.hour === '*' &&
|
|
||||||
obj.day === '*' &&
|
|
||||||
obj.month === '*' &&
|
|
||||||
obj.week === '?'
|
|
||||||
) {
|
|
||||||
selectedPeriod.value = 'second'
|
|
||||||
} else if (
|
|
||||||
isNumber(obj.second) &&
|
|
||||||
obj.min === '*' &&
|
obj.min === '*' &&
|
||||||
obj.hour === '*' &&
|
obj.hour === '*' &&
|
||||||
obj.day === '*' &&
|
obj.day === '*' &&
|
||||||
|
|
@ -390,9 +339,7 @@ function resolveExp() {
|
||||||
obj.week === '?'
|
obj.week === '?'
|
||||||
) {
|
) {
|
||||||
selectedPeriod.value = 'minute'
|
selectedPeriod.value = 'minute'
|
||||||
timeValues.value.second = parseInt(obj.second) || 0
|
|
||||||
} else if (
|
} else if (
|
||||||
isNumber(obj.second) &&
|
|
||||||
isNumber(obj.min) &&
|
isNumber(obj.min) &&
|
||||||
obj.hour === '*' &&
|
obj.hour === '*' &&
|
||||||
obj.day === '*' &&
|
obj.day === '*' &&
|
||||||
|
|
@ -400,10 +347,8 @@ function resolveExp() {
|
||||||
obj.week === '?'
|
obj.week === '?'
|
||||||
) {
|
) {
|
||||||
selectedPeriod.value = 'hour'
|
selectedPeriod.value = 'hour'
|
||||||
timeValues.value.second = parseInt(obj.second) || 0
|
|
||||||
timeValues.value.minute = parseInt(obj.min) || 0
|
timeValues.value.minute = parseInt(obj.min) || 0
|
||||||
} else if (
|
} else if (
|
||||||
isNumber(obj.second) &&
|
|
||||||
isNumber(obj.min) &&
|
isNumber(obj.min) &&
|
||||||
isNumber(obj.hour) &&
|
isNumber(obj.hour) &&
|
||||||
obj.day === '*' &&
|
obj.day === '*' &&
|
||||||
|
|
@ -411,11 +356,9 @@ function resolveExp() {
|
||||||
obj.week === '?'
|
obj.week === '?'
|
||||||
) {
|
) {
|
||||||
selectedPeriod.value = 'day'
|
selectedPeriod.value = 'day'
|
||||||
timeValues.value.second = parseInt(obj.second) || 0
|
|
||||||
timeValues.value.minute = parseInt(obj.min) || 0
|
timeValues.value.minute = parseInt(obj.min) || 0
|
||||||
timeValues.value.hour = parseInt(obj.hour) || 0
|
timeValues.value.hour = parseInt(obj.hour) || 0
|
||||||
} else if (
|
} else if (
|
||||||
isNumber(obj.second) &&
|
|
||||||
isNumber(obj.min) &&
|
isNumber(obj.min) &&
|
||||||
isNumber(obj.hour) &&
|
isNumber(obj.hour) &&
|
||||||
obj.day === '?' &&
|
obj.day === '?' &&
|
||||||
|
|
@ -423,12 +366,10 @@ function resolveExp() {
|
||||||
isNumber(obj.week)
|
isNumber(obj.week)
|
||||||
) {
|
) {
|
||||||
selectedPeriod.value = 'week'
|
selectedPeriod.value = 'week'
|
||||||
timeValues.value.second = parseInt(obj.second) || 0
|
|
||||||
timeValues.value.minute = parseInt(obj.min) || 0
|
timeValues.value.minute = parseInt(obj.min) || 0
|
||||||
timeValues.value.hour = parseInt(obj.hour) || 0
|
timeValues.value.hour = parseInt(obj.hour) || 0
|
||||||
selectedWeek.value = parseInt(obj.week) || 1
|
selectedWeek.value = parseInt(obj.week) || 1
|
||||||
} else if (
|
} else if (
|
||||||
isNumber(obj.second) &&
|
|
||||||
isNumber(obj.min) &&
|
isNumber(obj.min) &&
|
||||||
isNumber(obj.hour) &&
|
isNumber(obj.hour) &&
|
||||||
isNumber(obj.day) &&
|
isNumber(obj.day) &&
|
||||||
|
|
@ -436,12 +377,10 @@ function resolveExp() {
|
||||||
obj.week === '?'
|
obj.week === '?'
|
||||||
) {
|
) {
|
||||||
selectedPeriod.value = 'month'
|
selectedPeriod.value = 'month'
|
||||||
timeValues.value.second = parseInt(obj.second) || 0
|
|
||||||
timeValues.value.minute = parseInt(obj.min) || 0
|
timeValues.value.minute = parseInt(obj.min) || 0
|
||||||
timeValues.value.hour = parseInt(obj.hour) || 0
|
timeValues.value.hour = parseInt(obj.hour) || 0
|
||||||
timeValues.value.day = parseInt(obj.day) || 1
|
timeValues.value.day = parseInt(obj.day) || 1
|
||||||
} else if (
|
} else if (
|
||||||
isNumber(obj.second) &&
|
|
||||||
isNumber(obj.min) &&
|
isNumber(obj.min) &&
|
||||||
isNumber(obj.hour) &&
|
isNumber(obj.hour) &&
|
||||||
isNumber(obj.day) &&
|
isNumber(obj.day) &&
|
||||||
|
|
@ -449,15 +388,13 @@ function resolveExp() {
|
||||||
obj.week === '?'
|
obj.week === '?'
|
||||||
) {
|
) {
|
||||||
selectedPeriod.value = 'year'
|
selectedPeriod.value = 'year'
|
||||||
timeValues.value.second = parseInt(obj.second) || 0
|
|
||||||
timeValues.value.minute = parseInt(obj.min) || 0
|
timeValues.value.minute = parseInt(obj.min) || 0
|
||||||
timeValues.value.hour = parseInt(obj.hour) || 0
|
timeValues.value.hour = parseInt(obj.hour) || 0
|
||||||
timeValues.value.day = parseInt(obj.day) || 1
|
timeValues.value.day = parseInt(obj.day) || 1
|
||||||
timeValues.value.month = parseInt(obj.month) || 1
|
timeValues.value.month = parseInt(obj.month) || 1
|
||||||
} else {
|
} else {
|
||||||
// 如果无法匹配,默认使用每秒
|
// 如果无法匹配,默认使用每分钟
|
||||||
selectedPeriod.value = 'second'
|
selectedPeriod.value = 'minute'
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
clearCron()
|
clearCron()
|
||||||
|
|
@ -477,10 +414,9 @@ function submitFill() {
|
||||||
|
|
||||||
// 重置
|
// 重置
|
||||||
function clearCron() {
|
function clearCron() {
|
||||||
selectedPeriod.value = 'second'
|
selectedPeriod.value = 'minute'
|
||||||
selectedWeek.value = 1
|
selectedWeek.value = 1
|
||||||
timeValues.value = {
|
timeValues.value = {
|
||||||
second: 0,
|
|
||||||
minute: 0,
|
minute: 0,
|
||||||
hour: 0,
|
hour: 0,
|
||||||
day: 1,
|
day: 1,
|
||||||
|
|
|
||||||
|
|
@ -452,9 +452,29 @@ const parseCronToChinese = (cronExpression) => {
|
||||||
if (!cronExpression) return ''
|
if (!cronExpression) return ''
|
||||||
|
|
||||||
const parts = cronExpression.trim().split(/\s+/)
|
const parts = cronExpression.trim().split(/\s+/)
|
||||||
if (parts.length < 6) return ''
|
if (parts.length < 5) return ''
|
||||||
|
|
||||||
const [second, minute, hour, day, month, week, year] = parts
|
// 判断是5位格式(分钟 小时 日 月 星期)还是6/7位格式(秒 分钟 小时 日 月 星期 [年])
|
||||||
|
let second, minute, hour, day, month, week, year
|
||||||
|
if (parts.length === 5) {
|
||||||
|
// 5位格式:分钟 小时 日 月 星期,秒默认为0
|
||||||
|
second = '0'
|
||||||
|
minute = parts[0]
|
||||||
|
hour = parts[1]
|
||||||
|
day = parts[2]
|
||||||
|
month = parts[3]
|
||||||
|
week = parts[4]
|
||||||
|
year = ''
|
||||||
|
} else {
|
||||||
|
// 6位或7位格式:秒 分钟 小时 日 月 星期 [年]
|
||||||
|
second = parts[0]
|
||||||
|
minute = parts[1]
|
||||||
|
hour = parts[2]
|
||||||
|
day = parts[3]
|
||||||
|
month = parts[4]
|
||||||
|
week = parts[5]
|
||||||
|
year = parts[6] || ''
|
||||||
|
}
|
||||||
|
|
||||||
// 格式化时间(时分秒)
|
// 格式化时间(时分秒)
|
||||||
const formatTime = (h, m, s) => {
|
const formatTime = (h, m, s) => {
|
||||||
|
|
@ -539,7 +559,6 @@ const parseCronToChinese = (cronExpression) => {
|
||||||
|
|
||||||
// 特殊情况1:每天固定时间执行(最常用)
|
// 特殊情况1:每天固定时间执行(最常用)
|
||||||
if (
|
if (
|
||||||
second !== '?' &&
|
|
||||||
minute !== '?' &&
|
minute !== '?' &&
|
||||||
hour !== '?' &&
|
hour !== '?' &&
|
||||||
day === '*' &&
|
day === '*' &&
|
||||||
|
|
@ -547,11 +566,11 @@ const parseCronToChinese = (cronExpression) => {
|
||||||
week === '?' &&
|
week === '?' &&
|
||||||
(!year || year === '*')
|
(!year || year === '*')
|
||||||
) {
|
) {
|
||||||
const s = getSingleValue(second)
|
const s = second === '?' ? '0' : getSingleValue(second)
|
||||||
const m = getSingleValue(minute)
|
const m = getSingleValue(minute)
|
||||||
const h = getSingleValue(hour)
|
const h = getSingleValue(hour)
|
||||||
|
|
||||||
if (!hasStep(second) && !hasStep(minute) && !hasStep(hour)) {
|
if (!hasStep(minute) && !hasStep(hour)) {
|
||||||
let result = `每天${formatTime(h, m, s)}执行`
|
let result = `每天${formatTime(h, m, s)}执行`
|
||||||
// 清理所有可能的*符号
|
// 清理所有可能的*符号
|
||||||
result = result.replace(/(\d)\*/g, '$10').replace(/\*/g, '0')
|
result = result.replace(/(\d)\*/g, '$10').replace(/\*/g, '0')
|
||||||
|
|
@ -561,7 +580,6 @@ const parseCronToChinese = (cronExpression) => {
|
||||||
|
|
||||||
// 特殊情况2:每周固定时间执行
|
// 特殊情况2:每周固定时间执行
|
||||||
if (
|
if (
|
||||||
second !== '?' &&
|
|
||||||
minute !== '?' &&
|
minute !== '?' &&
|
||||||
hour !== '?' &&
|
hour !== '?' &&
|
||||||
day === '?' &&
|
day === '?' &&
|
||||||
|
|
@ -570,12 +588,12 @@ const parseCronToChinese = (cronExpression) => {
|
||||||
week !== '*' &&
|
week !== '*' &&
|
||||||
(!year || year === '*')
|
(!year || year === '*')
|
||||||
) {
|
) {
|
||||||
const s = getSingleValue(second)
|
const s = second === '?' ? '0' : getSingleValue(second)
|
||||||
const m = getSingleValue(minute)
|
const m = getSingleValue(minute)
|
||||||
const h = getSingleValue(hour)
|
const h = getSingleValue(hour)
|
||||||
const weekDesc = parseWeek(week)
|
const weekDesc = parseWeek(week)
|
||||||
|
|
||||||
if (!hasStep(second) && !hasStep(minute) && !hasStep(hour)) {
|
if (!hasStep(minute) && !hasStep(hour)) {
|
||||||
let result = `${weekDesc},${formatTime(h, m, s)}执行`
|
let result = `${weekDesc},${formatTime(h, m, s)}执行`
|
||||||
// 清理所有可能的*符号
|
// 清理所有可能的*符号
|
||||||
result = result.replace(/(\d)\*/g, '$10').replace(/\*/g, '0')
|
result = result.replace(/(\d)\*/g, '$10').replace(/\*/g, '0')
|
||||||
|
|
@ -585,7 +603,6 @@ const parseCronToChinese = (cronExpression) => {
|
||||||
|
|
||||||
// 特殊情况3:每月固定日期执行
|
// 特殊情况3:每月固定日期执行
|
||||||
if (
|
if (
|
||||||
second !== '?' &&
|
|
||||||
minute !== '?' &&
|
minute !== '?' &&
|
||||||
hour !== '?' &&
|
hour !== '?' &&
|
||||||
day !== '*' &&
|
day !== '*' &&
|
||||||
|
|
@ -594,12 +611,12 @@ const parseCronToChinese = (cronExpression) => {
|
||||||
week === '?' &&
|
week === '?' &&
|
||||||
(!year || year === '*')
|
(!year || year === '*')
|
||||||
) {
|
) {
|
||||||
const s = getSingleValue(second)
|
const s = second === '?' ? '0' : getSingleValue(second)
|
||||||
const m = getSingleValue(minute)
|
const m = getSingleValue(minute)
|
||||||
const h = getSingleValue(hour)
|
const h = getSingleValue(hour)
|
||||||
const dayDesc = parseDay(day)
|
const dayDesc = parseDay(day)
|
||||||
|
|
||||||
if (!hasStep(second) && !hasStep(minute) && !hasStep(hour)) {
|
if (!hasStep(minute) && !hasStep(hour)) {
|
||||||
let result = `${dayDesc},${formatTime(h, m, s)}执行`
|
let result = `${dayDesc},${formatTime(h, m, s)}执行`
|
||||||
// 清理所有可能的*符号
|
// 清理所有可能的*符号
|
||||||
result = result.replace(/(\d)\*/g, '$10').replace(/\*/g, '0')
|
result = result.replace(/(\d)\*/g, '$10').replace(/\*/g, '0')
|
||||||
|
|
@ -609,7 +626,6 @@ const parseCronToChinese = (cronExpression) => {
|
||||||
|
|
||||||
// 特殊情况4:每年固定日期时间执行
|
// 特殊情况4:每年固定日期时间执行
|
||||||
if (
|
if (
|
||||||
second !== '?' &&
|
|
||||||
minute !== '?' &&
|
minute !== '?' &&
|
||||||
hour !== '?' &&
|
hour !== '?' &&
|
||||||
day !== '*' &&
|
day !== '*' &&
|
||||||
|
|
@ -618,13 +634,13 @@ const parseCronToChinese = (cronExpression) => {
|
||||||
week === '?' &&
|
week === '?' &&
|
||||||
(!year || year === '*' || year === '')
|
(!year || year === '*' || year === '')
|
||||||
) {
|
) {
|
||||||
const s = getSingleValue(second)
|
const s = second === '?' ? '0' : getSingleValue(second)
|
||||||
const m = getSingleValue(minute)
|
const m = getSingleValue(minute)
|
||||||
const h = getSingleValue(hour)
|
const h = getSingleValue(hour)
|
||||||
const dayDesc = parseDay(day, true) // 每年模式,不显示"每月"
|
const dayDesc = parseDay(day, true) // 每年模式,不显示"每月"
|
||||||
const monthDesc = parseMonth(month)
|
const monthDesc = parseMonth(month)
|
||||||
|
|
||||||
if (!hasStep(second) && !hasStep(minute) && !hasStep(hour)) {
|
if (!hasStep(minute) && !hasStep(hour)) {
|
||||||
let result = `每年${monthDesc}${dayDesc},${formatTime(h, m, s)}执行`
|
let result = `每年${monthDesc}${dayDesc},${formatTime(h, m, s)}执行`
|
||||||
// 清理所有可能的*符号
|
// 清理所有可能的*符号
|
||||||
result = result.replace(/(\d)\*/g, '$10').replace(/\*/g, '0')
|
result = result.replace(/(\d)\*/g, '$10').replace(/\*/g, '0')
|
||||||
|
|
@ -679,11 +695,12 @@ const parseCronToChinese = (cronExpression) => {
|
||||||
timeParts.push('**')
|
timeParts.push('**')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (second !== '*' && !hasStep(second)) {
|
// 秒字段:如果是5位格式或秒为?,默认为00
|
||||||
|
if (second && second !== '*' && second !== '?' && !hasStep(second)) {
|
||||||
const s = getSingleValue(second)
|
const s = getSingleValue(second)
|
||||||
timeParts.push(s.padStart(2, '0'))
|
timeParts.push(s.padStart(2, '0'))
|
||||||
} else {
|
} else {
|
||||||
timeParts.push('**')
|
timeParts.push('00') // 默认秒为00
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果时间部分有具体值,添加到描述中
|
// 如果时间部分有具体值,添加到描述中
|
||||||
|
|
@ -704,22 +721,16 @@ const parseCronToChinese = (cronExpression) => {
|
||||||
const step = minute.split('/')[1]
|
const step = minute.split('/')[1]
|
||||||
partsDesc.push(`每${step}分钟`)
|
partsDesc.push(`每${step}分钟`)
|
||||||
}
|
}
|
||||||
if (second.includes('/') && second.split('/')[0] === '*') {
|
// 秒的步长表达式只在6/7位格式中处理
|
||||||
|
if (second && second.includes('/') && second.split('/')[0] === '*') {
|
||||||
const step = second.split('/')[1]
|
const step = second.split('/')[1]
|
||||||
partsDesc.push(`每${step}秒`)
|
partsDesc.push(`每${step}秒`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构建最终描述
|
// 构建最终描述
|
||||||
if (partsDesc.length === 0) {
|
if (partsDesc.length === 0) {
|
||||||
if (
|
if (minute === '*' && hour === '*' && day === '*' && month === '*' && week === '?') {
|
||||||
second === '*' &&
|
return '每分钟执行'
|
||||||
minute === '*' &&
|
|
||||||
hour === '*' &&
|
|
||||||
day === '*' &&
|
|
||||||
month === '*' &&
|
|
||||||
week === '?'
|
|
||||||
) {
|
|
||||||
return '每秒执行'
|
|
||||||
}
|
}
|
||||||
return `Cron表达式:${cronExpression}`
|
return `Cron表达式:${cronExpression}`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue