lzq 2025-12-24 01:19:09 +08:00
parent 8578d1164e
commit 6bb3688279
14 changed files with 864 additions and 583 deletions

View File

@ -3,7 +3,7 @@ import {
computed,
ref,
} from 'vue'
import { isEmpty } from '@/common/utils/strings.ts'
import Strings from '@/common/utils/strings.ts'
import Evt from '@/common/utils/evt.ts'
export const useAppUserStore = defineStore('AppUser', () => {
@ -15,7 +15,7 @@ export const useAppUserStore = defineStore('AppUser', () => {
const token = ref<string | null>(null)
const tenantId = ref<string | null>(null)
const tenantName = ref<string | null>(null)
const isAuthenticated = computed(() => !isEmpty(token.value))
const isAuthenticated = computed(() => !Strings.isEmpty(token.value))
function $reset() {
userId.value = null

View File

@ -3,7 +3,7 @@
*
* @param str
*/
export function isBlank(str?: string | null) {
function isBlank(str?: string | null) {
return str == null || str.trim().length === 0
}
@ -12,7 +12,7 @@ export function isBlank(str?: string | null) {
*
* @param str
*/
export function isEmpty(str?: string | null) {
function isEmpty(str?: string | null) {
return str == null || str === ''
}
@ -21,7 +21,7 @@ export function isEmpty(str?: string | null) {
*
* @param str
*/
export function capitalize(str?: string | null) {
function capitalize(str?: string | null) {
if (isBlank(str)) return ''
return str!.charAt(0).toUpperCase() + str!.slice(1)
}
@ -34,7 +34,7 @@ let splitCharPattern = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g
* @param str
* @param joiner (, )=>
*/
export function processWords(str: string | null | undefined, joiner: (word: string, index: number) => string) {
function processWords(str: string | null | undefined, joiner: (word: string, index: number) => string) {
if (isBlank(str)) return ''
return (str!
@ -49,7 +49,7 @@ export function processWords(str: string | null | undefined, joiner: (word: stri
*
* @param str
*/
export function camelCase(str?: string) {
function camelCase(str?: string) {
return processWords(str,
(word, index) => index !== 0 ? capitalize(word) : word,
)
@ -60,7 +60,7 @@ export function camelCase(str?: string) {
*
* @param str
*/
export function pascalCase(str?: string) {
function pascalCase(str?: string) {
return capitalize(camelCase(str))
}
@ -69,7 +69,7 @@ export function pascalCase(str?: string) {
*
* @param str
*/
export function snakeCase(str?: string) {
function snakeCase(str?: string) {
return processWords(str,
(word, index) => index !== 0 ? '_' + word : word,
)
@ -80,12 +80,20 @@ export function snakeCase(str?: string) {
*
* @param str
*/
export function kebabCase(str?: string) {
function kebabCase(str?: string) {
return processWords(str,
(word, index) => index !== 0 ? '-' + word : word,
)
}
function isNumStr(str: any) {
if (typeof str !== 'string') {
return false
}
const reg = /^[+-]?\d+(\.\d+)?$/
return reg.test(str)
}
export default {
isBlank,
isEmpty,
@ -95,4 +103,5 @@ export default {
kebabCase,
pascalCase,
processWords,
isNumStr,
}

View File

@ -17,22 +17,17 @@
</ElSelect>
</ElFormItem>
<ElFormItem label="调度方式">
<ElSelect v-model="taskFormData.scheduleType" placeholder="请选择调度方式" @change="taskFormData.scheduleConf = ''">
<ElSelect v-model="taskFormData.scheduleType" placeholder="请选择调度方式" @change="scheduleTypeChange">
<ElOption v-for="item in scheduleTypeList" :key="item.value" :label="item.label" :value="item.value"/>
</ElSelect>
</ElFormItem>
<ElFormItem label="调度配置" v-if="taskFormData.scheduleType != 'Manually'">
<ElFormItem v-if="taskFormData.scheduleType === 'Cron'" label="调度配置">
<Cron v-model="taskFormData.scheduleConf" :disabled="status === 'view'" placeholder="调度配置"/>
<!-- <ElInput v-model="taskFormData.scheduleConf" :disabled="status === 'view'" placeholder="调度配置">
<template #suffix>
<ElDropdown trigger="click">
<ElButton :icon="elIcons.Timer" type="text"/>
<template #dropdown>
<CronPanel/>
</template>
</ElDropdown>
</template>
</ElInput> -->
</ElFormItem>
<ElFormItem v-else-if="taskFormData.scheduleType === 'Fixed'" label="调度配置">
<ElInput v-model="taskFormData.scheduleConf" :disabled="status === 'view'" placeholder="调度配置">
<template #suffix>周期</template>
</ElInput>
</ElFormItem>
<ElFormItem label="是否禁用">
<ElSwitch v-model="taskFormData.disabled" active-text="" inactive-text=""/>
@ -76,7 +71,19 @@ function dialogCloseHandler() {
taskFormData.value = {}
}
function scheduleTypeChange(val: string) {
if (val === 'Manually') {
taskFormData.value.scheduleConf = ''
} else if (val === 'Fixed') {
taskFormData.value.scheduleConf = '1'
} else if (val === 'Cron') {
taskFormData.value.scheduleConf = '* * * * * ? ?'
}
}
function submitHandler() {
console.log(taskFormData.value.scheduleConf)
return
if (status.value === 'view') return
submiting.value = true
if (taskFormData.value.id != null) {

View File

@ -1,21 +1,43 @@
<script lang="ts" setup>
import { elIcons } from '@/common/element/element.ts'
import CronPanel from '@/pages/sys/task/cron/cron-panel/CronPanel.vue'
import { useCronStore } from '@/pages/sys/task/cron/cron-store.ts'
defineProps<{
const props = defineProps<{
modelValue?: string
}>()
const emits = defineEmits([ 'update:modelValue' ])
const {cronVal} = toRefs(useCronStore())
const showDialog = ref(false)
watch(
() => props.modelValue,
(newVal) => {
if (newVal !== undefined && newVal !== cronVal.value) {
console.log('设置', newVal)
cronVal.value = newVal
}
},
{immediate: true},
)
watch(
cronVal,
(newCronVal) => {
if (newCronVal !== props.modelValue) {
console.log('更新')
emits('update:modelValue', newCronVal)
}
},
)
function openPanel() {
showDialog.value = true
}
</script>
<template>
<ElInput :model-value="modelValue" v-bind="$attrs" @update:model-value="val=>emits('update:modelValue',val)">
<ElInput v-model="cronVal" v-bind="$attrs">
<template #suffix>
<ElButton :icon="elIcons.Timer" type="text" @click="openPanel"/>
</template>
@ -23,10 +45,7 @@ function openPanel() {
<ElDialog v-model="showDialog"
:close-on-click-modal="false"
destroy-on-close width="50vw">
<CronPanel :model-value="modelValue" @update:model-value="val=>emits('update:modelValue',val)"/>
<template #footer>
<div class="current-val">{{ modelValue }}</div>
</template>
<CronPanel/>
</ElDialog>
</template>

View File

@ -0,0 +1,241 @@
/**
* Unix Cron Cron
* 8:00 1:30
*
* <P>
* Cron 6 1
*
* <table cellspacing="8">
* <tr>
* <th align="left"></th>
* <th align="left">&nbsp;</th>
* <th align="left"></th>
* <th align="left">&nbsp;</th>
* <th align="left"></th>
* </tr>
* <tr>
* <td align="left"><code>Seconds</code></td>
* <td align="left">&nbsp;</th>
* <td align="left"><code>0-59</code></td>
* <td align="left">&nbsp;</th>
* <td align="left"><code>, - * /</code></td>
* </tr>
* <tr>
* <td align="left"><code>Minutes</code></td>
* <td align="left">&nbsp;</th>
* <td align="left"><code>0-59</code></td>
* <td align="left">&nbsp;</th>
* <td align="left"><code>, - * /</code></td>
* </tr>
* <tr>
* <td align="left"><code>Hours</code></td>
* <td align="left">&nbsp;</th>
* <td align="left"><code>0-23</code></td>
* <td align="left">&nbsp;</th>
* <td align="left"><code>, - * /</code></td>
* </tr>
* <tr>
* <td align="left"><code>Day-of-month</code></td>
* <td align="left">&nbsp;</th>
* <td align="left"><code>1-31</code></td>
* <td align="left">&nbsp;</th>
* <td align="left"><code>, - * ? / L W</code></td>
* </tr>
* <tr>
* <td align="left"><code>Month</code></td>
* <td align="left">&nbsp;</th>
* <td align="left"><code>0-11 JAN-DEC</code></td>
* <td align="left">&nbsp;</th>
* <td align="left"><code>, - * /</code></td>
* </tr>
* <tr>
* <td align="left"><code>Day-of-Week</code></td>
* <td align="left">&nbsp;</th>
* <td align="left"><code>1-7 SUN-SAT</code></td>
* <td align="left">&nbsp;</th>
* <td align="left"><code>, - * ? / L #</code></td>
* </tr>
* <tr>
* <td align="left"><code>Year</code></td>
* <td align="left">&nbsp;</th>
* <td align="left"><code>1970-2199</code></td>
* <td align="left">&nbsp;</th>
* <td align="left"><code>, - * /</code></td>
* </tr>
* </table>
* <P>
* '*' 使 "*"
* <P>
* '?' Day-of-monthDay-of-Week使
*
* <P>
* '-' 使 "10-12" 10 11 12
* <P>
* ',' 使 "MON,WED,FRI"
* <P>
* '/' 使 "0/15" 0 15 30 45
* "5/15" 5 20 35 50 '/' '*' 0
* 0-59 0-23
* 1-31 0-11 JAN DEC'/' n
* 使 "7/6" 7 6
* <P>
* 'L' Day-of-monthDay-of-Week使last
* 使 "L" 1 31
* 2 28 使 "L"7SAT
* 使 "6L"
* "L-3"
* <i>使 'L' </i>
* <P>
* 'W' Day-of-month使
* "15W" 15 15
* 14 15 16 15
* 15 "1W" 1 3
* 'W' 使
*
* <P>
* 'L' 'W' Day-of-month使 "LW"
* <P>
* '#' Day-of-Week使 n
* 使 "6#3" 6 "#3"
* "2#1" "4#5"
* "#5" 5
* 使 '#' "3#1,6#3"
* <P>
* <!--'C' Day-of-monthDay-of-Week使calendar
* 使
* 使 "5C" 5 5
* 使 "1C" -->
* <P>
*
*
* <p>
* <b></b>
* <ul>
* <li> Day-of-monthDay-of-Week
* 使 '?' </li>
* <li> 使 22-2 10 2
* 使 NOV-FEB 11 2 使
* CronExpression "0 0 14-6 ? * FRI-MON" </li>
* </ul>
* </p>
*
* @author ··
* @author ·
* @author · CronTrigger CronExpression
* <p>
* Quartz v2.3.1
*/
export class CronExpression {
// 公共常量:最大年份(当前年份+100与 Java 保持一致)
public static readonly MAX_YEAR: number = new Date().getFullYear() + 100
// 私有静态常量:字段索引(秒、分、时、日、月、周、年)
private static readonly SECOND: number = 0
private static readonly MINUTE: number = 1
private static readonly HOUR: number = 2
private static readonly DAY_OF_MONTH: number = 3
private static readonly MONTH: number = 4
private static readonly DAY_OF_WEEK: number = 5
private static readonly YEAR: number = 6
// 私有静态常量:特殊标记值(* 对应 99? 对应 98
private static readonly ALL_SPEC_INT: number = 99 // 对应 '*'
private static readonly NO_SPEC_INT: number = 98 // 对应 '?'
private static readonly ALL_SPEC: number = CronExpression.ALL_SPEC_INT
private static readonly NO_SPEC: number = CronExpression.NO_SPEC_INT
// 私有静态映射:月份英文缩写 -> 数字0-11与 Java 一致)
private static readonly monthMap: Record<string, number> = {JAN: 0, FEB: 1, MAR: 2, APR: 3, MAY: 4, JUN: 5, JUL: 6, AUG: 7, SEP: 8, OCT: 9, NOV: 10, DEC: 11}
// 私有静态映射:星期英文缩写 -> 数字1-7与 Java 一致)
private static readonly dayMap: Record<string, number> = {SUN: 1, MON: 2, TUE: 3, WED: 4, THU: 5, FRI: 6, SAT: 7}
// 实例属性
private readonly cronExpression: string
private seconds?: number[] // TS 中无原生TreeSet后续可实现或用SortedSet替代
private minutes?: number[]
private hours?: number[]
private daysOfMonth?: number[]
private months?: number[]
private daysOfWeek?: number[]
private years?: number[]
private lastdayOfWeek: boolean = false
private nthdayOfWeek: number = 0
private lastdayOfMonth: boolean = false
private nearestWeekday: boolean = false
private lastdayOffset: number = 0
private expressionParsed: boolean = false
private timeZone?: TimeZone // 对应 Java TimeZoneTS 中可用 string 或原生 TimeZone 替代
/**
* <code>CronExpression</code>
*
* @param cronExpression Cron
* @throws Error <code>CronExpression</code>
*/
constructor(cronExpression: string) {
if (cronExpression == null) {
throw new Error('表达式不能为空')
}
this.cronExpression = cronExpression.toUpperCase(Locale.US)
buildExpression(this.cronExpression)
}
/**
* Cron
*/
constructor(expression: CronExpression) {
this.cronExpression = expression.getCronExpression()
buildExpression(cronExpression)
if (expression.getTimeZone() != null) {
setTimeZone(<TimeZone>expression.getTimeZone().clone())
}
}
/**
* Cron Cron
* @param cronExpression Cron
* @returns Cron true false
*/
public static isValidExpression(cronExpression: string): boolean {
try {
new CronExpression(cronExpression)
} catch (e: Error) {
return false
}
return true
}
/**
* Cron
*
* @param date
* @returns Cron true false
*/
public isSatisfiedBy(date: Date): boolean {
const testDateCal = new Date(date.getTime())
testDateCal.setMilliseconds(0)
const originalDate = new Date(testDateCal.getTime())
testDateCal.setSeconds(date.getSeconds() - 1)
const timeAfter = this.getTimeAfter(testDateCal)
return timeAfter !== null && timeAfter.getTime() === originalDate.getTime()
}
}
/**
* Java TimeZone
*
*/
type TimeZone = {
id: string;
offset: number;
} | null;

View File

@ -6,63 +6,42 @@ import DayPanel from '@/pages/sys/task/cron/cron-panel/DayPanel.vue'
import MonthPanel from '@/pages/sys/task/cron/cron-panel/MonthPanel.vue'
import WeekPanel from '@/pages/sys/task/cron/cron-panel/WeekPanel.vue'
import YearPanel from '@/pages/sys/task/cron/cron-panel/YearPanel.vue'
import { useCronStore } from '@/pages/sys/task/cron/cron-store.ts'
const props = defineProps<{
modelValue: string
}>()
const emits = defineEmits([ 'update:modelValue' ])
const cronKernels = reactive({
second: '*',
minute: '*',
hour: '*',
day: '*',
month: '*',
week: '?',
year: '?',
})
watch(cronKernels, newVal => {
console.log(`${newVal.second} ${newVal.minute} ${newVal.hour} ${newVal.day} ${newVal.month} ${newVal.week} ${newVal.year}`)
emits('update:modelValue', `${newVal.second} ${newVal.minute} ${newVal.hour} ${newVal.day} ${newVal.month} ${newVal.week} ${newVal.year}`)
})
onMounted(() => {
let sections = props.modelValue.split(' ')
cronKernels.second = sections[0]
cronKernels.minute = sections[1]
cronKernels.hour = sections[2]
cronKernels.day = sections[3]
cronKernels.month = sections[4]
cronKernels.week = sections[5]
cronKernels.year = sections[6]
})
const {
secondVal,
minuteVal,
hourVal,
dayVal,
monthVal,
weekVal,
yearVal,
} = toRefs(useCronStore())
</script>
<template>
<div class="cron-panel">
<ElTabs type="border-card">
<ElTabPane :label="`秒(${cronKernels.second}`">
<SecondPanel v-model="cronKernels.second"/>
<ElTabPane :label="`秒(${secondVal}`">
<SecondPanel/>
</ElTabPane>
<ElTabPane :label="`分(${cronKernels.minute}`">
<MinutePanel v-model="cronKernels.minute"/>
<ElTabPane :label="`分(${minuteVal}`">
<MinutePanel/>
</ElTabPane>
<ElTabPane :label="`时(${cronKernels.hour}`">
<HourPanel v-model="cronKernels.hour"/>
<ElTabPane :label="`时(${hourVal}`">
<HourPanel/>
</ElTabPane>
<ElTabPane :label="`日(${cronKernels.day}`">
<DayPanel v-model="cronKernels.day"/>
<ElTabPane :label="`日(${dayVal}`">
<DayPanel/>
</ElTabPane>
<ElTabPane :label="`月(${cronKernels.month}`">
<MonthPanel v-model="cronKernels.month"/>
<ElTabPane :label="`月(${monthVal}`">
<MonthPanel/>
</ElTabPane>
<ElTabPane :label="`周(${cronKernels.week}`">
<WeekPanel v-model="cronKernels.week"/>
<ElTabPane :label="`周(${weekVal}`">
<WeekPanel/>
</ElTabPane>
<ElTabPane :label="`年(${cronKernels.year}`">
<YearPanel v-model="cronKernels.year"/>
<ElTabPane :label="`年(${yearVal}`">
<YearPanel/>
</ElTabPane>
</ElTabs>
</div>

View File

@ -1,112 +1,36 @@
<script lang="ts" setup>
const props = defineProps<{
modelValue: string
}>()
import { useCronStore } from '@/pages/sys/task/cron/cron-store.ts'
const emits = defineEmits([ 'update:modelValue' ])
const moduleData = ref('every')
const period1 = reactive({
start: undefined,
end: undefined,
})
const period2 = reactive({
start: undefined,
end: undefined,
})
const specify = ref<number[]>([])
const near = ref<number>(1)
const fn = {
none() {
emits('update:modelValue', '?')
},
every() {
emits('update:modelValue', '*')
},
last() {
emits('update:modelValue', 'L')
},
near() {
emits('update:modelValue', near.value + 'W')
},
period1() {
emits('update:modelValue', `${period1.start}-${period1.end}`)
},
period2() {
emits('update:modelValue', `${period2.start}/${period2.end}`)
},
specify() {
emits('update:modelValue', specify.value.join(','))
},
}
function moduleChange(val: 'none' | 'every' | 'last' | 'near' | 'period1' | 'period2' | 'specify') {
fn[val]?.()
}
function valueChange(module: 'none' | 'every' | 'last' | 'near' | 'period1' | 'period2' | 'specify') {
if (moduleData.value !== module) {
moduleData.value = module
}
moduleChange(module)
}
onMounted(() => {
let newModuleData = 'every'
if (props.modelValue === '?') {
newModuleData = 'none'
} else if (props.modelValue === 'L') {
newModuleData = 'last'
} else if (props.modelValue.includes('W')) {
const s = props.modelValue.split('W')
near.value = s[0]
newModuleData = 'near'
} else if (props.modelValue.includes('-')) {
const s = props.modelValue.split('-')
period1.start = +s[0]
period1.end = +s[1]
newModuleData = 'period1'
} else if (props.modelValue.includes('/')) {
const s = props.modelValue.split('/')
period2.start = +s[0]
period2.end = +s[1]
newModuleData = 'period2'
} else if (props.modelValue.includes(',')) {
specify.value = props.modelValue.split(',').map(it => +it)
newModuleData = 'specify'
}
moduleData.value = newModuleData
})
const {dayState} = toRefs(useCronStore())
</script>
<template>
<ElRadioGroup v-model="moduleData" class="select-panel" @change="moduleChange">
<ElRadioGroup v-model="dayState.mode" class="select-panel">
<ElRadio value="none">不指定</ElRadio>
<ElRadio value="every">每天</ElRadio>
<ElRadio value="last">每月最后一天</ElRadio>
<ElRadio value="near">
<span>每月</span>
<ElInputNumber v-model="near" :controls="false" :max="59" :min="1" size="small" @change="valueChange('near')"/>
<ElInputNumber v-model="dayState.near" :controls="false" :max="59" :min="1" size="small"/>
<span>号最近的那个工作日</span>
</ElRadio>
<ElRadio value="period1">
<span>周期</span>
<ElInputNumber v-model="period1.start" :controls="false" :max="59" :min="1" size="small" @change="valueChange('period1')"/>
<span></span>
<ElInputNumber v-model="period1.end" :controls="false" :max="59" :min="1" size="small" @change="valueChange('period1')"/>
<ElInputNumber v-model="dayState.period1.start" :controls="false" :max="59" :min="1" size="small"/>
<span>号到</span>
<ElInputNumber v-model="dayState.period1.end" :controls="false" :max="59" :min="1" size="small"/>
<span></span>
</ElRadio>
<ElRadio value="period2">
<span>周期从第</span>
<ElInputNumber v-model="period2.start" :controls="false" :max="59" :min="1" size="small" @change="valueChange('period2')"/>
<ElInputNumber v-model="dayState.period2.start" :controls="false" :max="59" :min="1" size="small"/>
<span>天开始</span>
<ElInputNumber v-model="period2.end" :controls="false" :max="60" :min="1" size="small" @change="valueChange('period2')"/>
<ElInputNumber v-model="dayState.period2.end" :controls="false" :max="60" :min="1" size="small"/>
<span>天执行一次</span>
</ElRadio>
<ElRadio value="specify">
<div>指定</div>
<ElCheckboxGroup v-model="specify" @change="valueChange('specify')">
<ElCheckboxGroup v-model="dayState.specify">
<ElCheckbox v-for="i in 31" :key="'DayPanel' + i" :label="i" :value="i"/>
</ElCheckboxGroup>
</ElRadio>
@ -119,7 +43,6 @@ onMounted(() => {
align-items start
gap 10px
width 100%;
//overflow auto
flex-wrap nowrap
:deep(.el-input-number) {

View File

@ -1,88 +1,29 @@
<script lang="ts" setup>
const props = defineProps<{
modelValue: string
}>()
import { useCronStore } from '@/pages/sys/task/cron/cron-store.ts'
const emits = defineEmits([ 'update:modelValue' ])
const moduleData = ref('every')
const period1 = reactive({
start: undefined,
end: undefined,
})
const period2 = reactive({
start: undefined,
end: undefined,
})
const specify = ref<number[]>([])
const fn = {
every() {
emits('update:modelValue', '*')
},
period1() {
emits('update:modelValue', `${period1.start}-${period1.end}`)
},
period2() {
emits('update:modelValue', `${period2.start}/${period2.end}`)
},
specify() {
emits('update:modelValue', specify.value.join(','))
},
}
function moduleChange(val: 'every' | 'period1' | 'period2' | 'specify') {
fn[val]?.()
}
function valueChange(module: 'every' | 'period1' | 'period2' | 'specify') {
if (moduleData.value !== module) {
moduleData.value = module
}
moduleChange(module)
}
onMounted(() => {
let newModuleData = 'every'
if (props.modelValue.includes('-')) {
const s = props.modelValue.split('-')
period1.start = +s[0]
period1.end = +s[1]
newModuleData = 'period1'
} else if (props.modelValue.includes('/')) {
const s = props.modelValue.split('/')
period2.start = +s[0]
period2.end = +s[1]
newModuleData = 'period2'
} else if (props.modelValue.includes(',')) {
specify.value = props.modelValue.split(',').map(it => +it)
newModuleData = 'specify'
}
moduleData.value = newModuleData
})
const {hourState} = toRefs(useCronStore())
</script>
<template>
<ElRadioGroup v-model="moduleData" class="select-panel" @change="moduleChange">
<ElRadioGroup v-model="hourState.mode" class="select-panel">
<ElRadio value="every">每小时</ElRadio>
<ElRadio value="period1">
<span>周期</span>
<ElInputNumber v-model="period1.start" :controls="false" :max="59" :min="1" size="small" @change="valueChange('period1')"/>
<ElInputNumber v-model="hourState.period1.start" :controls="false" :max="59" :min="1" size="small"/>
<span>时到</span>
<ElInputNumber v-model="period1.end" :controls="false" :max="59" :min="1" size="small" @change="valueChange('period1')"/>
<ElInputNumber v-model="hourState.period1.end" :controls="false" :max="59" :min="1" size="small"/>
<span></span>
</ElRadio>
<ElRadio value="period2">
<span>周期从第</span>
<ElInputNumber v-model="period2.start" :controls="false" :max="59" :min="1" size="small" @change="valueChange('period2')"/>
<ElInputNumber v-model="hourState.period2.start" :controls="false" :max="59" :min="1" size="small"/>
<span>时开始</span>
<ElInputNumber v-model="period2.end" :controls="false" :max="59" :min="1" size="small" @change="valueChange('period2')"/>
<ElInputNumber v-model="hourState.period2.end" :controls="false" :max="59" :min="1" size="small"/>
<span>小时执行一次</span>
</ElRadio>
<ElRadio value="specify">
<div>指定</div>
<ElCheckboxGroup v-model="specify" @change="valueChange('specify')">
<ElCheckboxGroup v-model="hourState.specify">
<ElCheckbox v-for="i in 24" :key="'HourPanel' + i" :label="(i-1)+''" :value="i-1"/>
</ElCheckboxGroup>
</ElRadio>
@ -95,7 +36,6 @@ onMounted(() => {
align-items start
gap 10px
width 100%;
//overflow auto
flex-wrap nowrap
:deep(.el-input-number) {

View File

@ -1,88 +1,29 @@
<script lang="ts" setup>
const props = defineProps<{
modelValue: string
}>()
import { useCronStore } from '@/pages/sys/task/cron/cron-store.ts'
const emits = defineEmits([ 'update:modelValue' ])
const moduleData = ref('every')
const period1 = reactive({
start: undefined,
end: undefined,
})
const period2 = reactive({
start: undefined,
end: undefined,
})
const specify = ref<number[]>([])
const fn = {
every() {
emits('update:modelValue', '*')
},
period1() {
emits('update:modelValue', `${period1.start}-${period1.end}`)
},
period2() {
emits('update:modelValue', `${period2.start}/${period2.end}`)
},
specify() {
emits('update:modelValue', specify.value.join(','))
},
}
function moduleChange(val: 'every' | 'period1' | 'period2' | 'specify') {
fn[val]?.()
}
function valueChange(module: 'every' | 'period1' | 'period2' | 'specify') {
if (moduleData.value !== module) {
moduleData.value = module
}
moduleChange(module)
}
onMounted(() => {
let newModuleData = 'every'
if (props.modelValue.includes('-')) {
const s = props.modelValue.split('-')
period1.start = +s[0]
period1.end = +s[1]
newModuleData = 'period1'
} else if (props.modelValue.includes('/')) {
const s = props.modelValue.split('/')
period2.start = +s[0]
period2.end = +s[1]
newModuleData = 'period2'
} else if (props.modelValue.includes(',')) {
specify.value = props.modelValue.split(',').map(it => +it)
newModuleData = 'specify'
}
moduleData.value = newModuleData
})
const {minuteState} = toRefs(useCronStore())
</script>
<template>
<ElRadioGroup v-model="moduleData" class="select-panel" @change="moduleChange">
<ElRadioGroup v-model="minuteState.mode" class="select-panel">
<ElRadio value="every">每分钟</ElRadio>
<ElRadio value="period1">
<span>周期</span>
<ElInputNumber v-model="period1.start" :controls="false" :max="59" :min="1" size="small" @change="valueChange('period1')"/>
<ElInputNumber v-model="minuteState.period1.start" :controls="false" :max="59" :min="1" size="small"/>
<span></span>
<ElInputNumber v-model="period1.end" :controls="false" :max="59" :min="1" size="small" @change="valueChange('period1')"/>
<ElInputNumber v-model="minuteState.period1.end" :controls="false" :max="59" :min="1" size="small"/>
</ElRadio>
<ElRadio value="period2">
<span>周期从第</span>
<ElInputNumber v-model="period2.start" :controls="false" :max="59" :min="1" size="small" @change="valueChange('period2')"/>
<ElInputNumber v-model="minuteState.period2.start" :controls="false" :max="59" :min="1" size="small"/>
<span>分钟开始</span>
<ElInputNumber v-model="period2.end" :controls="false" :max="59" :min="1" size="small" @change="valueChange('period2')"/>
<ElInputNumber v-model="minuteState.period2.end" :controls="false" :max="59" :min="1" size="small"/>
<span>分钟执行一次</span>
</ElRadio>
<ElRadio value="specify">
<div>指定</div>
<ElCheckboxGroup v-model="specify" @change="valueChange('specify')">
<ElCheckboxGroup v-model="minuteState.specify">
<ElCheckbox v-for="i in 60" :key="'MinutePanel' + i" :label="(i-1)+''" :value="i-1"/>
</ElCheckboxGroup>
</ElRadio>
@ -95,8 +36,6 @@ onMounted(() => {
align-items start
gap 10px
width 100%;
//width 600px;
//overflow auto
flex-wrap nowrap
:deep(.el-input-number) {

View File

@ -1,94 +1,39 @@
<script lang="ts" setup>
const props = defineProps<{
modelValue: string
}>()
import { useCronStore } from '@/pages/sys/task/cron/cron-store.ts'
const emits = defineEmits([ 'update:modelValue' ])
const moduleData = ref('every')
const period1 = reactive({
start: undefined,
end: undefined,
})
const period2 = reactive({
start: undefined,
end: undefined,
})
const specify = ref<number[]>([])
const fn = {
none() {
emits('update:modelValue', '?')
},
every() {
emits('update:modelValue', '*')
},
period1() {
emits('update:modelValue', `${period1.start}-${period1.end}`)
},
period2() {
emits('update:modelValue', `${period2.start}/${period2.end}`)
},
specify() {
emits('update:modelValue', specify.value.join(','))
},
}
function moduleChange(val: 'none' | 'every' | 'period1' | 'period2' | 'specify') {
fn[val]?.()
}
function valueChange(module: 'none' | 'every' | 'period1' | 'period2' | 'specify') {
if (moduleData.value !== module) {
moduleData.value = module
}
moduleChange(module)
}
onMounted(() => {
let newModuleData = 'every'
if (props.modelValue === '?') {
newModuleData = 'none'
} else if (props.modelValue.includes('-')) {
const s = props.modelValue.split('-')
period1.start = +s[0]
period1.end = +s[1]
newModuleData = 'period1'
} else if (props.modelValue.includes('/')) {
const s = props.modelValue.split('/')
period2.start = +s[0]
period2.end = +s[1]
newModuleData = 'period2'
} else if (props.modelValue.includes(',')) {
specify.value = props.modelValue.split(',').map(it => +it)
newModuleData = 'specify'
}
moduleData.value = newModuleData
})
const {monthState} = toRefs(useCronStore())
const months = [ '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月' ]
</script>
<template>
<ElRadioGroup v-model="moduleData" class="select-panel" @change="moduleChange">
<ElRadioGroup v-model="monthState.mode" class="select-panel">
<ElRadio value="none">不指定</ElRadio>
<ElRadio value="every">每月</ElRadio>
<ElRadio value="period1">
<span>周期</span>
<ElInputNumber v-model="period1.start" :controls="false" :max="59" :min="1" size="small" @change="valueChange('period1')"/>
<!-- <ElInputNumber v-model="monthState.period1.start" :controls="false" :max="59" :min="1" size="small"/> -->
<ElSelect v-model="monthState.period1.start" size="small">
<ElOption v-for="(month,i) in months" :key="'monthState.period1.start' + i" :label="month" :value="i"/>
</ElSelect>
<span></span>
<ElInputNumber v-model="period1.end" :controls="false" :max="59" :min="1" size="small" @change="valueChange('period1')"/>
<!-- <ElInputNumber v-model="monthState.period1.end" :controls="false" :max="59" :min="1" size="small"/> -->
<ElSelect v-model="monthState.period1.end" size="small">
<ElOption v-for="(month,i) in months" :key="'monthState.period1.end' + i" :disabled="i <= monthState.period1.start" :label="month" :value="i"/>
</ElSelect>
</ElRadio>
<ElRadio value="period2">
<span>周期从第</span>
<ElInputNumber v-model="period2.start" :controls="false" :max="59" :min="1" size="small" @change="valueChange('period2')"/>
<span>月开始</span>
<ElInputNumber v-model="period2.end" :controls="false" :max="60" :min="1" size="small" @change="valueChange('period2')"/>
<span>月执行一次</span>
<span>周期</span>
<ElSelect v-model="monthState.period2.start" size="small">
<ElOption v-for="(month,i) in months" :key="'monthState.period2.start' + i" :label="month" :value="i"/>
</ElSelect>
<span>开始</span>
<ElInputNumber v-model="monthState.period2.end" :controls="false" :max="12" :min="1" size="small"/>
<span>个月执行一次</span>
</ElRadio>
<ElRadio value="specify">
<div>指定</div>
<ElCheckboxGroup v-model="specify" @change="valueChange('specify')">
<ElCheckbox v-for="i in 12" :key="'MonthPanel' + i" :label="i" :value="i"/>
<ElCheckboxGroup v-model="monthState.specify">
<ElCheckbox v-for="(month,i) in months" :key="'monthState.specify' + i" :label="month" :value="i"/>
</ElCheckboxGroup>
</ElRadio>
</ElRadioGroup>
@ -100,8 +45,6 @@ onMounted(() => {
align-items start
gap 10px
width 100%;
//width 600px;
//overflow auto
flex-wrap nowrap
:deep(.el-input-number) {

View File

@ -1,88 +1,29 @@
<script lang="ts" setup>
const props = defineProps<{
modelValue: string
}>()
import { useCronStore } from '@/pages/sys/task/cron/cron-store.ts'
const emits = defineEmits([ 'update:modelValue' ])
const moduleData = ref('every')
const period1 = reactive({
start: undefined,
end: undefined,
})
const period2 = reactive({
start: undefined,
end: undefined,
})
const specify = ref<number[]>([])
const fn = {
every() {
emits('update:modelValue', '*')
},
period1() {
emits('update:modelValue', `${period1.start}-${period1.end}`)
},
period2() {
emits('update:modelValue', `${period2.start}/${period2.end}`)
},
specify() {
emits('update:modelValue', specify.value.join(','))
},
}
function moduleChange(val: 'every' | 'period1' | 'period2' | 'specify') {
fn[val]?.()
}
function valueChange(module: 'every' | 'period1' | 'period2' | 'specify') {
if (moduleData.value !== module) {
moduleData.value = module
}
moduleChange(module)
}
onMounted(() => {
let newModuleData = 'every'
if (props.modelValue.includes('-')) {
const s = props.modelValue.split('-')
period1.start = +s[0]
period1.end = +s[1]
newModuleData = 'period1'
} else if (props.modelValue.includes('/')) {
const s = props.modelValue.split('/')
period2.start = +s[0]
period2.end = +s[1]
newModuleData = 'period2'
} else if (props.modelValue.includes(',')) {
specify.value = props.modelValue.split(',').map(it => +it)
newModuleData = 'specify'
}
moduleData.value = newModuleData
})
const {secondState} = toRefs(useCronStore())
</script>
<template>
<ElRadioGroup v-model="moduleData" class="select-panel" @change="moduleChange">
<ElRadioGroup v-model="secondState.mode" class="select-panel">
<ElRadio value="every">每秒</ElRadio>
<ElRadio value="period1">
<span>周期</span>
<ElInputNumber v-model="period1.start" :controls="false" :max="59" :min="0" size="small" @change="valueChange('period1')"/>
<ElInputNumber v-model="secondState.period1.start" :controls="false" :max="59" :min="0" size="small"/>
<span></span>
<ElInputNumber v-model="period1.end" :controls="false" :max="59" :min="0" size="small" @change="valueChange('period1')"/>
<ElInputNumber v-model="secondState.period1.end" :controls="false" :max="59" :min="0" size="small"/>
</ElRadio>
<ElRadio value="period2">
<span>周期从第</span>
<ElInputNumber v-model="period2.start" :controls="false" :max="59" :min="1" size="small" @change="valueChange('period2')"/>
<ElInputNumber v-model="secondState.period2.start" :controls="false" :max="59" :min="1" size="small"/>
<span>秒开始</span>
<ElInputNumber v-model="period2.end" :controls="false" :max="59" :min="1" size="small" @change="valueChange('period2')"/>
<ElInputNumber v-model="secondState.period2.end" :controls="false" :max="59" :min="1" size="small"/>
<span>秒执行一次</span>
</ElRadio>
<ElRadio value="specify">
<div>指定</div>
<ElCheckboxGroup v-model="specify" @change="valueChange('specify')">
<ElCheckboxGroup v-model="secondState.specify">
<ElCheckbox v-for="i in 60" :key="'SecondPanel' + i" :label="(i-1)+''" :value="i-1"/>
</ElCheckboxGroup>
</ElRadio>
@ -95,7 +36,6 @@ onMounted(() => {
align-items start
gap 10px
width 100%;
//overflow auto
flex-wrap nowrap
:deep(.el-input-number) {

View File

@ -1,107 +1,42 @@
<script lang="ts" setup>
const props = defineProps<{
modelValue: string
}>()
const emits = defineEmits([ 'update:modelValue' ])
const moduleData = ref('none')
const period1 = reactive({
start: undefined,
end: undefined,
})
const period2 = reactive({
start: undefined,
end: undefined,
})
const specify = ref<number[]>([])
const last = ref<number>(1)
const fn = {
none() {
emits('update:modelValue', '?')
},
every() {
emits('update:modelValue', '*')
},
last() {
emits('update:modelValue', last.value + 'L')
},
period1() {
emits('update:modelValue', `${period1.start}-${period1.end}`)
},
period2() {
emits('update:modelValue', `${period2.start}#${period2.end}`)
},
specify() {
emits('update:modelValue', specify.value.join(','))
},
}
function moduleChange(val: 'none' | 'every' | 'last' | 'period1' | 'period2' | 'specify') {
fn[val]?.()
}
function valueChange(module: 'none' | 'every' | 'last' | 'period1' | 'period2' | 'specify') {
if (moduleData.value !== module) {
moduleData.value = module
}
moduleChange(module)
}
onMounted(() => {
let newModuleData = 'every'
if (props.modelValue === '?') {
newModuleData = 'none'
} else if (props.modelValue.includes('L')) {
const s = props.modelValue.split('L')
newModuleData = 'last'
last.value = +s[0]
} else if (props.modelValue.includes('-')) {
const s = props.modelValue.split('-')
period1.start = +s[0]
period1.end = +s[1]
newModuleData = 'period1'
} else if (props.modelValue.includes('#')) {
const s = props.modelValue.split('#')
period2.start = +s[0]
period2.end = +s[1]
newModuleData = 'period2'
} else if (props.modelValue.includes(',')) {
specify.value = props.modelValue.split(',').map(it => +it)
newModuleData = 'specify'
}
moduleData.value = newModuleData
})
import { useCronStore } from '@/pages/sys/task/cron/cron-store.ts'
const {weekState} = toRefs(useCronStore())
const weeks = [ '星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期天' ]
</script>
<template>
<ElRadioGroup v-model="moduleData" class="select-panel" @change="moduleChange">
<ElRadioGroup v-model="weekState.mode" class="select-panel">
<ElRadio value="none">不指定</ElRadio>
<ElRadio value="every">每周</ElRadio>
<ElRadio value="last">
<span>每月最后一个星期</span>
<ElInputNumber v-model="last" :controls="false" :max="59" :min="1" size="small" @change="valueChange('last')"/>
<span>每月最后一个</span>
<ElSelect v-model="weekState.last" size="small">
<ElOption v-for="(week,i) in weeks" :key="'weekState.last' + i" :label="week" :value="i"/>
</ElSelect>
</ElRadio>
<ElRadio value="period1">
<span>周期</span>
<ElInputNumber v-model="period1.start" :controls="false" :max="59" :min="1" size="small" @change="valueChange('period1')"/>
<ElSelect v-model="weekState.period1.start" size="small">
<ElOption v-for="(week,i) in weeks" :key="'weekState.period1.start' + i" :disabled="i === 7" :label="week" :value="i"/>
</ElSelect>
<span></span>
<ElInputNumber v-model="period1.end" :controls="false" :max="59" :min="1" size="small" @change="valueChange('period1')"/>
<ElSelect v-model="weekState.period1.end" size="small">
<ElOption v-for="(week,i) in weeks" :key="'weekState.period1.end' + i" :disabled="i <= weekState.period1.start" :label="week" :value="i"/>
</ElSelect>
</ElRadio>
<ElRadio value="period2">
<span>每月第</span>
<ElInputNumber v-model="period2.start" :controls="false" :max="59" :min="1" size="small" @change="valueChange('period2')"/>
<span>周的星期</span>
<ElInputNumber v-model="period2.end" :controls="false" :max="60" :min="1" size="small" @change="valueChange('period2')"/>
<ElInputNumber v-model="weekState.period2.start" :controls="false" :max="5" :min="1" size="small"/>
<span>个星期的星期</span>
<ElSelect v-model="weekState.period2.end" size="small">
<ElOption v-for="(week,i) in weeks" :key="'weekState.period2.end' + i" :label="week" :value="i"/>
</ElSelect>
</ElRadio>
<ElRadio value="specify">
<div>指定</div>
<ElCheckboxGroup v-model="specify" @change="valueChange('specify')">
<ElCheckbox v-for="i in 7" :key="'WeekPanel' + i" :label="i" :value="i"/>
<ElCheckboxGroup v-model="weekState.specify">
<ElCheckbox v-for="(week,i) in weeks" :key="'weekState.specify' + i" :label="week" :value="i"/>
</ElCheckboxGroup>
</ElRadio>
</ElRadioGroup>
@ -113,8 +48,6 @@ onMounted(() => {
align-items start
gap 10px
width 100%;
//width 600px;
//overflow auto
flex-wrap nowrap
:deep(.el-input-number) {

View File

@ -1,63 +1,20 @@
<script lang="ts" setup>
const props = defineProps<{
modelValue: string
}>()
import { useCronStore } from '@/pages/sys/task/cron/cron-store.ts'
const emits = defineEmits([ 'update:modelValue' ])
const {yearState} = toRefs(useCronStore())
let year = new Date().getFullYear()
const moduleData = ref('none')
const period1 = reactive({
start: undefined,
end: undefined,
})
const fn = {
none() {
emits('update:modelValue', '?')
},
every() {
emits('update:modelValue', '*')
},
period1() {
emits('update:modelValue', `${period1.start}-${period1.end}`)
},
}
function moduleChange(val: 'none' | 'every' | 'period1') {
fn[val]?.()
}
function valueChange(module: 'none' | 'every' | 'period1') {
if (moduleData.value !== module) {
moduleData.value = module
}
moduleChange(module)
}
onMounted(() => {
let newModuleData = 'every'
if (props.modelValue === '?') {
newModuleData = 'none'
} else if (props.modelValue.includes('-')) {
const s = props.modelValue.split('-')
period1.start = +s[0]
period1.end = +s[1]
newModuleData = 'period1'
}
moduleData.value = newModuleData
})
</script>
<template>
<ElRadioGroup v-model="moduleData" class="select-panel" @change="moduleChange">
<ElRadioGroup v-model="yearState.mode" class="select-panel">
<ElRadio value="none">不指定</ElRadio>
<ElRadio value="every">每年</ElRadio>
<ElRadio value="period1">
<span>周期</span>
<ElInputNumber v-model="period1.start" :controls="false" :max="59" :min="1" size="small" @change="valueChange('period1')"/>
<ElInputNumber v-model="yearState.period1.start" :controls="false" :max="year+99" :min="year" size="small"/>
<span></span>
<ElInputNumber v-model="period1.end" :controls="false" :max="59" :min="1" size="small" @change="valueChange('period1')"/>
<ElInputNumber v-model="yearState.period1.end" :controls="false" :max="year+100" :min="yearState.period1.start" size="small"/>
</ElRadio>
</ElRadioGroup>
</template>
@ -68,8 +25,6 @@ onMounted(() => {
align-items start
gap 10px
width 100%;
//width 600px;
//overflow auto
flex-wrap nowrap
:deep(.el-input-number) {

View File

@ -0,0 +1,453 @@
import { defineStore } from 'pinia'
import Strings from '@/common/utils/strings.ts'
export interface SMHState {
mode: 'every' | 'period1' | 'period2' | 'specify'
period1: {
start: number
end: number
}
period2: {
start: number
end: number
}
specify: number[]
}
export interface DState {
mode: 'none' | 'every' | 'last' | 'near' | 'period1' | 'period2' | 'specify'
period1: {
start: number
end: number
}
period2: {
start: number
end: number
}
specify: number[]
near: number
}
export interface MState {
mode: 'none' | 'every' | 'period1' | 'period2' | 'specify'
period1: {
start: number
end: number
}
period2: {
start: number
end: number
}
specify: number[]
}
export interface WState {
mode: 'none' | 'every' | 'last' | 'period1' | 'period2' | 'specify'
period1: {
start: number
end: number
}
period2: {
start: number
end: number
}
specify: number[]
last: number
}
export interface YState {
mode: 'none' | 'every' | 'period1'
period1: {
start: number
end: number
}
}
export const useCronStore = defineStore('Cron', () => {
const secondState = reactive<SMHState>({
mode: 'every',
period1: {
start: 1,
end: 2,
},
period2: {
start: 1,
end: 1,
},
specify: [],
})
const secondVal = computed(() => {
let data: string = '*'
if (secondState.mode === 'period1') {
data = `${secondState.period1.start}-${secondState.period1.end}`
} else if (secondState.mode === 'period2') {
data = `${secondState.period2.start}/${secondState.period2.end}`
} else if (secondState.mode === 'specify') {
data = secondState.specify.sort((a, b) => a - b).join(',')
}
return data
})
const setSecondVal = (val: string) => {
if (val.includes('-')) {
const s = val.split('-')
secondState.period1.start = +s[0]
secondState.period1.end = +s[1]
secondState.mode = 'period1'
} else if (val.includes('/')) {
const s = val.split('/')
secondState.period2.start = +s[0]
secondState.period2.end = +s[1]
secondState.mode = 'period2'
} else if (val.includes(',')) {
secondState.specify = val.split(',').map(it => +it)
secondState.mode = 'specify'
} else if (Strings.isNumStr(val)) {
secondState.specify = [ +val ]
secondState.mode = 'specify'
} else {
secondState.mode = 'every'
}
}
const minuteState = reactive<SMHState>({
mode: 'every',
period1: {
start: 1,
end: 2,
},
period2: {
start: 1,
end: 1,
},
specify: [],
})
const minuteVal = computed(() => {
let data: string = '*'
if (minuteState.mode === 'period1') {
data = `${minuteState.period1.start}-${minuteState.period1.end}`
} else if (minuteState.mode === 'period2') {
data = `${minuteState.period2.start}/${minuteState.period2.end}`
} else if (minuteState.mode === 'specify') {
data = minuteState.specify.sort((a, b) => a - b).join(',')
}
return data
})
const setMinuteVal = (val: string) => {
if (val.includes('-')) {
const s = val.split('-')
minuteState.period1.start = +s[0]
minuteState.period1.end = +s[1]
minuteState.mode = 'period1'
} else if (val.includes('/')) {
const s = val.split('/')
minuteState.period2.start = +s[0]
minuteState.period2.end = +s[1]
minuteState.mode = 'period2'
} else if (val.includes(',')) {
minuteState.specify = val.split(',').map(it => +it)
minuteState.mode = 'specify'
} else if (Strings.isNumStr(val)) {
minuteState.specify = [ +val ]
minuteState.mode = 'specify'
} else {
minuteState.mode = 'every'
}
}
const hourState = reactive<SMHState>({
mode: 'every',
period1: {
start: 1,
end: 2,
},
period2: {
start: 1,
end: 1,
},
specify: [],
})
const hourVal = computed(() => {
let data: string = '*'
if (hourState.mode === 'period1') {
data = `${hourState.period1.start}-${hourState.period1.end}`
} else if (hourState.mode === 'period2') {
data = `${hourState.period2.start}/${hourState.period2.end}`
} else if (hourState.mode === 'specify') {
data = hourState.specify.sort((a, b) => a - b).join(',')
}
return data
})
const setHourVal = (val: string) => {
if (val.includes('-')) {
const s = val.split('-')
hourState.period1.start = +s[0]
hourState.period1.end = +s[1]
hourState.mode = 'period1'
} else if (val.includes('/')) {
const s = val.split('/')
hourState.period2.start = +s[0]
hourState.period2.end = +s[1]
hourState.mode = 'period2'
} else if (val.includes(',')) {
hourState.specify = val.split(',').map(it => +it)
hourState.mode = 'specify'
} else if (Strings.isNumStr(val)) {
hourState.specify = [ +val ]
hourState.mode = 'specify'
} else {
hourState.mode = 'every'
}
}
const dayState = reactive<DState>({
mode: 'every',
period1: {
start: 1,
end: 2,
},
period2: {
start: 1,
end: 1,
},
specify: [],
near: 1,
})
const dayVal = computed(() => {
let data: string = '*'
if (dayState.mode === 'none') {
data = '?'
} else if (dayState.mode === 'last') {
data = 'L'
} else if (dayState.mode === 'near') {
data = `${dayState.near}W`
} else if (dayState.mode === 'period1') {
data = `${dayState.period1.start}-${dayState.period1.end}`
} else if (dayState.mode === 'period2') {
data = `${dayState.period2.start}/${dayState.period2.end}`
} else if (dayState.mode === 'specify') {
data = dayState.specify.sort((a, b) => a - b).join(',')
}
return data
})
const setDayVal = (val: string) => {
if (val === '?') {
dayState.mode = 'none'
} else if (val === 'L') {
dayState.mode = 'last'
} else if (val.includes('W')) {
const s = val.split('W')
dayState.near = +s[0]
dayState.mode = 'near'
} else if (val.includes('-')) {
const s = val.split('-')
dayState.period1.start = +s[0]
dayState.period1.end = +s[1]
dayState.mode = 'period1'
} else if (val.includes('/')) {
const s = val.split('/')
dayState.period2.start = +s[0]
dayState.period2.end = +s[1]
dayState.mode = 'period2'
} else if (val.includes(',')) {
dayState.specify = val.split(',').map(it => +it)
dayState.mode = 'specify'
} else if (Strings.isNumStr(val)) {
dayState.specify = [ +val ]
dayState.mode = 'specify'
} else {
dayState.mode = 'every'
}
}
const monthState = reactive<MState>({
mode: 'every',
period1: {
start: 1,
end: 2,
},
period2: {
start: 1,
end: 1,
},
specify: [],
})
const monthVal = computed(() => {
let data: string = '*'
if (monthState.mode === 'none') {
data = '?'
} else if (monthState.mode === 'period1') {
data = `${monthState.period1.start}-${monthState.period1.end}`
} else if (monthState.mode === 'period2') {
data = `${monthState.period2.start}/${monthState.period2.end}`
} else if (monthState.mode === 'specify') {
data = monthState.specify.sort((a, b) => a - b).join(',')
}
return data
})
const setMonthVal = (val: string) => {
if (val === '?') {
monthState.mode = 'none'
} else if (val.includes('-')) {
const s = val.split('-')
monthState.period1.start = +s[0]
monthState.period1.end = +s[1]
monthState.mode = 'period1'
} else if (val.includes('/')) {
const s = val.split('/')
monthState.period2.start = +s[0]
monthState.period2.end = +s[1]
monthState.mode = 'period2'
} else if (val.includes(',')) {
monthState.specify = val.split(',').map(it => +it)
monthState.mode = 'specify'
} else if (Strings.isNumStr(val)) {
monthState.specify = [ +val ]
monthState.mode = 'specify'
} else {
monthState.mode = 'every'
}
}
const weekState = reactive<WState>({
mode: 'none',
period1: {
start: 1,
end: 2,
},
period2: {
start: 1,
end: 1,
},
specify: [],
last: 1,
})
const weekVal = computed(() => {
let data: string = '*'
if (weekState.mode === 'none') {
data = '?'
} else if (weekState.mode === 'last') {
data = `${(weekState.last + 1) % 7}L`
} else if (weekState.mode === 'period1') {
data = `${(weekState.period1.start + 1) % 7}-${(weekState.period1.end + 1) % 7}`
} else if (weekState.mode === 'period2') {
data = `${(weekState.period2.start + 1) % 7}#${(weekState.period2.end + 1) % 7}`
} else if (weekState.mode === 'specify') {
data = weekState.specify.map(it => (it + 1) % 7).sort((a, b) => a - b).join(',')
}
return data
})
const setWeekVal = (val: string) => {
if (val === '?') {
weekState.mode = 'none'
} else if (val.includes('L')) {
const s = val.split('L')
let s0 = +s[0]
weekState.last = s0 === 0 ? 6 : (s0 - 1)
weekState.mode = 'last'
} else if (val.includes('-')) {
const s = val.split('-')
let s0 = +s[0]
let s1 = +s[1]
secondState.period1.start = s0 === 0 ? 6 : (s0 - 1)
secondState.period1.end = s1 === 0 ? 6 : (s1 - 1)
secondState.mode = 'period1'
} else if (val.includes('#')) {
const s = val.split('#')
let s0 = +s[0]
let s1 = +s[1]
weekState.period2.start = s0 === 0 ? 6 : (s0 - 1)
weekState.period2.end = s1 === 0 ? 6 : (s1 - 1)
weekState.mode = 'period2'
} else if (val.includes(',')) {
weekState.specify = val.split(',').map(it => {
let num = +it
return num === 0 ? 6 : (num - 1)
})
weekState.mode = 'specify'
} else if (Strings.isNumStr(val)) {
let num = +val
weekState.specify = [ num === 0 ? 6 : (num - 1) ]
weekState.mode = 'specify'
} else {
weekState.mode = 'every'
}
}
let year = new Date().getFullYear()
const yearState = reactive<YState>({
mode: 'none',
period1: {
start: year,
end: year + 10,
},
})
const yearVal = computed(() => {
let data: string = '*'
if (yearState.mode === 'none') {
data = '?'
} else if (yearState.mode === 'period1') {
data = `${yearState.period1.start}-${yearState.period1.end}`
}
return data
})
const setYearVal = (val: string) => {
if (val === '?') {
yearState.mode = 'none'
} else if (val.includes('-')) {
const s = val.split('-')
yearState.period1.start = +s[0]
yearState.period1.end = +s[1]
yearState.mode = 'period1'
} else {
yearState.mode = 'every'
}
}
const cronVal = computed({
get() {
console.log('获取值', `${secondVal.value} ${minuteVal.value} ${hourVal.value} ${dayVal.value} ${monthVal.value} ${weekVal.value} ${yearVal.value}`)
return `${secondVal.value} ${minuteVal.value} ${hourVal.value} ${dayVal.value} ${monthVal.value} ${weekVal.value} ${yearVal.value}`
},
set(val: string = '* * * * * ? ?') {
let sections = val.split(' ')
if (sections.length != 7) {
sections = '* * * * * ? ?'.split(' ')
}
console.log('设置值', val, sections)
setSecondVal(sections[0])
setMinuteVal(sections[1])
setHourVal(sections[2])
setDayVal(sections[3])
setMonthVal(sections[4])
setWeekVal(sections[5])
setYearVal(sections[6])
},
})
return {
secondState,
secondVal,
setSecondVal,
minuteState,
minuteVal,
setMinuteVal,
hourState,
hourVal,
setHourVal,
dayState,
dayVal,
setDayVal,
monthState,
monthVal,
setMonthVal,
weekState,
weekVal,
setWeekVal,
yearState,
yearVal,
setYearVal,
cronVal,
// setCronVal,
}
})