2026-08-07 11:44:12 +08:00
|
|
|
|
/**
|
2026-08-09 17:55:40 +08:00
|
|
|
|
* 任务流转卡片堆叠视图 — 与移动端 TaskSwipeCards.vue 核心逻辑完全对齐
|
2026-08-07 11:44:12 +08:00
|
|
|
|
*/
|
2026-08-09 17:55:40 +08:00
|
|
|
|
import { memo, useMemo, useState } from "react";
|
2026-08-07 11:44:12 +08:00
|
|
|
|
import {
|
2026-08-09 17:55:40 +08:00
|
|
|
|
GitBranch, ArrowDown, AlertTriangle, Clock,
|
|
|
|
|
|
CheckCircle, Flag, FileText, X, Image,
|
2026-08-07 11:44:12 +08:00
|
|
|
|
} from "lucide-react";
|
2026-08-09 17:55:40 +08:00
|
|
|
|
import type { TaskResponse, TaskRecordResponse } from "../../types/api";
|
2026-08-07 11:44:12 +08:00
|
|
|
|
import { TASK_STATUS } from "../../types/api";
|
|
|
|
|
|
import { getStatusConfig } from "../../constants/task";
|
|
|
|
|
|
import type { ModalTarget } from "./TaskTreeViewer";
|
|
|
|
|
|
|
2026-08-07 17:29:36 +08:00
|
|
|
|
// ============================================================
|
2026-08-09 17:55:40 +08:00
|
|
|
|
// 工具函数
|
2026-08-07 17:29:36 +08:00
|
|
|
|
// ============================================================
|
2026-08-07 11:44:12 +08:00
|
|
|
|
|
2026-08-07 17:29:36 +08:00
|
|
|
|
function fmtTime(d: string | null) {
|
|
|
|
|
|
if (!d) return "";
|
|
|
|
|
|
const dt = new Date(d);
|
|
|
|
|
|
const pad = (n: number) => String(n).padStart(2, "0");
|
|
|
|
|
|
return `${dt.getFullYear()}-${pad(dt.getMonth() + 1)}-${pad(dt.getDate())} ${pad(dt.getHours())}:${pad(dt.getMinutes())}`;
|
|
|
|
|
|
}
|
2026-08-07 11:44:12 +08:00
|
|
|
|
|
2026-08-07 17:29:36 +08:00
|
|
|
|
function isMainTask(t: TaskResponse): boolean {
|
|
|
|
|
|
return !t.parent_task_id || t.task_type === "TRANSFER" || t.task_type === "RECOVERY"
|
|
|
|
|
|
|| (!t.task_type && !!t.parent_task_id);
|
2026-08-07 11:44:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-07 17:29:36 +08:00
|
|
|
|
// ============================================================
|
2026-08-09 17:55:40 +08:00
|
|
|
|
// 记录图片渲染
|
2026-08-07 17:29:36 +08:00
|
|
|
|
// ============================================================
|
2026-08-07 11:44:12 +08:00
|
|
|
|
|
2026-08-09 17:55:40 +08:00
|
|
|
|
function parseImages(imagesStr: string | null | undefined): string[] {
|
|
|
|
|
|
if (!imagesStr) return [];
|
|
|
|
|
|
try { return JSON.parse(imagesStr); } catch { return []; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function imageUrl(url: string) {
|
|
|
|
|
|
if (!url) return "";
|
|
|
|
|
|
if (url.startsWith("http")) return url;
|
|
|
|
|
|
return import.meta.env.VITE_API_BASE_URL + (url.startsWith("/") ? url : "/" + url);
|
2026-08-07 11:44:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-07 17:29:36 +08:00
|
|
|
|
// ============================================================
|
2026-08-09 17:55:40 +08:00
|
|
|
|
// 类型
|
|
|
|
|
|
// ============================================================
|
|
|
|
|
|
|
|
|
|
|
|
interface LevelGroup { depth: number; tasks: TaskResponse[]; }
|
|
|
|
|
|
|
|
|
|
|
|
// ============================================================
|
|
|
|
|
|
// 任务树解析
|
2026-08-07 17:29:36 +08:00
|
|
|
|
// ============================================================
|
2026-08-07 11:44:12 +08:00
|
|
|
|
|
|
|
|
|
|
function flattenLevels(tasks: TaskResponse[], depth: number = 0): LevelGroup[] {
|
|
|
|
|
|
const result: LevelGroup[] = [];
|
|
|
|
|
|
if (!tasks || tasks.length === 0) return result;
|
|
|
|
|
|
result.push({ depth, tasks });
|
|
|
|
|
|
for (const t of tasks) {
|
|
|
|
|
|
if (t.child_tasks && t.child_tasks.length > 0) {
|
2026-08-07 17:29:36 +08:00
|
|
|
|
result.push(...flattenLevels(t.child_tasks, depth + 1));
|
2026-08-07 11:44:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function groupByDepth(levels: LevelGroup[]): Map<number, TaskResponse[]> {
|
|
|
|
|
|
const map = new Map<number, TaskResponse[]>();
|
|
|
|
|
|
for (const lvl of levels) {
|
|
|
|
|
|
if (!map.has(lvl.depth)) map.set(lvl.depth, []);
|
2026-08-07 17:29:36 +08:00
|
|
|
|
const existing = map.get(lvl.depth)!;
|
|
|
|
|
|
for (const t of lvl.tasks) {
|
|
|
|
|
|
if (!existing.find((e) => e.id === t.id)) existing.push(t);
|
|
|
|
|
|
}
|
2026-08-07 11:44:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
return map;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-07 17:29:36 +08:00
|
|
|
|
// ============================================================
|
2026-08-09 17:55:40 +08:00
|
|
|
|
// 单张任务卡片
|
2026-08-07 17:29:36 +08:00
|
|
|
|
// ============================================================
|
2026-08-07 11:44:12 +08:00
|
|
|
|
|
|
|
|
|
|
const FlowCard = memo(function FlowCard({
|
2026-08-09 17:55:40 +08:00
|
|
|
|
task, isActive, onAction, currentUser, assigneeName,
|
|
|
|
|
|
onViewRecords,
|
2026-08-07 11:44:12 +08:00
|
|
|
|
}: {
|
|
|
|
|
|
task: TaskResponse;
|
|
|
|
|
|
isActive: boolean;
|
|
|
|
|
|
onAction: (target: ModalTarget) => void;
|
2026-08-07 17:26:14 +08:00
|
|
|
|
currentUser?: { username?: string; role?: string } | null;
|
|
|
|
|
|
assigneeName?: string;
|
2026-08-09 17:55:40 +08:00
|
|
|
|
onViewRecords?: (task: TaskResponse) => void;
|
2026-08-07 11:44:12 +08:00
|
|
|
|
}) {
|
|
|
|
|
|
const cfg = getStatusConfig(task.status);
|
|
|
|
|
|
const dwell = calcDwell(task.received_at, task.completed_at, task.status);
|
|
|
|
|
|
const isCompleted = task.status?.toUpperCase() === TASK_STATUS.COMPLETED;
|
|
|
|
|
|
const isArchived = task.status?.toUpperCase() === TASK_STATUS.ARCHIVED;
|
2026-08-07 17:29:36 +08:00
|
|
|
|
const isCanceled = task.status?.toUpperCase() === "CANCELED";
|
|
|
|
|
|
const main = isMainTask(task);
|
|
|
|
|
|
|
2026-08-07 17:26:14 +08:00
|
|
|
|
const isOwner = !!(currentUser?.username && task.assignee_id === currentUser.username);
|
|
|
|
|
|
const isManager = currentUser?.role === "SUPER_ADMIN" || currentUser?.role === "SUPERVISOR";
|
2026-08-07 11:44:12 +08:00
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div
|
2026-08-07 17:29:36 +08:00
|
|
|
|
className={`relative shrink-0 w-56 rounded-xl border-2 bg-white p-3.5 shadow-md transition-all ${
|
2026-08-07 11:44:12 +08:00
|
|
|
|
isActive
|
|
|
|
|
|
? `border-blue-400 ${cfg.ring} shadow-lg shadow-blue-100 scale-105 z-10`
|
2026-08-09 17:55:40 +08:00
|
|
|
|
: isCompleted || isArchived ? "border-gray-200 opacity-70"
|
|
|
|
|
|
: isCanceled ? "border-gray-200 opacity-50"
|
|
|
|
|
|
: "border-gray-200 hover:shadow-lg"
|
2026-08-07 11:44:12 +08:00
|
|
|
|
} ${task.is_rework ? "border-l-red-500 border-l-4" : ""}`}
|
|
|
|
|
|
>
|
2026-08-09 17:55:40 +08:00
|
|
|
|
{/* 主线/分支 角标 */}
|
|
|
|
|
|
<div className={`absolute top-3 right-3 rounded px-2 py-0.5 text-[9px] font-bold text-white z-2 ${main ? "bg-blue-600" : "bg-purple-500"}`}>
|
2026-08-07 17:29:36 +08:00
|
|
|
|
{main ? "主分支" : "分支"}
|
|
|
|
|
|
</div>
|
2026-08-07 11:44:12 +08:00
|
|
|
|
|
2026-08-09 17:55:40 +08:00
|
|
|
|
{/* 返工/入库 */}
|
2026-08-07 17:29:36 +08:00
|
|
|
|
<div className="mb-1 flex flex-wrap gap-1">
|
2026-08-09 17:55:40 +08:00
|
|
|
|
{task.is_rework && <span className="inline-flex items-center rounded bg-red-600 px-1.5 py-0.5 text-[9px] font-bold text-white animate-pulse"><AlertTriangle className="mr-0.5 h-2.5 w-2.5" />返工</span>}
|
|
|
|
|
|
{task.status === "ARCHIVED" && <span className="inline-flex items-center rounded border border-dashed border-purple-300 bg-purple-50 px-1.5 py-0.5 text-[9px] font-bold text-purple-600">📦 入库</span>}
|
2026-08-07 17:29:36 +08:00
|
|
|
|
</div>
|
2026-08-07 11:44:12 +08:00
|
|
|
|
|
2026-08-09 17:55:40 +08:00
|
|
|
|
{/* 头部 */}
|
2026-08-07 17:29:36 +08:00
|
|
|
|
<div className="flex items-center justify-between mt-1">
|
|
|
|
|
|
<div className="flex items-center gap-1.5 flex-wrap">
|
2026-08-09 17:55:40 +08:00
|
|
|
|
<span className={`rounded px-2 py-0.5 text-[9px] font-bold text-white ${main ? "bg-blue-600" : "bg-purple-100 text-purple-700"}`}>{main ? "主分支" : "分支"}</span>
|
|
|
|
|
|
{task.child_tasks.length > 1 && <span className="inline-flex items-center rounded bg-purple-100 px-1.5 py-0.5 text-[9px] font-medium text-purple-700"><GitBranch className="mr-0.5 h-2.5 w-2.5" />裂变×{task.child_tasks.length}</span>}
|
2026-08-07 17:29:36 +08:00
|
|
|
|
</div>
|
2026-08-09 17:55:40 +08:00
|
|
|
|
<span className={`inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-medium ${cfg.bg} ${cfg.text}`}>{cfg.label}</span>
|
2026-08-07 11:44:12 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-08-09 17:55:40 +08:00
|
|
|
|
{/* 任务名 */}
|
2026-08-07 17:29:36 +08:00
|
|
|
|
<p className="mt-2 text-base font-extrabold text-gray-800 leading-tight">{task.task_name}</p>
|
|
|
|
|
|
|
2026-08-09 17:55:40 +08:00
|
|
|
|
{/* 负责人 */}
|
2026-08-07 17:29:36 +08:00
|
|
|
|
<div className="mt-2 flex items-center gap-2 text-[11px]">
|
|
|
|
|
|
<span className="text-gray-400">👤 负责人</span>
|
|
|
|
|
|
<span className="font-semibold text-gray-700">{assigneeName || task.assignee_id || "未分配"}</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-08-09 17:55:40 +08:00
|
|
|
|
{/* 备注 */}
|
2026-08-07 17:29:36 +08:00
|
|
|
|
{task.remark && (
|
|
|
|
|
|
<div className="mt-2 rounded-lg border border-yellow-200 bg-yellow-50 px-2.5 py-2">
|
|
|
|
|
|
<p className="text-[10px] font-bold text-yellow-700">📌 备注</p>
|
|
|
|
|
|
<p className="mt-0.5 text-[11px] text-gray-700 leading-relaxed">{task.remark}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
2026-08-09 17:55:40 +08:00
|
|
|
|
{/* 提交记录 — 可点击 */}
|
2026-08-07 17:29:36 +08:00
|
|
|
|
{task.records && task.records.length > 0 && (
|
2026-08-09 17:55:40 +08:00
|
|
|
|
<div
|
|
|
|
|
|
onClick={(e) => { e.stopPropagation(); onViewRecords?.(task); }}
|
|
|
|
|
|
className="mt-2 flex cursor-pointer items-center gap-1.5 rounded-lg border border-blue-200 bg-gradient-to-r from-blue-50 to-indigo-50 px-2.5 py-2 transition-colors hover:from-blue-100 hover:to-indigo-100"
|
|
|
|
|
|
>
|
2026-08-07 17:29:36 +08:00
|
|
|
|
<FileText className="h-3.5 w-3.5 text-blue-500" />
|
2026-08-09 17:55:40 +08:00
|
|
|
|
<span className="flex-1 text-[11px] font-bold text-blue-600">共 {task.records.length} 条提交记录</span>
|
|
|
|
|
|
<span className="text-[10px] text-blue-400">查看 ›</span>
|
2026-08-07 17:29:36 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
2026-08-09 17:55:40 +08:00
|
|
|
|
{/* 耗时 */}
|
2026-08-07 11:44:12 +08:00
|
|
|
|
{dwell && (
|
2026-08-07 17:29:36 +08:00
|
|
|
|
<p className={`mt-1.5 flex items-center gap-1 text-[10px] ${dwell.highlight ? "text-red-500 font-semibold" : "text-orange-500"}`}>
|
2026-08-07 11:44:12 +08:00
|
|
|
|
<Clock className="h-3 w-3" />
|
2026-08-07 17:29:36 +08:00
|
|
|
|
{dwell.highlight ? <span className="animate-pulse">⏳ 停留: {dwell.text}</span> : <span>耗时: {dwell.text}</span>}
|
2026-08-07 11:44:12 +08:00
|
|
|
|
</p>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{/* 驳回原因 */}
|
2026-08-09 17:55:40 +08:00
|
|
|
|
{task.reject_reason && <p className="mt-1 text-[10px] text-red-500 line-clamp-2">驳回原因: {task.reject_reason}</p>}
|
2026-08-07 11:44:12 +08:00
|
|
|
|
|
2026-08-09 17:55:40 +08:00
|
|
|
|
{/* 状态标记 */}
|
2026-08-07 17:29:36 +08:00
|
|
|
|
<div className="mt-2 flex flex-wrap gap-1.5">
|
2026-08-09 17:55:40 +08:00
|
|
|
|
{task.received_at && <span className="inline-flex items-center gap-1 rounded-md bg-gray-100 px-1.5 py-0.5 text-[9px] font-semibold text-gray-600"><CheckCircle className="h-2.5 w-2.5" />已接收</span>}
|
|
|
|
|
|
{task.completed_at && <span className="inline-flex items-center gap-1 rounded-md bg-green-50 px-1.5 py-0.5 text-[9px] font-semibold text-green-600"><Flag className="h-2.5 w-2.5" />已完工</span>}
|
2026-08-07 17:29:36 +08:00
|
|
|
|
</div>
|
2026-08-07 11:44:12 +08:00
|
|
|
|
|
2026-08-09 17:55:40 +08:00
|
|
|
|
{/* 时间 */}
|
2026-08-07 17:29:36 +08:00
|
|
|
|
<div className="mt-2 border-t border-gray-100 pt-2">
|
|
|
|
|
|
<p className="text-[9px] text-gray-400">创建: {fmtTime(task.created_at)}</p>
|
|
|
|
|
|
{task.received_at && <p className="text-[9px] text-gray-400">接收: {fmtTime(task.received_at)}</p>}
|
|
|
|
|
|
{task.completed_at && <p className="text-[9px] text-gray-400">完工: {fmtTime(task.completed_at)}</p>}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-08-09 17:55:40 +08:00
|
|
|
|
{/* 🔧 BugFix #1: 权限严格互斥 */}
|
|
|
|
|
|
{/* 本人:正常操作按钮 */}
|
|
|
|
|
|
{isActive && isOwner && (
|
2026-08-07 11:44:12 +08:00
|
|
|
|
<div className="mt-2 flex gap-1.5 border-t border-gray-100 pt-2">
|
|
|
|
|
|
{task.status?.toUpperCase() === TASK_STATUS.PENDING && (
|
|
|
|
|
|
<>
|
2026-08-09 17:55:40 +08:00
|
|
|
|
<button onClick={() => onAction({ task, action: "receive" })} className="flex-1 rounded border border-blue-200 bg-blue-50 py-1 text-[10px] font-medium text-blue-600 hover:bg-blue-100">接收</button>
|
|
|
|
|
|
<button onClick={() => onAction({ task, action: "reject" })} className="rounded border border-red-200 bg-red-50 px-2 py-1 text-[10px] font-medium text-red-500 hover:bg-red-100">驳回</button>
|
|
|
|
|
|
<button onClick={() => onAction({ task, action: "transfer" })} className="rounded border border-green-200 bg-green-50 px-2 py-1 text-[10px] font-medium text-green-600 hover:bg-green-100">转交</button>
|
2026-08-07 11:44:12 +08:00
|
|
|
|
</>
|
|
|
|
|
|
)}
|
|
|
|
|
|
{task.status?.toUpperCase() === TASK_STATUS.WIP && (
|
|
|
|
|
|
<>
|
2026-08-09 17:55:40 +08:00
|
|
|
|
<button onClick={() => onAction({ task, action: "reject" })} className="flex-1 rounded border border-red-200 bg-red-50 py-1 text-[10px] font-medium text-red-500 hover:bg-red-100">驳回</button>
|
|
|
|
|
|
<button onClick={() => onAction({ task, action: "transfer" })} className="flex-1 rounded border border-green-200 bg-green-50 py-1 text-[10px] font-medium text-green-600 hover:bg-green-100">转交</button>
|
2026-08-07 11:44:12 +08:00
|
|
|
|
</>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
2026-08-09 17:55:40 +08:00
|
|
|
|
|
|
|
|
|
|
{/* 管理员看别人:仅干预按钮 */}
|
2026-08-07 17:26:14 +08:00
|
|
|
|
{isActive && !isOwner && isManager && (
|
|
|
|
|
|
<div className="mt-2 border-t border-orange-100 pt-2">
|
2026-08-07 17:29:36 +08:00
|
|
|
|
<p className="mb-1 text-[9px] text-orange-500">⚠ 运维干预模式</p>
|
|
|
|
|
|
<div className="flex gap-1.5">
|
2026-08-09 17:55:40 +08:00
|
|
|
|
<button onClick={() => onAction({ task, action: "reject" })} className="flex-1 rounded border border-orange-200 bg-orange-50 py-1 text-[10px] font-medium text-orange-600 hover:bg-orange-100">强制驳回</button>
|
|
|
|
|
|
<button onClick={() => onAction({ task, action: "transfer" })} className="flex-1 rounded border border-orange-200 bg-orange-50 py-1 text-[10px] font-medium text-orange-600 hover:bg-orange-100">强制转交</button>
|
2026-08-07 17:29:36 +08:00
|
|
|
|
</div>
|
2026-08-07 17:26:14 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
2026-08-09 17:55:40 +08:00
|
|
|
|
|
|
|
|
|
|
{/* 普通人看别人:什么按钮都没有 */}
|
|
|
|
|
|
{isActive && !isOwner && !isManager && (
|
2026-08-07 17:26:14 +08:00
|
|
|
|
<div className="mt-2 border-t border-gray-100 pt-2">
|
2026-08-07 17:29:36 +08:00
|
|
|
|
<p className="text-center text-[9px] text-gray-400">非当前任务责任人,无法操作</p>
|
2026-08-07 17:26:14 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
2026-08-07 11:44:12 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-08-07 17:29:36 +08:00
|
|
|
|
// ============================================================
|
2026-08-09 17:55:40 +08:00
|
|
|
|
// 记录查看弹窗 — 与移动端 records 页面样式对齐
|
2026-08-07 17:29:36 +08:00
|
|
|
|
// ============================================================
|
|
|
|
|
|
|
2026-08-09 17:55:40 +08:00
|
|
|
|
export const RecordsModal = memo(function RecordsModal({
|
|
|
|
|
|
open, task, onClose,
|
|
|
|
|
|
}: {
|
|
|
|
|
|
open: boolean; task: TaskResponse | null; onClose: () => void;
|
|
|
|
|
|
}) {
|
|
|
|
|
|
if (!open || !task) return null;
|
|
|
|
|
|
const records = task.records || [];
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div className="fixed inset-0 z-50 flex items-center justify-center">
|
|
|
|
|
|
<div className="absolute inset-0 bg-black/40 backdrop-blur-sm" onClick={onClose} />
|
|
|
|
|
|
<div className="relative z-10 mx-4 w-full max-w-md max-h-[80vh] overflow-y-auto rounded-xl bg-white shadow-2xl">
|
|
|
|
|
|
<div className="sticky top-0 z-10 flex items-center justify-between border-b border-gray-100 bg-white px-5 py-4 rounded-t-xl">
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<h3 className="text-base font-bold text-gray-800">提交记录</h3>
|
|
|
|
|
|
<p className="text-xs text-gray-400">{task.task_name}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<button onClick={onClose} className="rounded-lg p-1 text-gray-400 hover:bg-gray-100 hover:text-gray-600"><X className="h-5 w-5" /></button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="px-5 py-3">
|
|
|
|
|
|
{records.length === 0 ? (
|
|
|
|
|
|
<div className="flex flex-col items-center py-12 text-gray-400">
|
|
|
|
|
|
<span className="text-4xl mb-2">📭</span>
|
|
|
|
|
|
<p className="text-sm">暂无历史记录</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<div className="space-y-3">
|
|
|
|
|
|
{[...records].reverse().map((rec, i) => (
|
|
|
|
|
|
<div key={rec.id} className="relative pl-6">
|
|
|
|
|
|
{/* 时间轴竖线 */}
|
|
|
|
|
|
<div className="absolute left-2 top-0 bottom-0 flex flex-col items-center">
|
|
|
|
|
|
<div className={`h-3 w-3 rounded-full ${i === 0 ? "bg-blue-500 shadow-[0_0_0_4px_rgba(37,99,235,0.15)]" : "bg-gray-300"}`} />
|
|
|
|
|
|
{i < records.length - 1 && <div className="flex-1 w-0.5 bg-gray-200 min-h-[12px]" />}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
{/* 内容卡片 */}
|
|
|
|
|
|
<div className="rounded-lg bg-gray-50 px-3 py-2.5">
|
|
|
|
|
|
<p className="text-[11px] text-gray-400">{fmtTime(rec.created_at)}</p>
|
|
|
|
|
|
{rec.note && <p className="mt-1 text-sm text-gray-700 leading-relaxed">{rec.note}</p>}
|
|
|
|
|
|
{rec.remark && <p className="mt-1 text-sm text-gray-700 leading-relaxed">{rec.remark}</p>}
|
|
|
|
|
|
{/* 图片 */}
|
|
|
|
|
|
{(() => {
|
|
|
|
|
|
const imgs = parseImages((rec as any).images);
|
|
|
|
|
|
if (!imgs.length) return null;
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div className="mt-2 flex gap-1.5 flex-wrap">
|
|
|
|
|
|
{imgs.map((img, j) => (
|
|
|
|
|
|
<img key={j} src={imageUrl(img)} alt="" className="h-16 w-16 rounded-lg border border-gray-200 object-cover cursor-pointer hover:opacity-80"
|
|
|
|
|
|
onClick={() => window.open(imageUrl(img), "_blank")} />
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
})()}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// ============================================================
|
|
|
|
|
|
// 停留耗时
|
|
|
|
|
|
// ============================================================
|
|
|
|
|
|
|
|
|
|
|
|
function calcDwell(receivedAt: string | null, completedAt: string | null, status: string): { text: string; highlight: boolean } | null {
|
2026-08-07 17:29:36 +08:00
|
|
|
|
if (!receivedAt) return null;
|
|
|
|
|
|
const start = new Date(receivedAt).getTime();
|
|
|
|
|
|
const end = completedAt ? new Date(completedAt).getTime() : Date.now();
|
|
|
|
|
|
const diffMs = end - start;
|
|
|
|
|
|
if (diffMs < 0) return null;
|
|
|
|
|
|
const totalMin = Math.floor(diffMs / 60000);
|
|
|
|
|
|
if (totalMin < 1) return { text: "< 1分钟", highlight: status === "WIP" };
|
|
|
|
|
|
if (totalMin < 60) return { text: `${totalMin}分钟`, highlight: status === "WIP" };
|
|
|
|
|
|
const hours = Math.floor(totalMin / 60);
|
|
|
|
|
|
const remainMin = totalMin % 60;
|
|
|
|
|
|
if (hours < 24) return { text: `${hours}小时${remainMin > 0 ? remainMin + "分钟" : ""}`, highlight: status === "WIP" };
|
|
|
|
|
|
const days = Math.floor(hours / 24);
|
|
|
|
|
|
const remainHr = hours % 24;
|
|
|
|
|
|
return { text: `${days}天${remainHr > 0 ? remainHr + "小时" : ""}`, highlight: status === "WIP" };
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ============================================================
|
|
|
|
|
|
// 主视图
|
|
|
|
|
|
// ============================================================
|
2026-08-07 11:44:12 +08:00
|
|
|
|
|
|
|
|
|
|
interface TaskFlowViewProps {
|
|
|
|
|
|
tasks: TaskResponse[];
|
|
|
|
|
|
onAction: (target: ModalTarget) => void;
|
2026-08-07 17:26:14 +08:00
|
|
|
|
currentUser?: { username?: string; role?: string } | null;
|
|
|
|
|
|
assigneeNames?: Record<string, string>;
|
2026-08-07 11:44:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-07 17:26:14 +08:00
|
|
|
|
export const TaskFlowView = memo(function TaskFlowView({ tasks, onAction, currentUser, assigneeNames }: TaskFlowViewProps) {
|
2026-08-09 17:55:40 +08:00
|
|
|
|
const [recordsTask, setRecordsTask] = useState<TaskResponse | null>(null);
|
|
|
|
|
|
|
2026-08-07 11:44:12 +08:00
|
|
|
|
const depthMap = useMemo(() => {
|
|
|
|
|
|
if (!tasks || tasks.length === 0) return new Map<number, TaskResponse[]>();
|
2026-08-07 17:29:36 +08:00
|
|
|
|
return groupByDepth(flattenLevels(tasks));
|
2026-08-07 11:44:12 +08:00
|
|
|
|
}, [tasks]);
|
|
|
|
|
|
|
|
|
|
|
|
const depths = Array.from(depthMap.keys()).sort((a, b) => a - b);
|
|
|
|
|
|
if (depths.length === 0) return null;
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
2026-08-09 17:55:40 +08:00
|
|
|
|
<>
|
|
|
|
|
|
<div className="space-y-4">
|
|
|
|
|
|
{depths.map((depth) => {
|
|
|
|
|
|
const levelTasks = depthMap.get(depth) || [];
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div key={depth}>
|
|
|
|
|
|
<div className="mb-2 flex items-center gap-2">
|
|
|
|
|
|
<span className="text-[10px] font-semibold text-gray-400 uppercase tracking-wider">{depth === 0 ? "顶层任务" : `第 ${depth} 层子任务`}</span>
|
|
|
|
|
|
<div className="h-px flex-1 bg-gray-100" />
|
2026-08-07 11:44:12 +08:00
|
|
|
|
</div>
|
2026-08-09 17:55:40 +08:00
|
|
|
|
<div className="flex gap-3 overflow-x-auto pb-2 pl-2" style={{ scrollSnapType: "x mandatory" }}>
|
|
|
|
|
|
{levelTasks.map((task) => {
|
|
|
|
|
|
const isActive = task.status?.toUpperCase() === TASK_STATUS.PENDING || task.status?.toUpperCase() === TASK_STATUS.WIP;
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div key={task.id} style={{ scrollSnapAlign: "start" }}>
|
|
|
|
|
|
<FlowCard task={task} isActive={isActive} onAction={onAction}
|
|
|
|
|
|
currentUser={currentUser}
|
|
|
|
|
|
assigneeName={assigneeNames?.[task.assignee_id || ""]}
|
|
|
|
|
|
onViewRecords={setRecordsTask} />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
})}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
{depth < depths.length - 1 && (
|
|
|
|
|
|
<div className="flex justify-center py-1"><ArrowDown className="h-4 w-4 text-gray-300" /></div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
})}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<RecordsModal open={!!recordsTask} task={recordsTask} onClose={() => setRecordsTask(null)} />
|
|
|
|
|
|
</>
|
2026-08-07 11:44:12 +08:00
|
|
|
|
);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
export default TaskFlowView;
|