refactor(Crontab): 重构vue3版本

- 优化了 radioValue 的赋值方式,使用 :value 替代 label
- 调整了 input-number 和 select 组件的样式,增加空格和对齐
- 重构了计算逻辑,简化了 cycleTotal、averageTotal 等计算属性
- 优化了 watch 监听和 radio 变化处理逻辑
- 新增 changeRadioValue 函数处理 radio 值的变化
- 统一了 emit 方法的调用方式
master
zch 1 week ago
parent b6ad3ffb3b
commit c068f8ce8e

@ -1,171 +1,174 @@
<template> <template>
<el-form size="small"> <el-form>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="1"> <el-radio v-model='radioValue' :value="1">
允许的通配符[, - * ? / L W] 允许的通配符[, - * ? / L W]
</el-radio> </el-radio>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="2"> <el-radio v-model='radioValue' :value="2">
不指定 不指定
</el-radio> </el-radio>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="3"> <el-radio v-model='radioValue' :value="3">
周期从 周期从
<el-input-number v-model='cycle01' :min="1" :max="30" /> - <el-input-number v-model='cycle01' :min="1" :max="30" /> -
<el-input-number v-model='cycle02' :min="cycle01 ? cycle01 + 1 : 2" :max="31" /> <el-input-number v-model='cycle02' :min="cycle01 + 1" :max="31" />
</el-radio> </el-radio>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="4"> <el-radio v-model='radioValue' :value="4">
<el-input-number v-model='average01' :min="1" :max="30" /> 号开始 <el-input-number v-model='average01' :min="1" :max="30" /> 号开始
<el-input-number v-model='average02' :min="1" :max="31 - average01 || 1" /> 日执行一次 <el-input-number v-model='average02' :min="1" :max="31 - average01" /> 日执行一次
</el-radio> </el-radio>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="5"> <el-radio v-model='radioValue' :value="5">
每月 每月
<el-input-number v-model='workday' :min="1" :max="31" /> 号最近的那个工作日 <el-input-number v-model='workday' :min="1" :max="31" /> 号最近的那个工作日
</el-radio> </el-radio>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="6"> <el-radio v-model='radioValue' :value="6">
本月最后一天 本月最后一天
</el-radio> </el-radio>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="7"> <el-radio v-model='radioValue' :value="7">
指定 指定
<el-select clearable v-model="checkboxList" placeholder="可多选" multiple style="width:100%"> <el-select clearable v-model="checkboxList" placeholder="可多选" multiple :multiple-limit="10">
<el-option v-for="item in 31" :key="item" :value="item">{{item}}</el-option> <el-option v-for="item in 31" :key="item" :label="item" :value="item" />
</el-select> </el-select>
</el-radio> </el-radio>
</el-form-item> </el-form-item>
</el-form> </el-form>
</template> </template>
<script setup>
<script setup lang="ts" name="CrontabDay"> const emit = defineEmits(['update'])
import { ref, computed, watch, defineProps, defineEmits } from 'vue';
const props = defineProps({ const props = defineProps({
check: {
type: Function,
required: true
},
cron: { cron: {
type: Object, type: Object,
default: () => ({}) default: {
second: "*",
min: "*",
hour: "*",
day: "*",
month: "*",
week: "?",
year: "",
} }
}); },
check: {
const emit = defineEmits(['update']); type: Function,
default: () => {
const radioValue = ref(1); }
const workday = ref(1); }
const cycle01 = ref(1); })
const cycle02 = ref(2); const radioValue = ref(1)
const average01 = ref(1); const cycle01 = ref(1)
const average02 = ref(1); const cycle02 = ref(2)
const checkboxList = ref([]); const average01 = ref(1)
const average02 = ref(1)
// const workday = ref(1)
const checkboxList = ref([])
const checkCopy = ref([1])
const cycleTotal = computed(() => { const cycleTotal = computed(() => {
const cycleVal01 = props.check(cycle01.value, 1, 30); cycle01.value = props.check(cycle01.value, 1, 30)
const cycleVal02 = props.check(cycle02.value, cycleVal01 ? cycleVal01 + 1 : 2, 31, 31); cycle02.value = props.check(cycle02.value, cycle01.value + 1, 31)
return `${cycleVal01}-${cycleVal02}`; return cycle01.value + '-' + cycle02.value
}); })
//
const averageTotal = computed(() => { const averageTotal = computed(() => {
const averageVal01 = props.check(average01.value, 1, 30); average01.value = props.check(average01.value, 1, 30)
const averageVal02 = props.check(average02.value, 1, 31 - averageVal01 || 0); average02.value = props.check(average02.value, 1, 31 - average01.value)
return `${averageVal01}/${averageVal02}`; return average01.value + '/' + average02.value
}); })
const workdayTotal = computed(() => {
// workday.value = props.check(workday.value, 1, 31)
const workdayCheck = computed(() => { return workday.value + 'W'
return props.check(workday.value, 1, 31); })
});
// checkbox
const checkboxString = computed(() => { const checkboxString = computed(() => {
let str = checkboxList.value.join(); return checkboxList.value.join(',')
return str === '' ? '*' : str; })
}); watch(() => props.cron.day, value => changeRadioValue(value))
watch([radioValue, cycleTotal, averageTotal, workdayTotal, checkboxString], () => onRadioChange())
function changeRadioValue(value) {
if (value === "*") {
radioValue.value = 1
} else if (value === "?") {
radioValue.value = 2
} else if (value.indexOf("-") > -1) {
const indexArr = value.split('-')
cycle01.value = Number(indexArr[0])
cycle02.value = Number(indexArr[1])
radioValue.value = 3
} else if (value.indexOf("/") > -1) {
const indexArr = value.split('/')
average01.value = Number(indexArr[0])
average02.value = Number(indexArr[1])
radioValue.value = 4
} else if (value.indexOf("W") > -1) {
const indexArr = value.split("W")
workday.value = Number(indexArr[0])
radioValue.value = 5
} else if (value === "L") {
radioValue.value = 6
} else {
checkboxList.value = [...new Set(value.split(',').map(item => Number(item)))]
radioValue.value = 7
}
}
// //
const radioChange = () => { function onRadioChange() {
console.log('day rachange'); if (radioValue.value === 2 && props.cron.week === '?') {
emit('update', 'week', '*', 'day')
}
if (radioValue.value !== 2 && props.cron.week !== '?') { if (radioValue.value !== 2 && props.cron.week !== '?') {
emit('update', 'week', '?', 'day'); emit('update', 'week', '?', 'day')
} }
switch (radioValue.value) { switch (radioValue.value) {
case 1: case 1:
emit('update', 'day', '*'); emit('update', 'day', '*', 'day')
break; break
case 2: case 2:
emit('update', 'day', '?'); emit('update', 'day', '?', 'day')
break; break
case 3: case 3:
emit('update', 'day', cycleTotal.value); emit('update', 'day', cycleTotal.value, 'day')
break; break
case 4: case 4:
emit('update', 'day', averageTotal.value); emit('update', 'day', averageTotal.value, 'day')
break; break
case 5: case 5:
emit('update', 'day', workdayCheck.value + 'W'); emit('update', 'day', workdayTotal.value, 'day')
break; break
case 6: case 6:
emit('update', 'day', 'L'); emit('update', 'day', 'L', 'day')
break; break
case 7: case 7:
emit('update', 'day', checkboxString.value); if (checkboxList.value.length === 0) {
break; checkboxList.value.push(checkCopy.value[0])
} } else {
console.log('day rachange end'); checkCopy.value = checkboxList.value
};
//
const cycleChange = () => {
if (radioValue.value === 3) {
emit('update', 'day', cycleTotal.value);
} }
}; emit('update', 'day', checkboxString.value, 'day')
break
//
const averageChange = () => {
if (radioValue.value === 4) {
emit('update', 'day', averageTotal.value);
}
};
//
const workdayChange = () => {
if (radioValue.value === 5) {
emit('update', 'day', workdayCheck.value + 'W');
} }
}; }
// checkbox
const checkboxChange = () => {
if (radioValue.value === 7) {
emit('update', 'day', checkboxString.value);
}
};
//
watch(() => radioValue.value, radioChange);
watch(() => cycleTotal.value, cycleChange);
watch(() => averageTotal.value, averageChange);
watch(() => workdayCheck.value, workdayChange);
watch(() => checkboxString.value, checkboxChange);
</script> </script>
<style lang="scss" scoped>
.el-input-number--small, .el-select, .el-select--small {
margin: 0 0.2rem;
}
.el-select, .el-select--small {
width: 18.8rem;
}
</style>

@ -1,123 +1,133 @@
<template> <template>
<el-form size="small"> <el-form>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="1"> <el-radio v-model='radioValue' :value="1">
小时允许的通配符[, - * /] 小时允许的通配符[, - * /]
</el-radio> </el-radio>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="2"> <el-radio v-model='radioValue' :value="2">
周期从 周期从
<el-input-number v-model='cycle01' :min="0" :max="22" /> - <el-input-number v-model='cycle01' :min="0" :max="22" /> -
<el-input-number v-model='cycle02' :min="cycle01 ? cycle01 + 1 : 1" :max="23" /> <el-input-number v-model='cycle02' :min="cycle01 + 1" :max="23" />
</el-radio> </el-radio>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="3"> <el-radio v-model='radioValue' :value="3">
<el-input-number v-model='average01' :min="0" :max="22" /> 时开始 <el-input-number v-model='average01' :min="0" :max="22" /> 时开始
<el-input-number v-model='average02' :min="1" :max="23 - average01 || 0" /> 小时执行一次 <el-input-number v-model='average02' :min="1" :max="23 - average01" /> 小时执行一次
</el-radio> </el-radio>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="4"> <el-radio v-model='radioValue' :value="4">
指定 指定
<el-select clearable v-model="checkboxList" placeholder="可多选" multiple style="width:100%"> <el-select clearable v-model="checkboxList" placeholder="可多选" multiple :multiple-limit="10">
<el-option v-for="item in 24" :key="item" :value="item-1">{{item-1}}</el-option> <el-option v-for="item in 24" :key="item" :label="item - 1" :value="item - 1" />
</el-select> </el-select>
</el-radio> </el-radio>
</el-form-item> </el-form-item>
</el-form> </el-form>
</template> </template>
<script setup lang="ts" name="CrontabHour"> <script setup>
import { ref, computed, watch, defineProps, defineEmits } from 'vue'; const emit = defineEmits(['update'])
const props = defineProps({ const props = defineProps({
check: {
type: Function,
required: true
},
cron: { cron: {
type: Object, type: Object,
default: () => ({}) default: {
second: "*",
min: "*",
hour: "*",
day: "*",
month: "*",
week: "?",
year: "",
} }
}); },
check: {
const emit = defineEmits(['update']); type: Function,
default: () => {
const radioValue = ref(1); }
const cycle01 = ref(0); }
const cycle02 = ref(1); })
const average01 = ref(0); const radioValue = ref(1)
const average02 = ref(1); const cycle01 = ref(0)
const checkboxList = ref([]); const cycle02 = ref(1)
const average01 = ref(0)
// const average02 = ref(1)
const checkboxList = ref([])
const checkCopy = ref([0])
const cycleTotal = computed(() => { const cycleTotal = computed(() => {
const cycleVal01 = props.check(cycle01.value, 0, 22); cycle01.value = props.check(cycle01.value, 0, 22)
const cycleVal02 = props.check(cycle02.value, cycleVal01 ? cycleVal01 + 1 : 1, 23); cycle02.value = props.check(cycle02.value, cycle01.value + 1, 23)
return `${cycleVal01}-${cycleVal02}`; return cycle01.value + '-' + cycle02.value
}); })
//
const averageTotal = computed(() => { const averageTotal = computed(() => {
const averageVal01 = props.check(average01.value, 0, 22); average01.value = props.check(average01.value, 0, 22)
const averageVal02 = props.check(average02.value, 1, 23 - averageVal01 || 0); average02.value = props.check(average02.value, 1, 23 - average01.value)
return `${averageVal01}/${averageVal02}`; return average01.value + '/' + average02.value
}); })
// checkbox
const checkboxString = computed(() => { const checkboxString = computed(() => {
let str = checkboxList.value.join(); return checkboxList.value.join(',')
return str === '' ? '*' : str; })
}); watch(() => props.cron.hour, value => changeRadioValue(value))
watch([radioValue, cycleTotal, averageTotal, checkboxString], () => onRadioChange())
// function changeRadioValue(value) {
const radioChange = () => { if (props.cron.min === '*') {
emit('update', 'min', '0', 'hour');
}
if (props.cron.second === '*') {
emit('update', 'second', '0', 'hour');
}
if (value === '*') {
radioValue.value = 1
} else if (value.indexOf('-') > -1) {
const indexArr = value.split('-')
cycle01.value = Number(indexArr[0])
cycle02.value = Number(indexArr[1])
radioValue.value = 2
} else if (value.indexOf('/') > -1) {
const indexArr = value.split('/')
average01.value = Number(indexArr[0])
average02.value = Number(indexArr[1])
radioValue.value = 3
} else {
checkboxList.value = [...new Set(value.split(',').map(item => Number(item)))]
radioValue.value = 4
}
}
function onRadioChange() {
switch (radioValue.value) { switch (radioValue.value) {
case 1: case 1:
emit('update', 'hour', '*'); emit('update', 'hour', '*', 'hour')
break; break
case 2: case 2:
emit('update', 'hour', cycleTotal.value); emit('update', 'hour', cycleTotal.value, 'hour')
break; break
case 3: case 3:
emit('update', 'hour', averageTotal.value); emit('update', 'hour', averageTotal.value, 'hour')
break; break
case 4: case 4:
emit('update', 'hour', checkboxString.value); if (checkboxList.value.length === 0) {
break; checkboxList.value.push(checkCopy.value[0])
} } else {
}; checkCopy.value = checkboxList.value
//
const cycleChange = () => {
if (radioValue.value === 2) {
emit('update', 'hour', cycleTotal.value);
}
};
//
const averageChange = () => {
if (radioValue.value === 3) {
emit('update', 'hour', averageTotal.value);
} }
}; emit('update', 'hour', checkboxString.value, 'hour')
break
// checkbox
const checkboxChange = () => {
if (radioValue.value === 4) {
emit('update', 'hour', checkboxString.value);
} }
}; }
//
watch(() => radioValue.value, radioChange);
watch(() => cycleTotal.value, cycleChange);
watch(() => averageTotal.value, averageChange);
watch(() => checkboxString.value, checkboxChange);
</script> </script>
<style lang="scss" scoped>
.el-input-number--small, .el-select, .el-select--small {
margin: 0 0.2rem;
}
.el-select, .el-select--small {
width: 18.8rem;
}
</style>

@ -70,33 +70,41 @@
<p class="title">时间表达式</p> <p class="title">时间表达式</p>
<table> <table>
<thead> <thead>
<th v-for="item of tabTitles" width="40" :key="item">{{item}}</th> <th v-for="item of tabTitles" :key="item">{{item}}</th>
<th>Cron 表达式</th> <th>Cron 表达式</th>
</thead> </thead>
<tbody> <tbody>
<td> <td>
<span>{{crontabValueObj.second}}</span> <span v-if="crontabValueObj.second.length < 10">{{crontabValueObj.second}}</span>
<el-tooltip v-else :content="crontabValueObj.second" placement="top"><span>{{crontabValueObj.second}}</span></el-tooltip>
</td> </td>
<td> <td>
<span>{{crontabValueObj.min}}</span> <span v-if="crontabValueObj.min.length < 10">{{crontabValueObj.min}}</span>
<el-tooltip v-else :content="crontabValueObj.min" placement="top"><span>{{crontabValueObj.min}}</span></el-tooltip>
</td> </td>
<td> <td>
<span>{{crontabValueObj.hour}}</span> <span v-if="crontabValueObj.hour.length < 10">{{crontabValueObj.hour}}</span>
<el-tooltip v-else :content="crontabValueObj.hour" placement="top"><span>{{crontabValueObj.hour}}</span></el-tooltip>
</td> </td>
<td> <td>
<span>{{crontabValueObj.day}}</span> <span v-if="crontabValueObj.day.length < 10">{{crontabValueObj.day}}</span>
<el-tooltip v-else :content="crontabValueObj.day" placement="top"><span>{{crontabValueObj.day}}</span></el-tooltip>
</td> </td>
<td> <td>
<span>{{crontabValueObj.month}}</span> <span v-if="crontabValueObj.month.length < 10">{{crontabValueObj.month}}</span>
<el-tooltip v-else :content="crontabValueObj.month" placement="top"><span>{{crontabValueObj.month}}</span></el-tooltip>
</td> </td>
<td> <td>
<span>{{crontabValueObj.week}}</span> <span v-if="crontabValueObj.week.length < 10">{{crontabValueObj.week}}</span>
<el-tooltip v-else :content="crontabValueObj.week" placement="top"><span>{{crontabValueObj.week}}</span></el-tooltip>
</td> </td>
<td> <td>
<span>{{crontabValueObj.year}}</span> <span v-if="crontabValueObj.year.length < 10">{{crontabValueObj.year}}</span>
<el-tooltip v-else :content="crontabValueObj.year" placement="top"><span>{{crontabValueObj.year}}</span></el-tooltip>
</td> </td>
<td> <td class="result">
<span>{{crontabValueString}}</span> <span v-if="crontabValueString.length < 90">{{crontabValueString}}</span>
<el-tooltip v-else :content="crontabValueString" placement="top"><span>{{crontabValueString}}</span></el-tooltip>
</td> </td>
</tbody> </tbody>
</table> </table>
@ -104,43 +112,40 @@
<CrontabResult :ex="crontabValueString"></CrontabResult> <CrontabResult :ex="crontabValueString"></CrontabResult>
<div class="pop_btn"> <div class="pop_btn">
<el-button size="small" type="primary" @click="submitFill"></el-button> <el-button type="primary" @click="submitFill"></el-button>
<el-button size="small" type="warning" @click="clearCron"></el-button> <el-button type="warning" @click="clearCron"></el-button>
<el-button size="small" @click="hidePopup"></el-button> <el-button @click="hidePopup"></el-button>
</div> </div>
</div> </div>
</div> </div>
</template> </template>
<script setup lang="ts" name="Crontab"> <script setup>
import { ref, reactive, computed, watch, onMounted } from 'vue'; import CrontabSecond from "./second.vue"
import CrontabSecond from "./second.vue"; import CrontabMin from "./min.vue"
import CrontabMin from "./min.vue"; import CrontabHour from "./hour.vue"
import CrontabHour from "./hour.vue"; import CrontabDay from "./day.vue"
import CrontabDay from "./day.vue"; import CrontabMonth from "./month.vue"
import CrontabMonth from "./month.vue"; import CrontabWeek from "./week.vue"
import CrontabWeek from "./week.vue"; import CrontabYear from "./year.vue"
import CrontabYear from "./year.vue"; import CrontabResult from "./result.vue"
import CrontabResult from "./result.vue"; const { proxy } = getCurrentInstance()
const emit = defineEmits(['hide', 'fill'])
const props = defineProps({ const props = defineProps({
hideComponent: {
type: Array,
default: () => [],
},
expression: { expression: {
type: String, type: String,
default: '' default: ""
}, }
hideComponent: { })
type: Array as () => string[], const tabTitles = ref(["秒", "分钟", "小时", "日", "月", "周", "年"])
default: () => [] const tabActive = ref(0)
} const hideComponent = ref([])
}); const expression = ref('')
const crontabValueObj = ref({
const emit = defineEmits(['hide', 'fill']);
const tabTitles = ref(["秒", "分钟", "小时", "日", "月", "周", "年"]);
const tabActive = ref(0);
const myindex = ref(0);
const crontabValueObj = reactive({
second: "*", second: "*",
min: "*", min: "*",
hour: "*", hour: "*",
@ -148,242 +153,81 @@ const crontabValueObj = reactive({
month: "*", month: "*",
week: "?", week: "?",
year: "", year: "",
}); })
const crontabValueString = computed(() => {
const cronsecond = ref(null); const obj = crontabValueObj.value
const cronmin = ref(null); return obj.second
const cronhour = ref(null); + " "
const cronday = ref(null); + obj.min
const cronmonth = ref(null); + " "
const cronweek = ref(null); + obj.hour
const cronyear = ref(null); + " "
+ obj.day
// + " "
const shouldHide = (key: string) => { + obj.month
if (props.hideComponent && props.hideComponent.includes(key)) { + " "
return false; + obj.week
} + (obj.year === "" ? "" : " " + obj.year)
return true; })
}; watch(expression, () => resolveExp())
function shouldHide(key) {
// return !(hideComponent.value && hideComponent.value.includes(key))
const resolveExp = () => { }
// function resolveExp() {
if (props.expression) { //
const arr = props.expression.split(" "); if (expression.value) {
const arr = expression.value.split(/\s+/)
if (arr.length >= 6) { if (arr.length >= 6) {
// 6 //6
const obj = { let obj = {
second: arr[0], second: arr[0],
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] : "", year: arr[6] ? arr[6] : ""
};
Object.assign(crontabValueObj, obj);
for (let i in obj) {
if (obj[i]) {
changeRadio(i, obj[i]);
} }
crontabValueObj.value = {
...obj,
} }
} }
} else { } else {
// //
clearCron(); clearCron()
} }
}; }
// tab // tab
const tabCheck = (index: number) => { function tabCheck(index) {
tabActive.value = index; tabActive.value = index
}; }
// //
const updateCrontabValue = (name: string, value: string, from?: string) => { function updateCrontabValue(name, value, from) {
console.log("updateCrontabValue", name, value, from); crontabValueObj.value[name] = value
crontabValueObj[name] = value; }
if (from && from !== name) { // -props
console.log(`来自组件 ${from} 改变了 ${name} ${value}`); function checkNumber(value, minLimit, maxLimit) {
changeRadio(name, value);
}
};
// ref
const getRefComponent = (refName: string) => {
switch(refName) {
case 'cronsecond': return cronsecond.value;
case 'cronmin': return cronmin.value;
case 'cronhour': return cronhour.value;
case 'cronday': return cronday.value;
case 'cronmonth': return cronmonth.value;
case 'cronweek': return cronweek.value;
case 'cronyear': return cronyear.value;
default: return null;
}
};
//
const changeRadio = (name: string, value: string) => {
const arr = ["second", "min", "hour", "month"];
const refName = "cron" + name;
let insValue;
const refComponent = getRefComponent(refName);
if (!refComponent) return;
if (arr.includes(name)) {
if (value === "*") {
insValue = 1;
} else if (value.indexOf("-") > -1) {
const indexArr = value.split("-");
if (refComponent.cycle01 !== undefined) {
refComponent.cycle01 = isNaN(parseInt(indexArr[0])) ? 0 : parseInt(indexArr[0]);
}
if (refComponent.cycle02 !== undefined) {
refComponent.cycle02 = parseInt(indexArr[1]);
}
insValue = 2;
} else if (value.indexOf("/") > -1) {
const indexArr = value.split("/");
if (refComponent.average01 !== undefined) {
refComponent.average01 = isNaN(parseInt(indexArr[0])) ? 0 : parseInt(indexArr[0]);
}
if (refComponent.average02 !== undefined) {
refComponent.average02 = parseInt(indexArr[1]);
}
insValue = 3;
} else {
insValue = 4;
if (refComponent.checkboxList !== undefined) {
refComponent.checkboxList = value.split(",");
}
}
} else if (name == "day") {
if (value === "*") {
insValue = 1;
} else if (value == "?") {
insValue = 2;
} else if (value.indexOf("-") > -1) {
const indexArr = value.split("-");
if (refComponent.cycle01 !== undefined) {
refComponent.cycle01 = isNaN(parseInt(indexArr[0])) ? 0 : parseInt(indexArr[0]);
}
if (refComponent.cycle02 !== undefined) {
refComponent.cycle02 = parseInt(indexArr[1]);
}
insValue = 3;
} else if (value.indexOf("/") > -1) {
const indexArr = value.split("/");
if (refComponent.average01 !== undefined) {
refComponent.average01 = isNaN(parseInt(indexArr[0])) ? 0 : parseInt(indexArr[0]);
}
if (refComponent.average02 !== undefined) {
refComponent.average02 = parseInt(indexArr[1]);
}
insValue = 4;
} else if (value.indexOf("W") > -1) {
const indexArr = value.split("W");
if (refComponent.workday !== undefined) {
refComponent.workday = isNaN(parseInt(indexArr[0])) ? 0 : parseInt(indexArr[0]);
}
insValue = 5;
} else if (value === "L") {
insValue = 6;
} else {
if (refComponent.checkboxList !== undefined) {
refComponent.checkboxList = value.split(",");
}
insValue = 7;
}
} else if (name == "week") {
if (value === "*") {
insValue = 1;
} else if (value == "?") {
insValue = 2;
} else if (value.indexOf("-") > -1) {
const indexArr = value.split("-");
if (refComponent.cycle01 !== undefined) {
refComponent.cycle01 = isNaN(parseInt(indexArr[0])) ? 0 : parseInt(indexArr[0]);
}
if (refComponent.cycle02 !== undefined) {
refComponent.cycle02 = parseInt(indexArr[1]);
}
insValue = 3;
} else if (value.indexOf("#") > -1) {
const indexArr = value.split("#");
if (refComponent.average01 !== undefined) {
refComponent.average01 = isNaN(parseInt(indexArr[1])) ? 1 : parseInt(indexArr[1]);
}
if (refComponent.average02 !== undefined) {
refComponent.average02 = parseInt(indexArr[0]);
}
insValue = 4;
} else if (value.indexOf("L") > -1) {
const indexArr = value.split("L");
if (refComponent.weekday !== undefined) {
refComponent.weekday = isNaN(parseInt(indexArr[0])) ? 1 : parseInt(indexArr[0]);
}
insValue = 5;
} else {
if (refComponent.checkboxList !== undefined) {
refComponent.checkboxList = value.split(",");
}
insValue = 6;
}
} else if (name == "year") {
if (value == "") {
insValue = 1;
} else if (value == "*") {
insValue = 2;
} else if (value.indexOf("-") > -1) {
insValue = 3;
} else if (value.indexOf("/") > -1) {
insValue = 4;
} else {
if (refComponent.checkboxList !== undefined) {
refComponent.checkboxList = value.split(",");
}
insValue = 5;
}
}
if (refComponent.radioValue !== undefined) {
refComponent.radioValue = insValue;
}
};
//
const checkNumber = (value: number, minLimit: number, maxLimit: number): number => {
// //
value = Math.floor(value); value = Math.floor(value)
if (value < minLimit) { if (value < minLimit) {
value = minLimit; value = minLimit
} else if (value > maxLimit) { } else if (value > maxLimit) {
value = maxLimit; value = maxLimit
} }
return value; return value
}; }
// //
const hidePopup = () => { function hidePopup() {
emit("hide"); emit("hide")
}; }
// //
const submitFill = () => { function submitFill() {
emit("fill", crontabValueString.value); emit("fill", crontabValueString.value)
hidePopup(); hidePopup()
}; }
function clearCron() {
//
const clearCron = () => {
// //
console.log("准备还原"); crontabValueObj.value = {
Object.assign(crontabValueObj, {
second: "*", second: "*",
min: "*", min: "*",
hour: "*", hour: "*",
@ -391,44 +235,15 @@ const clearCron = () => {
month: "*", month: "*",
week: "?", week: "?",
year: "", year: "",
});
for (let j in crontabValueObj) {
changeRadio(j, crontabValueObj[j]);
} }
}; }
// cron
const crontabValueString = computed(() => {
const obj = crontabValueObj;
const str =
obj.second +
" " +
obj.min +
" " +
obj.hour +
" " +
obj.day +
" " +
obj.month +
" " +
obj.week +
(obj.year == "" ? "" : " " + obj.year);
return str;
});
// props
watch(() => props.expression, resolveExp);
watch(() => props.hideComponent, (value) => {
//
});
//
onMounted(() => { onMounted(() => {
resolveExp(); expression.value = props.expression
}); hideComponent.value = props.hideComponent
})
</script> </script>
<style scoped>
<style lang="scss" scoped>
.pop_btn { .pop_btn {
text-align: center; text-align: center;
margin-top: 20px; margin-top: 20px;
@ -436,7 +251,6 @@ onMounted(() => {
.popup-main { .popup-main {
position: relative; position: relative;
margin: 10px auto; margin: 10px auto;
background: #fff;
border-radius: 5px; border-radius: 5px;
font-size: 12px; font-size: 12px;
overflow: hidden; overflow: hidden;
@ -471,6 +285,11 @@ onMounted(() => {
width: 100%; width: 100%;
margin: 0 auto; margin: 0 auto;
} }
.popup-result table td:not(.result) {
width: 3.5rem;
min-width: 3.5rem;
max-width: 3.5rem;
}
.popup-result table span { .popup-result table span {
display: block; display: block;
width: 100%; width: 100%;

@ -1,124 +1,126 @@
<template> <template>
<el-form size="small"> <el-form>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="1"> <el-radio v-model='radioValue' :value="1">
分钟允许的通配符[, - * /] 分钟允许的通配符[, - * /]
</el-radio> </el-radio>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="2"> <el-radio v-model='radioValue' :value="2">
周期从 周期从
<el-input-number v-model='cycle01' :min="0" :max="58" /> - <el-input-number v-model='cycle01' :min="0" :max="58" /> -
<el-input-number v-model='cycle02' :min="cycle01 ? cycle01 + 1 : 1" :max="59" /> 分钟 <el-input-number v-model='cycle02' :min="cycle01 + 1" :max="59" /> 分钟
</el-radio> </el-radio>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="3"> <el-radio v-model='radioValue' :value="3">
<el-input-number v-model='average01' :min="0" :max="58" /> 分钟开始 <el-input-number v-model='average01' :min="0" :max="58" /> 分钟开始
<el-input-number v-model='average02' :min="1" :max="59 - average01 || 0" /> 分钟执行一次 <el-input-number v-model='average02' :min="1" :max="59 - average01" /> 分钟执行一次
</el-radio> </el-radio>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="4"> <el-radio v-model='radioValue' :value="4">
指定 指定
<el-select clearable v-model="checkboxList" placeholder="可多选" multiple style="width:100%"> <el-select clearable v-model="checkboxList" placeholder="可多选" multiple :multiple-limit="10">
<el-option v-for="item in 60" :key="item" :value="item-1">{{item-1}}</el-option> <el-option v-for="item in 60" :key="item" :label="item - 1" :value="item - 1" />
</el-select> </el-select>
</el-radio> </el-radio>
</el-form-item> </el-form-item>
</el-form> </el-form>
</template> </template>
<script setup>
<script setup lang="ts" name="CrontabMin"> const emit = defineEmits(['update'])
import { ref, computed, watch, defineProps, defineEmits } from 'vue';
const props = defineProps({ const props = defineProps({
check: {
type: Function,
required: true
},
cron: { cron: {
type: Object, type: Object,
default: () => ({}) default: {
second: "*",
min: "*",
hour: "*",
day: "*",
month: "*",
week: "?",
year: "",
} }
}); },
check: {
const emit = defineEmits(['update']); type: Function,
default: () => {
const radioValue = ref(1); }
const cycle01 = ref(1); }
const cycle02 = ref(2); })
const average01 = ref(0); const radioValue = ref(1)
const average02 = ref(1); const cycle01 = ref(0)
const checkboxList = ref([]); const cycle02 = ref(1)
const average01 = ref(0)
// const average02 = ref(1)
const checkboxList = ref([])
const checkCopy = ref([0])
const cycleTotal = computed(() => { const cycleTotal = computed(() => {
const cycleVal01 = props.check(cycle01.value, 0, 58); cycle01.value = props.check(cycle01.value, 0, 58)
const cycleVal02 = props.check(cycle02.value, cycleVal01 ? cycleVal01 + 1 : 1, 59); cycle02.value = props.check(cycle02.value, cycle01.value + 1, 59)
return `${cycleVal01}-${cycleVal02}`; return cycle01.value + '-' + cycle02.value
}); })
//
const averageTotal = computed(() => { const averageTotal = computed(() => {
const averageVal01 = props.check(average01.value, 0, 58); average01.value = props.check(average01.value, 0, 58)
const averageVal02 = props.check(average02.value, 1, 59 - averageVal01 || 0); average02.value = props.check(average02.value, 1, 59 - average01.value)
return `${averageVal01}/${averageVal02}`; return average01.value + '/' + average02.value
}); })
// checkbox
const checkboxString = computed(() => { const checkboxString = computed(() => {
let str = checkboxList.value.join(); return checkboxList.value.join(',')
return str === '' ? '*' : str; })
}); watch(() => props.cron.min, value => changeRadioValue(value))
watch([radioValue, cycleTotal, averageTotal, checkboxString], () => onRadioChange())
// function changeRadioValue(value) {
const radioChange = () => { if (value === '*') {
radioValue.value = 1
} else if (value.indexOf('-') > -1) {
const indexArr = value.split('-')
cycle01.value = Number(indexArr[0])
cycle02.value = Number(indexArr[1])
radioValue.value = 2
} else if (value.indexOf('/') > -1) {
const indexArr = value.split('/')
average01.value = Number(indexArr[0])
average02.value = Number(indexArr[1])
radioValue.value = 3
} else {
checkboxList.value = [...new Set(value.split(',').map(item => Number(item)))]
radioValue.value = 4
}
}
function onRadioChange() {
switch (radioValue.value) { switch (radioValue.value) {
case 1: case 1:
emit('update', 'min', '*', 'min'); emit('update', 'min', '*', 'min')
break; break
case 2: case 2:
emit('update', 'min', cycleTotal.value, 'min'); emit('update', 'min', cycleTotal.value, 'min')
break; break
case 3: case 3:
emit('update', 'min', averageTotal.value, 'min'); emit('update', 'min', averageTotal.value, 'min')
break; break
case 4: case 4:
emit('update', 'min', checkboxString.value, 'min'); if (checkboxList.value.length === 0) {
break; checkboxList.value.push(checkCopy.value[0])
} } else {
}; checkCopy.value = checkboxList.value
//
const cycleChange = () => {
if (radioValue.value === 2) {
emit('update', 'min', cycleTotal.value, 'min');
}
};
//
const averageChange = () => {
if (radioValue.value === 3) {
emit('update', 'min', averageTotal.value, 'min');
} }
}; emit('update', 'min', checkboxString.value, 'min')
break
// checkbox
const checkboxChange = () => {
if (radioValue.value === 4) {
emit('update', 'min', checkboxString.value, 'min');
} }
}; }
//
watch(() => radioValue.value, radioChange);
watch(() => cycleTotal.value, cycleChange);
watch(() => averageTotal.value, averageChange);
watch(() => checkboxString.value, checkboxChange);
</script> </script>
<style lang="scss" scoped>
.el-input-number--small, .el-select, .el-select--small {
margin: 0 0.2rem;
}
.el-select, .el-select--small {
width: 19.8rem;
}
</style>

@ -1,123 +1,141 @@
<template> <template>
<el-form size='small'> <el-form>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="1"> <el-radio v-model='radioValue' :value="1">
允许的通配符[, - * /] 允许的通配符[, - * /]
</el-radio> </el-radio>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="2"> <el-radio v-model='radioValue' :value="2">
周期从 周期从
<el-input-number v-model='cycle01' :min="1" :max="11" /> - <el-input-number v-model='cycle01' :min="1" :max="11" /> -
<el-input-number v-model='cycle02' :min="cycle01 ? cycle01 + 1 : 2" :max="12" /> <el-input-number v-model='cycle02' :min="cycle01 + 1" :max="12" />
</el-radio> </el-radio>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="3"> <el-radio v-model='radioValue' :value="3">
<el-input-number v-model='average01' :min="1" :max="11" /> 月开始 <el-input-number v-model='average01' :min="1" :max="11" /> 月开始
<el-input-number v-model='average02' :min="1" :max="12 - average01 || 0" /> 月月执行一次 <el-input-number v-model='average02' :min="1" :max="12 - average01" /> 月月执行一次
</el-radio> </el-radio>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="4"> <el-radio v-model='radioValue' :value="4">
指定 指定
<el-select clearable v-model="checkboxList" placeholder="可多选" multiple style="width:100%"> <el-select clearable v-model="checkboxList" placeholder="可多选" multiple :multiple-limit="8">
<el-option v-for="item in 12" :key="item" :value="item">{{item}}</el-option> <el-option v-for="item in monthList" :key="item.key" :label="item.value" :value="item.key" />
</el-select> </el-select>
</el-radio> </el-radio>
</el-form-item> </el-form-item>
</el-form> </el-form>
</template> </template>
<script setup lang="ts" name="CrontabMonth"> <script setup>
import { ref, computed, watch, defineProps, defineEmits } from 'vue'; const emit = defineEmits(['update'])
const props = defineProps({ const props = defineProps({
check: {
type: Function,
required: true
},
cron: { cron: {
type: Object, type: Object,
default: () => ({}) default: {
second: "*",
min: "*",
hour: "*",
day: "*",
month: "*",
week: "?",
year: "",
} }
}); },
check: {
const emit = defineEmits(['update']); type: Function,
default: () => {
const radioValue = ref(1); }
const cycle01 = ref(1); }
const cycle02 = ref(2); })
const average01 = ref(1); const radioValue = ref(1)
const average02 = ref(1); const cycle01 = ref(1)
const checkboxList = ref([]); const cycle02 = ref(2)
const average01 = ref(1)
// const average02 = ref(1)
const checkboxList = ref([])
const checkCopy = ref([1])
const monthList = ref([
{key: 1, value: '一月'},
{key: 2, value: '二月'},
{key: 3, value: '三月'},
{key: 4, value: '四月'},
{key: 5, value: '五月'},
{key: 6, value: '六月'},
{key: 7, value: '七月'},
{key: 8, value: '八月'},
{key: 9, value: '九月'},
{key: 10, value: '十月'},
{key: 11, value: '十一月'},
{key: 12, value: '十二月'}
])
const cycleTotal = computed(() => { const cycleTotal = computed(() => {
const cycleVal01 = props.check(cycle01.value, 1, 11); cycle01.value = props.check(cycle01.value, 1, 11)
const cycleVal02 = props.check(cycle02.value, cycleVal01 ? cycleVal01 + 1 : 2, 12); cycle02.value = props.check(cycle02.value, cycle01.value + 1, 12)
return `${cycleVal01}-${cycleVal02}`; return cycle01.value + '-' + cycle02.value
}); })
//
const averageTotal = computed(() => { const averageTotal = computed(() => {
const averageVal01 = props.check(average01.value, 1, 11); average01.value = props.check(average01.value, 1, 11)
const averageVal02 = props.check(average02.value, 1, 12 - averageVal01 || 0); average02.value = props.check(average02.value, 1, 12 - average01.value)
return `${averageVal01}/${averageVal02}`; return average01.value + '/' + average02.value
}); })
// checkbox
const checkboxString = computed(() => { const checkboxString = computed(() => {
let str = checkboxList.value.join(); return checkboxList.value.join(',')
return str === '' ? '*' : str; })
}); watch(() => props.cron.month, value => changeRadioValue(value))
watch([radioValue, cycleTotal, averageTotal, checkboxString], () => onRadioChange())
// function changeRadioValue(value) {
const radioChange = () => { if (value === '*') {
radioValue.value = 1
} else if (value.indexOf('-') > -1) {
const indexArr = value.split('-')
cycle01.value = Number(indexArr[0])
cycle02.value = Number(indexArr[1])
radioValue.value = 2
} else if (value.indexOf('/') > -1) {
const indexArr = value.split('/')
average01.value = Number(indexArr[0])
average02.value = Number(indexArr[1])
radioValue.value = 3
} else {
checkboxList.value = [...new Set(value.split(',').map(item => Number(item)))]
radioValue.value = 4
}
}
function onRadioChange() {
switch (radioValue.value) { switch (radioValue.value) {
case 1: case 1:
emit('update', 'month', '*'); emit('update', 'month', '*', 'month')
break; break
case 2: case 2:
emit('update', 'month', cycleTotal.value); emit('update', 'month', cycleTotal.value, 'month')
break; break
case 3: case 3:
emit('update', 'month', averageTotal.value); emit('update', 'month', averageTotal.value, 'month')
break; break
case 4: case 4:
emit('update', 'month', checkboxString.value); if (checkboxList.value.length === 0) {
break; checkboxList.value.push(checkCopy.value[0])
} else {
checkCopy.value = checkboxList.value
} }
}; emit('update', 'month', checkboxString.value, 'month')
break
//
const cycleChange = () => {
if (radioValue.value === 2) {
emit('update', 'month', cycleTotal.value);
} }
}; }
//
const averageChange = () => {
if (radioValue.value === 3) {
emit('update', 'month', averageTotal.value);
}
};
// checkbox
const checkboxChange = () => {
if (radioValue.value === 4) {
emit('update', 'month', checkboxString.value);
}
};
//
watch(() => radioValue.value, radioChange);
watch(() => cycleTotal.value, cycleChange);
watch(() => averageTotal.value, averageChange);
watch(() => checkboxString.value, checkboxChange);
</script> </script>
<style lang="scss" scoped>
.el-input-number--small, .el-select, .el-select--small {
margin: 0 0.2rem;
}
.el-select, .el-select--small {
width: 18.8rem;
}
</style>

@ -10,253 +10,21 @@
</div> </div>
</template> </template>
<script setup lang="ts" name="CrontabResult"> <script setup>
import { ref, watch, defineProps } from 'vue';
const props = defineProps({ const props = defineProps({
ex: { ex: {
type: String, type: String,
default: '' default: ''
} }
}); })
const dayRule = ref('')
const dayRule = ref(''); const dayRuleSup = ref('')
const dayRuleSup = ref(''); const dateArr = ref([])
const dateArr = ref([]); const resultList = ref([])
const resultList = ref([]); const isShow = ref(false)
const isShow = ref(false); watch(() => props.ex, () => expressionChange())
// min-max
const getOrderArr = (min, max) => {
let arr = [];
for (let i = min; i <= max; i++) {
arr.push(i);
}
return arr;
};
// Array.sort
const compare = (value1, value2) => {
if (value2 - value1 > 0) {
return -1;
} else {
return 1;
}
};
//
const getAssignArr = (rule) => {
let arr = [];
let assiginArr = rule.split(',');
for (let i = 0; i < assiginArr.length; i++) {
arr[i] = Number(assiginArr[i])
}
arr.sort(compare);
return arr;
};
//
const getAverageArr = (rule, limit) => {
let arr = [];
let agArr = rule.split('/');
let min = Number(agArr[0]);
let step = Number(agArr[1]);
while (min <= limit) {
arr.push(min);
min += step;
}
return arr;
};
//
const getCycleArr = (rule, limit, status) => {
// status--01
let arr = [];
let cycleArr = rule.split('-');
let min = Number(cycleArr[0]);
let max = Number(cycleArr[1]);
if (min > max) {
max += limit;
}
for (let i = min; i <= max; i++) {
let add = 0;
if (status == false && i % limit == 0) {
add = limit;
}
arr.push(Math.round(i % limit + add))
}
arr.sort(compare);
return arr;
};
//
const getIndex = (arr, value) => {
if (value <= arr[0] || value > arr[arr.length - 1]) {
return 0;
} else {
for (let i = 0; i < arr.length - 1; i++) {
if (value > arr[i] && value <= arr[i + 1]) {
return i + 1;
}
}
}
return 0;
};
// 2017-9-19 18:04:33
const formatDate = (value, type) => {
//
let time = typeof value == 'number' ? new Date(value) : value;
let Y = time.getFullYear();
let M = time.getMonth() + 1;
let D = time.getDate();
let h = time.getHours();
let m = time.getMinutes();
let s = time.getSeconds();
let week = time.getDay();
// type
if (type == undefined) {
return Y + '-' + (M < 10 ? '0' + M : M) + '-' + (D < 10 ? '0' + D : D) + ' ' + (h < 10 ? '0' + h : h) + ':' + (m < 10 ? '0' + m : m) + ':' + (s < 10 ? '0' + s : s);
} else if (type == 'week') {
// quartz 1
return week + 1;
}
return '';
};
//
const checkDate = (value) => {
let time = new Date(value);
let format = formatDate(time);
return value === format;
};
// ""
const getSecondArr = (rule) => {
dateArr.value[0] = getOrderArr(0, 59);
if (rule.indexOf('-') >= 0) {
dateArr.value[0] = getCycleArr(rule, 60, true);
} else if (rule.indexOf('/') >= 0) {
dateArr.value[0] = getAverageArr(rule, 59);
} else if (rule !== '*' && rule !== '0') {
dateArr.value[0] = getAssignArr(rule);
}
//0
else if (rule == '*') {
dateArr.value[0] = '0';
}
};
// ""
const getMinArr = (rule) => {
dateArr.value[1] = getOrderArr(0, 59);
if (rule.indexOf('-') >= 0) {
dateArr.value[1] = getCycleArr(rule, 60, true);
} else if (rule.indexOf('/') >= 0) {
dateArr.value[1] = getAverageArr(rule, 59);
} else if (rule !== '*' && rule !== '0') {
dateArr.value[1] = getAssignArr(rule);
} else if (rule == '*') {
dateArr.value[1] = '0';
}
};
// ""
const getHourArr = (rule) => {
dateArr.value[2] = getOrderArr(0, 23);
if (rule.indexOf('-') >= 0) {
dateArr.value[2] = getCycleArr(rule, 24, true);
} else if (rule.indexOf('/') >= 0) {
dateArr.value[2] = getAverageArr(rule, 23);
} else if (rule !== '*') {
dateArr.value[2] = getAssignArr(rule);
}
};
// ""-
const getDayArr = (rule) => {
dateArr.value[3] = getOrderArr(1, 31);
dayRule.value = '';
dayRuleSup.value = '';
if (rule.indexOf('-') >= 0) {
dateArr.value[3] = getCycleArr(rule, 31, false);
dayRuleSup.value = 'null';
} else if (rule.indexOf('/') >= 0) {
dateArr.value[3] = getAverageArr(rule, 31);
dayRuleSup.value = 'null';
} else if (rule.indexOf('W') >= 0) {
dayRule.value = 'workDay';
dayRuleSup.value = Number(rule.match(/[0-9]{1,2}/g)[0]);
dateArr.value[3] = [dayRuleSup.value];
} else if (rule.indexOf('L') >= 0) {
dayRule.value = 'lastDay';
dayRuleSup.value = 'null';
dateArr.value[3] = [31];
} else if (rule !== '*' && rule !== '?') {
dateArr.value[3] = getAssignArr(rule);
dayRuleSup.value = 'null';
} else if (rule == '*') {
dayRuleSup.value = 'null';
}
};
// ""-
const getWeekArr = (rule) => {
// ""
if (dayRule.value == '' && dayRuleSup.value == '') {
if (rule.indexOf('-') >= 0) {
dayRule.value = 'weekDay';
dayRuleSup.value = getCycleArr(rule, 7, false);
} else if (rule.indexOf('#') >= 0) {
dayRule.value = 'assWeek';
let matchRule = rule.match(/[0-9]{1}/g);
dayRuleSup.value = [Number(matchRule[1]), Number(matchRule[0])];
dateArr.value[3] = [1];
if (dayRuleSup.value[1] == 7) {
dayRuleSup.value[1] = 0;
}
} else if (rule.indexOf('L') >= 0) {
dayRule.value = 'lastWeek';
dayRuleSup.value = Number(rule.match(/[0-9]{1,2}/g)[0]);
dateArr.value[3] = [31];
if (dayRuleSup.value == 7) {
dayRuleSup.value = 0;
}
} else if (rule !== '*' && rule !== '?') {
dayRule.value = 'weekDay';
dayRuleSup.value = getAssignArr(rule);
}
}
};
// ""
const getMonthArr = (rule) => {
dateArr.value[4] = getOrderArr(1, 12);
if (rule.indexOf('-') >= 0) {
dateArr.value[4] = getCycleArr(rule, 12, false);
} else if (rule.indexOf('/') >= 0) {
dateArr.value[4] = getAverageArr(rule, 12);
} else if (rule !== '*') {
dateArr.value[4] = getAssignArr(rule);
}
};
// ""
const getYearArr = (rule, year) => {
dateArr.value[5] = getOrderArr(year, year + 100);
if (rule !== undefined) {
if (rule.indexOf('-') >= 0) {
dateArr.value[5] = getCycleArr(rule, year + 100, false);
} else if (rule.indexOf('/') >= 0) {
dateArr.value[5] = getAverageArr(rule, year + 100);
} else if (rule !== '*') {
dateArr.value[5] = getAssignArr(rule);
}
}
};
// //
const expressionChange = () => { function expressionChange() {
// - // -
isShow.value = false; isShow.value = false;
// [0123456] // [0123456]
@ -273,7 +41,6 @@ const expressionChange = () => {
let nHour = nTime.getHours(); let nHour = nTime.getHours();
let nMin = nTime.getMinutes(); let nMin = nTime.getMinutes();
let nSecond = nTime.getSeconds(); let nSecond = nTime.getSeconds();
// 100 // 100
getSecondArr(ruleArr[0]); getSecondArr(ruleArr[0]);
getMinArr(ruleArr[1]); getMinArr(ruleArr[1]);
@ -282,7 +49,6 @@ const expressionChange = () => {
getMonthArr(ruleArr[4]); getMonthArr(ruleArr[4]);
getWeekArr(ruleArr[5]); getWeekArr(ruleArr[5]);
getYearArr(ruleArr[6], nYear); getYearArr(ruleArr[6], nYear);
// -便使 // -便使
let sDate = dateArr.value[0]; let sDate = dateArr.value[0];
let mDate = dateArr.value[1]; let mDate = dateArr.value[1];
@ -290,7 +56,6 @@ const expressionChange = () => {
let DDate = dateArr.value[3]; let DDate = dateArr.value[3];
let MDate = dateArr.value[4]; let MDate = dateArr.value[4];
let YDate = dateArr.value[5]; let YDate = dateArr.value[5];
// //
let sIdx = getIndex(sDate, nSecond); let sIdx = getIndex(sDate, nSecond);
let mIdx = getIndex(mDate, nMin); let mIdx = getIndex(mDate, nMin);
@ -298,37 +63,31 @@ const expressionChange = () => {
let DIdx = getIndex(DDate, nDay); let DIdx = getIndex(DDate, nDay);
let MIdx = getIndex(MDate, nMonth); let MIdx = getIndex(MDate, nMonth);
let YIdx = getIndex(YDate, nYear); let YIdx = getIndex(YDate, nYear);
// () // ()
const resetSecond = function () { const resetSecond = function () {
sIdx = 0; sIdx = 0;
nSecond = sDate[sIdx]; nSecond = sDate[sIdx]
}; }
const resetMin = function () { const resetMin = function () {
mIdx = 0; mIdx = 0;
nMin = mDate[mIdx]; nMin = mDate[mIdx]
resetSecond(); resetSecond();
}; }
const resetHour = function () { const resetHour = function () {
hIdx = 0; hIdx = 0;
nHour = hDate[hIdx]; nHour = hDate[hIdx]
resetMin(); resetMin();
}; }
const resetDay = function () { const resetDay = function () {
DIdx = 0; DIdx = 0;
nDay = DDate[DIdx]; nDay = DDate[DIdx]
resetHour(); resetHour();
}; }
const resetMonth = function () { const resetMonth = function () {
MIdx = 0; MIdx = 0;
nMonth = MDate[MIdx]; nMonth = MDate[MIdx]
resetDay(); resetDay();
}; }
// //
if (nYear !== YDate[YIdx]) { if (nYear !== YDate[YIdx]) {
resetMonth(); resetMonth();
@ -337,19 +96,18 @@ const expressionChange = () => {
if (nMonth !== MDate[MIdx]) { if (nMonth !== MDate[MIdx]) {
resetDay(); resetDay();
} }
// "" //
if (nDay !== DDate[DIdx]) { if (nDay !== DDate[DIdx]) {
resetHour(); resetHour();
} }
// "" //
if (nHour !== hDate[hIdx]) { if (nHour !== hDate[hIdx]) {
resetMin(); resetMin();
} }
// "" //
if (nMin !== mDate[mIdx]) { if (nMin !== mDate[mIdx]) {
resetSecond(); resetSecond();
} }
// //
goYear: for (let Yi = YIdx; Yi < YDate.length; Yi++) { goYear: for (let Yi = YIdx; Yi < YDate.length; Yi++) {
let YY = YDate[Yi]; let YY = YDate[Yi];
@ -358,7 +116,6 @@ const expressionChange = () => {
resetMonth(); resetMonth();
continue; continue;
} }
// //
goMonth: for (let Mi = MIdx; Mi < MDate.length; Mi++) { goMonth: for (let Mi = MIdx; Mi < MDate.length; Mi++) {
// 便 // 便
@ -367,25 +124,23 @@ const expressionChange = () => {
// //
if (nDay > DDate[DDate.length - 1]) { if (nDay > DDate[DDate.length - 1]) {
resetDay(); resetDay();
if (Mi == MDate.length - 1) { if (Mi === MDate.length - 1) {
resetMonth(); resetMonth();
continue goYear; continue goYear;
} }
continue; continue;
} }
// //
goDay: for (let Di = DIdx; Di < DDate.length; Di++) { goDay: for (let Di = DIdx; Di < DDate.length; Di++) {
// 便 // 便
let DD = DDate[Di]; let DD = DDate[Di];
let thisDD = DD < 10 ? '0' + DD : DD; let thisDD = DD < 10 ? '0' + DD : DD;
// //
if (nHour > hDate[hDate.length - 1]) { if (nHour > hDate[hDate.length - 1]) {
resetHour(); resetHour();
if (Di == DDate.length - 1) { if (Di === DDate.length - 1) {
resetDay(); resetDay();
if (Mi == MDate.length - 1) { if (Mi === MDate.length - 1) {
resetMonth(); resetMonth();
continue goYear; continue goYear;
} }
@ -393,15 +148,13 @@ const expressionChange = () => {
} }
continue; continue;
} }
// //
if (checkDate(YY + '-' + MM + '-' + thisDD + ' 00:00:00') !== true && dayRule.value !== 'workDay' && dayRule.value !== 'lastWeek' && dayRule.value !== 'lastDay') { if (checkDate(YY + '-' + MM + '-' + thisDD + ' 00:00:00') !== true && dayRule.value !== 'workDay' && dayRule.value !== 'lastWeek' && dayRule.value !== 'lastDay') {
resetDay(); resetDay();
continue goMonth; continue goMonth;
} }
// //
if (dayRule.value == 'lastDay') { if (dayRule.value === 'lastDay') {
// //
if (checkDate(YY + '-' + MM + '-' + thisDD + ' 00:00:00') !== true) { if (checkDate(YY + '-' + MM + '-' + thisDD + ' 00:00:00') !== true) {
while (DD > 0 && checkDate(YY + '-' + MM + '-' + thisDD + ' 00:00:00') !== true) { while (DD > 0 && checkDate(YY + '-' + MM + '-' + thisDD + ' 00:00:00') !== true) {
@ -409,7 +162,7 @@ const expressionChange = () => {
thisDD = DD < 10 ? '0' + DD : DD; thisDD = DD < 10 ? '0' + DD : DD;
} }
} }
} else if (dayRule.value == 'workDay') { } else if (dayRule.value === 'workDay') {
// 230 // 230
if (checkDate(YY + '-' + MM + '-' + thisDD + ' 00:00:00') !== true) { if (checkDate(YY + '-' + MM + '-' + thisDD + ' 00:00:00') !== true) {
while (DD > 0 && checkDate(YY + '-' + MM + '-' + thisDD + ' 00:00:00') !== true) { while (DD > 0 && checkDate(YY + '-' + MM + '-' + thisDD + ' 00:00:00') !== true) {
@ -420,7 +173,7 @@ const expressionChange = () => {
// X // X
let thisWeek = formatDate(new Date(YY + '-' + MM + '-' + thisDD + ' 00:00:00'), 'week'); let thisWeek = formatDate(new Date(YY + '-' + MM + '-' + thisDD + ' 00:00:00'), 'week');
// //
if (thisWeek == 1) { if (thisWeek === 1) {
// //
DD++; DD++;
thisDD = DD < 10 ? '0' + DD : DD; thisDD = DD < 10 ? '0' + DD : DD;
@ -428,7 +181,7 @@ const expressionChange = () => {
if (checkDate(YY + '-' + MM + '-' + thisDD + ' 00:00:00') !== true) { if (checkDate(YY + '-' + MM + '-' + thisDD + ' 00:00:00') !== true) {
DD -= 3; DD -= 3;
} }
} else if (thisWeek == 7) { } else if (thisWeek === 7) {
// 61 // 61
if (dayRuleSup.value !== 1) { if (dayRuleSup.value !== 1) {
DD--; DD--;
@ -436,16 +189,16 @@ const expressionChange = () => {
DD += 2; DD += 2;
} }
} }
} else if (dayRule.value == 'weekDay') { } else if (dayRule.value === 'weekDay') {
// //
// //
let thisWeek = formatDate(new Date(YY + '-' + MM + '-' + DD + ' 00:00:00'), 'week'); let thisWeek = formatDate(new Date(YY + '-' + MM + '-' + DD + ' 00:00:00'), 'week');
// dayRuleSup // dayRuleSup
if (dayRuleSup.value.indexOf(thisWeek) < 0) { if (dayRuleSup.value.indexOf(thisWeek) < 0) {
// //
if (Di == DDate.length - 1) { if (Di === DDate.length - 1) {
resetDay(); resetDay();
if (Mi == MDate.length - 1) { if (Mi === MDate.length - 1) {
resetMonth(); resetMonth();
continue goYear; continue goYear;
} }
@ -453,7 +206,7 @@ const expressionChange = () => {
} }
continue; continue;
} }
} else if (dayRule.value == 'assWeek') { } else if (dayRule.value === 'assWeek') {
// //
// 1 // 1
let thisWeek = formatDate(new Date(YY + '-' + MM + '-' + DD + ' 00:00:00'), 'week'); let thisWeek = formatDate(new Date(YY + '-' + MM + '-' + DD + ' 00:00:00'), 'week');
@ -462,7 +215,7 @@ const expressionChange = () => {
} else { } else {
DD = dayRuleSup.value[0] * 7 + dayRuleSup.value[1] - thisWeek + 1; DD = dayRuleSup.value[0] * 7 + dayRuleSup.value[1] - thisWeek + 1;
} }
} else if (dayRule.value == 'lastWeek') { } else if (dayRule.value === 'lastWeek') {
// //
// 230 // 230
if (checkDate(YY + '-' + MM + '-' + thisDD + ' 00:00:00') !== true) { if (checkDate(YY + '-' + MM + '-' + thisDD + ' 00:00:00') !== true) {
@ -477,25 +230,22 @@ const expressionChange = () => {
if (dayRuleSup.value < thisWeek) { if (dayRuleSup.value < thisWeek) {
DD -= thisWeek - dayRuleSup.value; DD -= thisWeek - dayRuleSup.value;
} else if (dayRuleSup.value > thisWeek) { } else if (dayRuleSup.value > thisWeek) {
DD -= 7 - (dayRuleSup.value - thisWeek); DD -= 7 - (dayRuleSup.value - thisWeek)
} }
} }
// 1005
// 10"05"
DD = DD < 10 ? '0' + DD : DD; DD = DD < 10 ? '0' + DD : DD;
//
// ""
goHour: for (let hi = hIdx; hi < hDate.length; hi++) { goHour: for (let hi = hIdx; hi < hDate.length; hi++) {
let hh = hDate[hi] < 10 ? '0' + hDate[hi] : hDate[hi]; let hh = hDate[hi] < 10 ? '0' + hDate[hi] : hDate[hi]
// //
if (nMin > mDate[mDate.length - 1]) { if (nMin > mDate[mDate.length - 1]) {
resetMin(); resetMin();
if (hi == hDate.length - 1) { if (hi === hDate.length - 1) {
resetHour(); resetHour();
if (Di == DDate.length - 1) { if (Di === DDate.length - 1) {
resetDay(); resetDay();
if (Mi == MDate.length - 1) { if (Mi === MDate.length - 1) {
resetMonth(); resetMonth();
continue goYear; continue goYear;
} }
@ -505,21 +255,19 @@ const expressionChange = () => {
} }
continue; continue;
} }
// "" // ""
goMin: for (let mi = mIdx; mi < mDate.length; mi++) { goMin: for (let mi = mIdx; mi < mDate.length; mi++) {
let mm = mDate[mi] < 10 ? '0' + mDate[mi] : mDate[mi]; let mm = mDate[mi] < 10 ? '0' + mDate[mi] : mDate[mi];
// //
if (nSecond > sDate[sDate.length - 1]) { if (nSecond > sDate[sDate.length - 1]) {
resetSecond(); resetSecond();
if (mi == mDate.length - 1) { if (mi === mDate.length - 1) {
resetMin(); resetMin();
if (hi == hDate.length - 1) { if (hi === hDate.length - 1) {
resetHour(); resetHour();
if (Di == DDate.length - 1) { if (Di === DDate.length - 1) {
resetDay(); resetDay();
if (Mi == MDate.length - 1) { if (Mi === MDate.length - 1) {
resetMonth(); resetMonth();
continue goYear; continue goYear;
} }
@ -531,27 +279,26 @@ const expressionChange = () => {
} }
continue; continue;
} }
// "" // ""
goSecond: for (let si = sIdx; si <= sDate.length - 1; si++) { goSecond: for (let si = sIdx; si <= sDate.length - 1; si++) {
let ss = sDate[si] < 10 ? '0' + sDate[si] : sDate[si]; let ss = sDate[si] < 10 ? '0' + sDate[si] : sDate[si];
// //
if (MM !== '00' && DD !== '00') { if (MM !== '00' && DD !== '00') {
resultArr.push(YY + '-' + MM + '-' + DD + ' ' + hh + ':' + mm + ':' + ss); resultArr.push(YY + '-' + MM + '-' + DD + ' ' + hh + ':' + mm + ':' + ss)
nums++; nums++;
} }
// 退 // 退
if (nums == 5) break goYear; if (nums === 5) break goYear;
// //
if (si == sDate.length - 1) { if (si === sDate.length - 1) {
resetSecond(); resetSecond();
if (mi == mDate.length - 1) { if (mi === mDate.length - 1) {
resetMin(); resetMin();
if (hi == hDate.length - 1) { if (hi === hDate.length - 1) {
resetHour(); resetHour();
if (Di == DDate.length - 1) { if (Di === DDate.length - 1) {
resetDay(); resetDay();
if (Mi == MDate.length - 1) { if (Mi === MDate.length - 1) {
resetMonth(); resetMonth();
continue goYear; continue goYear;
} }
@ -569,21 +316,225 @@ const expressionChange = () => {
}//goDay }//goDay
}//goMonth }//goMonth
} }
// 100 // 100
if (resultArr.length == 0) { if (resultArr.length === 0) {
resultList.value = ['没有达到条件的结果!']; resultList.value = ['没有达到条件的结果!'];
} else { } else {
resultList.value = resultArr; resultList.value = resultArr;
if (resultArr.length !== 5) { if (resultArr.length !== 5) {
resultList.value.push('最近100年内只有上面' + resultArr.length + '条结果!'); resultList.value.push('最近100年内只有上面' + resultArr.length + '条结果!')
} }
} }
// - // -
isShow.value = true; isShow.value = true;
}; }
//
// function getIndex(arr, value) {
watch(() => props.ex, expressionChange); if (value <= arr[0] || value > arr[arr.length - 1]) {
return 0;
} else {
for (let i = 0; i < arr.length - 1; i++) {
if (value > arr[i] && value <= arr[i + 1]) {
return i + 1;
}
}
}
}
// ""
function getYearArr(rule, year) {
dateArr.value[5] = getOrderArr(year, year + 100);
if (rule !== undefined) {
if (rule.indexOf('-') >= 0) {
dateArr.value[5] = getCycleArr(rule, year + 100, false)
} else if (rule.indexOf('/') >= 0) {
dateArr.value[5] = getAverageArr(rule, year + 100)
} else if (rule !== '*') {
dateArr.value[5] = getAssignArr(rule)
}
}
}
// ""
function getMonthArr(rule) {
dateArr.value[4] = getOrderArr(1, 12);
if (rule.indexOf('-') >= 0) {
dateArr.value[4] = getCycleArr(rule, 12, false)
} else if (rule.indexOf('/') >= 0) {
dateArr.value[4] = getAverageArr(rule, 12)
} else if (rule !== '*') {
dateArr.value[4] = getAssignArr(rule)
}
}
// ""-
function getWeekArr(rule) {
//
if (dayRule.value === '' && dayRuleSup.value === '') {
if (rule.indexOf('-') >= 0) {
dayRule.value = 'weekDay';
dayRuleSup.value = getCycleArr(rule, 7, false)
} else if (rule.indexOf('#') >= 0) {
dayRule.value = 'assWeek';
let matchRule = rule.match(/[0-9]{1}/g);
dayRuleSup.value = [Number(matchRule[1]), Number(matchRule[0])];
dateArr.value[3] = [1];
if (dayRuleSup.value[1] === 7) {
dayRuleSup.value[1] = 0;
}
} else if (rule.indexOf('L') >= 0) {
dayRule.value = 'lastWeek';
dayRuleSup.value = Number(rule.match(/[0-9]{1,2}/g)[0]);
dateArr.value[3] = [31];
if (dayRuleSup.value === 7) {
dayRuleSup.value = 0;
}
} else if (rule !== '*' && rule !== '?') {
dayRule.value = 'weekDay';
dayRuleSup.value = getAssignArr(rule)
}
}
}
// ""-
function getDayArr(rule) {
dateArr.value[3] = getOrderArr(1, 31);
dayRule.value = '';
dayRuleSup.value = '';
if (rule.indexOf('-') >= 0) {
dateArr.value[3] = getCycleArr(rule, 31, false)
dayRuleSup.value = 'null';
} else if (rule.indexOf('/') >= 0) {
dateArr.value[3] = getAverageArr(rule, 31)
dayRuleSup.value = 'null';
} else if (rule.indexOf('W') >= 0) {
dayRule.value = 'workDay';
dayRuleSup.value = Number(rule.match(/[0-9]{1,2}/g)[0]);
dateArr.value[3] = [dayRuleSup.value];
} else if (rule.indexOf('L') >= 0) {
dayRule.value = 'lastDay';
dayRuleSup.value = 'null';
dateArr.value[3] = [31];
} else if (rule !== '*' && rule !== '?') {
dateArr.value[3] = getAssignArr(rule)
dayRuleSup.value = 'null';
} else if (rule === '*') {
dayRuleSup.value = 'null';
}
}
// ""
function getHourArr(rule) {
dateArr.value[2] = getOrderArr(0, 23);
if (rule.indexOf('-') >= 0) {
dateArr.value[2] = getCycleArr(rule, 24, true)
} else if (rule.indexOf('/') >= 0) {
dateArr.value[2] = getAverageArr(rule, 23)
} else if (rule !== '*') {
dateArr.value[2] = getAssignArr(rule)
}
}
// ""
function getMinArr(rule) {
dateArr.value[1] = getOrderArr(0, 59);
if (rule.indexOf('-') >= 0) {
dateArr.value[1] = getCycleArr(rule, 60, true)
} else if (rule.indexOf('/') >= 0) {
dateArr.value[1] = getAverageArr(rule, 59)
} else if (rule !== '*') {
dateArr.value[1] = getAssignArr(rule)
}
}
// ""
function getSecondArr(rule) {
dateArr.value[0] = getOrderArr(0, 59);
if (rule.indexOf('-') >= 0) {
dateArr.value[0] = getCycleArr(rule, 60, true)
} else if (rule.indexOf('/') >= 0) {
dateArr.value[0] = getAverageArr(rule, 59)
} else if (rule !== '*') {
dateArr.value[0] = getAssignArr(rule)
}
}
// min-max
function getOrderArr(min, max) {
let arr = [];
for (let i = min; i <= max; i++) {
arr.push(i);
}
return arr;
}
//
function getAssignArr(rule) {
let arr = [];
let assiginArr = rule.split(',');
for (let i = 0; i < assiginArr.length; i++) {
arr[i] = Number(assiginArr[i])
}
arr.sort(compare)
return arr;
}
//
function getAverageArr(rule, limit) {
let arr = [];
let agArr = rule.split('/');
let min = Number(agArr[0]);
let step = Number(agArr[1]);
while (min <= limit) {
arr.push(min);
min += step;
}
return arr;
}
//
function getCycleArr(rule, limit, status) {
// status--01
let arr = [];
let cycleArr = rule.split('-');
let min = Number(cycleArr[0]);
let max = Number(cycleArr[1]);
if (min > max) {
max += limit;
}
for (let i = min; i <= max; i++) {
let add = 0;
if (status === false && i % limit === 0) {
add = limit;
}
arr.push(Math.round(i % limit + add))
}
arr.sort(compare)
return arr;
}
// Array.sort
function compare(value1, value2) {
if (value2 - value1 > 0) {
return -1;
} else {
return 1;
}
}
// 2017-9-19 18:04:33
function formatDate(value, type) {
//
let time = typeof value == 'number' ? new Date(value) : value;
let Y = time.getFullYear();
let M = time.getMonth() + 1;
let D = time.getDate();
let h = time.getHours();
let m = time.getMinutes();
let s = time.getSeconds();
let week = time.getDay();
// type
if (type === undefined) {
return Y + '-' + (M < 10 ? '0' + M : M) + '-' + (D < 10 ? '0' + D : D) + ' ' + (h < 10 ? '0' + h : h) + ':' + (m < 10 ? '0' + m : m) + ':' + (s < 10 ? '0' + s : s);
} else if (type === 'week') {
// quartz 1
return week + 1;
}
}
//
function checkDate(value) {
let time = new Date(value);
let format = formatDate(time)
return value === format;
}
onMounted(() => {
expressionChange()
})
</script> </script>

@ -1,132 +1,128 @@
<template> <template>
<el-form size="small"> <el-form>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="1"> <el-radio v-model='radioValue' :value="1">
允许的通配符[, - * /] 允许的通配符[, - * /]
</el-radio> </el-radio>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="2"> <el-radio v-model='radioValue' :value="2">
周期从 周期从
<el-input-number v-model='cycle01' :min="0" :max="58" /> - <el-input-number v-model='cycle01' :min="0" :max="58" /> -
<el-input-number v-model='cycle02' :min="cycle01 ? cycle01 + 1 : 1" :max="59" /> <el-input-number v-model='cycle02' :min="cycle01 + 1" :max="59" />
</el-radio> </el-radio>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="3"> <el-radio v-model='radioValue' :value="3">
<el-input-number v-model='average01' :min="0" :max="58" /> 秒开始 <el-input-number v-model='average01' :min="0" :max="58" /> 秒开始
<el-input-number v-model='average02' :min="1" :max="59 - average01 || 0" /> 秒执行一次 <el-input-number v-model='average02' :min="1" :max="59 - average01" /> 秒执行一次
</el-radio> </el-radio>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="4"> <el-radio v-model='radioValue' :value="4">
指定 指定
<el-select clearable v-model="checkboxList" placeholder="可多选" multiple style="width:100%"> <el-select clearable v-model="checkboxList" placeholder="可多选" multiple :multiple-limit="10">
<el-option v-for="item in 60" :key="item" :value="item-1">{{item-1}}</el-option> <el-option v-for="item in 60" :key="item" :label="item - 1" :value="item - 1" />
</el-select> </el-select>
</el-radio> </el-radio>
</el-form-item> </el-form-item>
</el-form> </el-form>
</template> </template>
<script setup lang="ts" name="CrontabSecond"> <script setup>
import { ref, computed, watch, defineProps, defineEmits } from 'vue'; const emit = defineEmits(['update'])
const props = defineProps({ const props = defineProps({
check: {
type: Function,
required: true
},
radioParent: {
type: Number,
default: undefined
},
cron: { cron: {
type: Object, type: Object,
default: () => ({}) default: {
second: "*",
min: "*",
hour: "*",
day: "*",
month: "*",
week: "?",
year: "",
} }
}); },
check: {
const emit = defineEmits(['update']); type: Function,
default: () => {
const radioValue = ref(1); }
const cycle01 = ref(1); }
const cycle02 = ref(2); })
const average01 = ref(0); const radioValue = ref(1)
const average02 = ref(1); const cycle01 = ref(0)
const checkboxList = ref([]); const cycle02 = ref(1)
const average01 = ref(0)
// const average02 = ref(1)
const checkboxList = ref([])
const checkCopy = ref([0])
const cycleTotal = computed(() => { const cycleTotal = computed(() => {
const cycleVal01 = props.check(cycle01.value, 0, 58); cycle01.value = props.check(cycle01.value, 0, 58)
const cycleVal02 = props.check(cycle02.value, cycleVal01 ? cycleVal01 + 1 : 1, 59); cycle02.value = props.check(cycle02.value, cycle01.value + 1, 59)
return `${cycleVal01}-${cycleVal02}`; return cycle01.value + '-' + cycle02.value
}); })
//
const averageTotal = computed(() => { const averageTotal = computed(() => {
const averageVal01 = props.check(average01.value, 0, 58); average01.value = props.check(average01.value, 0, 58)
const averageVal02 = props.check(average02.value, 1, 59 - averageVal01 || 0); average02.value = props.check(average02.value, 1, 59 - average01.value)
return `${averageVal01}/${averageVal02}`; return average01.value + '/' + average02.value
}); })
// checkbox
const checkboxString = computed(() => { const checkboxString = computed(() => {
let str = checkboxList.value.join(); return checkboxList.value.join(',')
return str === '' ? '*' : str; })
}); watch(() => props.cron.second, value => changeRadioValue(value))
watch([radioValue, cycleTotal, averageTotal, checkboxString], () => onRadioChange())
function changeRadioValue(value) {
if (value === '*') {
radioValue.value = 1
} else if (value.indexOf('-') > -1) {
const indexArr = value.split('-')
cycle01.value = Number(indexArr[0])
cycle02.value = Number(indexArr[1])
radioValue.value = 2
} else if (value.indexOf('/') > -1) {
const indexArr = value.split('/')
average01.value = Number(indexArr[0])
average02.value = Number(indexArr[1])
radioValue.value = 3
} else {
checkboxList.value = [...new Set(value.split(',').map(item => Number(item)))]
radioValue.value = 4
}
}
// //
const radioChange = () => { function onRadioChange() {
switch (radioValue.value) { switch (radioValue.value) {
case 1: case 1:
emit('update', 'second', '*', 'second'); emit('update', 'second', '*', 'second')
break; break
case 2: case 2:
emit('update', 'second', cycleTotal.value); emit('update', 'second', cycleTotal.value, 'second')
break; break
case 3: case 3:
emit('update', 'second', averageTotal.value); emit('update', 'second', averageTotal.value, 'second')
break; break
case 4: case 4:
emit('update', 'second', checkboxString.value); if (checkboxList.value.length === 0) {
break; checkboxList.value.push(checkCopy.value[0])
} } else {
}; checkCopy.value = checkboxList.value
//
const cycleChange = () => {
if (radioValue.value === 2) {
emit('update', 'second', cycleTotal.value);
} }
}; emit('update', 'second', checkboxString.value, 'second')
break
//
const averageChange = () => {
if (radioValue.value === 3) {
emit('update', 'second', averageTotal.value);
}
};
// checkbox
const checkboxChange = () => {
if (radioValue.value === 4) {
emit('update', 'second', checkboxString.value);
} }
}; }
//
watch(() => radioValue.value, radioChange);
watch(() => cycleTotal.value, cycleChange);
watch(() => averageTotal.value, averageChange);
watch(() => checkboxString.value, checkboxChange);
watch(() => props.radioParent, (newVal) => {
if (newVal !== undefined) {
radioValue.value = newVal;
}
});
</script> </script>
<style lang="scss" scoped>
.el-input-number--small, .el-select, .el-select--small {
margin: 0 0.2rem;
}
.el-select, .el-select--small {
width: 18.8rem;
}
</style>

@ -1,27 +1,27 @@
<template> <template>
<el-form size='small'> <el-form>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="1"> <el-radio v-model='radioValue' :value="1">
允许的通配符[, - * ? / L #] 允许的通配符[, - * ? / L #]
</el-radio> </el-radio>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="2"> <el-radio v-model='radioValue' :value="2">
不指定 不指定
</el-radio> </el-radio>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="3"> <el-radio v-model='radioValue' :value="3">
周期从星期 周期从
<el-select clearable v-model="cycle01"> <el-select clearable v-model="cycle01">
<el-option <el-option
v-for="(item,index) of weekList" v-for="(item,index) of weekList"
:key="index" :key="index"
:label="item.value" :label="item.value"
:value="item.key" :value="item.key"
:disabled="item.key === 1" :disabled="item.key === 7"
>{{item.value}}</el-option> >{{item.value}}</el-option>
</el-select> </el-select>
- -
@ -31,36 +31,36 @@
:key="index" :key="index"
:label="item.value" :label="item.value"
:value="item.key" :value="item.key"
:disabled="item.key < cycle01 && item.key !== 1" :disabled="item.key <= cycle01"
>{{item.value}}</el-option> >{{item.value}}</el-option>
</el-select> </el-select>
</el-radio> </el-radio>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="4"> <el-radio v-model='radioValue' :value="4">
<el-input-number v-model='average01' :min="1" :max="4" /> 周的星期 <el-input-number v-model='average01' :min="1" :max="4" /> 周的
<el-select clearable v-model="average02"> <el-select clearable v-model="average02">
<el-option v-for="(item,index) of weekList" :key="index" :label="item.value" :value="item.key">{{item.value}}</el-option> <el-option v-for="item in weekList" :key="item.key" :label="item.value" :value="item.key" />
</el-select> </el-select>
</el-radio> </el-radio>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="5"> <el-radio v-model='radioValue' :value="5">
本月最后一个星期 本月最后一个
<el-select clearable v-model="weekday"> <el-select clearable v-model="weekday">
<el-option v-for="(item,index) of weekList" :key="index" :label="item.value" :value="item.key">{{item.value}}</el-option> <el-option v-for="item in weekList" :key="item.key" :label="item.value" :value="item.key" />
</el-select> </el-select>
</el-radio> </el-radio>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-radio v-model='radioValue' :label="6"> <el-radio v-model='radioValue' :value="6">
指定 指定
<el-select clearable v-model="checkboxList" placeholder="可多选" multiple style="width:100%"> <el-select class="multiselect" clearable v-model="checkboxList" placeholder="可多选" multiple :multiple-limit="6">
<el-option v-for="(item,index) of weekList" :key="index" :label="item.value" :value="String(item.key)">{{item.value}}</el-option> <el-option v-for="item in weekList" :key="item.key" :label="item.value" :value="item.key" />
</el-select> </el-select>
</el-radio> </el-radio>
</el-form-item> </el-form-item>
@ -68,145 +68,130 @@
</el-form> </el-form>
</template> </template>
<script setup lang="ts" name="CrontabWeek"> <script setup>
import { ref, computed, watch, defineProps, defineEmits } from 'vue'; const emit = defineEmits(['update'])
const props = defineProps({ const props = defineProps({
check: {
type: Function,
required: true
},
cron: { cron: {
type: Object, type: Object,
default: () => ({}) default: {
second: "*",
min: "*",
hour: "*",
day: "*",
month: "*",
week: "?",
year: ""
} }
});
const emit = defineEmits(['update']);
const radioValue = ref(2);
const weekday = ref(2);
const cycle01 = ref(2);
const cycle02 = ref(3);
const average01 = ref(1);
const average02 = ref(2);
const checkboxList = ref([]);
const weekList = ref([
{
key: 2,
value: '星期一'
},
{
key: 3,
value: '星期二'
}, },
{ check: {
key: 4, type: Function,
value: '星期三' default: () => {
},
{
key: 5,
value: '星期四'
},
{
key: 6,
value: '星期五'
},
{
key: 7,
value: '星期六'
},
{
key: 1,
value: '星期日'
} }
]); }
})
// const radioValue = ref(2)
const cycle01 = ref(2)
const cycle02 = ref(3)
const average01 = ref(1)
const average02 = ref(2)
const weekday = ref(2)
const checkboxList = ref([])
const checkCopy = ref([2])
const weekList = ref([
{key: 1, value: '星期日'},
{key: 2, value: '星期一'},
{key: 3, value: '星期二'},
{key: 4, value: '星期三'},
{key: 5, value: '星期四'},
{key: 6, value: '星期五'},
{key: 7, value: '星期六'}
])
const cycleTotal = computed(() => { const cycleTotal = computed(() => {
const cycleVal01 = props.check(cycle01.value, 1, 7); cycle01.value = props.check(cycle01.value, 1, 6)
const cycleVal02 = props.check(cycle02.value, 1, 7); cycle02.value = props.check(cycle02.value, cycle01.value + 1, 7)
return `${cycleVal01}-${cycleVal02}`; return cycle01.value + '-' + cycle02.value
}); })
//
const averageTotal = computed(() => { const averageTotal = computed(() => {
const averageVal01 = props.check(average01.value, 1, 4); average01.value = props.check(average01.value, 1, 4)
const averageVal02 = props.check(average02.value, 1, 7); average02.value = props.check(average02.value, 1, 7)
return `${averageVal02}#${averageVal01}`; return average02.value + '#' + average01.value
}); })
const weekdayTotal = computed(() => {
// weekday.value = props.check(weekday.value, 1, 7)
const weekdayCheck = computed(() => { return weekday.value + 'L'
return props.check(weekday.value, 1, 7); })
});
// checkbox
const checkboxString = computed(() => { const checkboxString = computed(() => {
let str = checkboxList.value.join(); return checkboxList.value.join(',')
return str === '' ? '*' : str; })
}); watch(() => props.cron.week, value => changeRadioValue(value))
watch([radioValue, cycleTotal, averageTotal, weekdayTotal, checkboxString], () => onRadioChange())
// function changeRadioValue(value) {
const radioChange = () => { if (value === "*") {
radioValue.value = 1
} else if (value === "?") {
radioValue.value = 2
} else if (value.indexOf("-") > -1) {
const indexArr = value.split('-')
cycle01.value = Number(indexArr[0])
cycle02.value = Number(indexArr[1])
radioValue.value = 3
} else if (value.indexOf("#") > -1) {
const indexArr = value.split('#')
average01.value = Number(indexArr[1])
average02.value = Number(indexArr[0])
radioValue.value = 4
} else if (value.indexOf("L") > -1) {
const indexArr = value.split("L")
weekday.value = Number(indexArr[0])
radioValue.value = 5
} else {
checkboxList.value = [...new Set(value.split(',').map(item => Number(item)))]
radioValue.value = 6
}
}
function onRadioChange() {
if (radioValue.value === 2 && props.cron.day === '?') {
emit('update', 'day', '*', 'week')
}
if (radioValue.value !== 2 && props.cron.day !== '?') { if (radioValue.value !== 2 && props.cron.day !== '?') {
emit('update', 'day', '?', 'week'); emit('update', 'day', '?', 'week')
} }
switch (radioValue.value) { switch (radioValue.value) {
case 1: case 1:
emit('update', 'week', '*'); emit('update', 'week', '*', 'week')
break; break
case 2: case 2:
emit('update', 'week', '?'); emit('update', 'week', '?', 'week')
break; break
case 3: case 3:
emit('update', 'week', cycleTotal.value); emit('update', 'week', cycleTotal.value, 'week')
break; break
case 4: case 4:
emit('update', 'week', averageTotal.value); emit('update', 'week', averageTotal.value, 'week')
break; break
case 5: case 5:
emit('update', 'week', weekdayCheck.value + 'L'); emit('update', 'week', weekdayTotal.value, 'week')
break; break
case 6: case 6:
emit('update', 'week', checkboxString.value); if (checkboxList.value.length === 0) {
break; checkboxList.value.push(checkCopy.value[0])
} } else {
}; checkCopy.value = checkboxList.value
//
const cycleChange = () => {
if (radioValue.value === 3) {
emit('update', 'week', cycleTotal.value);
}
};
//
const averageChange = () => {
if (radioValue.value === 4) {
emit('update', 'week', averageTotal.value);
}
};
//
const weekdayChange = () => {
if (radioValue.value === 5) {
emit('update', 'week', weekday.value + 'L');
} }
}; emit('update', 'week', checkboxString.value, 'week')
break
// checkbox
const checkboxChange = () => {
if (radioValue.value === 6) {
emit('update', 'week', checkboxString.value);
} }
}; }
//
watch(() => radioValue.value, radioChange);
watch(() => cycleTotal.value, cycleChange);
watch(() => averageTotal.value, averageChange);
watch(() => weekdayCheck.value, weekdayChange);
watch(() => checkboxString.value, checkboxChange);
</script> </script>
<style lang="scss" scoped>
.el-input-number--small, .el-select, .el-select--small {
margin: 0 0.5rem;
}
.el-select, .el-select--small {
width: 8rem;
}
.el-select.multiselect, .el-select--small.multiselect {
width: 17.8rem;
}
</style>

@ -1,38 +1,38 @@
<template> <template>
<el-form size="small"> <el-form>
<el-form-item> <el-form-item>
<el-radio :label="1" v-model='radioValue'> <el-radio :value="1" v-model='radioValue'>
不填允许的通配符[, - * /] 不填允许的通配符[, - * /]
</el-radio> </el-radio>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-radio :label="2" v-model='radioValue'> <el-radio :value="2" v-model='radioValue'>
每年 每年
</el-radio> </el-radio>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-radio :label="3" v-model='radioValue'> <el-radio :value="3" v-model='radioValue'>
周期从 周期从
<el-input-number v-model='cycle01' :min='fullYear' :max="2098" /> - <el-input-number v-model='cycle01' :min='fullYear' :max="2098"/> -
<el-input-number v-model='cycle02' :min="cycle01 ? cycle01 + 1 : fullYear + 1" :max="2099" /> <el-input-number v-model='cycle02' :min="cycle01 ? cycle01 + 1 : fullYear + 1" :max="2099"/>
</el-radio> </el-radio>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-radio :label="4" v-model='radioValue'> <el-radio :value="4" v-model='radioValue'>
<el-input-number v-model='average01' :min='fullYear' :max="2098"/> 年开始 <el-input-number v-model='average01' :min='fullYear' :max="2098"/> 年开始
<el-input-number v-model='average02' :min="1" :max="2099 - average01 || fullYear" /> 年执行一次 <el-input-number v-model='average02' :min="1" :max="2099 - average01 || fullYear"/> 年执行一次
</el-radio> </el-radio>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-radio :label="5" v-model='radioValue'> <el-radio :value="5" v-model='radioValue'>
指定 指定
<el-select clearable v-model="checkboxList" placeholder="可多选" multiple> <el-select clearable v-model="checkboxList" placeholder="可多选" multiple :multiple-limit="8">
<el-option v-for="item in 9" :key="item" :value="item - 1 + fullYear" :label="item -1 + fullYear" /> <el-option v-for="item in 9" :key="item" :value="item - 1 + fullYear" :label="item -1 + fullYear" />
</el-select> </el-select>
</el-radio> </el-radio>
@ -40,106 +40,110 @@
</el-form> </el-form>
</template> </template>
<script setup lang="ts" name="CrontabYear"> <script setup>
import { ref, computed, watch, defineProps, defineEmits, onMounted } from 'vue'; const emit = defineEmits(['update'])
const props = defineProps({ const props = defineProps({
check: {
type: Function,
required: true
},
month: {
type: [String, Number],
default: ''
},
cron: { cron: {
type: Object, type: Object,
default: () => ({}) default: {
second: "*",
min: "*",
hour: "*",
day: "*",
month: "*",
week: "?",
year: ""
} }
}); },
check: {
const emit = defineEmits(['update']); type: Function,
default: () => {
const fullYear = ref(0); }
const radioValue = ref(1); }
const cycle01 = ref(0); })
const cycle02 = ref(0); const fullYear = ref(0)
const average01 = ref(0); const maxFullYear = ref(0)
const average02 = ref(1); const radioValue = ref(1)
const checkboxList = ref([]); const cycle01 = ref(0)
const cycle02 = ref(0)
// const average01 = ref(0)
const average02 = ref(1)
const checkboxList = ref([])
const checkCopy = ref([])
const cycleTotal = computed(() => { const cycleTotal = computed(() => {
const cycleVal01 = props.check(cycle01.value, fullYear.value, 2098); cycle01.value = props.check(cycle01.value, fullYear.value, maxFullYear.value - 1)
const cycleVal02 = props.check(cycle02.value, cycleVal01 ? cycleVal01 + 1 : fullYear.value + 1, 2099); cycle02.value = props.check(cycle02.value, cycle01.value + 1, maxFullYear.value)
return `${cycleVal01}-${cycleVal02}`; return cycle01.value + '-' + cycle02.value
}); })
//
const averageTotal = computed(() => { const averageTotal = computed(() => {
const averageVal01 = props.check(average01.value, fullYear.value, 2098); average01.value = props.check(average01.value, fullYear.value, maxFullYear.value - 1)
const averageVal02 = props.check(average02.value, 1, 2099 - averageVal01 || fullYear.value); average02.value = props.check(average02.value, 1, 10)
return `${averageVal01}/${averageVal02}`; return average01.value + '/' + average02.value
}); })
// checkbox
const checkboxString = computed(() => { const checkboxString = computed(() => {
return checkboxList.value.join(); return checkboxList.value.join(',')
}); })
watch(() => props.cron.year, value => changeRadioValue(value))
// watch([radioValue, cycleTotal, averageTotal, checkboxString], () => onRadioChange())
const radioChange = () => { function changeRadioValue(value) {
if (value === '') {
radioValue.value = 1
} else if (value === "*") {
radioValue.value = 2
} else if (value.indexOf("-") > -1) {
const indexArr = value.split('-')
cycle01.value = Number(indexArr[0])
cycle02.value = Number(indexArr[1])
radioValue.value = 3
} else if (value.indexOf("/") > -1) {
const indexArr = value.split('/')
average01.value = Number(indexArr[1])
average02.value = Number(indexArr[0])
radioValue.value = 4
} else {
checkboxList.value = [...new Set(value.split(',').map(item => Number(item)))]
radioValue.value = 5
}
}
function onRadioChange() {
switch (radioValue.value) { switch (radioValue.value) {
case 1: case 1:
emit('update', 'year', ''); emit('update', 'year', '', 'year')
break; break
case 2: case 2:
emit('update', 'year', '*'); emit('update', 'year', '*', 'year')
break; break
case 3: case 3:
emit('update', 'year', cycleTotal.value); emit('update', 'year', cycleTotal.value, 'year')
break; break
case 4: case 4:
emit('update', 'year', averageTotal.value); emit('update', 'year', averageTotal.value, 'year')
break; break
case 5: case 5:
emit('update', 'year', checkboxString.value); if (checkboxList.value.length === 0) {
break; checkboxList.value.push(checkCopy.value[0])
} } else {
}; checkCopy.value = checkboxList.value
//
const cycleChange = () => {
if (radioValue.value === 3) {
emit('update', 'year', cycleTotal.value);
} }
}; emit('update', 'year', checkboxString.value, 'year')
break
//
const averageChange = () => {
if (radioValue.value === 4) {
emit('update', 'year', averageTotal.value);
}
};
// checkbox
const checkboxChange = () => {
if (radioValue.value === 5) {
emit('update', 'year', checkboxString.value);
} }
}; }
//
watch(() => radioValue.value, radioChange);
watch(() => cycleTotal.value, cycleChange);
watch(() => averageTotal.value, averageChange);
watch(() => checkboxString.value, checkboxChange);
//
onMounted(() => { onMounted(() => {
// fullYear.value = Number(new Date().getFullYear())
fullYear.value = Number(new Date().getFullYear()); maxFullYear.value = fullYear.value + 10
cycle01.value = fullYear.value; cycle01.value = fullYear.value
average01.value = fullYear.value; cycle02.value = cycle01.value + 1
}); average01.value = fullYear.value
checkCopy.value = [fullYear.value]
})
</script> </script>
<style lang="scss" scoped>
.el-input-number--small, .el-select, .el-select--small {
margin: 0 0.2rem;
}
.el-select, .el-select--small {
width: 18.8rem;
}
</style>
Loading…
Cancel
Save