forked from longtao.wu/droboticflow
2703 lines
119 KiB
TypeScript
2703 lines
119 KiB
TypeScript
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
||
import { Link, useLocation, useParams, useSearchParams } from "react-router-dom";
|
||
import {
|
||
CheckCircle2,
|
||
ClipboardCheck,
|
||
Loader2,
|
||
Plus,
|
||
RefreshCw,
|
||
RotateCcw,
|
||
Send,
|
||
Scissors,
|
||
Merge,
|
||
Trash2,
|
||
Undo2,
|
||
XCircle,
|
||
Video,
|
||
Eye,
|
||
ShieldCheck,
|
||
ChevronDown,
|
||
ChevronUp,
|
||
Download,
|
||
FileJson,
|
||
} from "lucide-react";
|
||
import type {
|
||
AnnotationSegment,
|
||
AnnotationTaskDetail,
|
||
AnnotationTaskRecord,
|
||
AnnotationTemplate,
|
||
AnnotationWorkgroup,
|
||
AnnotationWorkloadSummary,
|
||
HumanReject,
|
||
HumanItem,
|
||
DeliveryPackage,
|
||
DeliveryPackageContents,
|
||
DeliveryPackageManifestItem,
|
||
ExecutionData,
|
||
Project,
|
||
ProjectAnnotationMembership,
|
||
SliceOperation,
|
||
SliceSegment,
|
||
} from "../types";
|
||
import { useUser } from "../context/UserContext";
|
||
import { useTimeZone } from "../context/TimeZoneContext";
|
||
import { annotationOperationsApi } from "../services/api/annotation-operations";
|
||
import { humanLoopApi } from "../services/api/human-loop";
|
||
import { deliveryPackagesApi } from "../services/api/delivery-packages";
|
||
import { projectsApi } from "../services/api/projects";
|
||
import { normalizeAnnotationSegments, summarizeAnnotationWorkload } from "../lib/annotation-operations.js";
|
||
import { formatCompactDateTime } from "../lib/datetime";
|
||
import { getActionErrorMessage } from "../lib/action-errors.js";
|
||
import { artifactContentPath } from "../lib/artifact-download.js";
|
||
import AnnotationTimelineEditor from "../components/AnnotationTimelineEditor";
|
||
import RerunArtifactPreview from "../components/RerunArtifactPreview";
|
||
import { LazyVideoPreview } from "../components/LazyVideoPreview";
|
||
import { PageSubnav } from "../components/PageSubnav";
|
||
import { usePlugins } from "../context/PluginContext";
|
||
import { buildBrowserPlayableVideoURL } from "../lib/video-preview.js";
|
||
import { getPluginNavigationContributions } from "../lib/plugin-navigation.js";
|
||
|
||
type Tab = "queue" | "rejects" | "templates" | "groups" | "workload";
|
||
type WorkspaceMode = "clip" | "clip-quality" | "annotate" | "quality" | "acceptance";
|
||
type TaskPoolView = "available" | "mine" | "all";
|
||
type HumanPools = Record<TaskPoolView, HumanItem[]>;
|
||
|
||
const emptyHumanPools: HumanPools = { available: [], mine: [], all: [] };
|
||
|
||
const statusLabels: Record<string, string> = {
|
||
pending_annotation: "待标注/剪切",
|
||
pending_quality: "待质检",
|
||
pending_acceptance: "待验收",
|
||
rework: "返工中",
|
||
accepted: "已通过",
|
||
rejected: "已拒绝",
|
||
};
|
||
|
||
const emptyTemplate = {
|
||
name: "泛宇语义模板",
|
||
version: 1,
|
||
labels: "静止观察,平稳活动,快速移动",
|
||
phrases: "手部,前景目标",
|
||
};
|
||
|
||
const emptyTask = {
|
||
sourceVideo: "",
|
||
clipStart: "0",
|
||
clipEnd: "30",
|
||
workgroupId: "",
|
||
templateId: "",
|
||
};
|
||
|
||
const emptyPrepackageAcceptanceStatistics = {
|
||
videoQuality: "",
|
||
annotationAccuracy: "",
|
||
annotationCompleteness: "",
|
||
overallGrade: "",
|
||
};
|
||
|
||
type PrepackageAcceptanceStatistics = typeof emptyPrepackageAcceptanceStatistics;
|
||
|
||
function prepackageAcceptanceStatisticsAreValid(statistics: PrepackageAcceptanceStatistics) {
|
||
const accuracy = Number(statistics.annotationAccuracy);
|
||
const completeness = Number(statistics.annotationCompleteness);
|
||
return (
|
||
statistics.videoQuality.trim() !== "" &&
|
||
statistics.overallGrade.trim() !== "" &&
|
||
statistics.annotationAccuracy.trim() !== "" &&
|
||
statistics.annotationCompleteness.trim() !== "" &&
|
||
Number.isFinite(accuracy) &&
|
||
accuracy >= 0 &&
|
||
accuracy <= 100 &&
|
||
Number.isFinite(completeness) &&
|
||
completeness >= 0 &&
|
||
completeness <= 100
|
||
);
|
||
}
|
||
|
||
function deliveryArtifactPreviewURL(item: ExecutionData | undefined) {
|
||
const preview = item?.data?.preview;
|
||
if (preview && typeof preview === "object" && typeof preview.url === "string") return preview.url;
|
||
return "";
|
||
}
|
||
|
||
function deliveryArtifactDownloadURL(item: ExecutionData) {
|
||
return artifactContentPath(item, { download: true });
|
||
}
|
||
|
||
function deliveryActions(item: DeliveryPackageManifestItem) {
|
||
return Array.isArray(item.annotation?.actions) ? item.annotation.actions : [];
|
||
}
|
||
|
||
function poseEvidenceRefs(summary: Record<string, any>, key: string, fallbackKey?: string) {
|
||
const direct = Array.isArray(summary[key]) ? summary[key] : [];
|
||
if (direct.length > 0 || !fallbackKey) return direct as Array<Record<string, any>>;
|
||
return (Array.isArray(summary[fallbackKey]) ? summary[fallbackKey] : []) as Array<Record<string, any>>;
|
||
}
|
||
|
||
function PoseEvidencePreview({
|
||
itemId,
|
||
artifact,
|
||
title,
|
||
frameCount,
|
||
}: {
|
||
itemId: string;
|
||
artifact?: Record<string, any>;
|
||
title: string;
|
||
frameCount: number;
|
||
}) {
|
||
const artifactId = String(artifact?.artifactId || "").trim();
|
||
if (!artifactId) {
|
||
return (
|
||
<div className="rounded-xl border border-dashed border-[#2a2b2f] bg-[#101114] p-4 text-xs text-gray-500">
|
||
{title}:没有可视化预标证据
|
||
</div>
|
||
);
|
||
}
|
||
const evidenceURL = humanLoopApi.evidenceContentURL(itemId, artifactId);
|
||
return (
|
||
<div className="space-y-3 rounded-xl border border-[#2a2b2f] bg-[#101114] p-4">
|
||
<div className="flex items-center justify-between gap-3">
|
||
<div>
|
||
<div className="text-sm font-medium text-white">{title}</div>
|
||
<div className="mt-1 text-xs text-gray-500">
|
||
{frameCount} 帧 · {String(artifact?.name || artifactId)}
|
||
</div>
|
||
</div>
|
||
<span className="rounded-full border border-blue-500/30 px-2 py-1 text-[10px] text-blue-200">人工质检证据</span>
|
||
</div>
|
||
<LazyVideoPreview
|
||
src={buildBrowserPlayableVideoURL(evidenceURL)}
|
||
originalSrc={evidenceURL}
|
||
title={title}
|
||
errorTitle={`${title}渲染失败`}
|
||
errorDescription="系统未能播放预标叠加视频,可打开原始证据检查;该预标不能在未质检时直接交付。"
|
||
/>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
const panelClass = "rounded-2xl border border-[#2a2b2f] bg-[#151619]";
|
||
const inputClass =
|
||
"w-full rounded-lg border border-[#2a2b2f] bg-[#0a0a0a] px-3 py-2 text-sm text-white outline-none focus:border-blue-500";
|
||
|
||
function taskVisibleInMode(task: AnnotationTaskRecord, mode: WorkspaceMode) {
|
||
if (task.humanStageId) {
|
||
if (mode === "clip") return task.humanStageId === "split_annotation" || task.humanStageId === "cut_adjustment";
|
||
if (mode === "clip-quality")
|
||
return task.humanStageId === "split_quality_review" || task.humanStageId === "cut_review";
|
||
if (mode === "annotate") return task.humanStageId === "semantic_annotation";
|
||
if (mode === "quality") return task.humanStageId === "quality_review" || task.humanStageId === "semantic_review";
|
||
}
|
||
if (mode === "clip") {
|
||
return (
|
||
(task.status === "pending_annotation" && task.currentRevision === 0) ||
|
||
(task.status === "rework" && task.currentRevision === 0)
|
||
);
|
||
}
|
||
if (mode === "clip-quality") {
|
||
return task.status === "pending_quality" && task.currentRevision === 0;
|
||
}
|
||
if (mode === "annotate") {
|
||
return (
|
||
(task.status === "pending_annotation" && task.currentRevision > 0) ||
|
||
(task.status === "rework" && task.currentRevision > 0) ||
|
||
(task.templateVersion >= 5 && (task.status === "pending_annotation" || task.status === "rework")) ||
|
||
(task.status === "pending_annotation" && task.currentRevision === 0 && !task.sourceVideo)
|
||
);
|
||
}
|
||
if (mode === "quality") {
|
||
return task.status === "pending_quality" && task.currentRevision > 0;
|
||
}
|
||
if (mode === "acceptance") {
|
||
return task.status === "pending_acceptance";
|
||
}
|
||
return true;
|
||
}
|
||
|
||
function humanItemVisibleInMode(item: HumanItem, mode: WorkspaceMode) {
|
||
if (mode === "clip") return item.currentStageId === "split_annotation" || item.currentStageId === "cut_adjustment";
|
||
if (mode === "clip-quality")
|
||
return item.currentStageId === "split_quality_review" || item.currentStageId === "cut_review";
|
||
if (mode === "annotate")
|
||
return item.currentStageId === "semantic_annotation" || item.currentStageId === "annotation_combined";
|
||
if (mode === "quality") return item.currentStageId === "quality_review" || item.currentStageId === "semantic_review";
|
||
return item.currentStageId === "acceptance" || item.currentStageId === "prepackage_acceptance";
|
||
}
|
||
|
||
function assignmentRoleForStage(stageId: string): ProjectAnnotationMembership["assignmentRole"] {
|
||
if (stageId === "split_annotation" || stageId === "cut_adjustment") return "cutter";
|
||
if (
|
||
stageId === "split_quality_review" ||
|
||
stageId === "cut_review" ||
|
||
stageId === "semantic_annotation" ||
|
||
stageId === "annotation_combined"
|
||
) {
|
||
return "annotator";
|
||
}
|
||
return "quality_reviewer";
|
||
}
|
||
|
||
function assignmentRoleMatches(
|
||
actual: ProjectAnnotationMembership["assignmentRole"],
|
||
required: ProjectAnnotationMembership["assignmentRole"],
|
||
) {
|
||
return (
|
||
actual === required ||
|
||
(required === "quality_reviewer" && actual === "acceptance_reviewer") ||
|
||
(required === "acceptance_reviewer" && actual === "quality_reviewer")
|
||
);
|
||
}
|
||
|
||
function assignmentRoleLabel(role: ProjectAnnotationMembership["assignmentRole"]) {
|
||
if (role === "cutter") return "人工剪切员";
|
||
if (role === "annotator") return "标注员";
|
||
if (role === "quality_reviewer") return "审核员";
|
||
if (role === "acceptance_reviewer") return "旧版验收员";
|
||
return "供应商管理员";
|
||
}
|
||
|
||
export default function AnnotationOperations() {
|
||
const { users, role, currentUser } = useUser();
|
||
const { statuses: pluginStatuses } = usePlugins();
|
||
const { timeZone } = useTimeZone();
|
||
const [searchParams, setSearchParams] = useSearchParams();
|
||
const location = useLocation();
|
||
const { workflowId: pathWorkflowId, itemId: pathItemId } = useParams();
|
||
const workspaceMode: WorkspaceMode = location.pathname.endsWith("/clip")
|
||
? "clip"
|
||
: location.pathname.endsWith("/clip-quality")
|
||
? "clip-quality"
|
||
: location.pathname.endsWith("/quality")
|
||
? "quality"
|
||
: location.pathname.endsWith("/acceptance")
|
||
? "acceptance"
|
||
: "annotate";
|
||
const requestedProjectId = searchParams.get("projectId")?.trim() || "";
|
||
const requestedDataTaskId = searchParams.get("dataTaskId")?.trim() || "";
|
||
const requestedWorkflowId =
|
||
(pathWorkflowId && pathWorkflowId !== "all" ? pathWorkflowId.trim() : "") ||
|
||
searchParams.get("workflowId")?.trim() ||
|
||
"";
|
||
const requestedRunId = searchParams.get("runId")?.trim() || "";
|
||
const requestedNodeId = searchParams.get("nodeId")?.trim() || "";
|
||
const requestedArtifactId = searchParams.get("artifactId")?.trim() || "";
|
||
const requestedTaskId = searchParams.get("taskId")?.trim() || "";
|
||
const [tab, setTab] = useState<Tab>("queue");
|
||
const [projects, setProjects] = useState<Project[]>([]);
|
||
const [projectId, setProjectId] = useState("");
|
||
const [workgroups, setWorkgroups] = useState<AnnotationWorkgroup[]>([]);
|
||
const [memberships, setMemberships] = useState<ProjectAnnotationMembership[]>([]);
|
||
const [templates, setTemplates] = useState<AnnotationTemplate[]>([]);
|
||
const [tasks, setTasks] = useState<AnnotationTaskRecord[]>([]);
|
||
const [humanPools, setHumanPools] = useState<HumanPools>(emptyHumanPools);
|
||
const [taskPoolView, setTaskPoolView] = useState<TaskPoolView>("available");
|
||
const [workload, setWorkload] = useState<AnnotationWorkloadSummary>({ items: [], eventCount: 0 });
|
||
const [rejects, setRejects] = useState<HumanReject[]>([]);
|
||
const [deliveryPackages, setDeliveryPackages] = useState<DeliveryPackage[]>([]);
|
||
const [expandedDeliveryPackageId, setExpandedDeliveryPackageId] = useState("");
|
||
const [deliveryPackageContents, setDeliveryPackageContents] = useState<Record<string, DeliveryPackageContents>>({});
|
||
const [deliveryPackageContentsLoading, setDeliveryPackageContentsLoading] = useState("");
|
||
const [deliveryPackageContentsErrors, setDeliveryPackageContentsErrors] = useState<Record<string, string>>({});
|
||
const [prepackageAcceptanceItems, setPrepackageAcceptanceItems] = useState<HumanItem[]>([]);
|
||
const [selectedAcceptanceEvidence, setSelectedAcceptanceEvidence] = useState<{ itemId: string; index: number }>({
|
||
itemId: "",
|
||
index: 0,
|
||
});
|
||
const [selectedTaskId, setSelectedTaskId] = useState("");
|
||
const [detail, setDetail] = useState<AnnotationTaskDetail | null>(null);
|
||
const [segments, setSegments] = useState<AnnotationSegment[]>([]);
|
||
const [sliceSegments, setSliceSegments] = useState<SliceSegment[]>([]);
|
||
const [sliceOperations, setSliceOperations] = useState<SliceOperation[]>([]);
|
||
const [sliceHistory, setSliceHistory] = useState<SliceSegment[][]>([]);
|
||
const [segmentDraft, setSegmentDraft] = useState({ labelId: "", label: "", start: "0", end: "1" });
|
||
const [reviewComment, setReviewComment] = useState("");
|
||
const [qualityDraft, setQualityDraft] = useState({
|
||
videoQuality: "qualified",
|
||
annotationAccuracy: "100",
|
||
annotationCompleteness: "100",
|
||
overallGrade: "A",
|
||
});
|
||
const [prepackageAcceptanceDrafts, setPrepackageAcceptanceDrafts] = useState<
|
||
Record<string, PrepackageAcceptanceStatistics>
|
||
>({});
|
||
const [groupDraft, setGroupDraft] = useState({ name: "", vendorId: "", description: "" });
|
||
const [membershipDraft, setMembershipDraft] = useState({
|
||
userId: "",
|
||
workgroupId: "",
|
||
assignmentRole: "annotator" as ProjectAnnotationMembership["assignmentRole"],
|
||
});
|
||
const [templateDraft, setTemplateDraft] = useState(emptyTemplate);
|
||
const [taskDraft, setTaskDraft] = useState(emptyTask);
|
||
const [loading, setLoading] = useState(true);
|
||
const [saving, setSaving] = useState(false);
|
||
const [error, setError] = useState("");
|
||
|
||
const [previewTab, setPreviewTab] = useState<"video" | "rerun">("video");
|
||
|
||
const isManager = role === "admin";
|
||
|
||
useEffect(() => {
|
||
setTaskPoolView((current) =>
|
||
isManager ? (current === "available" ? "all" : current) : current === "all" ? "available" : current,
|
||
);
|
||
}, [isManager]);
|
||
const annotationStageTabs = useMemo(
|
||
() =>
|
||
role
|
||
? getPluginNavigationContributions(pluginStatuses, role).map((item) => {
|
||
const path = item.path.replace("/workflows/all/", `/workflows/${requestedWorkflowId || "all"}/`);
|
||
return {
|
||
label: item.label,
|
||
to: `${path}${projectId ? `?projectId=${encodeURIComponent(projectId)}` : ""}`,
|
||
match: [path],
|
||
};
|
||
})
|
||
: [],
|
||
[pluginStatuses, projectId, requestedWorkflowId, role],
|
||
);
|
||
|
||
const loadBase = useCallback(async () => {
|
||
setLoading(true);
|
||
setError("");
|
||
try {
|
||
const [nextProjects, nextGroups] = await Promise.all([
|
||
projectsApi.list(),
|
||
annotationOperationsApi.listWorkgroups(),
|
||
]);
|
||
setProjects(nextProjects);
|
||
setWorkgroups(nextGroups);
|
||
setProjectId(
|
||
(current) =>
|
||
current || nextProjects.find((item) => item.id === requestedProjectId)?.id || nextProjects[0]?.id || "",
|
||
);
|
||
} catch (loadError) {
|
||
setError(getActionErrorMessage(loadError, "加载标注运营基础数据失败"));
|
||
} finally {
|
||
setLoading(false);
|
||
}
|
||
}, [requestedProjectId]);
|
||
|
||
const loadProject = useCallback(async () => {
|
||
if (!projectId) {
|
||
setMemberships([]);
|
||
setTemplates([]);
|
||
setTasks([]);
|
||
setHumanPools(emptyHumanPools);
|
||
setWorkload({ items: [], eventCount: 0 });
|
||
return;
|
||
}
|
||
setLoading(true);
|
||
setError("");
|
||
try {
|
||
const [
|
||
nextMemberships,
|
||
nextTemplates,
|
||
nextTasks,
|
||
availableHumanItems,
|
||
myHumanItems,
|
||
allHumanItems,
|
||
nextWorkload,
|
||
nextRejects,
|
||
nextPackages,
|
||
availableAcceptance,
|
||
myAcceptance,
|
||
allAcceptance,
|
||
] = await Promise.all([
|
||
annotationOperationsApi.listMemberships(projectId),
|
||
annotationOperationsApi.listTemplates(projectId),
|
||
annotationOperationsApi.listTasks({
|
||
projectId,
|
||
workflowId: requestedWorkflowId || undefined,
|
||
runId: requestedRunId || undefined,
|
||
nodeId: requestedNodeId || undefined,
|
||
artifactId: requestedArtifactId || undefined,
|
||
}),
|
||
humanLoopApi.listItems({
|
||
pluginId: "annotation-qa",
|
||
projectId,
|
||
workflowId: requestedWorkflowId || undefined,
|
||
runId: requestedRunId || undefined,
|
||
pool: "available",
|
||
}),
|
||
humanLoopApi.listItems({
|
||
pluginId: "annotation-qa",
|
||
projectId,
|
||
workflowId: requestedWorkflowId || undefined,
|
||
runId: requestedRunId || undefined,
|
||
pool: "mine",
|
||
}),
|
||
isManager
|
||
? humanLoopApi.listItems({
|
||
pluginId: "annotation-qa",
|
||
projectId,
|
||
workflowId: requestedWorkflowId || undefined,
|
||
runId: requestedRunId || undefined,
|
||
pool: "all",
|
||
})
|
||
: Promise.resolve([] as HumanItem[]),
|
||
annotationOperationsApi.workloadSummary(projectId),
|
||
humanLoopApi.listRejects({ projectId }),
|
||
deliveryPackagesApi.list({ projectId, workflowId: requestedWorkflowId || undefined }),
|
||
workspaceMode === "acceptance"
|
||
? humanLoopApi.listItems({
|
||
projectId,
|
||
workflowId: requestedWorkflowId || undefined,
|
||
stageId: "prepackage_acceptance",
|
||
pool: "available",
|
||
})
|
||
: Promise.resolve([] as HumanItem[]),
|
||
workspaceMode === "acceptance" && isManager
|
||
? humanLoopApi.listItems({
|
||
projectId,
|
||
workflowId: requestedWorkflowId || undefined,
|
||
stageId: "prepackage_acceptance",
|
||
pool: "all",
|
||
})
|
||
: Promise.resolve([] as HumanItem[]),
|
||
workspaceMode === "acceptance"
|
||
? humanLoopApi.listItems({
|
||
projectId,
|
||
workflowId: requestedWorkflowId || undefined,
|
||
stageId: "prepackage_acceptance",
|
||
pool: "mine",
|
||
})
|
||
: Promise.resolve([] as HumanItem[]),
|
||
]);
|
||
setMemberships(nextMemberships);
|
||
setTemplates(nextTemplates);
|
||
setTasks(nextTasks);
|
||
setHumanPools({ available: availableHumanItems, mine: myHumanItems, all: allHumanItems });
|
||
setWorkload(nextWorkload);
|
||
setRejects(nextRejects);
|
||
setDeliveryPackages(nextPackages);
|
||
setPrepackageAcceptanceItems(
|
||
Array.from(
|
||
new Map([...availableAcceptance, ...myAcceptance, ...allAcceptance].map((item) => [item.id, item])).values(),
|
||
),
|
||
);
|
||
} catch (loadError) {
|
||
setError(getActionErrorMessage(loadError, "加载项目标注运营数据失败"));
|
||
} finally {
|
||
setLoading(false);
|
||
}
|
||
}, [projectId, isManager, requestedArtifactId, requestedNodeId, requestedRunId, requestedWorkflowId, workspaceMode]);
|
||
|
||
useEffect(() => {
|
||
void loadBase();
|
||
}, [loadBase]);
|
||
|
||
useEffect(() => {
|
||
void loadProject();
|
||
}, [loadProject]);
|
||
|
||
useEffect(() => {
|
||
if (!pathItemId) return;
|
||
humanLoopApi
|
||
.getItem(pathItemId)
|
||
.then(({ item }) => {
|
||
if (item.legacyTaskId) {
|
||
setProjectId(item.projectId);
|
||
setSelectedTaskId(item.legacyTaskId);
|
||
const next = new URLSearchParams(searchParams);
|
||
next.set("projectId", item.projectId);
|
||
next.set("taskId", item.legacyTaskId);
|
||
if (item.workflowId) next.set("workflowId", item.workflowId);
|
||
if (item.runId) next.set("runId", item.runId);
|
||
setSearchParams(next, { replace: true });
|
||
}
|
||
})
|
||
.catch((loadError) => setError(getActionErrorMessage(loadError, "加载人类在环任务失败")));
|
||
}, [pathItemId]);
|
||
|
||
useEffect(() => {
|
||
if (!selectedTaskId) {
|
||
setDetail(null);
|
||
setSegments([]);
|
||
return;
|
||
}
|
||
annotationOperationsApi
|
||
.getTask(selectedTaskId)
|
||
.then((next) => {
|
||
setDetail(next);
|
||
const latest = next.revisions[next.revisions.length - 1];
|
||
setSegments(latest?.segments || []);
|
||
const latestSlice = next.sliceRevisions[next.sliceRevisions.length - 1];
|
||
setSliceSegments(
|
||
latestSlice?.segments || [
|
||
{ id: `slice-${next.task.id}-1`, start: next.task.clipStart, end: next.task.clipEnd },
|
||
],
|
||
);
|
||
setSliceOperations([]);
|
||
setSliceHistory([]);
|
||
})
|
||
.catch((loadError) => setError(getActionErrorMessage(loadError, "加载标注任务详情失败")));
|
||
}, [selectedTaskId]);
|
||
|
||
const selectedTemplate = useMemo(
|
||
() =>
|
||
templates.find((item) => item.id === detail?.task.templateId) ||
|
||
templates.find((item) => item.status === "published") ||
|
||
null,
|
||
[detail?.task.templateId, templates],
|
||
);
|
||
const editableTimelineStart = detail?.task.sourceIsFullVideo ? 0 : detail?.task.clipStart || 0;
|
||
const editableTimelineEnd = detail?.task.sourceIsFullVideo
|
||
? detail?.task.sourceDurationSeconds || detail?.task.clipEnd || 0
|
||
: detail?.task.clipEnd || 0;
|
||
const workloadTotals = useMemo(() => summarizeAnnotationWorkload(workload.items), [workload.items]);
|
||
const annotationStage =
|
||
detail?.humanItem?.currentStageId ||
|
||
(workspaceMode === "clip"
|
||
? "split_annotation"
|
||
: workspaceMode === "clip-quality"
|
||
? "split_quality_review"
|
||
: workspaceMode === "quality"
|
||
? "quality_review"
|
||
: workspaceMode === "acceptance"
|
||
? "acceptance"
|
||
: detail?.task?.currentRevision && detail.task.currentRevision > 0
|
||
? "semantic_annotation"
|
||
: "split_annotation");
|
||
const poolItems = humanPools[isManager ? taskPoolView : taskPoolView === "all" ? "available" : taskPoolView];
|
||
const visiblePoolItems = useMemo(
|
||
() => poolItems.filter((item) => humanItemVisibleInMode(item, workspaceMode)),
|
||
[poolItems, workspaceMode],
|
||
);
|
||
const visibleTasks = useMemo(() => {
|
||
const taskIds = new Set(visiblePoolItems.map((item) => item.legacyTaskId).filter(Boolean));
|
||
return tasks.filter(
|
||
(task) =>
|
||
taskVisibleInMode(task, workspaceMode) &&
|
||
(taskIds.has(task.id) || (isManager && taskPoolView === "all" && !task.humanStageId)),
|
||
);
|
||
}, [isManager, taskPoolView, tasks, visiblePoolItems, workspaceMode]);
|
||
const visibleHumanItemByTaskId = useMemo(
|
||
() =>
|
||
new Map(visiblePoolItems.filter((item) => item.legacyTaskId).map((item) => [item.legacyTaskId as string, item])),
|
||
[visiblePoolItems],
|
||
);
|
||
const poolCounts = useMemo(
|
||
() => ({
|
||
available: humanPools.available.filter((item) => humanItemVisibleInMode(item, workspaceMode)).length,
|
||
mine: humanPools.mine.filter((item) => humanItemVisibleInMode(item, workspaceMode)).length,
|
||
all: humanPools.all.filter((item) => humanItemVisibleInMode(item, workspaceMode)).length,
|
||
}),
|
||
[humanPools, workspaceMode],
|
||
);
|
||
|
||
useEffect(() => {
|
||
setSelectedTaskId((current) => {
|
||
if (visibleTasks.some((item) => item.id === current)) return current;
|
||
if (visibleTasks.some((item) => item.id === requestedTaskId)) return requestedTaskId;
|
||
return visibleTasks[0]?.id || "";
|
||
});
|
||
}, [requestedTaskId, visibleTasks]);
|
||
const selectedHumanItem = detail?.humanItem;
|
||
const selectedRequiredRole = assignmentRoleForStage(selectedHumanItem?.currentStageId || annotationStage);
|
||
const eligibleAssigneesForScope = useCallback(
|
||
(
|
||
workgroupId: string | undefined,
|
||
vendorId: string | undefined,
|
||
requiredRole: ProjectAnnotationMembership["assignmentRole"],
|
||
currentAssigneeId = "",
|
||
) => {
|
||
if (!isManager) return [];
|
||
const eligibleIds = new Set(
|
||
memberships
|
||
.filter(
|
||
(membership) =>
|
||
assignmentRoleMatches(membership.assignmentRole, requiredRole) &&
|
||
membership.workgroupId === workgroupId &&
|
||
(!membership.vendorId || !vendorId || membership.vendorId === vendorId),
|
||
)
|
||
.map((membership) => membership.userId),
|
||
);
|
||
if (currentUser?.id) eligibleIds.add(currentUser.id);
|
||
if (currentAssigneeId) eligibleIds.add(currentAssigneeId);
|
||
return users.filter((user) => eligibleIds.has(user.id) && user.status !== "disabled");
|
||
},
|
||
[currentUser?.id, isManager, memberships, users],
|
||
);
|
||
const eligibleAssignees = useMemo(
|
||
() =>
|
||
selectedHumanItem
|
||
? eligibleAssigneesForScope(
|
||
selectedHumanItem.workgroupId,
|
||
selectedHumanItem.vendorId,
|
||
selectedRequiredRole,
|
||
selectedHumanItem.assignedUserId,
|
||
)
|
||
: [],
|
||
[eligibleAssigneesForScope, selectedHumanItem, selectedRequiredRole],
|
||
);
|
||
// Old combined v5 batches remain readable while all newly created v5 work
|
||
// uses the four independent stage IDs above.
|
||
const isV5Combined = Boolean(
|
||
detail && detail.task.templateVersion >= 5 && selectedHumanItem?.currentStageId === "annotation_combined",
|
||
);
|
||
const isV5CombinedQuality = Boolean(
|
||
detail && detail.task.templateVersion >= 5 && selectedHumanItem?.currentStageId === "quality_review",
|
||
);
|
||
const selectedClaimedByMe = Boolean(
|
||
selectedHumanItem &&
|
||
selectedHumanItem.assignedUserId === currentUser?.id &&
|
||
["claimed", "in_progress"].includes(selectedHumanItem.status),
|
||
);
|
||
const workspaceTitle =
|
||
workspaceMode === "clip"
|
||
? "人工调切"
|
||
: workspaceMode === "clip-quality"
|
||
? "剪切审核"
|
||
: workspaceMode === "quality"
|
||
? "标注审核"
|
||
: workspaceMode === "acceptance"
|
||
? "最终验收"
|
||
: "语义标注";
|
||
const queueTabLabel =
|
||
workspaceMode === "clip"
|
||
? "调切队列"
|
||
: workspaceMode === "clip-quality"
|
||
? "剪切审核队列"
|
||
: workspaceMode === "quality"
|
||
? "标注审核队列"
|
||
: workspaceMode === "acceptance"
|
||
? "验收队列"
|
||
: "标注队列";
|
||
|
||
const addSegment = () => {
|
||
if (!detail) return;
|
||
const label = selectedTemplate?.labels.find((item) => item.id === segmentDraft.labelId);
|
||
const next = normalizeAnnotationSegments(
|
||
[
|
||
...segments,
|
||
{
|
||
id: `segment-${Date.now()}`,
|
||
labelId: label?.id || segmentDraft.labelId,
|
||
label: label?.name || segmentDraft.label,
|
||
start: Number(segmentDraft.start),
|
||
end: Number(segmentDraft.end),
|
||
confidence: 1,
|
||
source: "manual",
|
||
},
|
||
],
|
||
editableTimelineStart,
|
||
editableTimelineEnd,
|
||
);
|
||
setSegments(next);
|
||
};
|
||
|
||
const applySliceChange = (next: SliceSegment[], operation: Omit<SliceOperation, "before" | "after">) => {
|
||
const sorted = [...next].sort((left, right) => left.start - right.start);
|
||
setSliceHistory((history) => [...history, sliceSegments]);
|
||
setSliceOperations((operations) => [...operations, { ...operation, before: sliceSegments, after: sorted }]);
|
||
setSliceSegments(sorted);
|
||
};
|
||
|
||
const adjustSlice = (id: string, field: "start" | "end", value: number) => {
|
||
const next = sliceSegments.map((item) => (item.id === id ? { ...item, [field]: value } : item));
|
||
applySliceChange(next, { type: "adjust", segmentIds: [id] });
|
||
};
|
||
|
||
const splitSlice = (index: number) => {
|
||
const current = sliceSegments[index];
|
||
if (!current || current.end - current.start < 0.2) return;
|
||
const at = Number(((current.start + current.end) / 2).toFixed(3));
|
||
const next = [...sliceSegments];
|
||
next.splice(
|
||
index,
|
||
1,
|
||
{ id: `${current.id}-a-${Date.now()}`, start: current.start, end: at, sourceIds: [current.id] },
|
||
{ id: `${current.id}-b-${Date.now()}`, start: at, end: current.end, sourceIds: [current.id] },
|
||
);
|
||
applySliceChange(next, { type: "split", segmentIds: [current.id], at });
|
||
};
|
||
|
||
const mergeSlice = (index: number) => {
|
||
const current = sliceSegments[index];
|
||
const nextItem = sliceSegments[index + 1];
|
||
if (!current || !nextItem) return;
|
||
const next = [...sliceSegments];
|
||
next.splice(index, 2, {
|
||
id: `merged-${Date.now()}`,
|
||
start: current.start,
|
||
end: nextItem.end,
|
||
sourceIds: [current.id, nextItem.id],
|
||
});
|
||
applySliceChange(next, { type: "merge", segmentIds: [current.id, nextItem.id] });
|
||
};
|
||
|
||
const deleteSlice = (index: number) => {
|
||
if (sliceSegments.length <= 1) return;
|
||
const current = sliceSegments[index];
|
||
applySliceChange(
|
||
sliceSegments.filter((_, itemIndex) => itemIndex !== index),
|
||
{
|
||
type: "delete",
|
||
segmentIds: current ? [current.id] : [],
|
||
},
|
||
);
|
||
};
|
||
|
||
const undoSlice = () => {
|
||
const previous = sliceHistory[sliceHistory.length - 1];
|
||
if (!previous) return;
|
||
setSliceSegments(previous);
|
||
setSliceHistory((history) => history.slice(0, -1));
|
||
setSliceOperations((operations) => operations.slice(0, -1));
|
||
};
|
||
|
||
const submitSliceRevision = async () => {
|
||
if (!detail || sliceSegments.length === 0) return;
|
||
setSaving(true);
|
||
setError("");
|
||
try {
|
||
await annotationOperationsApi.submitSliceRevision(detail.task.id, {
|
||
segments: sliceSegments,
|
||
operations: sliceOperations,
|
||
changeReason: detail.sliceRevisions.length ? "切片返工修订" : "首轮切片校正",
|
||
});
|
||
const next = await annotationOperationsApi.getTask(detail.task.id);
|
||
setDetail(next);
|
||
setSliceOperations([]);
|
||
setSliceHistory([]);
|
||
await loadProject();
|
||
} catch (saveError) {
|
||
setError(getActionErrorMessage(saveError, "提交切片校正失败"));
|
||
} finally {
|
||
setSaving(false);
|
||
}
|
||
};
|
||
|
||
const submitRevision = async () => {
|
||
if (!detail || segments.length === 0) return;
|
||
setSaving(true);
|
||
setError("");
|
||
try {
|
||
await annotationOperationsApi.submitRevision(detail.task.id, {
|
||
segments,
|
||
changeReason: detail.task.currentRevision > 0 ? "人工返工修订" : "首轮人工标注",
|
||
});
|
||
await loadProject();
|
||
setDetail(await annotationOperationsApi.getTask(detail.task.id));
|
||
} catch (saveError) {
|
||
setError(getActionErrorMessage(saveError, "提交标注版本失败"));
|
||
} finally {
|
||
setSaving(false);
|
||
}
|
||
};
|
||
|
||
const submitCombined = async () => {
|
||
// An empty semantic list is an explicit, accepted no-action negative
|
||
// sample. Slices still must exist because they define the final media.
|
||
if (!detail?.humanItem || sliceSegments.length === 0) return;
|
||
setSaving(true);
|
||
setError("");
|
||
try {
|
||
await annotationOperationsApi.submitCombined(detail.task.id, {
|
||
version: detail.humanItem.version,
|
||
sliceSegments,
|
||
sliceOperations,
|
||
segments,
|
||
changeReason: detail.task.currentRevision > 0 ? "v5 同任务返工切片与语义修订" : "v5 同任务首次切片与语义标注",
|
||
});
|
||
setSliceOperations([]);
|
||
setSliceHistory([]);
|
||
await loadProject();
|
||
setDetail(await annotationOperationsApi.getTask(detail.task.id));
|
||
} catch (saveError) {
|
||
setError(getActionErrorMessage(saveError, "提交切片与语义标注失败"));
|
||
} finally {
|
||
setSaving(false);
|
||
}
|
||
};
|
||
|
||
const rejectAnnotationInput = async () => {
|
||
if (!detail || !reviewComment.trim()) {
|
||
setError("拒绝输入必须填写原因。");
|
||
return;
|
||
}
|
||
setSaving(true);
|
||
setError("");
|
||
try {
|
||
await annotationOperationsApi.rejectTask(detail.task.id, {
|
||
reasonCodes: ["annotation_input_rejected"],
|
||
comment: reviewComment.trim(),
|
||
});
|
||
setReviewComment("");
|
||
await loadProject();
|
||
setDetail(await annotationOperationsApi.getTask(detail.task.id));
|
||
} catch (saveError) {
|
||
setError(getActionErrorMessage(saveError, "拒绝标注输入失败"));
|
||
} finally {
|
||
setSaving(false);
|
||
}
|
||
};
|
||
|
||
const review = async (
|
||
stage: "split_quality" | "quality" | "acceptance",
|
||
decision: "approved" | "rejected",
|
||
rejectTarget?: "cut_adjustment" | "semantic_annotation",
|
||
) => {
|
||
if (!detail) return;
|
||
if (decision === "rejected" && !reviewComment.trim()) {
|
||
setError("打回必须填写原因,便于操作员按轮次返工。");
|
||
return;
|
||
}
|
||
setSaving(true);
|
||
setError("");
|
||
try {
|
||
await annotationOperationsApi.review(detail.task.id, {
|
||
stage,
|
||
decision,
|
||
comment: reviewComment,
|
||
rejectTargets:
|
||
decision === "rejected"
|
||
? selectedHumanItem?.currentStageId === "cut_review"
|
||
? ["cut_adjustment"]
|
||
: selectedHumanItem?.currentStageId === "semantic_review"
|
||
? [rejectTarget || "semantic_annotation"]
|
||
: stage === "split_quality"
|
||
? ["split_annotation"]
|
||
: stage === "quality"
|
||
? ["semantic_annotation"]
|
||
: ["quality_review"]
|
||
: undefined,
|
||
reasonCodes: decision === "rejected" ? ["manual_review_reject"] : undefined,
|
||
videoQuality: qualityDraft.videoQuality,
|
||
annotationAccuracy: Number(qualityDraft.annotationAccuracy),
|
||
annotationCompleteness: Number(qualityDraft.annotationCompleteness),
|
||
overallGrade: qualityDraft.overallGrade,
|
||
});
|
||
setReviewComment("");
|
||
await loadProject();
|
||
setDetail(await annotationOperationsApi.getTask(detail.task.id));
|
||
} catch (saveError) {
|
||
setError(getActionErrorMessage(saveError, "提交审核决定失败"));
|
||
} finally {
|
||
setSaving(false);
|
||
}
|
||
};
|
||
|
||
const createGroup = async () => {
|
||
if (!groupDraft.name.trim() || !groupDraft.vendorId.trim()) return;
|
||
setSaving(true);
|
||
try {
|
||
await annotationOperationsApi.createWorkgroup(groupDraft);
|
||
setGroupDraft({ name: "", vendorId: "", description: "" });
|
||
await loadBase();
|
||
} catch (saveError) {
|
||
setError(getActionErrorMessage(saveError, "创建供应商分组失败"));
|
||
} finally {
|
||
setSaving(false);
|
||
}
|
||
};
|
||
|
||
const createMembership = async () => {
|
||
if (!projectId || !membershipDraft.userId || !membershipDraft.workgroupId) return;
|
||
setSaving(true);
|
||
try {
|
||
await annotationOperationsApi.createMembership({ projectId, ...membershipDraft });
|
||
await loadProject();
|
||
} catch (saveError) {
|
||
setError(getActionErrorMessage(saveError, "分配项目角色失败"));
|
||
} finally {
|
||
setSaving(false);
|
||
}
|
||
};
|
||
|
||
const createTemplate = async () => {
|
||
if (!projectId || !templateDraft.name.trim()) return;
|
||
const labels = templateDraft.labels
|
||
.split(",")
|
||
.map((name, index) => ({ id: `label-${index + 1}`, name: name.trim() }))
|
||
.filter((item) => item.name);
|
||
setSaving(true);
|
||
try {
|
||
await annotationOperationsApi.createTemplate({
|
||
projectId,
|
||
name: templateDraft.name,
|
||
version: Number(templateDraft.version),
|
||
labels,
|
||
phrases: templateDraft.phrases
|
||
.split(",")
|
||
.map((item) => item.trim())
|
||
.filter(Boolean),
|
||
prelabel: { enabled: true, minimumConfidence: 0.7, enableWilor: true, enableHead: false },
|
||
});
|
||
setTemplateDraft(emptyTemplate);
|
||
await loadProject();
|
||
} catch (saveError) {
|
||
setError(getActionErrorMessage(saveError, "创建语义模板失败"));
|
||
} finally {
|
||
setSaving(false);
|
||
}
|
||
};
|
||
|
||
const createTask = async () => {
|
||
if (!projectId || !taskDraft.sourceVideo || !taskDraft.templateId || !taskDraft.workgroupId) return;
|
||
setSaving(true);
|
||
try {
|
||
await annotationOperationsApi.createTask({
|
||
projectId,
|
||
dataTaskId: requestedDataTaskId || undefined,
|
||
workflowId: requestedWorkflowId || undefined,
|
||
runId: requestedRunId || undefined,
|
||
nodeId: requestedNodeId || undefined,
|
||
artifactId: requestedArtifactId || undefined,
|
||
sourceVideo: taskDraft.sourceVideo,
|
||
clipStart: Number(taskDraft.clipStart),
|
||
clipEnd: Number(taskDraft.clipEnd),
|
||
templateId: taskDraft.templateId,
|
||
workgroupId: taskDraft.workgroupId,
|
||
});
|
||
setTaskDraft(emptyTask);
|
||
await loadProject();
|
||
} catch (saveError) {
|
||
setError(getActionErrorMessage(saveError, "创建逐段标注任务失败"));
|
||
} finally {
|
||
setSaving(false);
|
||
}
|
||
};
|
||
|
||
const claimSelectedTask = async () => {
|
||
if (!detail?.humanItem) return;
|
||
setSaving(true);
|
||
setError("");
|
||
try {
|
||
await humanLoopApi.claim(detail.humanItem.id, detail.humanItem.version);
|
||
setTaskPoolView("mine");
|
||
setDetail(await annotationOperationsApi.getTask(detail.task.id));
|
||
await loadProject();
|
||
} catch (claimError) {
|
||
setError(getActionErrorMessage(claimError, "领取任务失败,任务可能已被其他成员领取"));
|
||
} finally {
|
||
setSaving(false);
|
||
}
|
||
};
|
||
|
||
const releaseSelectedTask = async () => {
|
||
if (!detail?.humanItem) return;
|
||
setSaving(true);
|
||
setError("");
|
||
try {
|
||
await humanLoopApi.release(detail.humanItem.id, detail.humanItem.version);
|
||
setTaskPoolView("available");
|
||
setDetail(await annotationOperationsApi.getTask(detail.task.id));
|
||
await loadProject();
|
||
} catch (releaseError) {
|
||
setError(getActionErrorMessage(releaseError, "释放任务失败"));
|
||
} finally {
|
||
setSaving(false);
|
||
}
|
||
};
|
||
|
||
const assignHumanItem = async (item: HumanItem, assignedUserId: string, taskId = "") => {
|
||
if (!isManager) return;
|
||
setSaving(true);
|
||
setError("");
|
||
try {
|
||
await humanLoopApi.assign(item.id, item.version, assignedUserId);
|
||
if (taskId) setDetail(await annotationOperationsApi.getTask(taskId));
|
||
await loadProject();
|
||
} catch (assignmentError) {
|
||
setError(getActionErrorMessage(assignmentError, "管理员改派任务失败"));
|
||
} finally {
|
||
setSaving(false);
|
||
}
|
||
};
|
||
|
||
const assignSelectedTask = async (assignedUserId: string) => {
|
||
if (!detail?.humanItem) return;
|
||
await assignHumanItem(detail.humanItem, assignedUserId, detail.task.id);
|
||
};
|
||
|
||
const reopenReject = async (reject: HumanReject, targetStageId: string) => {
|
||
setSaving(true);
|
||
setError("");
|
||
try {
|
||
let itemVersion: number;
|
||
try {
|
||
const { item } = await humanLoopApi.getItem(reject.itemId);
|
||
itemVersion = item.version;
|
||
} catch {
|
||
itemVersion = (await deliveryPackagesApi.get(reject.itemId)).version;
|
||
}
|
||
await humanLoopApi.reopen(reject.id, {
|
||
itemVersion,
|
||
rejectVersion: reject.version,
|
||
targetStageId,
|
||
comment: "管理员从拒绝区定向重开",
|
||
});
|
||
await loadProject();
|
||
} catch (saveError) {
|
||
setError(getActionErrorMessage(saveError, "从拒绝区重开任务失败"));
|
||
} finally {
|
||
setSaving(false);
|
||
}
|
||
};
|
||
|
||
const decideDeliveryPackage = async (item: DeliveryPackage, decision: "approved" | "rejected") => {
|
||
if (decision === "rejected" && !reviewComment.trim()) {
|
||
setError("验收拒绝必须填写原因。");
|
||
return;
|
||
}
|
||
setSaving(true);
|
||
setError("");
|
||
try {
|
||
await deliveryPackagesApi.decide(item.id, {
|
||
version: item.version,
|
||
decision,
|
||
comment: reviewComment.trim(),
|
||
videoQuality: qualityDraft.videoQuality,
|
||
annotationAccuracy: Number(qualityDraft.annotationAccuracy),
|
||
annotationCompleteness: Number(qualityDraft.annotationCompleteness),
|
||
overallGrade: qualityDraft.overallGrade,
|
||
reasonCodes: decision === "rejected" ? ["acceptance_rejected"] : undefined,
|
||
});
|
||
setReviewComment("");
|
||
await loadProject();
|
||
} catch (saveError) {
|
||
setError(getActionErrorMessage(saveError, "提交成品包验收失败"));
|
||
} finally {
|
||
setSaving(false);
|
||
}
|
||
};
|
||
|
||
const claimDeliveryPackage = async (item: DeliveryPackage) => {
|
||
if (!item.acceptanceHumanItemId || !item.acceptanceHumanItemVersion) {
|
||
setError("验收任务池记录尚未就绪,请稍后刷新。");
|
||
return;
|
||
}
|
||
setSaving(true);
|
||
setError("");
|
||
try {
|
||
await humanLoopApi.claim(item.acceptanceHumanItemId, item.acceptanceHumanItemVersion);
|
||
await loadProject();
|
||
} catch (claimError) {
|
||
setError(getActionErrorMessage(claimError, "领取验收任务失败"));
|
||
} finally {
|
||
setSaving(false);
|
||
}
|
||
};
|
||
|
||
const releaseDeliveryPackage = async (item: DeliveryPackage) => {
|
||
if (!item.acceptanceHumanItemId || !item.acceptanceHumanItemVersion) {
|
||
setError("验收任务池记录尚未就绪,请稍后刷新。");
|
||
return;
|
||
}
|
||
setSaving(true);
|
||
setError("");
|
||
try {
|
||
await humanLoopApi.release(item.acceptanceHumanItemId, item.acceptanceHumanItemVersion);
|
||
await loadProject();
|
||
} catch (releaseError) {
|
||
setError(getActionErrorMessage(releaseError, "释放验收任务失败"));
|
||
} finally {
|
||
setSaving(false);
|
||
}
|
||
};
|
||
|
||
const assignDeliveryPackage = async (item: DeliveryPackage, assignedUserId: string) => {
|
||
if (!isManager || !item.acceptanceHumanItemId || !item.acceptanceHumanItemVersion) return;
|
||
setSaving(true);
|
||
setError("");
|
||
try {
|
||
await humanLoopApi.assign(item.acceptanceHumanItemId, item.acceptanceHumanItemVersion, assignedUserId);
|
||
await loadProject();
|
||
} catch (assignmentError) {
|
||
setError(getActionErrorMessage(assignmentError, "管理员改派成品包验收任务失败"));
|
||
} finally {
|
||
setSaving(false);
|
||
}
|
||
};
|
||
|
||
const toggleDeliveryPackageContents = async (item: DeliveryPackage) => {
|
||
if (expandedDeliveryPackageId === item.id) {
|
||
setExpandedDeliveryPackageId("");
|
||
return;
|
||
}
|
||
setExpandedDeliveryPackageId(item.id);
|
||
if (deliveryPackageContents[item.id]) return;
|
||
setDeliveryPackageContentsLoading(item.id);
|
||
setDeliveryPackageContentsErrors((current) => ({ ...current, [item.id]: "" }));
|
||
try {
|
||
const contents = await deliveryPackagesApi.contents(item.id);
|
||
setDeliveryPackageContents((current) => ({ ...current, [item.id]: contents }));
|
||
} catch (loadError) {
|
||
setDeliveryPackageContentsErrors((current) => ({
|
||
...current,
|
||
[item.id]: getActionErrorMessage(loadError, "加载验收内容失败"),
|
||
}));
|
||
} finally {
|
||
setDeliveryPackageContentsLoading("");
|
||
}
|
||
};
|
||
|
||
const releasePrepackageAcceptance = async (item: HumanItem) => {
|
||
setSaving(true);
|
||
setError("");
|
||
try {
|
||
await humanLoopApi.release(item.id, item.version);
|
||
await loadProject();
|
||
} catch (releaseError) {
|
||
setError(getActionErrorMessage(releaseError, "释放包前最终验收失败"));
|
||
} finally {
|
||
setSaving(false);
|
||
}
|
||
};
|
||
|
||
const claimPrepackageAcceptance = async (item: HumanItem) => {
|
||
setSaving(true);
|
||
setError("");
|
||
try {
|
||
await humanLoopApi.claim(item.id, item.version);
|
||
await loadProject();
|
||
} catch (claimError) {
|
||
setError(getActionErrorMessage(claimError, "领取包前最终验收失败"));
|
||
} finally {
|
||
setSaving(false);
|
||
}
|
||
};
|
||
|
||
const confirmPrepackageAcceptance = async (item: HumanItem, statistics: PrepackageAcceptanceStatistics) => {
|
||
if (!prepackageAcceptanceStatisticsAreValid(statistics)) {
|
||
setError("请填写视频质量、总体等级,以及 0–100 的标注准确性和完整性后再确认。");
|
||
return;
|
||
}
|
||
setSaving(true);
|
||
setError("");
|
||
try {
|
||
await humanLoopApi.decide(item.id, {
|
||
version: item.version,
|
||
decision: "approved",
|
||
reviewedRevision: item.currentRevision,
|
||
comment: reviewComment.trim(),
|
||
videoQuality: statistics.videoQuality,
|
||
annotationAccuracy: Number(statistics.annotationAccuracy),
|
||
annotationCompleteness: Number(statistics.annotationCompleteness),
|
||
overallGrade: statistics.overallGrade,
|
||
});
|
||
setReviewComment("");
|
||
await loadProject();
|
||
} catch (confirmError) {
|
||
setError(getActionErrorMessage(confirmError, "确认最终验收失败;下游打包未释放"));
|
||
} finally {
|
||
setSaving(false);
|
||
}
|
||
};
|
||
|
||
const selectProject = (nextProjectId: string) => {
|
||
setProjectId(nextProjectId);
|
||
const next = new URLSearchParams(searchParams);
|
||
if (nextProjectId) next.set("projectId", nextProjectId);
|
||
else next.delete("projectId");
|
||
next.delete("taskId");
|
||
setSearchParams(next, { replace: true });
|
||
};
|
||
|
||
const selectTask = (taskId: string) => {
|
||
setSelectedTaskId(taskId);
|
||
const next = new URLSearchParams(searchParams);
|
||
if (taskId) next.set("taskId", taskId);
|
||
else next.delete("taskId");
|
||
setSearchParams(next, { replace: true });
|
||
};
|
||
|
||
return (
|
||
<div className="space-y-4">
|
||
<div className="flex flex-wrap items-center justify-between gap-3">
|
||
<div className="min-w-0 flex-1">
|
||
<h1 className="text-2xl font-semibold text-white">{workspaceTitle}</h1>
|
||
<PageSubnav compact items={annotationStageTabs} label="标注中心阶段导航" />
|
||
</div>
|
||
<div className="flex items-center gap-2">
|
||
<select
|
||
className={inputClass}
|
||
value={tab}
|
||
onChange={(event) => setTab(event.target.value as Tab)}
|
||
aria-label="当前工作台视图"
|
||
>
|
||
<option value="queue">{queueTabLabel}</option>
|
||
<option value="rejects">拒绝区</option>
|
||
<option value="templates">模板版本</option>
|
||
<option value="groups">供应商与角色</option>
|
||
<option value="workload">工时统计</option>
|
||
</select>
|
||
{isManager ? (
|
||
<Link
|
||
to={`/sampling${projectId ? `?projectId=${encodeURIComponent(projectId)}` : ""}`}
|
||
className="rounded-lg border border-[#2a2b2f] px-3 py-2 text-sm text-gray-300 hover:border-blue-500/50 hover:text-white"
|
||
>
|
||
主动抽检
|
||
</Link>
|
||
) : null}
|
||
<select className={inputClass} value={projectId} onChange={(event) => selectProject(event.target.value)}>
|
||
<option value="">选择项目</option>
|
||
{projects.map((project) => (
|
||
<option key={project.id} value={project.id}>
|
||
{project.name}
|
||
</option>
|
||
))}
|
||
</select>
|
||
<button
|
||
type="button"
|
||
onClick={() => void loadProject()}
|
||
className="rounded-lg border border-[#2a2b2f] p-2 text-gray-300 hover:border-blue-500/50 hover:text-white"
|
||
title="刷新"
|
||
>
|
||
{loading ? <Loader2 className="h-4 w-4 animate-spin" /> : <RefreshCw className="h-4 w-4" />}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
{error ? (
|
||
<div className="rounded-xl border border-red-500/30 bg-red-500/10 px-4 py-3 text-sm text-red-200">{error}</div>
|
||
) : null}
|
||
|
||
{tab === "rejects" ? (
|
||
<div className={`${panelClass} p-5`}>
|
||
<div className="flex items-center justify-between">
|
||
<div>
|
||
<div className="text-lg font-semibold text-white">拒绝区</div>
|
||
<div className="mt-1 text-sm text-gray-500">
|
||
拒绝事实永久保留;重开会创建新 Attempt,不修改原审核结论。
|
||
</div>
|
||
</div>
|
||
<span className="rounded-full border border-red-500/30 px-3 py-1 text-xs text-red-200">
|
||
{rejects.filter((item) => item.status === "open").length} 待处置
|
||
</span>
|
||
</div>
|
||
<div className="mt-4 space-y-3">
|
||
{rejects.map((reject) => (
|
||
<div key={reject.id} className="rounded-xl border border-[#2a2b2f] bg-[#101114] p-4">
|
||
<div className="flex flex-wrap items-start justify-between gap-3">
|
||
<div>
|
||
<div className="font-mono text-xs text-red-200">{reject.itemId}</div>
|
||
<div className="mt-1 text-sm text-white">
|
||
{reject.stageId} · {reject.comment}
|
||
</div>
|
||
<div className="mt-1 text-xs text-gray-500">
|
||
原因:{reject.reasonCodes.join("、") || "未填写"} · round {reject.attemptRound}
|
||
</div>
|
||
</div>
|
||
<span className="text-xs text-gray-400">{reject.status}</span>
|
||
</div>
|
||
{isManager && reject.status === "open" ? (
|
||
<div className="mt-3 flex flex-wrap gap-2">
|
||
{reject.allowedReopenStages.map((stage) => (
|
||
<button
|
||
key={stage}
|
||
type="button"
|
||
disabled={saving}
|
||
onClick={() => void reopenReject(reject, stage)}
|
||
className="rounded-lg border border-blue-500/30 px-3 py-2 text-xs text-blue-200 hover:bg-blue-500/10 disabled:opacity-50"
|
||
>
|
||
重开至 {stage}
|
||
</button>
|
||
))}
|
||
</div>
|
||
) : null}
|
||
</div>
|
||
))}
|
||
{rejects.length === 0 ? (
|
||
<div className="py-12 text-center text-sm text-gray-500">当前项目没有拒绝记录</div>
|
||
) : null}
|
||
</div>
|
||
</div>
|
||
) : null}
|
||
|
||
{tab === "queue" && workspaceMode === "acceptance" ? (
|
||
<div className="space-y-4">
|
||
{prepackageAcceptanceItems.map((item) => {
|
||
const payload = item.subject.payload || {};
|
||
const statistics = (payload.statistics || {}) as Record<string, any>;
|
||
const evidenceItems = Array.isArray(payload.items) ? payload.items : [];
|
||
const selectedIndex = selectedAcceptanceEvidence.itemId === item.id ? selectedAcceptanceEvidence.index : 0;
|
||
const selectedEvidence = evidenceItems[selectedIndex] as Record<string, any> | undefined;
|
||
const selectedPoseSummary = (selectedEvidence?.poseSummary || {}) as Record<string, any>;
|
||
const headposeRender = poseEvidenceRefs(selectedPoseSummary, "headposeRenderArtifacts")[0];
|
||
const handPrelabelRender = poseEvidenceRefs(
|
||
selectedPoseSummary,
|
||
"handPrelabelRenderArtifacts",
|
||
"handposeRenderArtifacts",
|
||
)[0];
|
||
const selectedClipArtifactId = String(selectedEvidence?.clipArtifactId || "");
|
||
const claimedByMe = item.assignedUserId === currentUser?.id;
|
||
const acceptanceStatistics = prepackageAcceptanceDrafts[item.id] || emptyPrepackageAcceptanceStatistics;
|
||
const acceptanceAssignees = eligibleAssigneesForScope(
|
||
item.workgroupId,
|
||
item.vendorId,
|
||
"quality_reviewer",
|
||
item.assignedUserId,
|
||
);
|
||
return (
|
||
<div key={item.id} className={`${panelClass} space-y-4 border-blue-500/30 p-5`}>
|
||
<div className="flex flex-wrap items-start justify-between gap-3">
|
||
<div>
|
||
<div className="text-base font-semibold text-white">包前最终验收 · 全部切片汇总</div>
|
||
<div className="mt-1 text-xs text-gray-400">
|
||
{statistics.taskCount || evidenceItems.length || 0} 个任务 · {statistics.sliceCount || 0}{" "}
|
||
个最终切片 · {statistics.annotationSegmentCount || 0} 条语义标注
|
||
</div>
|
||
</div>
|
||
{isManager ? (
|
||
<select
|
||
aria-label="管理员最终验收改派"
|
||
className="rounded-lg border border-[#2a2b2f] bg-[#0a0a0a] px-3 py-2 text-xs text-white"
|
||
value={item.assignedUserId || ""}
|
||
disabled={saving || ["accepted", "rejected", "escalated"].includes(item.status)}
|
||
onChange={(event) => void assignHumanItem(item, event.target.value)}
|
||
>
|
||
<option value="">退回最终验收池</option>
|
||
{acceptanceAssignees.map((user) => (
|
||
<option key={user.id} value={user.id}>
|
||
{user.name} · {user.id === currentUser?.id ? "管理员" : "审核员"}
|
||
</option>
|
||
))}
|
||
</select>
|
||
) : null}
|
||
{!item.assignedUserId && ["ready", "rework", "submitted"].includes(item.status) ? (
|
||
<button
|
||
type="button"
|
||
disabled={saving}
|
||
onClick={() => void claimPrepackageAcceptance(item)}
|
||
className="rounded-lg bg-blue-600 px-4 py-2 text-sm text-white disabled:opacity-50"
|
||
>
|
||
领取最终验收
|
||
</button>
|
||
) : null}
|
||
{claimedByMe ? (
|
||
<button
|
||
type="button"
|
||
disabled={saving}
|
||
onClick={() => void releasePrepackageAcceptance(item)}
|
||
className="rounded-lg border border-amber-500/40 px-4 py-2 text-sm text-amber-200 disabled:opacity-50"
|
||
>
|
||
释放任务
|
||
</button>
|
||
) : null}
|
||
</div>
|
||
<div className="grid gap-3 md:grid-cols-4">
|
||
<div className="rounded-lg bg-[#101114] p-3 text-xs text-gray-300">
|
||
HeadPose 预标:
|
||
{statistics.headposeEnabled === false
|
||
? "本次未启用"
|
||
: statistics.headposeAvailable
|
||
? `${statistics.headposeFrameCount || 0} 帧`
|
||
: "缺失"}
|
||
</div>
|
||
<div className="rounded-lg bg-[#101114] p-3 text-xs text-gray-300">
|
||
手部预标(标手):
|
||
{statistics.handPrelabelEnabled === false && statistics.handposeEnabled === false
|
||
? "本次未启用"
|
||
: statistics.handPrelabelAvailable || statistics.handposeAvailable
|
||
? `${statistics.handPrelabelFrameCount || statistics.handposeFrameCount || 0} 帧`
|
||
: "缺失"}
|
||
</div>
|
||
<div className="rounded-lg bg-[#101114] p-3 text-xs text-gray-300">
|
||
供应商隔离:{item.vendorId || "-"}
|
||
</div>
|
||
<div className="rounded-lg bg-[#101114] p-3 text-xs text-gray-300">状态:{item.status}</div>
|
||
</div>
|
||
{selectedClipArtifactId ? (
|
||
<video
|
||
controls
|
||
preload="metadata"
|
||
className="max-h-72 w-full rounded-lg bg-black object-contain"
|
||
src={buildBrowserPlayableVideoURL(humanLoopApi.evidenceContentURL(item.id, selectedClipArtifactId))}
|
||
/>
|
||
) : null}
|
||
<div className="grid gap-4 xl:grid-cols-2">
|
||
<PoseEvidencePreview
|
||
itemId={item.id}
|
||
artifact={headposeRender}
|
||
title="HeadPose 姿态轴渲染"
|
||
frameCount={Number(selectedPoseSummary.headposeFrameCount || 0)}
|
||
/>
|
||
<PoseEvidencePreview
|
||
itemId={item.id}
|
||
artifact={handPrelabelRender}
|
||
title="手部预标(标手辅助)"
|
||
frameCount={Number(
|
||
selectedPoseSummary.handPrelabelFrameCount || selectedPoseSummary.handposeFrameCount || 0,
|
||
)}
|
||
/>
|
||
</div>
|
||
<div className="max-h-56 space-y-2 overflow-auto rounded-lg border border-[#2a2b2f] p-3 text-xs text-gray-300">
|
||
{evidenceItems.map((evidence, index) => {
|
||
const entry = evidence as Record<string, any>;
|
||
const annotations = Array.isArray(entry.annotation) ? entry.annotation : [];
|
||
const slices = Array.isArray(entry.finalSlices) ? entry.finalSlices : [];
|
||
return (
|
||
<button
|
||
type="button"
|
||
key={`${entry.taskId || index}`}
|
||
onClick={() => setSelectedAcceptanceEvidence({ itemId: item.id, index })}
|
||
className={`block w-full rounded border p-2 text-left ${selectedIndex === index ? "border-blue-500 bg-blue-500/10" : "border-[#2a2b2f]"}`}
|
||
>
|
||
切片任务 {index + 1} · {slices.length} 段 · {annotations.length} 条标签 · HeadPose 预标{" "}
|
||
{entry.poseSummary?.headposeFrameCount || 0} 帧 · 标手预标{" "}
|
||
{entry.poseSummary?.handPrelabelFrameCount || entry.poseSummary?.handposeFrameCount || 0} 帧
|
||
</button>
|
||
);
|
||
})}
|
||
</div>
|
||
{claimedByMe ? (
|
||
<div className="space-y-2 rounded-xl border border-emerald-500/30 bg-emerald-500/5 p-4">
|
||
<div className="text-sm font-medium text-emerald-100">包前验收统计(必填)</div>
|
||
<div className="grid gap-3 md:grid-cols-4">
|
||
<label className="space-y-1 text-xs text-gray-300">
|
||
<span>视频质量</span>
|
||
<select
|
||
className={inputClass}
|
||
value={acceptanceStatistics.videoQuality}
|
||
onChange={(event) =>
|
||
setPrepackageAcceptanceDrafts((current) => ({
|
||
...current,
|
||
[item.id]: { ...acceptanceStatistics, videoQuality: event.target.value },
|
||
}))
|
||
}
|
||
>
|
||
<option value="" disabled>
|
||
请选择
|
||
</option>
|
||
<option value="qualified">合格</option>
|
||
<option value="unqualified">不合格</option>
|
||
</select>
|
||
</label>
|
||
<label className="space-y-1 text-xs text-gray-300">
|
||
<span>标注准确性(0–100)</span>
|
||
<input
|
||
className={inputClass}
|
||
type="number"
|
||
min="0"
|
||
max="100"
|
||
value={acceptanceStatistics.annotationAccuracy}
|
||
onChange={(event) =>
|
||
setPrepackageAcceptanceDrafts((current) => ({
|
||
...current,
|
||
[item.id]: { ...acceptanceStatistics, annotationAccuracy: event.target.value },
|
||
}))
|
||
}
|
||
/>
|
||
</label>
|
||
<label className="space-y-1 text-xs text-gray-300">
|
||
<span>标注完整性(0–100)</span>
|
||
<input
|
||
className={inputClass}
|
||
type="number"
|
||
min="0"
|
||
max="100"
|
||
value={acceptanceStatistics.annotationCompleteness}
|
||
onChange={(event) =>
|
||
setPrepackageAcceptanceDrafts((current) => ({
|
||
...current,
|
||
[item.id]: { ...acceptanceStatistics, annotationCompleteness: event.target.value },
|
||
}))
|
||
}
|
||
/>
|
||
</label>
|
||
<label className="space-y-1 text-xs text-gray-300">
|
||
<span>总体等级</span>
|
||
<select
|
||
className={inputClass}
|
||
value={acceptanceStatistics.overallGrade}
|
||
onChange={(event) =>
|
||
setPrepackageAcceptanceDrafts((current) => ({
|
||
...current,
|
||
[item.id]: { ...acceptanceStatistics, overallGrade: event.target.value },
|
||
}))
|
||
}
|
||
>
|
||
<option value="" disabled>
|
||
请选择
|
||
</option>
|
||
<option value="A">A</option>
|
||
<option value="B">B</option>
|
||
<option value="C">C</option>
|
||
<option value="D">D</option>
|
||
</select>
|
||
</label>
|
||
</div>
|
||
<textarea
|
||
className={inputClass}
|
||
rows={2}
|
||
value={reviewComment}
|
||
onChange={(event) => setReviewComment(event.target.value)}
|
||
placeholder="验收统计备注(可选)"
|
||
/>
|
||
<button
|
||
type="button"
|
||
disabled={saving || !prepackageAcceptanceStatisticsAreValid(acceptanceStatistics)}
|
||
onClick={() => void confirmPrepackageAcceptance(item, acceptanceStatistics)}
|
||
className="rounded-lg bg-emerald-600 px-4 py-2 text-sm font-medium text-white disabled:opacity-50"
|
||
>
|
||
确认验收并进入打包
|
||
</button>
|
||
<div className="text-xs text-emerald-200">此阶段只提供确认,不提供拒绝或打回。</div>
|
||
</div>
|
||
) : null}
|
||
</div>
|
||
);
|
||
})}
|
||
{deliveryPackages.map((item) => {
|
||
const prePackageAcceptance = item.qualitySummary?.prePackageAcceptance as
|
||
| { statistics?: { overallGrade?: string } }
|
||
| undefined;
|
||
const overallGrade =
|
||
prePackageAcceptance?.statistics?.overallGrade || item.acceptanceReviews?.at(-1)?.overallGrade || "-";
|
||
const assignedToMe = item.assignedUserId === currentUser?.id;
|
||
const packageAssignees = eligibleAssigneesForScope(
|
||
item.workgroupId,
|
||
item.vendorId,
|
||
"quality_reviewer",
|
||
item.assignedUserId,
|
||
);
|
||
const isExpanded = expandedDeliveryPackageId === item.id;
|
||
const contents = deliveryPackageContents[item.id];
|
||
const manifestItems = contents?.manifest?.items || [];
|
||
const acceptanceStatistics = (
|
||
contents?.deliveryPackage.qualitySummary?.prePackageAcceptance as
|
||
| { statistics?: Record<string, string | number | boolean> }
|
||
| undefined
|
||
)?.statistics;
|
||
return (
|
||
<div key={item.id} className={`${panelClass} space-y-4 p-5`}>
|
||
<div className="flex flex-wrap items-center justify-between gap-3">
|
||
<div>
|
||
<div className="text-base font-semibold text-white">交付包 {item.id}</div>
|
||
<div className="mt-1 text-xs text-gray-400">
|
||
v{item.version} · {item.itemIds.length} 个样本 · {item.finalExportArtifactIds?.length || 0}{" "}
|
||
个最终产物 · 状态 {item.status} · 质检等级 {overallGrade}
|
||
</div>
|
||
</div>
|
||
<div className="flex flex-wrap gap-2">
|
||
{isManager && item.acceptanceHumanItemId ? (
|
||
<select
|
||
aria-label="管理员成品包验收改派"
|
||
className="rounded-lg border border-[#2a2b2f] bg-[#0a0a0a] px-3 py-2 text-xs text-white"
|
||
value={item.assignedUserId || ""}
|
||
disabled={saving || item.status !== "pending_acceptance"}
|
||
onChange={(event) => void assignDeliveryPackage(item, event.target.value)}
|
||
>
|
||
<option value="">退回成品验收池</option>
|
||
{packageAssignees.map((user) => (
|
||
<option key={user.id} value={user.id}>
|
||
{user.name} · {user.id === currentUser?.id ? "管理员" : "审核员"}
|
||
</option>
|
||
))}
|
||
</select>
|
||
) : null}
|
||
<button
|
||
type="button"
|
||
onClick={() => void toggleDeliveryPackageContents(item)}
|
||
className="inline-flex items-center gap-2 rounded-lg border border-blue-500/40 px-4 py-2 text-sm text-blue-200 hover:bg-blue-500/10"
|
||
>
|
||
<Eye className="h-4 w-4" />
|
||
{isExpanded ? "收起验收内容" : "查看验收内容"}
|
||
{isExpanded ? <ChevronUp className="h-4 w-4" /> : <ChevronDown className="h-4 w-4" />}
|
||
</button>
|
||
{item.status === "pending_acceptance" && item.acceptanceHumanItemId && !item.assignedUserId ? (
|
||
<button
|
||
type="button"
|
||
disabled={saving}
|
||
onClick={() => void claimDeliveryPackage(item)}
|
||
className="rounded-lg bg-blue-600 px-4 py-2 text-sm text-white disabled:opacity-50"
|
||
>
|
||
领取验收
|
||
</button>
|
||
) : null}
|
||
{assignedToMe ? (
|
||
<button
|
||
type="button"
|
||
disabled={saving}
|
||
onClick={() => void releaseDeliveryPackage(item)}
|
||
className="rounded-lg border border-amber-500/40 px-4 py-2 text-sm text-amber-200 disabled:opacity-50"
|
||
>
|
||
释放验收
|
||
</button>
|
||
) : null}
|
||
</div>
|
||
</div>
|
||
|
||
{isExpanded ? (
|
||
<div className="space-y-4 border-t border-[#2a2b2f] pt-4">
|
||
{deliveryPackageContentsLoading === item.id ? (
|
||
<div className="flex items-center gap-2 py-8 text-sm text-gray-400">
|
||
<Loader2 className="h-4 w-4 animate-spin" /> 正在加载验收内容...
|
||
</div>
|
||
) : deliveryPackageContentsErrors[item.id] ? (
|
||
<div className="rounded-lg border border-red-500/30 bg-red-500/10 p-3 text-sm text-red-200">
|
||
{deliveryPackageContentsErrors[item.id]}
|
||
</div>
|
||
) : contents ? (
|
||
<>
|
||
<div className="grid gap-3 text-xs sm:grid-cols-2 xl:grid-cols-6">
|
||
{[
|
||
["视频质量", acceptanceStatistics?.videoQuality === "qualified" ? "合格" : "-"],
|
||
["标注准确性", acceptanceStatistics?.annotationAccuracy ?? "-"],
|
||
["标注完整性", acceptanceStatistics?.annotationCompleteness ?? "-"],
|
||
["总体等级", acceptanceStatistics?.overallGrade ?? overallGrade],
|
||
[
|
||
"HeadPose 预标",
|
||
acceptanceStatistics?.headposeEnabled === false ? "未启用" : "已进入人工质检",
|
||
],
|
||
[
|
||
"手部预标(标手)",
|
||
acceptanceStatistics?.handPrelabelEnabled === false &&
|
||
acceptanceStatistics?.handposeEnabled === false
|
||
? "未启用"
|
||
: "已进入人工质检",
|
||
],
|
||
].map(([label, value]) => (
|
||
<div key={String(label)} className="rounded-lg bg-[#101114] p-3">
|
||
<div className="text-gray-500">{label}</div>
|
||
<div className="mt-1 text-sm font-medium text-white">{String(value)}</div>
|
||
</div>
|
||
))}
|
||
</div>
|
||
|
||
<div className="grid gap-4 xl:grid-cols-2">
|
||
{manifestItems.map((packageItem) => {
|
||
const videoArtifact = contents.artifacts.find(
|
||
(artifact) => artifact.name === packageItem.clipName,
|
||
);
|
||
const videoURL = deliveryArtifactPreviewURL(videoArtifact);
|
||
const actions = deliveryActions(packageItem);
|
||
return (
|
||
<div key={packageItem.clipId} className="space-y-3 rounded-xl bg-[#101114] p-4">
|
||
<div>
|
||
<div className="break-all text-sm font-medium text-white">{packageItem.clipName}</div>
|
||
<div className="mt-1 text-xs text-gray-400">
|
||
最终边界 {packageItem.startSecond.toFixed(2)}–{packageItem.endSecond.toFixed(2)}s ·
|
||
时长 {packageItem.duration.toFixed(2)}s
|
||
</div>
|
||
</div>
|
||
{videoURL ? (
|
||
<video
|
||
controls
|
||
preload="metadata"
|
||
className="max-h-72 w-full rounded-lg bg-black object-contain"
|
||
src={buildBrowserPlayableVideoURL(videoURL)}
|
||
/>
|
||
) : (
|
||
<div className="rounded-lg border border-[#2a2b2f] p-4 text-xs text-gray-500">
|
||
当前切片没有可播放视频。
|
||
</div>
|
||
)}
|
||
<div className="space-y-2">
|
||
{actions.map((action: Record<string, any>, actionIndex: number) => (
|
||
<div
|
||
key={String(action.id || actionIndex)}
|
||
className="rounded-lg border border-emerald-500/20 bg-emerald-500/5 p-3 text-xs"
|
||
>
|
||
<div className="font-medium text-emerald-200">
|
||
{action.labelId} · {action.label}
|
||
</div>
|
||
<div className="mt-1 text-gray-400">
|
||
标注区间 {Number(action.start || 0).toFixed(2)}–
|
||
{Number(action.end || 0).toFixed(2)}s
|
||
</div>
|
||
{Array.isArray(action.phrases) && action.phrases.length > 0 ? (
|
||
<div className="mt-1 text-gray-500">{action.phrases.join(";")}</div>
|
||
) : null}
|
||
</div>
|
||
))}
|
||
</div>
|
||
</div>
|
||
);
|
||
})}
|
||
</div>
|
||
|
||
<div className="rounded-xl bg-[#101114]">
|
||
<div className="border-b border-[#2a2b2f] px-4 py-3 text-sm font-medium text-white">
|
||
最终交付文件({contents.artifacts.length})
|
||
</div>
|
||
<div className="divide-y divide-[#202227]">
|
||
{contents.artifacts.map((artifact) => (
|
||
<div
|
||
key={artifact.id}
|
||
className="flex flex-wrap items-center justify-between gap-3 px-4 py-3"
|
||
>
|
||
<div className="flex min-w-0 items-center gap-3">
|
||
{artifact.type === "video" ? (
|
||
<Video className="h-4 w-4 shrink-0 text-blue-300" />
|
||
) : (
|
||
<FileJson className="h-4 w-4 shrink-0 text-amber-300" />
|
||
)}
|
||
<div className="min-w-0">
|
||
<div className="truncate text-sm text-gray-200">{artifact.name}</div>
|
||
<div className="mt-0.5 text-xs text-gray-500">{artifact.size}</div>
|
||
</div>
|
||
</div>
|
||
<a
|
||
href={deliveryArtifactDownloadURL(artifact)}
|
||
className="inline-flex items-center gap-1 rounded-md border border-[#2a2b2f] px-3 py-1.5 text-xs text-gray-300 hover:bg-white/5"
|
||
>
|
||
<Download className="h-3.5 w-3.5" /> 下载
|
||
</a>
|
||
</div>
|
||
))}
|
||
</div>
|
||
</div>
|
||
</>
|
||
) : null}
|
||
</div>
|
||
) : null}
|
||
|
||
{assignedToMe ? (
|
||
<div className="space-y-3 rounded-xl border border-[#2a2b2f] bg-[#101114] p-4">
|
||
<div className="grid gap-3 md:grid-cols-4">
|
||
<select
|
||
className={inputClass}
|
||
value={qualityDraft.videoQuality}
|
||
onChange={(event) =>
|
||
setQualityDraft((current) => ({ ...current, videoQuality: event.target.value }))
|
||
}
|
||
>
|
||
<option value="qualified">视频质量合格</option>
|
||
<option value="unqualified">视频质量不合格</option>
|
||
</select>
|
||
<input
|
||
className={inputClass}
|
||
type="number"
|
||
min="0"
|
||
max="100"
|
||
value={qualityDraft.annotationAccuracy}
|
||
onChange={(event) =>
|
||
setQualityDraft((current) => ({ ...current, annotationAccuracy: event.target.value }))
|
||
}
|
||
placeholder="准确性"
|
||
/>
|
||
<input
|
||
className={inputClass}
|
||
type="number"
|
||
min="0"
|
||
max="100"
|
||
value={qualityDraft.annotationCompleteness}
|
||
onChange={(event) =>
|
||
setQualityDraft((current) => ({ ...current, annotationCompleteness: event.target.value }))
|
||
}
|
||
placeholder="完整性"
|
||
/>
|
||
<select
|
||
className={inputClass}
|
||
value={qualityDraft.overallGrade}
|
||
onChange={(event) =>
|
||
setQualityDraft((current) => ({ ...current, overallGrade: event.target.value }))
|
||
}
|
||
>
|
||
<option>A</option>
|
||
<option>B</option>
|
||
<option>C</option>
|
||
<option>D</option>
|
||
</select>
|
||
</div>
|
||
<textarea
|
||
className={inputClass}
|
||
rows={2}
|
||
value={reviewComment}
|
||
onChange={(event) => setReviewComment(event.target.value)}
|
||
placeholder="最终验收意见;拒绝时必填"
|
||
/>
|
||
<div className="flex gap-3">
|
||
<button
|
||
type="button"
|
||
disabled={saving}
|
||
onClick={() => void decideDeliveryPackage(item, "approved")}
|
||
className="rounded-lg bg-emerald-600 px-4 py-2 text-sm text-white disabled:opacity-50"
|
||
>
|
||
验收通过
|
||
</button>
|
||
<button
|
||
type="button"
|
||
disabled={saving}
|
||
onClick={() => void decideDeliveryPackage(item, "rejected")}
|
||
className="rounded-lg bg-red-600 px-4 py-2 text-sm text-white disabled:opacity-50"
|
||
>
|
||
验收拒绝
|
||
</button>
|
||
</div>
|
||
</div>
|
||
) : null}
|
||
</div>
|
||
);
|
||
})}
|
||
{deliveryPackages.length === 0 && prepackageAcceptanceItems.length === 0 ? (
|
||
<div className={`${panelClass} py-16 text-center text-sm text-gray-500`}>暂无成品包验收任务</div>
|
||
) : null}
|
||
</div>
|
||
) : null}
|
||
|
||
{tab === "queue" && workspaceMode !== "acceptance" ? (
|
||
<div className="grid gap-6 xl:grid-cols-[320px_1fr]">
|
||
<div className="space-y-4">
|
||
<div className={`${panelClass} p-4`}>
|
||
<div className="text-sm font-semibold text-white">任务池</div>
|
||
<div className="mt-1 text-xs text-gray-500">领取后进入“我的任务”;释放或打回后回到对应阶段池。</div>
|
||
<div className="mt-3 flex flex-wrap gap-2">
|
||
{(
|
||
[
|
||
["available", "可领取", poolCounts.available],
|
||
["mine", "我的任务", poolCounts.mine],
|
||
...(isManager ? ([["all", "全部任务", poolCounts.all]] as const) : []),
|
||
] as Array<[TaskPoolView, string, number]>
|
||
).map(([value, label, count]) => (
|
||
<button
|
||
key={value}
|
||
type="button"
|
||
onClick={() => setTaskPoolView(value)}
|
||
className={`rounded-lg border px-3 py-2 text-xs transition-colors ${taskPoolView === value ? "border-blue-500 bg-blue-500/10 text-blue-200" : "border-[#2a2b2f] text-gray-400 hover:text-white"}`}
|
||
>
|
||
{label} {count}
|
||
</button>
|
||
))}
|
||
</div>
|
||
<div className="mt-4 text-xs font-medium text-gray-400">逐段任务</div>
|
||
<div className="mt-3 space-y-2">
|
||
{visibleTasks.map((task) => {
|
||
const humanItem = visibleHumanItemByTaskId.get(task.id);
|
||
const assignee = users.find((user) => user.id === humanItem?.assignedUserId);
|
||
return (
|
||
<button
|
||
key={task.id}
|
||
type="button"
|
||
onClick={() => selectTask(task.id)}
|
||
className={`w-full rounded-xl border p-3 text-left ${selectedTaskId === task.id ? "border-blue-500 bg-blue-500/10" : "border-[#2a2b2f] bg-[#0f1012]"}`}
|
||
>
|
||
<div className="truncate text-sm font-medium text-white">{task.sourceVideo}</div>
|
||
<div className="mt-1 flex items-center justify-between text-xs text-gray-500">
|
||
<span>
|
||
{task.clipStart.toFixed(1)}–{task.clipEnd.toFixed(1)}s
|
||
</span>
|
||
<span>{statusLabels[task.status] || task.status}</span>
|
||
</div>
|
||
<div className="mt-1 text-[10px] text-gray-500">
|
||
{humanItem?.assignedUserId
|
||
? `领取人:${assignee?.name || humanItem.assignedUserId}`
|
||
: "尚未领取"}
|
||
</div>
|
||
{task.runId ? (
|
||
<div className="mt-1 truncate font-mono text-[10px] text-blue-300/70">Run {task.runId}</div>
|
||
) : null}
|
||
</button>
|
||
);
|
||
})}
|
||
{visibleTasks.length === 0 ? (
|
||
<div className="py-8 text-center text-sm text-gray-500">暂无可见任务</div>
|
||
) : null}
|
||
</div>
|
||
</div>
|
||
|
||
{isManager && (workspaceMode === "clip" || workspaceMode === "annotate") ? (
|
||
<div className={`${panelClass} space-y-3 p-4`}>
|
||
<div className="text-sm font-semibold text-white">创建标注任务</div>
|
||
<input
|
||
className={inputClass}
|
||
placeholder="视频或 artifact 路径 (.mp4 / .rrd)"
|
||
value={taskDraft.sourceVideo}
|
||
onChange={(event) => setTaskDraft((current) => ({ ...current, sourceVideo: event.target.value }))}
|
||
/>
|
||
<div className="grid grid-cols-2 gap-2">
|
||
<input
|
||
className={inputClass}
|
||
type="number"
|
||
value={taskDraft.clipStart}
|
||
onChange={(event) => setTaskDraft((current) => ({ ...current, clipStart: event.target.value }))}
|
||
/>
|
||
<input
|
||
className={inputClass}
|
||
type="number"
|
||
value={taskDraft.clipEnd}
|
||
onChange={(event) => setTaskDraft((current) => ({ ...current, clipEnd: event.target.value }))}
|
||
/>
|
||
</div>
|
||
<select
|
||
className={inputClass}
|
||
value={taskDraft.templateId}
|
||
onChange={(event) => setTaskDraft((current) => ({ ...current, templateId: event.target.value }))}
|
||
>
|
||
<option value="">已发布模板</option>
|
||
{templates
|
||
.filter((item) => item.status === "published")
|
||
.map((item) => (
|
||
<option key={item.id} value={item.id}>
|
||
{item.name} v{item.version}
|
||
</option>
|
||
))}
|
||
</select>
|
||
<select
|
||
className={inputClass}
|
||
value={taskDraft.workgroupId}
|
||
onChange={(event) => setTaskDraft((current) => ({ ...current, workgroupId: event.target.value }))}
|
||
>
|
||
<option value="">供应商分组</option>
|
||
{workgroups.map((item) => (
|
||
<option key={item.id} value={item.id}>
|
||
{item.vendorId} / {item.name}
|
||
</option>
|
||
))}
|
||
</select>
|
||
<div className="rounded-lg border border-blue-500/20 bg-blue-500/10 px-3 py-2 text-xs text-blue-100">
|
||
任务创建后进入供应商工作组待领取池,不指定人员、不发送推送。
|
||
</div>
|
||
<button
|
||
type="button"
|
||
onClick={() => void createTask()}
|
||
disabled={saving}
|
||
className="w-full rounded-lg bg-blue-600 px-3 py-2 text-sm font-medium text-white disabled:opacity-50"
|
||
>
|
||
创建任务
|
||
</button>
|
||
</div>
|
||
) : null}
|
||
</div>
|
||
|
||
<div className={`${panelClass} min-h-[640px] p-5`}>
|
||
{detail ? (
|
||
<div className="space-y-6">
|
||
<div className="flex flex-wrap items-start justify-between gap-3">
|
||
<div>
|
||
<div className="text-lg font-semibold text-white">
|
||
{detail.task.artifactId || detail.task.sourceVideo}
|
||
</div>
|
||
<div className="mt-1 text-sm text-gray-500">
|
||
模板 v{detail.task.templateVersion} · {statusLabels[detail.task.status]}
|
||
</div>
|
||
<div className="mt-2 flex flex-wrap gap-3 text-xs text-gray-500">
|
||
{detail.task.runId && role === "admin" ? (
|
||
<Link
|
||
className="text-blue-300 hover:text-blue-200"
|
||
to={`/monitoring?runId=${encodeURIComponent(detail.task.runId)}`}
|
||
>
|
||
返回 Run 监控
|
||
</Link>
|
||
) : null}
|
||
{detail.task.workflowId ? (
|
||
<span className="font-mono">Workflow {detail.task.workflowId}</span>
|
||
) : null}
|
||
{detail.task.dataTaskId ? (
|
||
<span className="font-mono">DataTask {detail.task.dataTaskId}</span>
|
||
) : null}
|
||
</div>
|
||
</div>
|
||
|
||
<div className="flex flex-wrap items-center gap-2">
|
||
<div className="flex items-center gap-1 rounded-lg border border-[#2a2b2f] bg-[#0a0a0a] p-1">
|
||
<button
|
||
type="button"
|
||
onClick={() => setPreviewTab("video")}
|
||
className={`inline-flex items-center gap-1 rounded px-2.5 py-1 text-xs font-medium ${previewTab === "video" ? "bg-blue-600 text-white" : "text-gray-400 hover:text-white"}`}
|
||
>
|
||
<Video className="h-3.5 w-3.5" /> 视频播放
|
||
</button>
|
||
{detail.task.sourceVideo.toLowerCase().endsWith(".rrd") ? (
|
||
<button
|
||
type="button"
|
||
onClick={() => setPreviewTab("rerun")}
|
||
className={`inline-flex items-center gap-1 rounded px-2.5 py-1 text-xs font-medium ${previewTab === "rerun" ? "bg-blue-600 text-white" : "text-gray-400 hover:text-white"}`}
|
||
>
|
||
<Eye className="h-3.5 w-3.5" /> Rerun 可视化 (.rrd)
|
||
</button>
|
||
) : null}
|
||
</div>
|
||
|
||
<div className="rounded-full border border-blue-500/30 bg-blue-500/10 px-3 py-1 text-xs text-blue-200">
|
||
{annotationStage === "split_annotation" || annotationStage === "cut_adjustment"
|
||
? "人工剪切调整"
|
||
: annotationStage === "split_quality_review" || annotationStage === "cut_review"
|
||
? "剪切审核"
|
||
: annotationStage === "semantic_annotation"
|
||
? "语义标注"
|
||
: annotationStage === "semantic_review"
|
||
? "标注审核"
|
||
: "标注质检"}{" "}
|
||
· Revision {detail.task.currentRevision}
|
||
</div>
|
||
{isManager && selectedHumanItem ? (
|
||
<label className="flex items-center gap-2 rounded-lg border border-[#2a2b2f] bg-[#0a0a0a] px-2 py-1 text-xs text-gray-400">
|
||
<span>管理员改派</span>
|
||
<select
|
||
aria-label="管理员任务改派"
|
||
className="bg-transparent text-xs text-white outline-none"
|
||
value={selectedHumanItem.assignedUserId || ""}
|
||
disabled={saving || ["accepted", "rejected", "escalated"].includes(selectedHumanItem.status)}
|
||
onChange={(event) => void assignSelectedTask(event.target.value)}
|
||
>
|
||
<option value="">退回待领取池</option>
|
||
{eligibleAssignees.map((user) => (
|
||
<option key={user.id} value={user.id}>
|
||
{user.name} ·{" "}
|
||
{user.id === currentUser?.id ? "管理员" : assignmentRoleLabel(selectedRequiredRole)}
|
||
</option>
|
||
))}
|
||
</select>
|
||
</label>
|
||
) : null}
|
||
{selectedHumanItem &&
|
||
!selectedHumanItem.assignedUserId &&
|
||
["ready", "rework", "submitted"].includes(selectedHumanItem.status) ? (
|
||
<button
|
||
type="button"
|
||
onClick={() => void claimSelectedTask()}
|
||
disabled={saving}
|
||
className="rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white disabled:opacity-50"
|
||
>
|
||
{workspaceMode === "clip"
|
||
? "领取剪切任务"
|
||
: workspaceMode === "clip-quality"
|
||
? "领取剪切审核"
|
||
: workspaceMode === "quality"
|
||
? "领取标注审核"
|
||
: "领取标注任务"}
|
||
</button>
|
||
) : null}
|
||
{selectedHumanItem && selectedClaimedByMe && selectedHumanItem.assignedUserId ? (
|
||
<button
|
||
type="button"
|
||
onClick={() => void releaseSelectedTask()}
|
||
disabled={saving}
|
||
className="rounded-lg border border-amber-500/40 px-4 py-2 text-sm text-amber-200 disabled:opacity-50"
|
||
>
|
||
释放任务
|
||
</button>
|
||
) : null}
|
||
</div>
|
||
</div>
|
||
|
||
{workspaceMode === "clip" || workspaceMode === "clip-quality" || isV5Combined || isV5CombinedQuality ? (
|
||
<div className="space-y-4 rounded-xl border border-[#2a2b2f] bg-[#101114] p-4">
|
||
{detail.task.sourceVideo.toLowerCase().endsWith(".rrd") ||
|
||
(previewTab === "rerun" && detail.task.sourceVideo.toLowerCase().endsWith(".rrd")) ? (
|
||
<RerunArtifactPreview
|
||
src={detail.task.sourceVideo}
|
||
name={detail.task.artifactId || detail.task.sourceVideo.split("/").pop() || "rerun-data.rrd"}
|
||
/>
|
||
) : (
|
||
<video
|
||
className="max-h-[420px] w-full rounded-xl bg-black"
|
||
src={buildBrowserPlayableVideoURL(detail.task.sourceVideo)}
|
||
controls
|
||
preload="metadata"
|
||
onLoadedMetadata={(event) => {
|
||
if (detail.task.sourceIsFullVideo) {
|
||
event.currentTarget.currentTime = Math.max(0, detail.task.clipStart);
|
||
}
|
||
}}
|
||
/>
|
||
)}
|
||
<div className="flex items-center justify-between gap-3">
|
||
<div>
|
||
<div className="font-medium text-white">
|
||
{isV5Combined
|
||
? "v5 同任务切片校正与语义标注"
|
||
: isV5CombinedQuality
|
||
? "v5 统一质检:最终切片与语义标签"
|
||
: workspaceMode === "clip"
|
||
? "人工剪切边界校正"
|
||
: "剪切片段总览与质检"}
|
||
</div>
|
||
<div className="text-xs text-gray-500">
|
||
{isV5Combined
|
||
? "可先调整切片或先编辑 22 类语义;最终以同一次提交原子保存。"
|
||
: isV5CombinedQuality
|
||
? "只读核对最终切片、22 类语义标注和姿态统计;统一决定通过或打回到同一标注任务。"
|
||
: workspaceMode === "clip"
|
||
? "调整边界、拆分、合并或删除错误切片;提交后进入剪切质检池。"
|
||
: "核对操作员剪切边界与时长,通过后流转至人工标注,打回则退回人工剪切重新切片。"}
|
||
</div>
|
||
</div>
|
||
{workspaceMode === "clip" || isV5Combined ? (
|
||
<button
|
||
type="button"
|
||
onClick={undoSlice}
|
||
disabled={sliceHistory.length === 0}
|
||
className="inline-flex items-center gap-2 rounded-lg border border-[#2a2b2f] px-3 py-2 text-xs text-gray-300 disabled:opacity-40"
|
||
>
|
||
<Undo2 className="h-4 w-4" /> 撤销
|
||
</button>
|
||
) : null}
|
||
</div>
|
||
<div className="space-y-2">
|
||
{sliceSegments.map((slice, index) => (
|
||
<div
|
||
key={slice.id}
|
||
className="grid gap-2 rounded-lg border border-[#2a2b2f] p-3 md:grid-cols-[70px_1fr_1fr_auto_auto_auto] md:items-center"
|
||
>
|
||
<span className="text-xs font-medium text-blue-300">片段 {index + 1}</span>
|
||
<input
|
||
className={inputClass}
|
||
type="number"
|
||
step="0.1"
|
||
disabled={workspaceMode === "clip-quality"}
|
||
value={slice.start}
|
||
onChange={(event) => adjustSlice(slice.id, "start", Number(event.target.value))}
|
||
/>
|
||
<input
|
||
className={inputClass}
|
||
type="number"
|
||
step="0.1"
|
||
disabled={workspaceMode === "clip-quality"}
|
||
value={slice.end}
|
||
onChange={(event) => adjustSlice(slice.id, "end", Number(event.target.value))}
|
||
/>
|
||
{workspaceMode === "clip" || isV5Combined ? (
|
||
<>
|
||
<button
|
||
type="button"
|
||
title="拆分"
|
||
onClick={() => splitSlice(index)}
|
||
className="rounded-lg border border-blue-500/30 p-2 text-blue-200"
|
||
>
|
||
<Scissors className="h-4 w-4" />
|
||
</button>
|
||
<button
|
||
type="button"
|
||
title="与下一段合并"
|
||
disabled={index === sliceSegments.length - 1}
|
||
onClick={() => mergeSlice(index)}
|
||
className="rounded-lg border border-violet-500/30 p-2 text-violet-200 disabled:opacity-30"
|
||
>
|
||
<Merge className="h-4 w-4" />
|
||
</button>
|
||
<button
|
||
type="button"
|
||
title="删除"
|
||
disabled={sliceSegments.length <= 1}
|
||
onClick={() => deleteSlice(index)}
|
||
className="rounded-lg border border-red-500/30 p-2 text-red-200 disabled:opacity-30"
|
||
>
|
||
<Trash2 className="h-4 w-4" />
|
||
</button>
|
||
</>
|
||
) : (
|
||
<span className="text-xs text-gray-500 font-mono">
|
||
{(slice.end - slice.start).toFixed(2)}s
|
||
</span>
|
||
)}
|
||
</div>
|
||
))}
|
||
</div>
|
||
</div>
|
||
) : (
|
||
<AnnotationTimelineEditor
|
||
videoSource={detail.task.sourceVideo}
|
||
clipStart={editableTimelineStart}
|
||
clipEnd={editableTimelineEnd}
|
||
sourceIsFullVideo={detail.task.sourceIsFullVideo}
|
||
initialTime={detail.task.clipStart}
|
||
segments={segments}
|
||
labels={selectedTemplate?.labels || []}
|
||
onChange={setSegments}
|
||
readOnly={
|
||
workspaceMode !== "annotate" ||
|
||
(detail.task.status !== "pending_annotation" && detail.task.status !== "rework")
|
||
}
|
||
/>
|
||
)}
|
||
|
||
{isV5Combined || isV5CombinedQuality ? (
|
||
<AnnotationTimelineEditor
|
||
videoSource={detail.task.sourceVideo}
|
||
clipStart={editableTimelineStart}
|
||
clipEnd={editableTimelineEnd}
|
||
sourceIsFullVideo={detail.task.sourceIsFullVideo}
|
||
initialTime={detail.task.clipStart}
|
||
segments={segments}
|
||
labels={selectedTemplate?.labels || []}
|
||
onChange={setSegments}
|
||
readOnly={!isV5Combined || !selectedClaimedByMe}
|
||
/>
|
||
) : null}
|
||
|
||
{workspaceMode === "annotate" ? (
|
||
<div className="grid gap-3 rounded-xl border border-[#2a2b2f] bg-[#101114] p-4 md:grid-cols-[1.2fr_1fr_1fr_auto]">
|
||
<select
|
||
className={inputClass}
|
||
value={segmentDraft.labelId}
|
||
onChange={(event) => {
|
||
const label = selectedTemplate?.labels.find((item) => item.id === event.target.value);
|
||
setSegmentDraft((current) => ({
|
||
...current,
|
||
labelId: event.target.value,
|
||
label: label?.name || "",
|
||
}));
|
||
}}
|
||
>
|
||
<option value="">选择语义标签</option>
|
||
{selectedTemplate?.labels.map((label) => (
|
||
<option key={label.id} value={label.id}>
|
||
{label.name}
|
||
</option>
|
||
))}
|
||
</select>
|
||
<input
|
||
className={inputClass}
|
||
type="number"
|
||
step="0.1"
|
||
value={segmentDraft.start}
|
||
onChange={(event) => setSegmentDraft((current) => ({ ...current, start: event.target.value }))}
|
||
/>
|
||
<input
|
||
className={inputClass}
|
||
type="number"
|
||
step="0.1"
|
||
value={segmentDraft.end}
|
||
onChange={(event) => setSegmentDraft((current) => ({ ...current, end: event.target.value }))}
|
||
/>
|
||
<button
|
||
type="button"
|
||
onClick={addSegment}
|
||
className="rounded-lg border border-blue-500/40 px-3 text-blue-200"
|
||
>
|
||
<Plus className="h-4 w-4" />
|
||
</button>
|
||
</div>
|
||
) : null}
|
||
|
||
{workspaceMode === "clip-quality" || workspaceMode === "quality" ? (
|
||
<div className="grid gap-3 rounded-xl border border-[#2a2b2f] bg-[#101114] p-4 md:grid-cols-4">
|
||
<label className="space-y-1 text-xs text-gray-400">
|
||
<span>视频质量</span>
|
||
<select
|
||
className={inputClass}
|
||
value={qualityDraft.videoQuality}
|
||
onChange={(event) =>
|
||
setQualityDraft((current) => ({ ...current, videoQuality: event.target.value }))
|
||
}
|
||
>
|
||
<option value="qualified">合格</option>
|
||
<option value="unqualified">不合格</option>
|
||
</select>
|
||
</label>
|
||
<label className="space-y-1 text-xs text-gray-400">
|
||
<span>{workspaceMode === "clip-quality" ? "剪切准确性(0–100)" : "标注准确性(0–100)"}</span>
|
||
<input
|
||
className={inputClass}
|
||
type="number"
|
||
min="0"
|
||
max="100"
|
||
value={qualityDraft.annotationAccuracy}
|
||
onChange={(event) =>
|
||
setQualityDraft((current) => ({ ...current, annotationAccuracy: event.target.value }))
|
||
}
|
||
/>
|
||
</label>
|
||
<label className="space-y-1 text-xs text-gray-400">
|
||
<span>{workspaceMode === "clip-quality" ? "剪切完整性(0–100)" : "标注完整性(0–100)"}</span>
|
||
<input
|
||
className={inputClass}
|
||
type="number"
|
||
min="0"
|
||
max="100"
|
||
value={qualityDraft.annotationCompleteness}
|
||
onChange={(event) =>
|
||
setQualityDraft((current) => ({ ...current, annotationCompleteness: event.target.value }))
|
||
}
|
||
/>
|
||
</label>
|
||
<label className="space-y-1 text-xs text-gray-400">
|
||
<span>总体评价</span>
|
||
<select
|
||
className={inputClass}
|
||
value={qualityDraft.overallGrade}
|
||
onChange={(event) =>
|
||
setQualityDraft((current) => ({ ...current, overallGrade: event.target.value }))
|
||
}
|
||
>
|
||
<option value="A">A</option>
|
||
<option value="B">B</option>
|
||
<option value="C">C</option>
|
||
<option value="D">D</option>
|
||
</select>
|
||
</label>
|
||
</div>
|
||
) : null}
|
||
|
||
<div className="flex flex-wrap gap-3">
|
||
{workspaceMode === "clip" ? (
|
||
<button
|
||
type="button"
|
||
onClick={() => void submitSliceRevision()}
|
||
disabled={saving || sliceSegments.length === 0 || !selectedClaimedByMe}
|
||
className="inline-flex items-center gap-2 rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white disabled:opacity-50"
|
||
>
|
||
<Scissors className="h-4 w-4" /> 提交切片校正
|
||
</button>
|
||
) : null}
|
||
|
||
{isV5Combined ? (
|
||
<button
|
||
type="button"
|
||
onClick={() => void submitCombined()}
|
||
disabled={saving || sliceSegments.length === 0 || !selectedClaimedByMe}
|
||
className="inline-flex items-center gap-2 rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white disabled:opacity-50"
|
||
>
|
||
<Send className="h-4 w-4" /> 同时提交切片与语义标注
|
||
</button>
|
||
) : workspaceMode === "annotate" ? (
|
||
<button
|
||
type="button"
|
||
onClick={() => void submitRevision()}
|
||
disabled={saving || segments.length === 0 || !selectedClaimedByMe}
|
||
className="inline-flex items-center gap-2 rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white disabled:opacity-50"
|
||
>
|
||
<Send className="h-4 w-4" /> 提交语义标注
|
||
</button>
|
||
) : null}
|
||
|
||
{!isV5Combined && (workspaceMode === "clip" || workspaceMode === "annotate") && detail.humanItem ? (
|
||
<button
|
||
type="button"
|
||
onClick={() => void rejectAnnotationInput()}
|
||
disabled={saving || !selectedClaimedByMe}
|
||
className="inline-flex items-center gap-2 rounded-lg border border-red-500/40 px-4 py-2 text-sm text-red-200 disabled:opacity-50"
|
||
>
|
||
<XCircle className="h-4 w-4" />
|
||
拒绝输入
|
||
</button>
|
||
) : null}
|
||
|
||
{workspaceMode === "clip-quality" && detail.task.status === "pending_quality" ? (
|
||
<>
|
||
<button
|
||
type="button"
|
||
onClick={() => void review("split_quality", "approved")}
|
||
disabled={saving || !selectedClaimedByMe}
|
||
className="inline-flex items-center gap-2 rounded-lg bg-emerald-600 px-4 py-2 text-sm text-white"
|
||
>
|
||
<CheckCircle2 className="h-4 w-4" />
|
||
剪切审核通过
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={() => void review("split_quality", "rejected")}
|
||
disabled={saving || !selectedClaimedByMe}
|
||
className="inline-flex items-center gap-2 rounded-lg bg-red-600 px-4 py-2 text-sm text-white"
|
||
>
|
||
<RotateCcw className="h-4 w-4" />
|
||
剪切不可用,打回剪切池
|
||
</button>
|
||
</>
|
||
) : null}
|
||
|
||
{workspaceMode === "quality" && detail.task.status === "pending_quality" ? (
|
||
<>
|
||
<button
|
||
type="button"
|
||
onClick={() => void review("quality", "approved")}
|
||
disabled={saving || !selectedClaimedByMe}
|
||
className="inline-flex items-center gap-2 rounded-lg bg-emerald-600 px-4 py-2 text-sm text-white"
|
||
>
|
||
<CheckCircle2 className="h-4 w-4" />
|
||
标注审核通过
|
||
</button>
|
||
{selectedHumanItem?.currentStageId === "semantic_review" ? (
|
||
<>
|
||
<button
|
||
type="button"
|
||
onClick={() => void review("quality", "rejected", "semantic_annotation")}
|
||
disabled={saving || !selectedClaimedByMe}
|
||
className="inline-flex items-center gap-2 rounded-lg bg-red-600 px-4 py-2 text-sm text-white"
|
||
>
|
||
<RotateCcw className="h-4 w-4" />
|
||
打回语义标注
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={() => void review("quality", "rejected", "cut_adjustment")}
|
||
disabled={saving || !selectedClaimedByMe}
|
||
className="inline-flex items-center gap-2 rounded-lg border border-red-500/50 px-4 py-2 text-sm text-red-200"
|
||
>
|
||
<Scissors className="h-4 w-4" />
|
||
打回人工调切
|
||
</button>
|
||
</>
|
||
) : (
|
||
<button
|
||
type="button"
|
||
onClick={() => void review("quality", "rejected")}
|
||
disabled={saving || !selectedClaimedByMe}
|
||
className="inline-flex items-center gap-2 rounded-lg bg-red-600 px-4 py-2 text-sm text-white"
|
||
>
|
||
<RotateCcw className="h-4 w-4" />
|
||
标注审核打回
|
||
</button>
|
||
)}
|
||
</>
|
||
) : null}
|
||
</div>
|
||
|
||
<textarea
|
||
className={inputClass}
|
||
rows={3}
|
||
placeholder="审核意见;打回时必填"
|
||
value={reviewComment}
|
||
onChange={(event) => setReviewComment(event.target.value)}
|
||
/>
|
||
|
||
<div className="grid gap-4 md:grid-cols-2">
|
||
<div className="rounded-xl border border-[#2a2b2f] p-4">
|
||
<div className="text-sm font-medium text-white">切片与语义修订历史</div>
|
||
{detail.sliceRevisions.map((item) => (
|
||
<div key={item.id} className="mt-3 text-xs text-gray-400">
|
||
切片 v{item.revision} · {item.segments.length} 段 ·{" "}
|
||
{formatCompactDateTime(item.createdAt, timeZone)}
|
||
</div>
|
||
))}
|
||
{detail.revisions.map((item) => (
|
||
<div key={item.id} className="mt-3 text-xs text-gray-400">
|
||
v{item.revision} · {item.segments.length} 段 · {item.isRework ? "返工" : "首次产出"} ·{" "}
|
||
{formatCompactDateTime(item.createdAt, timeZone)}
|
||
</div>
|
||
))}
|
||
</div>
|
||
<div className="rounded-xl border border-[#2a2b2f] p-4">
|
||
<div className="text-sm font-medium text-white">审核历史</div>
|
||
{detail.reviews.map((item) => (
|
||
<div key={item.id} className="mt-3 text-xs text-gray-400">
|
||
{item.stage} · {item.decision} · revision {item.revision} ·{" "}
|
||
{formatCompactDateTime(item.createdAt, timeZone)}
|
||
</div>
|
||
))}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
) : (
|
||
<div className="flex min-h-[560px] items-center justify-center text-sm text-gray-500">
|
||
选择一个任务进入时间轴编辑
|
||
</div>
|
||
)}
|
||
</div>
|
||
</div>
|
||
) : null}
|
||
|
||
{tab === "templates" ? (
|
||
<div className="grid gap-6 lg:grid-cols-[360px_1fr]">
|
||
{isManager ? (
|
||
<div className={`${panelClass} space-y-3 p-5`}>
|
||
<div className="text-base font-semibold text-white">创建模板版本</div>
|
||
<input
|
||
className={inputClass}
|
||
value={templateDraft.name}
|
||
onChange={(event) => setTemplateDraft((current) => ({ ...current, name: event.target.value }))}
|
||
/>
|
||
<input
|
||
className={inputClass}
|
||
type="number"
|
||
value={templateDraft.version}
|
||
onChange={(event) =>
|
||
setTemplateDraft((current) => ({ ...current, version: Number(event.target.value) }))
|
||
}
|
||
/>
|
||
<textarea
|
||
className={inputClass}
|
||
value={templateDraft.labels}
|
||
onChange={(event) => setTemplateDraft((current) => ({ ...current, labels: event.target.value }))}
|
||
/>
|
||
<textarea
|
||
className={inputClass}
|
||
value={templateDraft.phrases}
|
||
onChange={(event) => setTemplateDraft((current) => ({ ...current, phrases: event.target.value }))}
|
||
/>
|
||
<button
|
||
type="button"
|
||
onClick={() => void createTemplate()}
|
||
className="w-full rounded-lg bg-blue-600 px-3 py-2 text-sm text-white"
|
||
>
|
||
创建草稿
|
||
</button>
|
||
</div>
|
||
) : null}
|
||
<div className={`${panelClass} p-5`}>
|
||
<div className="grid gap-3 md:grid-cols-2">
|
||
{templates.map((item) => (
|
||
<div key={item.id} className="rounded-xl border border-[#2a2b2f] bg-[#101114] p-4">
|
||
<div className="flex justify-between">
|
||
<div className="font-medium text-white">
|
||
{item.name} v{item.version}
|
||
</div>
|
||
<span className="text-xs text-gray-500">{item.status}</span>
|
||
</div>
|
||
<div className="mt-3 flex flex-wrap gap-2">
|
||
{item.labels.map((label) => (
|
||
<span key={label.id} className="rounded-full bg-blue-500/10 px-2 py-1 text-xs text-blue-200">
|
||
{label.name}
|
||
</span>
|
||
))}
|
||
</div>
|
||
{isManager && item.status === "draft" ? (
|
||
<button
|
||
type="button"
|
||
onClick={() => annotationOperationsApi.publishTemplate(item.id).then(loadProject)}
|
||
className="mt-4 rounded-lg border border-emerald-500/30 px-3 py-1.5 text-xs text-emerald-200"
|
||
>
|
||
发布版本
|
||
</button>
|
||
) : null}
|
||
</div>
|
||
))}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
) : null}
|
||
|
||
{tab === "groups" ? (
|
||
<div className="grid gap-6 lg:grid-cols-2">
|
||
<div className={`${panelClass} p-5`}>
|
||
<div className="text-base font-semibold text-white">供应商分组</div>
|
||
{isManager ? (
|
||
<div className="mt-4 grid gap-2 md:grid-cols-2">
|
||
<input
|
||
className={inputClass}
|
||
placeholder="分组名称"
|
||
value={groupDraft.name}
|
||
onChange={(event) => setGroupDraft((current) => ({ ...current, name: event.target.value }))}
|
||
/>
|
||
<input
|
||
className={inputClass}
|
||
placeholder="供应商 ID"
|
||
value={groupDraft.vendorId}
|
||
onChange={(event) => setGroupDraft((current) => ({ ...current, vendorId: event.target.value }))}
|
||
/>
|
||
<input
|
||
className={`${inputClass} md:col-span-2`}
|
||
placeholder="说明"
|
||
value={groupDraft.description}
|
||
onChange={(event) => setGroupDraft((current) => ({ ...current, description: event.target.value }))}
|
||
/>
|
||
<button
|
||
type="button"
|
||
onClick={() => void createGroup()}
|
||
className="rounded-lg bg-blue-600 px-3 py-2 text-sm text-white"
|
||
>
|
||
创建分组
|
||
</button>
|
||
</div>
|
||
) : null}
|
||
<div className="mt-5 space-y-2">
|
||
{workgroups.map((item) => (
|
||
<div key={item.id} className="rounded-xl border border-[#2a2b2f] p-3">
|
||
<div className="text-sm text-white">{item.name}</div>
|
||
<div className="text-xs text-gray-500">{item.vendorId}</div>
|
||
</div>
|
||
))}
|
||
</div>
|
||
</div>
|
||
<div className={`${panelClass} p-5`}>
|
||
<div className="text-base font-semibold text-white">项目角色</div>
|
||
{isManager ? (
|
||
<div className="mt-4 grid gap-2">
|
||
<select
|
||
className={inputClass}
|
||
value={membershipDraft.userId}
|
||
onChange={(event) => setMembershipDraft((current) => ({ ...current, userId: event.target.value }))}
|
||
>
|
||
<option value="">选择用户</option>
|
||
{users.map((item) => (
|
||
<option key={item.id} value={item.id}>
|
||
{item.name}
|
||
</option>
|
||
))}
|
||
</select>
|
||
<select
|
||
className={inputClass}
|
||
value={membershipDraft.workgroupId}
|
||
onChange={(event) =>
|
||
setMembershipDraft((current) => ({ ...current, workgroupId: event.target.value }))
|
||
}
|
||
>
|
||
<option value="">选择分组</option>
|
||
{workgroups.map((item) => (
|
||
<option key={item.id} value={item.id}>
|
||
{item.name}
|
||
</option>
|
||
))}
|
||
</select>
|
||
<select
|
||
className={inputClass}
|
||
value={membershipDraft.assignmentRole}
|
||
onChange={(event) =>
|
||
setMembershipDraft((current) => ({
|
||
...current,
|
||
assignmentRole: event.target.value as ProjectAnnotationMembership["assignmentRole"],
|
||
}))
|
||
}
|
||
>
|
||
<option value="cutter">人工剪切员</option>
|
||
<option value="annotator">标注员(剪切审核 + 语义标注)</option>
|
||
<option value="quality_reviewer">审核员(标注审核 + 最终验收)</option>
|
||
<option value="vendor_manager">供应商管理员</option>
|
||
</select>
|
||
<button
|
||
type="button"
|
||
onClick={() => void createMembership()}
|
||
className="rounded-lg bg-blue-600 px-3 py-2 text-sm text-white"
|
||
>
|
||
分配角色
|
||
</button>
|
||
</div>
|
||
) : null}
|
||
<div className="mt-5 space-y-2">
|
||
{memberships.map((item) => (
|
||
<div key={item.id} className="rounded-xl border border-[#2a2b2f] p-3 text-xs text-gray-400">
|
||
<div className="text-sm text-white">
|
||
{users.find((user) => user.id === item.userId)?.name || item.userId}
|
||
</div>
|
||
<div>
|
||
{item.vendorId} · {assignmentRoleLabel(item.assignmentRole)}
|
||
</div>
|
||
</div>
|
||
))}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
) : null}
|
||
|
||
{tab === "workload" ? (
|
||
<div className="space-y-5">
|
||
<div className="grid gap-3 md:grid-cols-5">
|
||
{[
|
||
["正式产出", workloadTotals.outputCount],
|
||
["返工", workloadTotals.reworkCount],
|
||
["通过", workloadTotals.approvedCount],
|
||
["拒绝", workloadTotals.rejectedCount],
|
||
["总工时", `${Math.round(workloadTotals.durationSeconds / 60)} min`],
|
||
].map(([label, value]) => (
|
||
<div key={String(label)} className={`${panelClass} p-4`}>
|
||
<div className="text-xs text-gray-500">{label}</div>
|
||
<div className="mt-2 text-2xl font-semibold text-white">{value}</div>
|
||
</div>
|
||
))}
|
||
</div>
|
||
<div className={`${panelClass} overflow-hidden`}>
|
||
<div className="grid grid-cols-[1.2fr_1fr_1fr_repeat(4,0.7fr)] gap-3 border-b border-[#2a2b2f] px-4 py-3 text-xs text-gray-500">
|
||
<span>用户</span>
|
||
<span>供应商</span>
|
||
<span>分组</span>
|
||
<span>模板</span>
|
||
<span>产出</span>
|
||
<span>返工</span>
|
||
<span>工时</span>
|
||
</div>
|
||
{workload.items.map((item, index) => (
|
||
<div
|
||
key={`${item.userId}-${item.workgroupId}-${item.templateVersion}-${index}`}
|
||
className="grid grid-cols-[1.2fr_1fr_1fr_repeat(4,0.7fr)] gap-3 border-b border-[#202227] px-4 py-3 text-sm text-gray-300"
|
||
>
|
||
<span>{users.find((user) => user.id === item.userId)?.name || item.userId || "系统"}</span>
|
||
<span>{item.vendorId}</span>
|
||
<span>{workgroups.find((group) => group.id === item.workgroupId)?.name || item.workgroupId}</span>
|
||
<span>v{item.templateVersion}</span>
|
||
<span>{item.outputCount}</span>
|
||
<span>{item.reworkCount}</span>
|
||
<span>{Math.round(item.durationSeconds / 60)}m</span>
|
||
</div>
|
||
))}
|
||
</div>
|
||
</div>
|
||
) : null}
|
||
</div>
|
||
);
|
||
}
|