mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-11-25 02:01:51 +08:00
支持计划任务日期范围
This commit is contained in:
1 parent
6a2bba4637
commit
98321d8262
12 files changed
+238
-35
No files matched your search
@@ -5,6 +5,7 @@ import * as React from "react";
|
||||
import { CalendarClock, Loader2, Pause, Play, Plus, Search, Trash2, Zap } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { DateSelect } from "@/components/date-select";
|
||||
import { TimeSelect } from "@/components/time-select";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
@@ -145,9 +146,25 @@ function ScheduleForm({
|
||||
</div>
|
||||
</div>
|
||||
{draft.schedule_type === "once" ? (
|
||||
<div className="grid gap-2">
|
||||
<Label>执行日期</Label>
|
||||
<Input type="date" value={draft.run_date ?? ""} onChange={(e) => set({ run_date: e.target.value })} />
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div className="grid gap-2">
|
||||
<Label>开始日期</Label>
|
||||
<DateSelect
|
||||
value={draft.run_date ?? ""}
|
||||
onValueChange={(value) => set({ run_date: value })}
|
||||
aria-label="开始日期"
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label>截止日期(可选)</Label>
|
||||
<DateSelect
|
||||
value={draft.end_date ?? ""}
|
||||
onValueChange={(value) => set({ end_date: value })}
|
||||
optional
|
||||
placeholder="不设置截止日期"
|
||||
aria-label="截止日期,可选"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid gap-2">
|
||||
@@ -186,7 +203,7 @@ function ScheduleForm({
|
||||
</div>
|
||||
</div>
|
||||
<p className="text-muted-foreground text-xs">
|
||||
结束时间为空表示开始后持续运行;结束时间早于开始时间表示跨午夜窗口。
|
||||
一次性计划可设置截止日期;截止日期为空时仅按结束时间控制。结束时间为空表示持续运行,结束时间早于开始时间表示跨午夜窗口。
|
||||
</p>
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<Checkbox
|
||||
@@ -344,6 +361,7 @@ export default function SchedulesPage() {
|
||||
timezone_mode: item.timezone_mode,
|
||||
schedule_type: item.schedule_type,
|
||||
run_date: item.run_date,
|
||||
end_date: item.end_date,
|
||||
weekdays: item.weekdays,
|
||||
start_time: item.start_time.slice(0, 5),
|
||||
end_time: item.end_time?.slice(0, 5),
|
||||
|
||||
@@ -45,10 +45,12 @@ import {
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { AssetInterceptRulesEditor } from "@/components/asset-intercept-rules-editor";
|
||||
import { DateSelect } from "@/components/date-select";
|
||||
import { StatusBadge } from "@/components/status-badge";
|
||||
import { TablePagination } from "@/components/table-pagination";
|
||||
import { TaskLLMProfileChain } from "@/components/task-llm-profile-chain";
|
||||
import { TaskTemplateControls } from "@/components/task-template-controls";
|
||||
import { TimeSelect } from "@/components/time-select";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
@@ -117,7 +119,6 @@ import { Switch } from "@/components/ui/switch";
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { TimeSelect } from "@/components/time-select";
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import { api, type ScheduleInput } from "@/lib/api";
|
||||
import { getLocalStorageValue, setLocalStorageValue } from "@/lib/local-storage.client";
|
||||
@@ -3101,6 +3102,7 @@ function CreateTaskSheet({
|
||||
const [schedule, setSchedule] = React.useState<ScheduleInput>({
|
||||
name: "新建任务计划",
|
||||
schedule_type: "weekly",
|
||||
end_date: "",
|
||||
weekdays: [6, 7],
|
||||
start_time: "18:00",
|
||||
end_time: "",
|
||||
@@ -3197,6 +3199,7 @@ function CreateTaskSheet({
|
||||
setSchedule({
|
||||
name: "新建任务计划",
|
||||
schedule_type: "weekly",
|
||||
end_date: "",
|
||||
weekdays: [6, 7],
|
||||
start_time: "18:00",
|
||||
end_time: "",
|
||||
@@ -3321,14 +3324,26 @@ function CreateTaskSheet({
|
||||
</Field>
|
||||
</div>
|
||||
{schedule.schedule_type === "once" ? (
|
||||
<Field>
|
||||
<FieldLabel>执行日期</FieldLabel>
|
||||
<Input
|
||||
type="date"
|
||||
value={schedule.run_date ?? ""}
|
||||
onChange={(e) => setSchedule({ ...schedule, run_date: e.target.value })}
|
||||
/>
|
||||
</Field>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<Field>
|
||||
<FieldLabel>开始日期</FieldLabel>
|
||||
<DateSelect
|
||||
value={schedule.run_date ?? ""}
|
||||
onValueChange={(value) => setSchedule({ ...schedule, run_date: value })}
|
||||
aria-label="开始日期"
|
||||
/>
|
||||
</Field>
|
||||
<Field>
|
||||
<FieldLabel>截止日期(可选)</FieldLabel>
|
||||
<DateSelect
|
||||
value={schedule.end_date ?? ""}
|
||||
onValueChange={(value) => setSchedule({ ...schedule, end_date: value })}
|
||||
optional
|
||||
placeholder="不设置截止日期"
|
||||
aria-label="截止日期,可选"
|
||||
/>
|
||||
</Field>
|
||||
</div>
|
||||
) : (
|
||||
<Field>
|
||||
<FieldLabel>星期(1=周一,7=周日)</FieldLabel>
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
|
||||
import { format, parse } from "date-fns";
|
||||
import { zhCN } from "date-fns/locale/zh-CN";
|
||||
import { CalendarDays, ChevronDown, X } from "lucide-react";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Calendar } from "@/components/ui/calendar";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
|
||||
function parseDate(value?: string) {
|
||||
if (!value) return undefined;
|
||||
const parsed = parse(value, "yyyy-MM-dd", new Date());
|
||||
return Number.isNaN(parsed.getTime()) ? undefined : parsed;
|
||||
}
|
||||
|
||||
export function DateSelect({
|
||||
value,
|
||||
onValueChange,
|
||||
optional = false,
|
||||
placeholder = "选择日期",
|
||||
"aria-label": ariaLabel,
|
||||
}: {
|
||||
value?: string;
|
||||
onValueChange: (value: string) => void;
|
||||
optional?: boolean;
|
||||
placeholder?: string;
|
||||
"aria-label"?: string;
|
||||
}) {
|
||||
const [open, setOpen] = React.useState(false);
|
||||
const selected = parseDate(value);
|
||||
return (
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
className="h-10 w-full justify-between bg-background px-3 font-normal"
|
||||
aria-label={ariaLabel}
|
||||
aria-expanded={open}
|
||||
>
|
||||
<span className="flex items-center gap-2">
|
||||
<CalendarDays className="size-4 text-muted-foreground" />
|
||||
{selected ? (
|
||||
format(selected, "yyyy年M月d日", { locale: zhCN })
|
||||
) : (
|
||||
<span className="text-muted-foreground">{placeholder}</span>
|
||||
)}
|
||||
</span>
|
||||
<span className="flex items-center gap-1">
|
||||
<ChevronDown className="size-4 text-muted-foreground" />
|
||||
</span>
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent align="start" className="w-auto overflow-hidden p-0">
|
||||
<Calendar
|
||||
mode="single"
|
||||
locale={zhCN}
|
||||
captionLayout="dropdown"
|
||||
startMonth={new Date(2020, 0, 1)}
|
||||
endMonth={new Date(2100, 11, 31)}
|
||||
selected={selected}
|
||||
defaultMonth={selected ?? new Date()}
|
||||
onSelect={(date) => {
|
||||
onValueChange(date ? format(date, "yyyy-MM-dd") : "");
|
||||
setOpen(false);
|
||||
}}
|
||||
/>
|
||||
{optional && selected && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
className="w-full rounded-none border-t"
|
||||
onClick={() => {
|
||||
onValueChange("");
|
||||
setOpen(false);
|
||||
}}
|
||||
>
|
||||
<X data-icon="inline-start" />
|
||||
清除日期
|
||||
</Button>
|
||||
)}
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
@@ -252,6 +252,7 @@ export type ScheduleInput = {
|
||||
timezone_mode?: "beijing" | "system";
|
||||
schedule_type: "once" | "weekly";
|
||||
run_date?: string;
|
||||
end_date?: string;
|
||||
weekdays?: number[];
|
||||
start_time: string;
|
||||
end_time?: string;
|
||||
@@ -266,6 +267,7 @@ function schedulePayload(input: ScheduleInput) {
|
||||
timezone_mode: input.timezone_mode ?? "beijing",
|
||||
schedule_type: input.schedule_type,
|
||||
run_date: input.run_date ?? "",
|
||||
end_date: input.end_date ?? "",
|
||||
weekdays: input.weekdays ?? [],
|
||||
start_time: input.start_time,
|
||||
end_time: input.end_time ?? "",
|
||||
|
||||
@@ -723,6 +723,7 @@ export interface TaskSchedule {
|
||||
timezone?: string;
|
||||
schedule_type: "once" | "weekly";
|
||||
run_date?: string;
|
||||
end_date?: string;
|
||||
weekdays: number[];
|
||||
start_time: string;
|
||||
end_time?: string;
|
||||
|
||||
Reference in new issue
Block a user