2022-04-14 02:02:05 +02:00
|
|
|
<script setup lang="ts">
|
2022-04-22 23:31:40 +02:00
|
|
|
import cronstrue from 'cronstrue';
|
2024-02-19 17:38:30 +08:00
|
|
|
import 'cronstrue/locales/zh_CN';
|
|
|
|
import 'cronstrue/locales/fr';
|
2022-04-22 23:31:40 +02:00
|
|
|
import { isValidCron } from 'cron-validator';
|
2022-04-18 09:18:48 +02:00
|
|
|
import { useStyleStore } from '@/stores/style.store';
|
2022-04-14 02:02:05 +02:00
|
|
|
|
|
|
|
function isCronValid(v: string) {
|
2022-04-22 23:31:40 +02:00
|
|
|
return isValidCron(v, { allowBlankDay: true, alias: true, seconds: true });
|
2022-04-14 02:02:05 +02:00
|
|
|
}
|
|
|
|
|
2022-04-22 23:31:40 +02:00
|
|
|
const styleStore = useStyleStore();
|
2022-04-18 09:18:48 +02:00
|
|
|
|
2024-02-19 17:38:30 +08:00
|
|
|
const { t, locale } = useI18n();
|
2022-04-22 23:31:40 +02:00
|
|
|
const cron = ref('40 * * * *');
|
2022-04-14 02:02:05 +02:00
|
|
|
const cronstrueConfig = reactive({
|
|
|
|
verbose: true,
|
|
|
|
dayOfWeekStartIndexZero: true,
|
|
|
|
use24HourTimeFormat: true,
|
2022-04-22 23:31:40 +02:00
|
|
|
throwExceptionOnParseError: true,
|
2024-02-19 17:38:30 +08:00
|
|
|
locale: locale.value === 'zh' ? 'zh_CN' : locale,
|
2022-04-22 23:31:40 +02:00
|
|
|
});
|
2022-04-14 02:02:05 +02:00
|
|
|
|
2022-04-18 09:18:48 +02:00
|
|
|
const helpers = [
|
2022-04-22 23:31:40 +02:00
|
|
|
{
|
|
|
|
symbol: '*',
|
2024-02-19 17:38:30 +08:00
|
|
|
meaning: t('tools.crontab-generator.anyMeaning'),
|
2022-04-22 23:31:40 +02:00
|
|
|
example: '* * * *',
|
2024-02-19 17:38:30 +08:00
|
|
|
equivalent: t('tools.crontab-generator.anyExample'),
|
2022-04-22 23:31:40 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
symbol: '-',
|
2024-02-19 17:38:30 +08:00
|
|
|
meaning: t('tools.crontab-generator.rangeMeaning'),
|
2022-04-22 23:31:40 +02:00
|
|
|
example: '1-10 * * *',
|
2024-02-19 17:38:30 +08:00
|
|
|
equivalent: t('tools.crontab-generator.rangeExample'),
|
2022-04-22 23:31:40 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
symbol: ',',
|
2024-02-19 17:38:30 +08:00
|
|
|
meaning: t('tools.crontab-generator.listMeaning'),
|
2022-04-22 23:31:40 +02:00
|
|
|
example: '1,10 * * *',
|
2024-02-19 17:38:30 +08:00
|
|
|
equivalent: t('tools.crontab-generator.listExample'),
|
2022-04-22 23:31:40 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
symbol: '/',
|
2024-02-19 17:38:30 +08:00
|
|
|
meaning: t('tools.crontab-generator.stepMeaning'),
|
2022-04-22 23:31:40 +02:00
|
|
|
example: '*/10 * * *',
|
2024-02-19 17:38:30 +08:00
|
|
|
equivalent: t('tools.crontab-generator.stepExample'),
|
2022-04-22 23:31:40 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
symbol: '@yearly',
|
2024-02-19 17:38:30 +08:00
|
|
|
meaning: t('tools.crontab-generator.yearlyMeaning'),
|
2022-04-22 23:31:40 +02:00
|
|
|
example: '@yearly',
|
|
|
|
equivalent: '0 0 1 1 *',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
symbol: '@annually',
|
2024-02-19 17:38:30 +08:00
|
|
|
meaning: t('tools.crontab-generator.annuallyMeaning', { yearly: '@yearly' }),
|
2022-04-22 23:31:40 +02:00
|
|
|
example: '@annually',
|
|
|
|
equivalent: '0 0 1 1 *',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
symbol: '@monthly',
|
2024-02-19 17:38:30 +08:00
|
|
|
meaning: t('tools.crontab-generator.monthlyMeaning'),
|
2022-04-22 23:31:40 +02:00
|
|
|
example: '@monthly',
|
|
|
|
equivalent: '0 0 1 * *',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
symbol: '@weekly',
|
2024-02-19 17:38:30 +08:00
|
|
|
meaning: t('tools.crontab-generator.weeklyMeaning'),
|
2022-04-22 23:31:40 +02:00
|
|
|
example: '@weekly',
|
|
|
|
equivalent: '0 0 * * 0',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
symbol: '@daily',
|
2024-02-19 17:38:30 +08:00
|
|
|
meaning: t('tools.crontab-generator.dailyMeaning'),
|
2022-04-22 23:31:40 +02:00
|
|
|
example: '@daily',
|
|
|
|
equivalent: '0 0 * * *',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
symbol: '@midnight',
|
2024-02-19 17:38:30 +08:00
|
|
|
meaning: t('tools.crontab-generator.midnightMeaning', { daily: '@daily' }),
|
2022-04-22 23:31:40 +02:00
|
|
|
example: '@midnight',
|
|
|
|
equivalent: '0 0 * * *',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
symbol: '@hourly',
|
2024-02-19 17:38:30 +08:00
|
|
|
meaning: t('tools.crontab-generator.hourlyMeaning'),
|
2022-04-22 23:31:40 +02:00
|
|
|
example: '@hourly',
|
|
|
|
equivalent: '0 * * * *',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
symbol: '@reboot',
|
2024-02-19 17:38:30 +08:00
|
|
|
meaning: t('tools.crontab-generator.rebootMeaning'),
|
2022-04-22 23:31:40 +02:00
|
|
|
example: '',
|
|
|
|
equivalent: '',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2022-04-14 02:02:05 +02:00
|
|
|
const cronString = computed(() => {
|
|
|
|
if (isCronValid(cron.value)) {
|
2022-04-22 23:31:40 +02:00
|
|
|
return cronstrue.toString(cron.value, cronstrueConfig);
|
2022-04-14 02:02:05 +02:00
|
|
|
}
|
2022-04-22 23:31:40 +02:00
|
|
|
return ' ';
|
|
|
|
});
|
2022-04-14 02:02:05 +02:00
|
|
|
|
2023-05-14 21:26:18 +02:00
|
|
|
const cronValidationRules = [
|
|
|
|
{
|
|
|
|
validator: (value: string) => isCronValid(value),
|
2024-02-19 17:38:30 +08:00
|
|
|
message: t('tools.crontab-generator.invalidMessage'),
|
2023-05-14 21:26:18 +02:00
|
|
|
},
|
|
|
|
];
|
2022-04-14 02:02:05 +02:00
|
|
|
</script>
|
|
|
|
|
2023-05-28 23:13:24 +02:00
|
|
|
<template>
|
|
|
|
<c-card>
|
|
|
|
<div mx-auto max-w-sm>
|
|
|
|
<c-input-text
|
|
|
|
v-model:value="cron"
|
|
|
|
size="large"
|
|
|
|
placeholder="* * * * *"
|
|
|
|
:validation-rules="cronValidationRules"
|
|
|
|
mb-3
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="cron-string">
|
|
|
|
{{ cronString }}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<n-divider />
|
|
|
|
|
|
|
|
<div flex justify-center>
|
|
|
|
<n-form :show-feedback="false" label-width="170" label-placement="left">
|
2024-02-19 17:38:30 +08:00
|
|
|
<n-form-item :label="t('tools.crontab-generator.verbose')">
|
2023-05-28 23:13:24 +02:00
|
|
|
<n-switch v-model:value="cronstrueConfig.verbose" />
|
|
|
|
</n-form-item>
|
2024-02-19 17:38:30 +08:00
|
|
|
<n-form-item :label="t('tools.crontab-generator.use24HourTimeFormat')">
|
2023-05-28 23:13:24 +02:00
|
|
|
<n-switch v-model:value="cronstrueConfig.use24HourTimeFormat" />
|
|
|
|
</n-form-item>
|
2024-02-19 17:38:30 +08:00
|
|
|
<n-form-item :label="t('tools.crontab-generator.dayOfWeekStartIndexZero')">
|
2023-05-28 23:13:24 +02:00
|
|
|
<n-switch v-model:value="cronstrueConfig.dayOfWeekStartIndexZero" />
|
|
|
|
</n-form-item>
|
|
|
|
</n-form>
|
|
|
|
</div>
|
|
|
|
</c-card>
|
|
|
|
<c-card>
|
|
|
|
<pre>
|
2024-02-19 17:38:30 +08:00
|
|
|
┌──────────── {{ t('tools.crontab-generator.secondDesc') }}
|
|
|
|
| ┌────────── {{ t('tools.crontab-generator.minuteDesc') }}
|
|
|
|
| | ┌──────── {{ t('tools.crontab-generator.hourDesc') }}
|
|
|
|
| | | ┌────── {{ t('tools.crontab-generator.dayOfMonthDesc') }}
|
|
|
|
| | | | ┌──── {{ t('tools.crontab-generator.monthDesc') }}
|
|
|
|
| | | | | ┌── {{ t('tools.crontab-generator.dayOfWeekDesc') }}
|
2023-05-28 23:13:24 +02:00
|
|
|
| | | | | |
|
2024-02-19 17:38:30 +08:00
|
|
|
* * * * * * {{ t('tools.crontab-generator.command') }}</pre>
|
2023-05-28 23:13:24 +02:00
|
|
|
|
|
|
|
<div v-if="styleStore.isSmallScreen">
|
|
|
|
<c-card v-for="{ symbol, meaning, example, equivalent } in helpers" :key="symbol" mb-3 important:border-none>
|
|
|
|
<div>
|
2024-02-19 17:38:30 +08:00
|
|
|
{{ t('tools.crontab-generator.symbol') }} <strong>{{ symbol }}</strong>
|
2023-05-28 23:13:24 +02:00
|
|
|
</div>
|
|
|
|
<div>
|
2024-02-19 17:38:30 +08:00
|
|
|
{{ t('tools.crontab-generator.meaning') }} <strong>{{ meaning }}</strong>
|
2023-05-28 23:13:24 +02:00
|
|
|
</div>
|
|
|
|
<div>
|
2024-02-19 17:38:30 +08:00
|
|
|
{{ t('tools.crontab-generator.example') }}
|
2023-05-28 23:13:24 +02:00
|
|
|
<strong><code>{{ example }}</code></strong>
|
|
|
|
</div>
|
|
|
|
<div>
|
2024-02-19 17:38:30 +08:00
|
|
|
{{ t('tools.crontab-generator.equivalent') }} <strong>{{ equivalent }}</strong>
|
2023-05-28 23:13:24 +02:00
|
|
|
</div>
|
|
|
|
</c-card>
|
|
|
|
</div>
|
2023-10-15 00:45:14 +02:00
|
|
|
|
|
|
|
<c-table v-else :data="helpers" />
|
2023-05-28 23:13:24 +02:00
|
|
|
</c-card>
|
|
|
|
</template>
|
|
|
|
|
2022-04-14 02:02:05 +02:00
|
|
|
<style lang="less" scoped>
|
2023-05-14 21:26:18 +02:00
|
|
|
::v-deep(input) {
|
|
|
|
font-size: 30px;
|
|
|
|
font-family: monospace;
|
|
|
|
padding: 5px;
|
2022-04-14 02:02:05 +02:00
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.cron-string {
|
|
|
|
text-align: center;
|
|
|
|
font-size: 22px;
|
|
|
|
opacity: 0.8;
|
|
|
|
margin: 5px 0 15px;
|
|
|
|
}
|
2022-04-18 08:50:57 +02:00
|
|
|
|
|
|
|
pre {
|
|
|
|
overflow: auto;
|
|
|
|
padding: 10px 0;
|
|
|
|
}
|
|
|
|
</style>
|