Files
interview-demo-code/frontend/admin/src/components/CronExpressionSelect.vue
Nikita Kiselev 0e48b9d56d
Some checks failed
Telegram Mini App Shop Builder / Compute version metadata (push) Has been cancelled
Telegram Mini App Shop Builder / Run Frontend tests (push) Has been cancelled
Telegram Mini App Shop Builder / Run Backend tests (push) Has been cancelled
Telegram Mini App Shop Builder / Run PHP_CodeSniffer (push) Has been cancelled
Telegram Mini App Shop Builder / Build module. (push) Has been cancelled
Telegram Mini App Shop Builder / release (push) Has been cancelled
Squashed commit message
2026-03-11 22:17:44 +03:00

49 lines
1.6 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<Dropdown
:model-value="modelValue"
:options="options"
option-label="label"
option-value="value"
placeholder="Интервал"
class="tw:w-[14rem] tw:shrink-0"
@update:model-value="$emit('update:modelValue', $event ?? '')"
/>
</template>
<script setup>
import { computed } from 'vue';
import Dropdown from 'primevue/dropdown';
const props = defineProps({
modelValue: {
type: String,
default: '',
},
});
defineEmits(['update:modelValue']);
/** Пресеты интервалов (label — для отображения, value — cron expression) */
const PRESETS = [
{ label: 'Раз в минуту', value: '* * * * *' },
{ label: 'Раз в 5 минут', value: '*/5 * * * *' },
{ label: 'Раз в 10 минут', value: '*/10 * * * *' },
{ label: 'Раз в час', value: '0 * * * *' },
{ label: 'Раз в 3 часа', value: '0 */3 * * *' },
{ label: 'Раз в 6 часов', value: '0 */6 * * *' },
{ label: 'Раз в сутки', value: '0 0 * * *' },
{ label: 'Раз в неделю', value: '0 0 * * 0' },
];
const presetValues = new Set(PRESETS.map((p) => p.value));
/** Только пресеты; если текущее значение не из списка — показываем его в списке (уже сохранённое в БД), чтобы не терять отображение */
const options = computed(() => {
const current = props.modelValue ?? '';
if (!current || presetValues.has(current)) {
return PRESETS;
}
return [{ label: current, value: current }, ...PRESETS];
});
</script>