"use client"; import { useState } from "react"; import { Timer, Info } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { toast } from "sonner"; export default function CronPage() { const [expression, setExpression] = useState("*/5 * * * *"); const parts = expression.split(/\s+/); const labels = ["分钟", "小时", "日期", "月份", "星期"]; const decodePart = (part: string, type: string) => { if (!part) return "-"; if (part === "*") return `每${type}`; if (part.includes("/")) { const [start, step] = part.split("/"); return `每隔 ${step} ${type}${start !== "*" ? ` (从第 ${start} 开始)` : ""}`; } if (part.includes("-")) { return `从 ${part.replace("-", " 到 ")} ${type}`; } if (part.includes(",")) { return `第 ${part} ${type}`; } return `第 ${part} ${type}`; }; return (
解析并说明 Cron 计划任务表达式
{label}
{parts[i] || "*"}
{decodePart(parts[i], label)}
该表达式意味着: {parts.length >= 5 ? labels.map((l, i) => decodePart(parts[i], l)).join(",") : "请输入完整的 5 位 Cron 表达式"}
*
匹配该字段的所有值
/n
指定数值增量 (每隔 n)
-
指定数值范围 (从 x 到 y)
,
指定多个值