Files
UHD_Media_Tool/apps/web/app/components/schedules/labels.ts
T
rootandClaude Opus 5.5 260f3ab27f feat(web): 首页只回答三件事、计划页巡检置顶与分组折叠、任务列表去噪(DEAI-2)
首页:顶部一行状态(自动化开关 + 只在异常时出现的服务 / 下载盘 / 站点账号 / 下载器问题),
下面只有「在忙什么」「要我处理」「最近入库」三块;去掉运行状态、计划、缓存、来源健康、
满足率与 0 值铺陈;0 订阅时写「还没有订阅。去搜索添加」。只读对账移出首页,设置里放进
自动化 →「高级」(与存储预算、流水保留、缓存有效期一起默认收起)。

计划页:「智能体巡检」移到最上面——巡检数量少、由用户自己建、每次会花钱,是这页最需要
看的;自动任务任务多、多数不用管,放在下面。自动任务按分类分组、每组可折叠:有失败或
运行中的组默认展开,其余收起为「N 个任务 · 下次 xx」一行,折叠状态记在 localStorage;
维护类整组叫「数据清理」,未接入调度的备份不列。巡检卡只留名称、开关、间隔、上次结果与
费用,目标 / 能力 / 预算 / 模型 / 最近会话收进「详情」。去掉顶部 6 个计数卡。定时任务说明
去掉表名、字段名与实现备注。

任务页:默认隐藏系统任务(无业务对象的引擎步骤、定时任务的成功运行),可一键显示;
标题不再用 ID;耗时移入技术信息;< 1 秒写「< 1 秒」;费用两位小数,不足一分写「< $0.01」。
下载盘相关文案改用「暂停线 / 恢复线」。

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-09-29 20:48:35 +08:00

132 lines
4.9 KiB
TypeScript

import type {
AgentCheckTrigger,
ScheduleGroup,
ScheduleRunStatus,
ScheduleSpec,
ScheduleTrigger,
} from "@umt/contracts";
import type { StatusTone } from "~/components/console/status-badge.tsx";
// 定时任务看板的标签映射(只在本页用,不放 lib/labels.ts)
export const GROUP_ORDER: ScheduleGroup[] = ["collect", "download", "organize", "maintain", "agent"];
/** 计划页「自动任务」一节的分组(智能体巡检单独一节,放在最上面);维护类合成一组「数据清理」 */
export const TASK_GROUPS: ScheduleGroup[] = ["collect", "download", "organize", "maintain"];
/** 计划页两节的锚点:/console/schedules#auto、#checks */
export type PlanSection = "auto" | "checks";
export const PLAN_PATH = "/console/schedules";
export function planPath(opts: { section?: PlanSection; job?: string } = {}): string {
const q = opts.job ? `?job=${encodeURIComponent(opts.job)}` : "";
return `${PLAN_PATH}${q}${opts.section ? `#${opts.section}` : ""}`;
}
/** 任务页里某个定时任务触发的任务(businessKind=schedule) */
export const scheduleStreamPath = (id: string) => `/console/tasks?tab=all&kind=schedule&ref=${encodeURIComponent(id)}`;
export const GROUP_LABEL: Record<ScheduleGroup, string> = {
collect: "采集",
download: "下载",
organize: "整理",
maintain: "数据清理",
agent: "智能体巡检",
};
export const RUN_STATUS: Record<ScheduleRunStatus, { label: string; tone: StatusTone }> = {
ok: { label: "成功", tone: "success" },
failed: { label: "失败", tone: "destructive" },
skipped: { label: "已跳过", tone: "warning" },
running: { label: "运行中", tone: "neutral" },
};
export const TRIGGER_LABEL: Record<ScheduleTrigger, string> = {
schedule: "定时",
manual: "手动",
skip: "跳过",
};
export const CHECK_TRIGGER_LABEL: Record<AgentCheckTrigger, string> = {
always: "每次运行",
open_decisions: "有待处理时",
stalled_downloads: "有下载无进展时",
subscriptions_active: "有追踪订阅时",
};
export type IntervalUnit = "s" | "m" | "h";
export const UNIT_MS: Record<IntervalUnit, number> = { s: 1000, m: 60_000, h: 3600_000 };
export const UNIT_LABEL: Record<IntervalUnit, string> = { s: "秒", m: "分钟", h: "小时" };
/** 间隔下拉的常用选项(毫秒);当前值不在其中时下拉另列一项 */
export const INTERVAL_PRESETS: number[] = [
30_000,
60_000,
5 * 60_000,
10 * 60_000,
30 * 60_000,
3600_000,
6 * 3600_000,
12 * 3600_000,
24 * 3600_000,
7 * 24 * 3600_000,
];
/** 美元费用:两位小数,不足一分写 "< $0.01";空值 "—" */
export function formatUsd(v: number | null | undefined): string {
if (v === null || v === undefined) return "—";
if (v === 0) return "$0";
if (v < 0.01) return "< $0.01";
return `$${v.toFixed(2)}`;
}
/** 毫秒 → 最大整除单位 */
export function splitInterval(ms: number): { value: number; unit: IntervalUnit } {
if (ms % UNIT_MS.h === 0) return { value: ms / UNIT_MS.h, unit: "h" };
if (ms % UNIT_MS.m === 0) return { value: ms / UNIT_MS.m, unit: "m" };
return { value: Math.max(1, Math.round(ms / 1000)), unit: "s" };
}
/** 调度的简短描述:"每 30 秒" / "cron 0 3 * * *" */
export function describeSchedule(s: ScheduleSpec): string {
if (s.type === "cron") return `cron ${s.cron}`;
if (s.everyMs < 1000) return `每 ${s.everyMs} 毫秒`;
const { value, unit } = splitInterval(s.everyMs);
// 整天的间隔按天说(每 168 小时 → 每 7 天)
if (unit === "h" && value >= 24 && value % 24 === 0) return `每 ${value / 24} 天`;
return `每 ${value} ${UNIT_LABEL[unit]}`;
}
/** 毫秒耗时:"320 毫秒" / "2.4 秒" / "3 分 5 秒" */
export function formatMs(ms: number | null | undefined): string {
if (ms === null || ms === undefined) return "—";
if (ms < 1000) return `${ms} 毫秒`;
if (ms < 60_000) return `${(ms / 1000).toFixed(ms < 10_000 ? 1 : 0)} 秒`;
const sec = Math.round(ms / 1000);
if (sec < 3600) return `${Math.floor(sec / 60)} 分 ${sec % 60} 秒`;
return `${Math.floor(sec / 3600)} 小时 ${Math.floor((sec % 3600) / 60)} 分`;
}
/** 倒计时:"12 秒后" / "3 分 5 秒后" / "已到期" */
export function countdown(iso: string, now: number): string {
const diff = Math.round((new Date(iso).getTime() - now) / 1000);
if (Number.isNaN(diff)) return "—";
if (diff <= 0) return "即将运行";
if (diff < 60) return `${diff} 秒后`;
if (diff < 3600) return `${Math.floor(diff / 60)} 分 ${diff % 60} 秒后`;
if (diff < 86400) return `${Math.floor(diff / 3600)} 小时 ${Math.floor((diff % 3600) / 60)} 分后`;
return `${Math.floor(diff / 86400)} 天 ${Math.floor((diff % 86400) / 3600)} 小时后`;
}
export function formatClock(iso: string | null | undefined): string {
if (!iso) return "—";
const d = new Date(iso);
if (Number.isNaN(d.getTime())) return iso;
return d.toLocaleString("zh-CN", {
hour12: false,
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
});
}