-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
333 additions
and
30 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
packages/ctool-core/src/tools/crontab/generate/Generate.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<template> | ||
<Tabs | ||
v-model="current" | ||
padding="20px 10px 0 20px" | ||
:lists="[ | ||
{name:`second`,label:$t('crontab_generate_second')}, | ||
{name:`minute`,label:$t('crontab_generate_minute')}, | ||
{name:`hour`,label:$t('crontab_generate_hour')}, | ||
{name:`day`,label:$t('crontab_generate_day')}, | ||
{name:`month`,label:$t('crontab_generate_month')}, | ||
{name:`week`,label:$t('crontab_generate_week')}, | ||
]" | ||
> | ||
<Item type="second" v-model="items.second"/> | ||
<Item type="minute" v-model="items.minute"/> | ||
<Item type="hour" v-model="items.hour"/> | ||
<Item type="day" v-model="items.day"/> | ||
<Item type="month" v-model="items.month"/> | ||
<Item type="week" v-model="items.week"/> | ||
</Tabs> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import './style.css' | ||
import Tabs from "@/components/ui/Tabs.vue"; | ||
import Item from "./Item.vue"; | ||
import {watch} from 'vue'; | ||
import {ItemType} from "./type"; | ||
const props = defineProps({ | ||
modelValue: { | ||
type: String, | ||
default: "" | ||
} | ||
}) | ||
const emit = defineEmits<{ (e: 'update:modelValue', value: string): void }>() | ||
let current = $ref<ItemType>('minute') | ||
let items = $ref({ | ||
second: "", | ||
minute: "*", | ||
hour: "*", | ||
day: "*", | ||
month: "*", | ||
week: "*" | ||
}) | ||
watch(() => { | ||
return {items} | ||
}, ({items}) => { | ||
emit('update:modelValue', [ | ||
...(items.second !== "" ? [items.second] : []), | ||
items.minute, | ||
items.hour, | ||
items.day, | ||
items.month, | ||
items.week | ||
].join(" ")) | ||
}, {immediate: true, deep: true}) | ||
</script> |
137 changes: 137 additions & 0 deletions
137
packages/ctool-core/src/tools/crontab/generate/Item.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
<template> | ||
<Align direction="vertical" gap="large"> | ||
<Option v-model="optionType" v-if="type==='second'" name="ignore" @select="(value)=>select(value)"/> | ||
<Option v-model="optionType" name="any" @select="(value)=>select(value)"> | ||
<code>*</code> | ||
</Option> | ||
<Option v-model="optionType" name="scope" @select="(value)=>select(value)"> | ||
<Align> | ||
<InputNumber size="small" v-model="optionValue.scope.start" :min="scope[0]" :max="scope[1]" :step="1"/> | ||
<code>-</code> | ||
<InputNumber size="small" v-model="optionValue.scope.end" :min="scope[0]" :max="scope[1]" :step="1"/> | ||
</Align> | ||
</Option> | ||
<Option v-model="optionType" name="interval" @select="(value)=>select(value)"> | ||
<Align> | ||
<Input size="small" v-model="optionValue.interval.start"/> | ||
<code>/</code> | ||
<InputNumber size="small" v-model="optionValue.interval.step" :min="interval[0]" :max="interval[1]" :step="1"/> | ||
</Align> | ||
</Option> | ||
<Option v-model="optionType" name="list" @select="(value)=>select(value)"> | ||
<Checkbox :options="list" v-model="optionValue.list"/> | ||
</Option> | ||
</Align> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import {watch, PropType} from 'vue'; | ||
import {range} from 'lodash'; | ||
import Align from "@/components/Align.vue"; | ||
import Option from "./Option.vue"; | ||
import Checkbox from "@/components/ui/Checkbox.vue"; | ||
import Input from "@/components/ui/Input.vue"; | ||
import InputNumber from "@/components/ui/InputNumber.vue"; | ||
import {ItemType, OptionType, OptionValue} from "./type"; | ||
const props = defineProps({ | ||
modelValue: { | ||
type: String, | ||
default: "" | ||
}, | ||
type: { | ||
type: String as PropType<ItemType>, | ||
default: "minute" | ||
} | ||
}) | ||
const emit = defineEmits<{ (e: 'update:modelValue', value: string): void }>() | ||
let optionType = $ref<OptionType>(props.type === "second" ? "ignore" : "any") | ||
let optionValue = $ref<OptionValue>({ | ||
any: "*", | ||
scope: { | ||
start: 2, | ||
end: 5, | ||
}, | ||
interval: { | ||
start: "*", | ||
step: 5 | ||
}, | ||
list: [] | ||
}) | ||
const select = (value: any) => { | ||
optionType = value | ||
} | ||
const scope = $computed<[number, number]>(() => { | ||
if (props.type === "hour") { | ||
return [0, 23] | ||
} | ||
if (props.type === "day") { | ||
return [1, 31] | ||
} | ||
if (props.type === "month") { | ||
return [1, 12] | ||
} | ||
if (props.type === "week") { | ||
return [0, 7] | ||
} | ||
return [0, 59] | ||
}) | ||
const interval = $computed<[number, number]>(() => { | ||
if (props.type === "hour") { | ||
return [2, 23] | ||
} | ||
if (props.type === "day") { | ||
return [2, 31] | ||
} | ||
if (props.type === "month") { | ||
return [2, 12] | ||
} | ||
if (props.type === "week") { | ||
return [2, 7] | ||
} | ||
return [0, 59] | ||
}) | ||
const list = $computed(() => { | ||
if (props.type === "hour") { | ||
return range(0, 24) | ||
} | ||
if (props.type === "day") { | ||
return [...range(1, 32), 'L'] | ||
} | ||
if (props.type === "month") { | ||
return range(1, 13) | ||
} | ||
if (props.type === "week") { | ||
return [...range(0, 8), ...range(1, 8).map(i => `${i}L`)] | ||
} | ||
return range(0, 60) | ||
}) | ||
watch(() => { | ||
return { | ||
type: optionType, | ||
value: optionValue | ||
} | ||
}, ({type, value}) => { | ||
if (type === "ignore") { | ||
return emit("update:modelValue", "") | ||
} | ||
if (type === "scope") { | ||
return emit("update:modelValue", `${value.scope.start}-${value.scope.end}`) | ||
} | ||
if (type === "interval") { | ||
let start = value.interval.start.trim() | ||
return emit("update:modelValue", `${["0", "*", ""].includes(start) ? "*" : value.interval.start}/${value.interval.step}`) | ||
} | ||
if (type === "list" && value.list.length > 0) { | ||
return emit("update:modelValue", value.list.join(",")) | ||
} | ||
emit("update:modelValue", "*") | ||
}, {deep: true}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<template> | ||
<div class="ctool-crontab-generate-layout" @click="emit('select',name)"> | ||
<Icon hover v-if="modelValue === name" :size="14" color="var(--primary)" name="checked"/> | ||
<Icon hover v-else :size="14" color="var(--ctool-border-color)" name="unchecked"/> | ||
<span>{{ $t(`crontab_generate_${name}`) }}</span> | ||
<div><slot></slot></div> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
const props = defineProps({ | ||
modelValue: { | ||
type: String, | ||
default: "" | ||
}, | ||
name: { | ||
type: String, | ||
default: "" | ||
} | ||
}) | ||
const emit = defineEmits<{ (e: 'select', value: string): void }>() | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.ctool-crontab-generate-layout { | ||
display: grid; | ||
grid-template-columns: auto auto minmax(0, 1fr); | ||
gap: 20px 10px; | ||
align-items: center; | ||
} | ||
.ctool-crontab-generate-layout .ctool-input input { | ||
text-align: center; | ||
} | ||
.ctool-crontab-generate-layout .ctool-input { | ||
width: 60px; | ||
} | ||
.ctool-crontab-generate-layout .ctool-checkbox .ctool-bool{ | ||
height: 24px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export type ItemType = "second" | "minute" | "hour" | "day" | "month" | "week" | ||
export type OptionType = "any" | "scope" | "interval" | "list" | "ignore" | ||
export type OptionValue = { | ||
any: "*", | ||
scope: { | ||
start: number, | ||
end: number, | ||
}, | ||
interval: { | ||
start: string, | ||
step: number | ||
}, | ||
list: (string | number)[] | ||
} |
Oops, something went wrong.