Files
UHD_Media_Tool/apps/web/app/components/tasks/labels.ts
T
rootandClaude Opus 5.5 21c55dfb3a feat(web): 记录抽屉与两层导航标准
控制台导航最多两层(侧栏一项 = 一页,页内最多一层页签 / 分段);从列表打开的
记录改成列表页上的右侧抽屉,打开的记录写在 ?open=,刷新、分享、前进后退都能还原,
后退就是关抽屉。标准写在 docs/design/console-ia.md §9,ui-controls.md 引用。

- DetailSheet 加 xl 宽度、标题下操作行;抽屉里再开的 DetailSheet 在同一抽屉里换成子视图(返回 / Esc)
- record-sheet.tsx:useRecordSheet / RecordLink / useOpenRecord / recordPath / taskPath
- 整理记录、订阅、站点(含页签)、下载、日志任务改成抽屉;旧业务任务 / 下载任务 id 在任务抽屉里换算
- 回收站并进文件管理右侧视图(?view=trash);设置左栏只列分区
- 规则组、策略版本、媒体库未识别 / 外部身份、设置实例编辑走 ?open=
- 旧地址 /console/{organize,subscriptions,sites,downloads}/:id、/tasks/:id、/files/trash 跳到列表页抽屉
- 站内链接、铃铛、命令面板、任务时间线改拼新地址;冒烟按 ?open= 检查抽屉

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Cxwgnn2pbzQ7rXv3rq7fei
2026-10-08 14:03:47 +08:00

126 lines
5.0 KiB
TypeScript

import type { EngineBusinessKind, EngineRun, EngineTriggeredBy } from "@umt/contracts";
import { consolePath } from "~/components/console/nav.ts";
import { recordPath } from "~/components/console/record-sheet.tsx";
import type { StatusTone } from "~/components/console/status-badge.tsx";
// 统一任务流的标签:引擎 run + business(W9-I)。一条 run = 一条任务。
export const BUSINESS_KIND_LABEL: Record<EngineBusinessKind, string> = {
subscription: "订阅",
download: "下载",
organization: "整理",
agent: "智能体",
schedule: "定时任务",
feed: "RSS",
site: "站点",
decision: "需要处理的事项",
media: "作品",
};
/** 来源:四类(定时/事件/手动/Agent);API Key 调用算手动 */
export type TaskSource = "schedule" | "event" | "manual" | "agent";
export const SOURCE_LABEL: Record<TaskSource, string> = {
schedule: "定时",
event: "事件",
manual: "手动",
agent: "智能体",
};
export function sourceOf(t: EngineTriggeredBy | null | undefined): TaskSource | null {
if (!t) return null;
if (t === "user" || t === "api_key") return "manual";
return t;
}
/** 引擎工作流名 → 做什么 */
export const WORKFLOW_LABEL: Record<string, string> = {
ingestFeed: "抓取 RSS",
resolveObservation: "识别资源",
evaluateAcquisition: "评估资源",
submitDownload: "提交下载",
verifyAndImport: "核验整理",
scrapeMedia: "刮削",
refreshMetadata: "刷新元数据",
prewarmMetadata: "预热元数据缓存",
reconcileLibrary: "文件核对",
cleanupDownloadCache: "清理缓存",
resolveDecision: "处理事项",
runAgent: "智能体会话",
snapshotSite: "站点抓取",
refreshSiteAccount: "刷新站点账号",
searchSubscription: "订阅搜索",
purgeTrash: "清理回收站",
refreshPiTokens: "刷新模型服务登录",
};
export const workflowLabel = (name: string) => WORKFLOW_LABEL[name] ?? name;
/** 引擎状态 → 任务状态 */
const RUN_STATUS: Record<string, { label: string; tone: StatusTone }> = {
pending: { label: "排队中", tone: "neutral" },
running: { label: "运行中", tone: "neutral" },
sleeping: { label: "等待中", tone: "neutral" },
completed: { label: "完成", tone: "success" },
succeeded: { label: "完成", tone: "success" },
failed: { label: "失败", tone: "destructive" },
canceled: { label: "已取消", tone: "warning" },
};
export const runStatus = (s: string) => RUN_STATUS[s] ?? { label: s, tone: "neutral" as StatusTone };
/**
* 任务行状态:引擎 run 正常结束但业务结果不是成功时以业务结果为准(Agent 会话超出预算 / 失败 / 已停止),
* 不把"引擎跑完"显示成「完成」
*/
const OUTCOME_STATUS: Record<string, { label: string; tone: StatusTone }> = {
budget_exceeded: { label: "超出预算", tone: "warning" },
failed: { label: "失败", tone: "destructive" },
cancelled: { label: "已停止", tone: "warning" },
waiting: { label: "等待", tone: "neutral" },
};
export function engineRunStatus(r: Pick<EngineRun, "status" | "business">) {
const outcome = r.business?.outcome;
if (outcome && (r.status === "completed" || r.status === "succeeded") && OUTCOME_STATUS[outcome])
return OUTCOME_STATUS[outcome];
return runStatus(r.status);
}
/** 行标题:业务对象名 > 业务类型 + 短 id > 工作流做什么 */
export function runTitle(r: Pick<EngineRun, "business" | "workflowName">): string {
const b = r.business;
if (b?.title) return b.title;
if (b) return BUSINESS_KIND_LABEL[b.kind];
return workflowLabel(r.workflowName);
}
/** 业务对象的"家"页面 */
export function businessLink(b: EngineRun["business"], input?: unknown): { to: string; label: string } | null {
if (!b) return null;
const id = encodeURIComponent(b.refId);
switch (b.kind) {
case "subscription":
return { to: consolePath("subscriptions"), label: "订阅" };
case "download": {
// 还没提交到下载器时 refId 是计划 id(下载面板按 ?plan= 打开对应行)
const i = (input ?? {}) as { downloadTaskId?: unknown; acquisitionPlanId?: unknown };
if (!i.downloadTaskId && i.acquisitionPlanId === b.refId)
return { to: `${consolePath("downloads")}?plan=${id}`, label: "下载" };
return { to: recordPath("downloads", id), label: "下载任务" };
}
case "organization":
return { to: recordPath("organize", id), label: "整理记录" };
case "agent":
return { to: `/console/agent/${id}`, label: "智能体会话" };
case "schedule":
return { to: `/console/logs?tab=schedules&job=${id}`, label: "定时任务" };
case "feed":
// RSS 属于站点(IA-2):旧 RSS 页按 ?feed= 查所属站点后跳到站点的 RSS Tab
return { to: `${consolePath("sources")}?feed=${encodeURIComponent(id)}`, label: "RSS" };
case "site":
return { to: recordPath("sites", id), label: "站点" };
// 事项是内部机制(2026-10-06 待处理中心取消),不单独链出
case "decision":
return null;
case "media":
return { to: `/console/library/${id}`, label: "作品" };
default:
return null;
}
}