|
@@ -1,9 +1,35 @@
|
|
|
|
|
+// src/components/admin/tasks/TaskTable.tsx
|
|
|
'use client';
|
|
'use client';
|
|
|
|
|
|
|
|
import { useState } from 'react';
|
|
import { useState } from 'react';
|
|
|
-import {
|
|
|
|
|
- RotateCcw, CheckCircle, ChevronDown, ChevronUp, Terminal, FileJson,
|
|
|
|
|
- User, History, Edit, MessageCircle, MessageSquare, X, Pause, Mail
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ RotateCcw,
|
|
|
|
|
+ CheckCircle,
|
|
|
|
|
+ ChevronDown,
|
|
|
|
|
+ ChevronUp,
|
|
|
|
|
+ Terminal,
|
|
|
|
|
+ FileJson,
|
|
|
|
|
+ User,
|
|
|
|
|
+ History,
|
|
|
|
|
+ Edit,
|
|
|
|
|
+ MessageCircle,
|
|
|
|
|
+ MessageSquare,
|
|
|
|
|
+ X,
|
|
|
|
|
+ Pause,
|
|
|
|
|
+ Mail,
|
|
|
|
|
+ Copy,
|
|
|
|
|
+ Check,
|
|
|
|
|
+ Clock,
|
|
|
|
|
+ ArrowUpDown,
|
|
|
|
|
+ ArrowUp,
|
|
|
|
|
+ ArrowDown,
|
|
|
|
|
+ AlertTriangle,
|
|
|
|
|
+ Layers,
|
|
|
|
|
+ Sparkles,
|
|
|
|
|
+ Phone,
|
|
|
|
|
+ Send,
|
|
|
|
|
+ ExternalLink,
|
|
|
|
|
+ Code2,
|
|
|
} from 'lucide-react';
|
|
} from 'lucide-react';
|
|
|
import LocalTime from '@/components/common/LocalTime';
|
|
import LocalTime from '@/components/common/LocalTime';
|
|
|
import api from '@/lib/api';
|
|
import api from '@/lib/api';
|
|
@@ -16,10 +42,23 @@ interface TaskTableProps {
|
|
|
onManualConfirm: (taskId: number) => void;
|
|
onManualConfirm: (taskId: number) => void;
|
|
|
onPause: (taskId: number) => void;
|
|
onPause: (taskId: number) => void;
|
|
|
onEdit: (task: VasTask) => void;
|
|
onEdit: (task: VasTask) => void;
|
|
|
- onViewDetail: (task: VasTask) => void;
|
|
|
|
|
|
|
+ onViewDetail?: (task: VasTask) => void;
|
|
|
|
|
+ sortField?: string;
|
|
|
|
|
+ sortOrder?: 'asc' | 'desc';
|
|
|
|
|
+ onSortChange?: (field: string) => void;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export default function TaskTable({ tasks, loading, onRetry, onManualConfirm, onPause, onEdit }: TaskTableProps) {
|
|
|
|
|
|
|
+export default function TaskTable({
|
|
|
|
|
+ tasks,
|
|
|
|
|
+ loading,
|
|
|
|
|
+ onRetry,
|
|
|
|
|
+ onManualConfirm,
|
|
|
|
|
+ onPause,
|
|
|
|
|
+ onEdit,
|
|
|
|
|
+ sortField = 'updated_at',
|
|
|
|
|
+ sortOrder = 'desc',
|
|
|
|
|
+ onSortChange,
|
|
|
|
|
+}: TaskTableProps) {
|
|
|
const [expandedRows, setExpandedRows] = useState<Set<number>>(new Set());
|
|
const [expandedRows, setExpandedRows] = useState<Set<number>>(new Set());
|
|
|
const [isMessageOpen, setIsMessageOpen] = useState(false);
|
|
const [isMessageOpen, setIsMessageOpen] = useState(false);
|
|
|
const [messageChannel, setMessageChannel] = useState<'sms' | 'whatsapp' | 'email'>('sms');
|
|
const [messageChannel, setMessageChannel] = useState<'sms' | 'whatsapp' | 'email'>('sms');
|
|
@@ -29,6 +68,7 @@ export default function TaskTable({ tasks, loading, onRetry, onManualConfirm, on
|
|
|
const [messageSending, setMessageSending] = useState(false);
|
|
const [messageSending, setMessageSending] = useState(false);
|
|
|
const [messageResult, setMessageResult] = useState<'idle' | 'success' | 'error'>('idle');
|
|
const [messageResult, setMessageResult] = useState<'idle' | 'success' | 'error'>('idle');
|
|
|
const [messageResultText, setMessageResultText] = useState('');
|
|
const [messageResultText, setMessageResultText] = useState('');
|
|
|
|
|
+ const [copiedOrderId, setCopiedOrderId] = useState<string | null>(null);
|
|
|
|
|
|
|
|
const toggleRow = (id: number) => {
|
|
const toggleRow = (id: number) => {
|
|
|
const newSet = new Set(expandedRows);
|
|
const newSet = new Set(expandedRows);
|
|
@@ -37,6 +77,29 @@ export default function TaskTable({ tasks, loading, onRetry, onManualConfirm, on
|
|
|
setExpandedRows(newSet);
|
|
setExpandedRows(newSet);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ const handleCopy = (text: string, id: string) => {
|
|
|
|
|
+ navigator.clipboard.writeText(text);
|
|
|
|
|
+ setCopiedOrderId(id);
|
|
|
|
|
+ setTimeout(() => setCopiedOrderId(null), 2000);
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const handleHeaderSort = (field: string) => {
|
|
|
|
|
+ if (onSortChange) {
|
|
|
|
|
+ onSortChange(field);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const renderSortIcon = (field: string) => {
|
|
|
|
|
+ if (sortField !== field) {
|
|
|
|
|
+ return <ArrowUpDown size={12} className="text-slate-400 opacity-60 ml-1" />;
|
|
|
|
|
+ }
|
|
|
|
|
+ return sortOrder === 'asc' ? (
|
|
|
|
|
+ <ArrowUp size={13} className="text-blue-600 ml-1 font-bold" />
|
|
|
|
|
+ ) : (
|
|
|
|
|
+ <ArrowDown size={13} className="text-blue-600 ml-1 font-bold" />
|
|
|
|
|
+ );
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
const openMessageModal = (task: VasTask, channel: 'sms' | 'whatsapp' | 'email') => {
|
|
const openMessageModal = (task: VasTask, channel: 'sms' | 'whatsapp' | 'email') => {
|
|
|
let template = '';
|
|
let template = '';
|
|
|
if (channel === 'whatsapp') {
|
|
if (channel === 'whatsapp') {
|
|
@@ -82,7 +145,9 @@ export default function TaskTable({ tasks, loading, onRetry, onManualConfirm, on
|
|
|
});
|
|
});
|
|
|
const ok = res.data?.code === 0;
|
|
const ok = res.data?.code === 0;
|
|
|
setMessageResult(ok ? 'success' : 'error');
|
|
setMessageResult(ok ? 'success' : 'error');
|
|
|
- setMessageResultText(ok ? 'WhatsApp sent successfully.' : (res.data?.message || 'Failed to send WhatsApp.'));
|
|
|
|
|
|
|
+ setMessageResultText(
|
|
|
|
|
+ ok ? 'WhatsApp sent successfully.' : res.data?.message || 'Failed to send WhatsApp.'
|
|
|
|
|
+ );
|
|
|
} else if (messageChannel === 'sms') {
|
|
} else if (messageChannel === 'sms') {
|
|
|
if (!target) {
|
|
if (!target) {
|
|
|
setMessageResult('error');
|
|
setMessageResult('error');
|
|
@@ -97,7 +162,9 @@ export default function TaskTable({ tasks, loading, onRetry, onManualConfirm, on
|
|
|
});
|
|
});
|
|
|
const ok = res.data?.code === 0;
|
|
const ok = res.data?.code === 0;
|
|
|
setMessageResult(ok ? 'success' : 'error');
|
|
setMessageResult(ok ? 'success' : 'error');
|
|
|
- setMessageResultText(ok ? 'SMS sent successfully.' : (res.data?.message || 'Failed to send SMS.'));
|
|
|
|
|
|
|
+ setMessageResultText(
|
|
|
|
|
+ ok ? 'SMS sent successfully.' : res.data?.message || 'Failed to send SMS.'
|
|
|
|
|
+ );
|
|
|
} else {
|
|
} else {
|
|
|
if (!email) {
|
|
if (!email) {
|
|
|
setMessageResult('error');
|
|
setMessageResult('error');
|
|
@@ -112,10 +179,17 @@ export default function TaskTable({ tasks, loading, onRetry, onManualConfirm, on
|
|
|
});
|
|
});
|
|
|
const ok = res.data?.code === 0;
|
|
const ok = res.data?.code === 0;
|
|
|
setMessageResult(ok ? 'success' : 'error');
|
|
setMessageResult(ok ? 'success' : 'error');
|
|
|
- setMessageResultText(ok ? 'Email sent successfully.' : (res.data?.message || 'Failed to send email.'));
|
|
|
|
|
|
|
+ setMessageResultText(
|
|
|
|
|
+ ok ? 'Email sent successfully.' : res.data?.message || 'Failed to send email.'
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
- const fallback = messageChannel === 'whatsapp' ? 'Failed to send WhatsApp.' : messageChannel === 'sms' ? 'Failed to send SMS.' : 'Failed to send email.';
|
|
|
|
|
|
|
+ const fallback =
|
|
|
|
|
+ messageChannel === 'whatsapp'
|
|
|
|
|
+ ? 'Failed to send WhatsApp.'
|
|
|
|
|
+ : messageChannel === 'sms'
|
|
|
|
|
+ ? 'Failed to send SMS.'
|
|
|
|
|
+ : 'Failed to send email.';
|
|
|
setMessageResult('error');
|
|
setMessageResult('error');
|
|
|
setMessageResultText(fallback);
|
|
setMessageResultText(fallback);
|
|
|
} finally {
|
|
} finally {
|
|
@@ -124,8 +198,9 @@ export default function TaskTable({ tasks, loading, onRetry, onManualConfirm, on
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const getRecipientName = (task: VasTask) => {
|
|
const getRecipientName = (task: VasTask) => {
|
|
|
- if (!task.user_inputs) return '-';
|
|
|
|
|
- const { first_name, last_name, social_media_account } = task.user_inputs;
|
|
|
|
|
|
|
+ if (!task.user_inputs) return 'Customer';
|
|
|
|
|
+ const { first_name, last_name, social_media_account, name } = task.user_inputs;
|
|
|
|
|
+ if (name) return name;
|
|
|
if (social_media_account) return social_media_account;
|
|
if (social_media_account) return social_media_account;
|
|
|
const full = `${first_name || ''} ${last_name || ''}`.trim();
|
|
const full = `${first_name || ''} ${last_name || ''}`.trim();
|
|
|
return full || 'Customer';
|
|
return full || 'Customer';
|
|
@@ -143,163 +218,383 @@ export default function TaskTable({ tasks, loading, onRetry, onManualConfirm, on
|
|
|
const getRecipientPhoneRaw = (task: VasTask) => {
|
|
const getRecipientPhoneRaw = (task: VasTask) => {
|
|
|
if (!task.user_inputs) return '';
|
|
if (!task.user_inputs) return '';
|
|
|
const code = String(task.user_inputs.phone_country_code || '').replace(/\D/g, '');
|
|
const code = String(task.user_inputs.phone_country_code || '').replace(/\D/g, '');
|
|
|
- const rawPhone = String(task.user_inputs.phone || '').replace(/\D/g, '').replace(/^0+/, '');
|
|
|
|
|
|
|
+ const rawPhone = String(task.user_inputs.phone || '')
|
|
|
|
|
+ .replace(/\D/g, '')
|
|
|
|
|
+ .replace(/^0+/, '');
|
|
|
return `${code}${rawPhone}`;
|
|
return `${code}${rawPhone}`;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const getSmsSender = (task: VasTask) => {
|
|
|
|
|
- return 'TextSkin';
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
const getRecipientEmail = (task: VasTask) => {
|
|
const getRecipientEmail = (task: VasTask) => {
|
|
|
- if (!task.user_inputs) return '';
|
|
|
|
|
- return task.user_inputs.email || '';
|
|
|
|
|
|
|
+ return task.user_inputs?.email || '';
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const getUserSummary = (inputs: any) => {
|
|
|
|
|
- if (!inputs) return '-';
|
|
|
|
|
- const name = inputs.social_media_account ? (inputs.social_media_account): `${inputs.first_name} ${inputs.last_name}`;
|
|
|
|
|
- return name || 'User Data';
|
|
|
|
|
|
|
+ const getSmsSender = (task: VasTask) => {
|
|
|
|
|
+ return task.user_inputs?.sms_sender || 'TextSkin';
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- // === 修改点 1:优化摘要显示,强制限制高度和行数 ===
|
|
|
|
|
- const getComplexSummary = (data: any, fallbackText: string = "No info") => {
|
|
|
|
|
- if (!data) return <span className="text-xs text-gray-300 italic">{fallbackText}</span>;
|
|
|
|
|
-
|
|
|
|
|
- let content = null;
|
|
|
|
|
-
|
|
|
|
|
- // 1. 如果是对象
|
|
|
|
|
- if (typeof data === 'object' && !Array.isArray(data)) {
|
|
|
|
|
- if (data.slot_date) content = `Slot: ${data.slot_date} ${data.slot_time}`;
|
|
|
|
|
- else if (data.msg || data.message) content = data.msg || data.message;
|
|
|
|
|
- else if (data.error) content = `Error: ${data.error}`;
|
|
|
|
|
- else content = JSON.stringify(data);
|
|
|
|
|
|
|
+ const renderPriorityBadge = (priority: number = 0) => {
|
|
|
|
|
+ if (priority >= 10) {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <span className="inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-bold bg-rose-100 text-rose-700 border border-rose-200">
|
|
|
|
|
+ P{priority} 紧急
|
|
|
|
|
+ </span>
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ if (priority >= 5) {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <span className="inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-bold bg-amber-100 text-amber-700 border border-amber-200">
|
|
|
|
|
+ P{priority} 高
|
|
|
|
|
+ </span>
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
- // 2. 如果是数组
|
|
|
|
|
- else if (Array.isArray(data) && data.length > 0) {
|
|
|
|
|
- const last = data[data.length - 1];
|
|
|
|
|
- content = typeof last === 'object' ? JSON.stringify(last) : String(last);
|
|
|
|
|
- }
|
|
|
|
|
- // 3. 其他
|
|
|
|
|
- else {
|
|
|
|
|
- content = String(data);
|
|
|
|
|
|
|
+ if (priority > 0) {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <span className="inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-blue-50 text-blue-700 border border-blue-200">
|
|
|
|
|
+ P{priority} 普通
|
|
|
|
|
+ </span>
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // 使用 line-clamp-2 限制最多显示两行,超出部分省略号
|
|
|
|
|
return (
|
|
return (
|
|
|
- <div className="text-xs text-slate-600 line-clamp-2 break-all max-w-full" title={String(content)}>
|
|
|
|
|
- {content || fallbackText}
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ <span className="inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-slate-100 text-slate-600">
|
|
|
|
|
+ P0 默认
|
|
|
|
|
+ </span>
|
|
|
);
|
|
);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const renderStatus = (status: string) => (
|
|
|
|
|
- <span className={`inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-bold uppercase whitespace-nowrap
|
|
|
|
|
- ${status === 'failed' ? 'bg-red-100 text-red-700' :
|
|
|
|
|
- status === 'grabbed' ? 'bg-purple-100 text-purple-700 animate-pulse' :
|
|
|
|
|
- status === 'running' ? 'bg-blue-100 text-blue-700 animate-pulse' :
|
|
|
|
|
- status === 'pause' ? 'bg-orange-100 text-orange-700' :
|
|
|
|
|
- status === 'completed' ? 'bg-green-100 text-green-700' :
|
|
|
|
|
- 'bg-gray-100 text-gray-600'}`}>
|
|
|
|
|
- {status}
|
|
|
|
|
- </span>
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ const renderStatus = (status: string) => {
|
|
|
|
|
+ const s = (status || '').toLowerCase();
|
|
|
|
|
+ switch (s) {
|
|
|
|
|
+ case 'running':
|
|
|
|
|
+ return (
|
|
|
|
|
+ <span className="inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-semibold bg-blue-50 text-blue-700 border border-blue-200">
|
|
|
|
|
+ <span className="w-1.5 h-1.5 rounded-full bg-blue-600 animate-ping" />
|
|
|
|
|
+ <span className="w-1.5 h-1.5 rounded-full bg-blue-600 -ml-2.5" />
|
|
|
|
|
+ 运行中
|
|
|
|
|
+ </span>
|
|
|
|
|
+ );
|
|
|
|
|
+ case 'pending':
|
|
|
|
|
+ return (
|
|
|
|
|
+ <span className="inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-semibold bg-amber-50 text-amber-700 border border-amber-200">
|
|
|
|
|
+ <span className="w-1.5 h-1.5 rounded-full bg-amber-500" />
|
|
|
|
|
+ 排队中
|
|
|
|
|
+ </span>
|
|
|
|
|
+ );
|
|
|
|
|
+ case 'pause':
|
|
|
|
|
+ case 'paused':
|
|
|
|
|
+ return (
|
|
|
|
|
+ <span className="inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-semibold bg-orange-50 text-orange-700 border border-orange-200">
|
|
|
|
|
+ <span className="w-1.5 h-1.5 rounded-full bg-orange-500" />
|
|
|
|
|
+ 已暂停
|
|
|
|
|
+ </span>
|
|
|
|
|
+ );
|
|
|
|
|
+ case 'completed':
|
|
|
|
|
+ return (
|
|
|
|
|
+ <span className="inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-semibold bg-emerald-50 text-emerald-700 border border-emerald-200">
|
|
|
|
|
+ <CheckCircle size={12} className="text-emerald-600" />
|
|
|
|
|
+ 已完成
|
|
|
|
|
+ </span>
|
|
|
|
|
+ );
|
|
|
|
|
+ case 'failed':
|
|
|
|
|
+ case 'error':
|
|
|
|
|
+ return (
|
|
|
|
|
+ <span className="inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-semibold bg-rose-50 text-rose-700 border border-rose-200">
|
|
|
|
|
+ <AlertTriangle size={12} className="text-rose-600" />
|
|
|
|
|
+ 异常/失败
|
|
|
|
|
+ </span>
|
|
|
|
|
+ );
|
|
|
|
|
+ default:
|
|
|
|
|
+ return (
|
|
|
|
|
+ <span className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-slate-100 text-slate-600">
|
|
|
|
|
+ {status || 'unknown'}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
- if (loading) return <div className="p-12 text-center text-gray-500 bg-white rounded-lg border border-slate-200">加载系统任务中...</div>;
|
|
|
|
|
- if (tasks.length === 0) return <div className="p-12 text-center text-gray-500 bg-white rounded-lg border border-slate-200">暂无待处理任务</div>;
|
|
|
|
|
|
|
+ if (loading) {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <div className="p-16 text-center bg-white rounded-2xl border border-slate-200 shadow-sm">
|
|
|
|
|
+ <div className="inline-block animate-spin rounded-full h-8 w-8 border-4 border-blue-600 border-t-transparent mb-3" />
|
|
|
|
|
+ <p className="text-sm font-medium text-slate-500">正在实时加载系统任务...</p>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (tasks.length === 0) {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <div className="p-16 text-center bg-white rounded-2xl border border-slate-200 shadow-sm">
|
|
|
|
|
+ <div className="w-12 h-12 rounded-2xl bg-blue-50 text-blue-600 flex items-center justify-center mx-auto mb-3">
|
|
|
|
|
+ <Layers size={24} />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <h3 className="text-base font-bold text-slate-800">暂无待处理系统任务</h3>
|
|
|
|
|
+ <p className="text-xs text-slate-500 mt-1 max-w-sm mx-auto">
|
|
|
|
|
+ 当前没有符合过滤条件的任务,可尝试切换筛选状态或等待新订单触发。
|
|
|
|
|
+ </p>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<div className="space-y-4">
|
|
<div className="space-y-4">
|
|
|
-
|
|
|
|
|
- {/* Desktop View */}
|
|
|
|
|
- <div className="hidden md:block bg-white rounded-lg shadow overflow-hidden border border-slate-200">
|
|
|
|
|
|
|
+ {/* Desktop Table View */}
|
|
|
|
|
+ <div className="hidden md:block bg-white rounded-2xl shadow-sm border border-slate-200 overflow-hidden">
|
|
|
<div className="overflow-x-auto">
|
|
<div className="overflow-x-auto">
|
|
|
- {/* 修改点 2:给表格加上 fixed 布局,并指定列宽百分比,防止内容撑开 */}
|
|
|
|
|
<table className="w-full text-sm text-left table-fixed">
|
|
<table className="w-full text-sm text-left table-fixed">
|
|
|
- <thead className="bg-slate-50 border-b border-slate-200">
|
|
|
|
|
|
|
+ <thead className="bg-slate-50/80 border-b border-slate-200 text-[11px] font-bold text-slate-500 uppercase tracking-wider">
|
|
|
<tr>
|
|
<tr>
|
|
|
- <th className="w-10 px-4 py-3"></th>
|
|
|
|
|
- <th className="w-[140px] px-2 py-3 font-medium text-slate-500">ID / Route</th>
|
|
|
|
|
- <th className="w-[180px] px-2 py-3 font-medium text-slate-500">Order / User</th>
|
|
|
|
|
- {/* 动态列如果不设宽度,Table-fixed 会自动平分剩余空间,这里给个大概比例 */}
|
|
|
|
|
- <th className="w-[20%] px-2 py-3 font-medium text-slate-500">业务进度 (History)</th>
|
|
|
|
|
- <th className="w-[20%] px-2 py-3 font-medium text-slate-500">系统调试 (Meta)</th>
|
|
|
|
|
- <th className="w-[100px] px-2 py-3 font-medium text-slate-500">状态</th>
|
|
|
|
|
- <th className="w-[120px] px-2 py-3 font-medium text-slate-500 text-right">操作</th>
|
|
|
|
|
|
|
+ <th className="w-10 px-3 py-3.5 text-center"></th>
|
|
|
|
|
+
|
|
|
|
|
+ {/* ID & Route */}
|
|
|
|
|
+ <th
|
|
|
|
|
+ onClick={() => handleHeaderSort('id')}
|
|
|
|
|
+ className="w-[170px] px-3 py-3.5 cursor-pointer hover:bg-slate-100 transition select-none"
|
|
|
|
|
+ >
|
|
|
|
|
+ <div className="flex items-center">
|
|
|
|
|
+ <span>任务ID / 路由</span>
|
|
|
|
|
+ {renderSortIcon('id')}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </th>
|
|
|
|
|
+
|
|
|
|
|
+ {/* 关联订单 & 客户 */}
|
|
|
|
|
+ <th className="w-[230px] px-3 py-3.5">关联订单 & 客户信息</th>
|
|
|
|
|
+
|
|
|
|
|
+ {/* 优先级 & 状态 */}
|
|
|
|
|
+ <th
|
|
|
|
|
+ onClick={() => handleHeaderSort('priority')}
|
|
|
|
|
+ className="w-[150px] px-3 py-3.5 cursor-pointer hover:bg-slate-100 transition select-none"
|
|
|
|
|
+ >
|
|
|
|
|
+ <div className="flex items-center">
|
|
|
|
|
+ <span>优先级 & 状态</span>
|
|
|
|
|
+ {renderSortIcon('priority')}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </th>
|
|
|
|
|
+
|
|
|
|
|
+ {/* 时间流 */}
|
|
|
|
|
+ <th
|
|
|
|
|
+ onClick={() => handleHeaderSort('updated_at')}
|
|
|
|
|
+ className="w-[190px] px-3 py-3.5 cursor-pointer hover:bg-slate-100 transition select-none"
|
|
|
|
|
+ >
|
|
|
|
|
+ <div className="flex items-center">
|
|
|
|
|
+ <span>活跃更新 / 创建时间</span>
|
|
|
|
|
+ {renderSortIcon('updated_at')}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </th>
|
|
|
|
|
+
|
|
|
|
|
+ {/* 操作列 */}
|
|
|
|
|
+ <th className="w-[160px] px-4 py-3.5 text-right">快捷操作</th>
|
|
|
</tr>
|
|
</tr>
|
|
|
</thead>
|
|
</thead>
|
|
|
|
|
+
|
|
|
{tasks.map((task) => {
|
|
{tasks.map((task) => {
|
|
|
const isExpanded = expandedRows.has(task.id);
|
|
const isExpanded = expandedRows.has(task.id);
|
|
|
-
|
|
|
|
|
|
|
+ const customerName = getRecipientName(task);
|
|
|
|
|
+ const phone = getRecipientPhone(task);
|
|
|
|
|
+ const email = getRecipientEmail(task);
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
- <tbody key={task.id} className="group hover:bg-slate-50 transition-colors border-b border-slate-100 last:border-0">
|
|
|
|
|
- <tr className="cursor-pointer" onClick={() => toggleRow(task.id)}>
|
|
|
|
|
- <td className="px-4 py-4 text-slate-400 align-top">
|
|
|
|
|
- {isExpanded ? <ChevronUp size={16} /> : <ChevronDown size={16} />}
|
|
|
|
|
|
|
+ <tbody
|
|
|
|
|
+ key={task.id}
|
|
|
|
|
+ className="group hover:bg-slate-50/70 transition-colors border-b border-slate-100 last:border-0"
|
|
|
|
|
+ >
|
|
|
|
|
+ <tr
|
|
|
|
|
+ className="cursor-pointer select-none"
|
|
|
|
|
+ onClick={() => toggleRow(task.id)}
|
|
|
|
|
+ >
|
|
|
|
|
+ {/* Expand Toggle */}
|
|
|
|
|
+ <td className="px-3 py-4 text-slate-400 text-center align-middle">
|
|
|
|
|
+ <div className="w-6 h-6 rounded-md flex items-center justify-center hover:bg-slate-200/60 transition text-slate-500">
|
|
|
|
|
+ {isExpanded ? <ChevronUp size={16} /> : <ChevronDown size={16} />}
|
|
|
|
|
+ </div>
|
|
|
</td>
|
|
</td>
|
|
|
- <td className="px-2 py-4 align-top">
|
|
|
|
|
- <div className="font-mono text-slate-500 text-xs mb-1">#{task.id}</div>
|
|
|
|
|
- <span className="font-mono text-[10px] text-blue-700 bg-blue-50 px-2 py-1 rounded border border-blue-100 inline-block break-all max-w-full truncate">
|
|
|
|
|
|
|
+
|
|
|
|
|
+ {/* Task ID & Route */}
|
|
|
|
|
+ <td className="px-3 py-4 align-top">
|
|
|
|
|
+ <div className="flex items-center gap-1.5 mb-1">
|
|
|
|
|
+ <span className="font-mono font-bold text-xs text-slate-800 bg-slate-100 px-1.5 py-0.5 rounded">
|
|
|
|
|
+ #{task.id}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ {task.script_version && (
|
|
|
|
|
+ <span className="font-mono text-[10px] text-purple-600 bg-purple-50 px-1 py-0.5 rounded border border-purple-100" title="执行脚本版本">
|
|
|
|
|
+ v{task.script_version}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ )}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div
|
|
|
|
|
+ className="font-mono text-[11px] text-blue-700 bg-blue-50/80 px-2 py-0.5 rounded-md border border-blue-100 truncate inline-block max-w-full font-medium"
|
|
|
|
|
+ title={task.routing_key}
|
|
|
|
|
+ >
|
|
|
{task.routing_key}
|
|
{task.routing_key}
|
|
|
- </span>
|
|
|
|
|
- </td>
|
|
|
|
|
- <td className="px-2 py-4 align-top">
|
|
|
|
|
- <div className="text-slate-900 font-bold text-xs mb-1 break-all font-mono truncate" title={task.order_id}>{task.order_id}</div>
|
|
|
|
|
- <div className="text-xs text-slate-500 flex items-center gap-1 truncate" title={getUserSummary(task.user_inputs)}>
|
|
|
|
|
- <User size={12} className="text-slate-400 flex-shrink-0" /> {getUserSummary(task.user_inputs)}
|
|
|
|
|
</div>
|
|
</div>
|
|
|
</td>
|
|
</td>
|
|
|
-
|
|
|
|
|
- {/* History Column */}
|
|
|
|
|
- <td className="px-2 py-4 align-top overflow-hidden">
|
|
|
|
|
- {getComplexSummary(task.grabbed_history, 'No history')}
|
|
|
|
|
|
|
+
|
|
|
|
|
+ {/* Order & Customer */}
|
|
|
|
|
+ <td className="px-3 py-4 align-top">
|
|
|
|
|
+ <div className="flex items-center gap-1 mb-1">
|
|
|
|
|
+ <span
|
|
|
|
|
+ className="font-mono font-bold text-xs text-slate-900 truncate max-w-[150px]"
|
|
|
|
|
+ title={task.order_id}
|
|
|
|
|
+ >
|
|
|
|
|
+ {task.order_id}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ <button
|
|
|
|
|
+ onClick={(e) => {
|
|
|
|
|
+ e.stopPropagation();
|
|
|
|
|
+ handleCopy(task.order_id, `order-${task.id}`);
|
|
|
|
|
+ }}
|
|
|
|
|
+ className="p-1 text-slate-400 hover:text-slate-700 rounded transition flex-shrink-0"
|
|
|
|
|
+ title="复制订单号"
|
|
|
|
|
+ >
|
|
|
|
|
+ {copiedOrderId === `order-${task.id}` ? (
|
|
|
|
|
+ <Check size={12} className="text-emerald-600" />
|
|
|
|
|
+ ) : (
|
|
|
|
|
+ <Copy size={12} />
|
|
|
|
|
+ )}
|
|
|
|
|
+ </button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <div className="flex items-center gap-1.5 text-xs text-slate-700 font-medium truncate">
|
|
|
|
|
+ <User size={13} className="text-slate-400 flex-shrink-0" />
|
|
|
|
|
+ <span className="truncate">{customerName}</span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ {phone !== '-' && (
|
|
|
|
|
+ <div className="text-[11px] text-slate-500 font-mono flex items-center gap-1 mt-0.5 truncate">
|
|
|
|
|
+ <Phone size={11} className="text-slate-400 flex-shrink-0" />
|
|
|
|
|
+ <span>{phone}</span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ )}
|
|
|
</td>
|
|
</td>
|
|
|
|
|
|
|
|
- {/* Meta Column */}
|
|
|
|
|
- <td className="px-2 py-4 align-top overflow-hidden">
|
|
|
|
|
- {getComplexSummary(task.meta, 'No logs')}
|
|
|
|
|
- <div className="text-[10px] text-slate-400 mt-1">
|
|
|
|
|
- <LocalTime date={task.updated_at} options={{hour:'2-digit', minute:'2-digit', second:'2-digit'}} />
|
|
|
|
|
|
|
+ {/* Priority & Status */}
|
|
|
|
|
+ <td className="px-3 py-4 align-top">
|
|
|
|
|
+ <div className="flex items-center gap-1.5 mb-1.5">
|
|
|
|
|
+ {renderStatus(task.status)}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div className="flex items-center gap-1.5 flex-wrap">
|
|
|
|
|
+ {renderPriorityBadge(task.priority)}
|
|
|
|
|
+ {task.attempt_count > 0 && (
|
|
|
|
|
+ <span
|
|
|
|
|
+ className="inline-flex items-center gap-0.5 text-[10px] font-bold text-rose-600 bg-rose-50 px-1.5 py-0.5 rounded border border-rose-100"
|
|
|
|
|
+ title={`已重试 ${task.attempt_count} 次`}
|
|
|
|
|
+ >
|
|
|
|
|
+ <RotateCcw size={10} /> {task.attempt_count}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ )}
|
|
|
</div>
|
|
</div>
|
|
|
</td>
|
|
</td>
|
|
|
|
|
|
|
|
- <td className="px-2 py-4 align-top">
|
|
|
|
|
- {renderStatus(task.status)}
|
|
|
|
|
- {task.attempt_count > 0 && <div className="text-[10px] text-slate-400 mt-1 pl-1">Retry: {task.attempt_count}</div>}
|
|
|
|
|
|
|
+ {/* Timestamps */}
|
|
|
|
|
+ <td className="px-3 py-4 align-top text-xs text-slate-600">
|
|
|
|
|
+ <div className="flex items-center gap-1 font-medium text-slate-800 mb-1">
|
|
|
|
|
+ <Clock size={13} className="text-blue-500 flex-shrink-0" />
|
|
|
|
|
+ <LocalTime
|
|
|
|
|
+ date={task.updated_at}
|
|
|
|
|
+ options={{
|
|
|
|
|
+ month: '2-digit',
|
|
|
|
|
+ day: '2-digit',
|
|
|
|
|
+ hour: '2-digit',
|
|
|
|
|
+ minute: '2-digit',
|
|
|
|
|
+ second: '2-digit',
|
|
|
|
|
+ }}
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div className="text-[11px] text-slate-400 pl-4">
|
|
|
|
|
+ 创建于:{' '}
|
|
|
|
|
+ <LocalTime
|
|
|
|
|
+ date={task.created_at}
|
|
|
|
|
+ options={{
|
|
|
|
|
+ month: '2-digit',
|
|
|
|
|
+ day: '2-digit',
|
|
|
|
|
+ hour: '2-digit',
|
|
|
|
|
+ minute: '2-digit',
|
|
|
|
|
+ }}
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
</td>
|
|
</td>
|
|
|
- <td className="px-2 py-4 text-right align-top" onClick={(e) => e.stopPropagation()}>
|
|
|
|
|
- <div className="flex justify-end gap-1 flex-wrap">
|
|
|
|
|
- <button onClick={() => onEdit(task)} className="p-1.5 rounded text-indigo-600 hover:bg-indigo-50 border border-transparent hover:border-indigo-100" title="编辑"><Edit size={16} /></button>
|
|
|
|
|
- <button onClick={() => onRetry(task.id)} className="p-1.5 rounded text-blue-600 hover:bg-blue-50 border border-transparent hover:border-blue-100" title="重置"><RotateCcw size={16} /></button>
|
|
|
|
|
- <button onClick={() => onPause(task.id)} className="p-1.5 rounded text-orange-600 hover:bg-orange-50 border border-transparent hover:border-orange-100" title="暂停"><Pause size={16} /></button>
|
|
|
|
|
- <button onClick={() => onManualConfirm(task.id)} className="p-1.5 rounded text-green-600 hover:bg-green-50 border border-transparent hover:border-green-100" title="完成"><CheckCircle size={16} /></button>
|
|
|
|
|
|
|
+
|
|
|
|
|
+ {/* Action buttons */}
|
|
|
|
|
+ <td
|
|
|
|
|
+ className="px-4 py-4 text-right align-middle"
|
|
|
|
|
+ onClick={(e) => e.stopPropagation()}
|
|
|
|
|
+ >
|
|
|
|
|
+ <div className="flex items-center justify-end gap-1">
|
|
|
|
|
+ {/* 编辑 */}
|
|
|
|
|
+ <button
|
|
|
|
|
+ onClick={() => onEdit(task)}
|
|
|
|
|
+ className="p-1.5 text-slate-500 hover:text-indigo-600 hover:bg-indigo-50 rounded-lg border border-slate-200 transition"
|
|
|
|
|
+ title="编辑任务配置"
|
|
|
|
|
+ >
|
|
|
|
|
+ <Edit size={14} />
|
|
|
|
|
+ </button>
|
|
|
|
|
+
|
|
|
|
|
+ {/* 重置回队列 */}
|
|
|
|
|
+ <button
|
|
|
|
|
+ onClick={() => onRetry(task.id)}
|
|
|
|
|
+ className="p-1.5 text-slate-500 hover:text-blue-600 hover:bg-blue-50 rounded-lg border border-slate-200 transition"
|
|
|
|
|
+ title="重置回队列 (Pending)"
|
|
|
|
|
+ >
|
|
|
|
|
+ <RotateCcw size={14} />
|
|
|
|
|
+ </button>
|
|
|
|
|
+
|
|
|
|
|
+ {/* 暂停任务 */}
|
|
|
|
|
+ <button
|
|
|
|
|
+ onClick={() => onPause(task.id)}
|
|
|
|
|
+ className="p-1.5 text-slate-500 hover:text-orange-600 hover:bg-orange-50 rounded-lg border border-slate-200 transition"
|
|
|
|
|
+ title="暂停任务"
|
|
|
|
|
+ >
|
|
|
|
|
+ <Pause size={14} />
|
|
|
|
|
+ </button>
|
|
|
|
|
+
|
|
|
|
|
+ {/* 强制标记完成 */}
|
|
|
|
|
+ <button
|
|
|
|
|
+ onClick={() => onManualConfirm(task.id)}
|
|
|
|
|
+ className="p-1.5 text-slate-500 hover:text-emerald-600 hover:bg-emerald-50 rounded-lg border border-slate-200 transition"
|
|
|
|
|
+ title="强制标记完成"
|
|
|
|
|
+ >
|
|
|
|
|
+ <CheckCircle size={14} />
|
|
|
|
|
+ </button>
|
|
|
|
|
+
|
|
|
|
|
+ {/* 联系客户 Dropdown */}
|
|
|
<div className="relative">
|
|
<div className="relative">
|
|
|
- <button
|
|
|
|
|
- onClick={() => setContactDropdownOpen(contactDropdownOpen === task.id ? null : task.id)}
|
|
|
|
|
- className="p-1.5 rounded text-cyan-600 hover:bg-cyan-50 border border-transparent hover:border-cyan-100"
|
|
|
|
|
- title="联系客户"
|
|
|
|
|
|
|
+ <button
|
|
|
|
|
+ onClick={() =>
|
|
|
|
|
+ setContactDropdownOpen(
|
|
|
|
|
+ contactDropdownOpen === task.id ? null : task.id
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ className="p-1.5 text-slate-500 hover:text-cyan-600 hover:bg-cyan-50 rounded-lg border border-slate-200 transition"
|
|
|
|
|
+ title="快速联系客户"
|
|
|
>
|
|
>
|
|
|
- <Mail size={16} />
|
|
|
|
|
|
|
+ <Mail size={14} />
|
|
|
</button>
|
|
</button>
|
|
|
{contactDropdownOpen === task.id && (
|
|
{contactDropdownOpen === task.id && (
|
|
|
- <div className="absolute right-0 top-full mt-1 bg-white border border-slate-200 rounded-lg shadow-lg z-10 min-w-[120px]">
|
|
|
|
|
- <button
|
|
|
|
|
- onClick={() => { openMessageModal(task, 'sms'); setContactDropdownOpen(null); }}
|
|
|
|
|
- className="flex items-center gap-2 w-full px-3 py-2 text-sm text-slate-700 hover:bg-amber-50 rounded-t-lg"
|
|
|
|
|
|
|
+ <div className="absolute right-0 top-full mt-1 bg-white border border-slate-200 rounded-xl shadow-xl z-20 min-w-[140px] p-1.5 text-xs text-left animate-fadeIn">
|
|
|
|
|
+ <button
|
|
|
|
|
+ onClick={() => {
|
|
|
|
|
+ openMessageModal(task, 'sms');
|
|
|
|
|
+ setContactDropdownOpen(null);
|
|
|
|
|
+ }}
|
|
|
|
|
+ className="flex items-center gap-2 w-full px-3 py-2 text-slate-700 hover:bg-amber-50 rounded-lg font-medium transition"
|
|
|
>
|
|
>
|
|
|
- <MessageSquare size={14} /> 短信
|
|
|
|
|
|
|
+ <MessageSquare size={14} className="text-amber-500" /> 发送短信
|
|
|
</button>
|
|
</button>
|
|
|
- <button
|
|
|
|
|
- onClick={() => { openMessageModal(task, 'whatsapp'); setContactDropdownOpen(null); }}
|
|
|
|
|
- className="flex items-center gap-2 w-full px-3 py-2 text-sm text-slate-700 hover:bg-emerald-50"
|
|
|
|
|
|
|
+ <button
|
|
|
|
|
+ onClick={() => {
|
|
|
|
|
+ openMessageModal(task, 'whatsapp');
|
|
|
|
|
+ setContactDropdownOpen(null);
|
|
|
|
|
+ }}
|
|
|
|
|
+ className="flex items-center gap-2 w-full px-3 py-2 text-slate-700 hover:bg-emerald-50 rounded-lg font-medium transition"
|
|
|
>
|
|
>
|
|
|
- <MessageCircle size={14} /> WhatsApp
|
|
|
|
|
|
|
+ <MessageCircle size={14} className="text-emerald-500" /> WhatsApp
|
|
|
</button>
|
|
</button>
|
|
|
- <button
|
|
|
|
|
- onClick={() => { openMessageModal(task, 'email'); setContactDropdownOpen(null); }}
|
|
|
|
|
- className="flex items-center gap-2 w-full px-3 py-2 text-sm text-slate-700 hover:bg-blue-50 rounded-b-lg"
|
|
|
|
|
|
|
+ <button
|
|
|
|
|
+ onClick={() => {
|
|
|
|
|
+ openMessageModal(task, 'email');
|
|
|
|
|
+ setContactDropdownOpen(null);
|
|
|
|
|
+ }}
|
|
|
|
|
+ className="flex items-center gap-2 w-full px-3 py-2 text-slate-700 hover:bg-blue-50 rounded-lg font-medium transition"
|
|
|
>
|
|
>
|
|
|
- <Mail size={14} /> 邮件
|
|
|
|
|
|
|
+ <Mail size={14} className="text-blue-500" /> 发送邮件
|
|
|
</button>
|
|
</button>
|
|
|
</div>
|
|
</div>
|
|
|
)}
|
|
)}
|
|
@@ -307,11 +602,16 @@ export default function TaskTable({ tasks, loading, onRetry, onManualConfirm, on
|
|
|
</div>
|
|
</div>
|
|
|
</td>
|
|
</td>
|
|
|
</tr>
|
|
</tr>
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ {/* 展开的结构化详情面板 */}
|
|
|
{isExpanded && (
|
|
{isExpanded && (
|
|
|
- <tr className="bg-slate-50 shadow-inner border-t border-slate-100">
|
|
|
|
|
- <td colSpan={7} className="px-4 py-4 w-full">
|
|
|
|
|
- <TaskDetailContent task={task} />
|
|
|
|
|
|
|
+ <tr className="bg-slate-50/90 shadow-inner border-t border-slate-200">
|
|
|
|
|
+ <td colSpan={6} className="p-4 w-full">
|
|
|
|
|
+ <TaskDetailTabs
|
|
|
|
|
+ task={task}
|
|
|
|
|
+ onOpenMessage={openMessageModal}
|
|
|
|
|
+ onEdit={onEdit}
|
|
|
|
|
+ />
|
|
|
</td>
|
|
</td>
|
|
|
</tr>
|
|
</tr>
|
|
|
)}
|
|
)}
|
|
@@ -322,74 +622,105 @@ export default function TaskTable({ tasks, loading, onRetry, onManualConfirm, on
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
- {/* Mobile View */}
|
|
|
|
|
- <div className="md:hidden space-y-4">
|
|
|
|
|
- {/* Mobile view logic keeps mostly same but ensures break-all is used */}
|
|
|
|
|
|
|
+ {/* Mobile Responsive Cards View */}
|
|
|
|
|
+ <div className="md:hidden space-y-3">
|
|
|
{tasks.map((task) => {
|
|
{tasks.map((task) => {
|
|
|
const isExpanded = expandedRows.has(task.id);
|
|
const isExpanded = expandedRows.has(task.id);
|
|
|
|
|
+ const customerName = getRecipientName(task);
|
|
|
|
|
+ const phone = getRecipientPhone(task);
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
- <div key={task.id} className="bg-white p-4 rounded-lg shadow-sm border border-slate-200">
|
|
|
|
|
- {/* ... (Header Section same as before) ... */}
|
|
|
|
|
- <div className="flex justify-between items-start mb-3">
|
|
|
|
|
- <div className="flex flex-col gap-1 overflow-hidden">
|
|
|
|
|
|
|
+ <div
|
|
|
|
|
+ key={task.id}
|
|
|
|
|
+ className="bg-white p-4 rounded-2xl shadow-sm border border-slate-200 space-y-3"
|
|
|
|
|
+ >
|
|
|
|
|
+ <div className="flex items-start justify-between gap-2">
|
|
|
|
|
+ <div>
|
|
|
<div className="flex items-center gap-2">
|
|
<div className="flex items-center gap-2">
|
|
|
- <span className="text-sm font-bold text-slate-900">#{task.id}</span>
|
|
|
|
|
|
|
+ <span className="font-mono font-bold text-sm text-slate-900">#{task.id}</span>
|
|
|
{renderStatus(task.status)}
|
|
{renderStatus(task.status)}
|
|
|
|
|
+ {renderPriorityBadge(task.priority)}
|
|
|
</div>
|
|
</div>
|
|
|
- <span className="text-xs font-mono text-blue-600 bg-blue-50 px-1.5 py-0.5 rounded w-fit truncate max-w-full">{task.routing_key}</span>
|
|
|
|
|
|
|
+ <span className="text-xs font-mono text-blue-600 bg-blue-50 px-2 py-0.5 rounded mt-1 inline-block">
|
|
|
|
|
+ {task.routing_key}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <div className="flex items-center gap-1">
|
|
|
|
|
+ <button
|
|
|
|
|
+ onClick={() => onRetry(task.id)}
|
|
|
|
|
+ className="p-1.5 bg-blue-50 text-blue-600 rounded-lg active:scale-95"
|
|
|
|
|
+ title="重置"
|
|
|
|
|
+ >
|
|
|
|
|
+ <RotateCcw size={15} />
|
|
|
|
|
+ </button>
|
|
|
|
|
+ <button
|
|
|
|
|
+ onClick={() => onPause(task.id)}
|
|
|
|
|
+ className="p-1.5 bg-orange-50 text-orange-600 rounded-lg active:scale-95"
|
|
|
|
|
+ title="暂停"
|
|
|
|
|
+ >
|
|
|
|
|
+ <Pause size={15} />
|
|
|
|
|
+ </button>
|
|
|
|
|
+ <button
|
|
|
|
|
+ onClick={() => onManualConfirm(task.id)}
|
|
|
|
|
+ className="p-1.5 bg-emerald-50 text-emerald-600 rounded-lg active:scale-95"
|
|
|
|
|
+ title="标记完成"
|
|
|
|
|
+ >
|
|
|
|
|
+ <CheckCircle size={15} />
|
|
|
|
|
+ </button>
|
|
|
|
|
+ <button
|
|
|
|
|
+ onClick={() => onEdit(task)}
|
|
|
|
|
+ className="p-1.5 bg-indigo-50 text-indigo-600 rounded-lg active:scale-95"
|
|
|
|
|
+ title="编辑"
|
|
|
|
|
+ >
|
|
|
|
|
+ <Edit size={15} />
|
|
|
|
|
+ </button>
|
|
|
</div>
|
|
</div>
|
|
|
-<div className="flex gap-2 flex-shrink-0">
|
|
|
|
|
- <button onClick={() => onRetry(task.id)} className="p-2 bg-blue-50 text-blue-600 rounded-lg active:scale-95"><RotateCcw size={18}/></button>
|
|
|
|
|
- <button onClick={() => onPause(task.id)} className="p-2 bg-orange-50 text-orange-600 rounded-lg active:scale-95"><Pause size={18}/></button>
|
|
|
|
|
- <button onClick={() => onManualConfirm(task.id)} className="p-2 bg-green-50 text-green-600 rounded-lg active:scale-95"><CheckCircle size={18}/></button>
|
|
|
|
|
- <div className="relative">
|
|
|
|
|
- <button onClick={() => setContactDropdownOpen(contactDropdownOpen === task.id ? null : task.id)} className="p-2 bg-cyan-50 text-cyan-600 rounded-lg active:scale-95"><Mail size={18}/></button>
|
|
|
|
|
- {contactDropdownOpen === task.id && (
|
|
|
|
|
- <div className="absolute right-0 top-full mt-1 bg-white border border-slate-200 rounded-lg shadow-lg z-10 min-w-[100px]">
|
|
|
|
|
- <button onClick={() => { openMessageModal(task, 'sms'); setContactDropdownOpen(null); }} className="flex items-center gap-2 w-full px-3 py-2 text-sm text-slate-700 hover:bg-amber-50 rounded-t-lg">
|
|
|
|
|
- <MessageSquare size={14} /> 短信
|
|
|
|
|
- </button>
|
|
|
|
|
- <button onClick={() => { openMessageModal(task, 'whatsapp'); setContactDropdownOpen(null); }} className="flex items-center gap-2 w-full px-3 py-2 text-sm text-slate-700 hover:bg-emerald-50">
|
|
|
|
|
- <MessageCircle size={14} /> WhatsApp
|
|
|
|
|
- </button>
|
|
|
|
|
- <button onClick={() => { openMessageModal(task, 'email'); setContactDropdownOpen(null); }} className="flex items-center gap-2 w-full px-3 py-2 text-sm text-slate-700 hover:bg-blue-50 rounded-b-lg">
|
|
|
|
|
- <Mail size={14} /> 邮件
|
|
|
|
|
- </button>
|
|
|
|
|
- </div>
|
|
|
|
|
- )}
|
|
|
|
|
- </div>
|
|
|
|
|
- </div>
|
|
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
- <div className="bg-slate-50 p-3 rounded-lg border border-slate-100 text-sm space-y-2 mb-3">
|
|
|
|
|
- <div className="flex justify-between">
|
|
|
|
|
- <span className="text-xs text-slate-400">Order ID</span>
|
|
|
|
|
- <span className="font-mono font-medium truncate ml-2">{task.order_id}</span>
|
|
|
|
|
- </div>
|
|
|
|
|
- {/* ... Mobile Content ... */}
|
|
|
|
|
- <div className="pt-2 border-t border-slate-200 mt-1 grid grid-cols-1 gap-1">
|
|
|
|
|
- <div className="flex flex-col text-xs">
|
|
|
|
|
- <span className="text-slate-400 mb-1">History:</span>
|
|
|
|
|
- <div className="bg-white p-1 rounded border border-slate-200">{getComplexSummary(task.grabbed_history)}</div>
|
|
|
|
|
- </div>
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ <div className="bg-slate-50 p-3 rounded-xl border border-slate-100 text-xs space-y-1.5">
|
|
|
|
|
+ <div className="flex justify-between">
|
|
|
|
|
+ <span className="text-slate-400">Order ID</span>
|
|
|
|
|
+ <span className="font-mono font-bold text-slate-800">{task.order_id}</span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div className="flex justify-between">
|
|
|
|
|
+ <span className="text-slate-400">客户姓名</span>
|
|
|
|
|
+ <span className="font-semibold text-slate-700">{customerName}</span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ {phone !== '-' && (
|
|
|
|
|
+ <div className="flex justify-between">
|
|
|
|
|
+ <span className="text-slate-400">联系电话</span>
|
|
|
|
|
+ <span className="font-mono text-slate-600">{phone}</span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ )}
|
|
|
|
|
+ <div className="flex justify-between pt-1 border-t border-slate-200 text-[11px]">
|
|
|
|
|
+ <span className="text-slate-400">更新时间</span>
|
|
|
|
|
+ <LocalTime date={task.updated_at} />
|
|
|
|
|
+ </div>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
- <button
|
|
|
|
|
|
|
+ <button
|
|
|
onClick={() => toggleRow(task.id)}
|
|
onClick={() => toggleRow(task.id)}
|
|
|
- className="w-full flex items-center justify-center py-2 bg-white border border-slate-200 text-slate-600 rounded-lg text-xs font-medium active:bg-slate-50 transition"
|
|
|
|
|
|
|
+ className="w-full flex items-center justify-center py-2 bg-slate-100 hover:bg-slate-200 text-slate-700 rounded-xl text-xs font-semibold transition"
|
|
|
>
|
|
>
|
|
|
- {isExpanded ? <>收起详情 <ChevronUp size={14} className="ml-1"/></> : <>查看日志 & 配置 <ChevronDown size={14} className="ml-1"/></>}
|
|
|
|
|
|
|
+ {isExpanded ? (
|
|
|
|
|
+ <>
|
|
|
|
|
+ 收起详情 <ChevronUp size={14} className="ml-1" />
|
|
|
|
|
+ </>
|
|
|
|
|
+ ) : (
|
|
|
|
|
+ <>
|
|
|
|
|
+ 展开结构化日志与配置 <ChevronDown size={14} className="ml-1" />
|
|
|
|
|
+ </>
|
|
|
|
|
+ )}
|
|
|
</button>
|
|
</button>
|
|
|
|
|
|
|
|
{isExpanded && (
|
|
{isExpanded && (
|
|
|
- <div className="mt-3 pt-3 border-t border-slate-100">
|
|
|
|
|
- <TaskDetailContent task={task} />
|
|
|
|
|
- <div className="mt-4 pt-4 border-t border-slate-100">
|
|
|
|
|
- <button onClick={() => onEdit(task)} className="w-full flex items-center justify-center py-2.5 bg-indigo-50 text-indigo-600 rounded-lg text-sm font-bold border border-indigo-100">
|
|
|
|
|
- <Edit size={16} className="mr-2"/> 编辑任务配置
|
|
|
|
|
- </button>
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ <div className="pt-2">
|
|
|
|
|
+ <TaskDetailTabs
|
|
|
|
|
+ task={task}
|
|
|
|
|
+ onOpenMessage={openMessageModal}
|
|
|
|
|
+ onEdit={onEdit}
|
|
|
|
|
+ />
|
|
|
</div>
|
|
</div>
|
|
|
)}
|
|
)}
|
|
|
</div>
|
|
</div>
|
|
@@ -397,72 +728,112 @@ export default function TaskTable({ tasks, loading, onRetry, onManualConfirm, on
|
|
|
})}
|
|
})}
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
+ {/* Message Modal */}
|
|
|
{isMessageOpen && messageTask && (
|
|
{isMessageOpen && messageTask && (
|
|
|
- <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm p-4">
|
|
|
|
|
- <div className="bg-white rounded-xl shadow-2xl w-full max-w-lg flex flex-col animate-in zoom-in duration-200">
|
|
|
|
|
|
|
+ <div className="fixed inset-0 z-50 flex items-center justify-center bg-slate-900/60 backdrop-blur-sm p-4 animate-fadeIn">
|
|
|
|
|
+ <div className="bg-white rounded-2xl shadow-2xl border border-slate-200 w-full max-w-lg overflow-hidden flex flex-col">
|
|
|
<div className="px-6 py-4 border-b flex justify-between items-center bg-slate-50">
|
|
<div className="px-6 py-4 border-b flex justify-between items-center bg-slate-50">
|
|
|
- <div>
|
|
|
|
|
- <h3 className="font-bold text-slate-900 text-lg">
|
|
|
|
|
- {messageChannel === 'sms' ? '发送短信' : messageChannel === 'whatsapp' ? '发送 WhatsApp' : '发送邮件'}
|
|
|
|
|
- </h3>
|
|
|
|
|
- <p className="text-xs text-slate-500 mt-1">Order #{messageTask.order_id}</p>
|
|
|
|
|
|
|
+ <div className="flex items-center gap-2.5">
|
|
|
|
|
+ <div className="w-8 h-8 rounded-lg bg-blue-50 text-blue-600 flex items-center justify-center font-bold">
|
|
|
|
|
+ <Send size={16} />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <h3 className="font-bold text-slate-900 text-base">
|
|
|
|
|
+ {messageChannel === 'sms'
|
|
|
|
|
+ ? '发送短信通知'
|
|
|
|
|
+ : messageChannel === 'whatsapp'
|
|
|
|
|
+ ? '发送 WhatsApp 消息'
|
|
|
|
|
+ : '发送邮件通知'}
|
|
|
|
|
+ </h3>
|
|
|
|
|
+ <p className="text-xs text-slate-400">Order #{messageTask.order_id}</p>
|
|
|
|
|
+ </div>
|
|
|
</div>
|
|
</div>
|
|
|
- <button onClick={closeMessageModal} className="text-slate-400 hover:text-slate-600 p-1 rounded-full hover:bg-slate-100 transition">
|
|
|
|
|
- <X size={20} />
|
|
|
|
|
|
|
+ <button
|
|
|
|
|
+ onClick={closeMessageModal}
|
|
|
|
|
+ className="text-slate-400 hover:text-slate-600 p-1.5 rounded-lg hover:bg-slate-100 transition"
|
|
|
|
|
+ >
|
|
|
|
|
+ <X size={18} />
|
|
|
</button>
|
|
</button>
|
|
|
</div>
|
|
</div>
|
|
|
- <div className="p-6 space-y-3">
|
|
|
|
|
- <div className="rounded-lg border border-slate-200 bg-slate-50 p-3 text-xs text-slate-600 space-y-1">
|
|
|
|
|
|
|
+
|
|
|
|
|
+ <div className="p-6 space-y-4">
|
|
|
|
|
+ <div className="rounded-xl border border-slate-200 bg-slate-50/70 p-3.5 text-xs text-slate-600 space-y-2">
|
|
|
<div className="flex justify-between">
|
|
<div className="flex justify-between">
|
|
|
- <span className="font-semibold text-slate-500">Recipient</span>
|
|
|
|
|
- <span className="text-slate-700">{getRecipientName(messageTask)}</span>
|
|
|
|
|
|
|
+ <span className="font-medium text-slate-400">接收客户</span>
|
|
|
|
|
+ <span className="font-semibold text-slate-800">
|
|
|
|
|
+ {getRecipientName(messageTask)}
|
|
|
|
|
+ </span>
|
|
|
</div>
|
|
</div>
|
|
|
{messageChannel === 'email' ? (
|
|
{messageChannel === 'email' ? (
|
|
|
<div className="flex justify-between">
|
|
<div className="flex justify-between">
|
|
|
- <span className="font-semibold text-slate-500">Email To</span>
|
|
|
|
|
- <span className="text-slate-700">{getRecipientEmail(messageTask) || '-'}</span>
|
|
|
|
|
|
|
+ <span className="font-medium text-slate-400">邮箱地址</span>
|
|
|
|
|
+ <span className="font-mono text-slate-700">
|
|
|
|
|
+ {getRecipientEmail(messageTask) || '-'}
|
|
|
|
|
+ </span>
|
|
|
</div>
|
|
</div>
|
|
|
) : (
|
|
) : (
|
|
|
<div className="flex justify-between">
|
|
<div className="flex justify-between">
|
|
|
- <span className="font-semibold text-slate-500">{messageChannel === 'sms' ? 'SMS To' : 'WhatsApp To'}</span>
|
|
|
|
|
- <span className="text-slate-700">{getRecipientPhone(messageTask)}</span>
|
|
|
|
|
|
|
+ <span className="font-medium text-slate-400">
|
|
|
|
|
+ {messageChannel === 'sms' ? '短信手机号' : 'WhatsApp 号码'}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ <span className="font-mono text-slate-700 font-semibold">
|
|
|
|
|
+ {getRecipientPhone(messageTask)}
|
|
|
|
|
+ </span>
|
|
|
</div>
|
|
</div>
|
|
|
)}
|
|
)}
|
|
|
{messageChannel === 'sms' && (
|
|
{messageChannel === 'sms' && (
|
|
|
<div className="flex justify-between">
|
|
<div className="flex justify-between">
|
|
|
- <span className="font-semibold text-slate-500">Sender</span>
|
|
|
|
|
- <span className="text-slate-700">{getSmsSender(messageTask)}</span>
|
|
|
|
|
|
|
+ <span className="font-medium text-slate-400">发信签名 (Sender)</span>
|
|
|
|
|
+ <span className="font-semibold text-blue-600">
|
|
|
|
|
+ {getSmsSender(messageTask)}
|
|
|
|
|
+ </span>
|
|
|
</div>
|
|
</div>
|
|
|
)}
|
|
)}
|
|
|
</div>
|
|
</div>
|
|
|
- <label className="text-xs font-bold uppercase text-slate-500">Message (English)</label>
|
|
|
|
|
- <textarea
|
|
|
|
|
- rows={4}
|
|
|
|
|
- value={messageText}
|
|
|
|
|
- onChange={(e) => setMessageText(e.target.value)}
|
|
|
|
|
- className="w-full border border-slate-200 rounded-lg p-3 text-sm text-slate-700 focus:ring-2 focus:ring-blue-500 outline-none"
|
|
|
|
|
- />
|
|
|
|
|
- <p className="text-xs text-slate-400">Keep it concise (about 20 words).</p>
|
|
|
|
|
|
|
+
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <label className="block text-xs font-semibold text-slate-700 uppercase tracking-wider mb-1.5">
|
|
|
|
|
+ 消息正文 (Message Content)
|
|
|
|
|
+ </label>
|
|
|
|
|
+ <textarea
|
|
|
|
|
+ rows={4}
|
|
|
|
|
+ value={messageText}
|
|
|
|
|
+ onChange={(e) => setMessageText(e.target.value)}
|
|
|
|
|
+ className="w-full border border-slate-200 rounded-xl p-3 text-xs text-slate-800 focus:ring-2 focus:ring-blue-500/20 focus:border-blue-500 outline-none transition"
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
{messageResult !== 'idle' && (
|
|
{messageResult !== 'idle' && (
|
|
|
- <div className={`text-xs rounded-lg px-3 py-2 border ${
|
|
|
|
|
- messageResult === 'success'
|
|
|
|
|
- ? 'border-green-200 bg-green-50 text-green-700'
|
|
|
|
|
- : 'border-red-200 bg-red-50 text-red-700'
|
|
|
|
|
- }`}>
|
|
|
|
|
- {messageResultText}
|
|
|
|
|
|
|
+ <div
|
|
|
|
|
+ className={`text-xs rounded-xl p-3 border flex items-center gap-2 ${
|
|
|
|
|
+ messageResult === 'success'
|
|
|
|
|
+ ? 'border-emerald-200 bg-emerald-50 text-emerald-700'
|
|
|
|
|
+ : 'border-rose-200 bg-rose-50 text-rose-700'
|
|
|
|
|
+ }`}
|
|
|
|
|
+ >
|
|
|
|
|
+ {messageResult === 'success' ? (
|
|
|
|
|
+ <CheckCircle size={15} />
|
|
|
|
|
+ ) : (
|
|
|
|
|
+ <AlertTriangle size={15} />
|
|
|
|
|
+ )}
|
|
|
|
|
+ <span>{messageResultText}</span>
|
|
|
</div>
|
|
</div>
|
|
|
)}
|
|
)}
|
|
|
</div>
|
|
</div>
|
|
|
- <div className="px-6 py-4 border-t bg-slate-50 flex justify-end gap-3">
|
|
|
|
|
- <button onClick={closeMessageModal} className="px-4 py-2 border border-slate-200 rounded-lg text-slate-600 text-sm hover:bg-slate-100">
|
|
|
|
|
- Cancel
|
|
|
|
|
|
|
+
|
|
|
|
|
+ <div className="px-6 py-4 border-t bg-slate-50/80 flex justify-end gap-3">
|
|
|
|
|
+ <button
|
|
|
|
|
+ onClick={closeMessageModal}
|
|
|
|
|
+ className="px-4 py-2 border border-slate-200 rounded-xl text-slate-600 text-xs font-medium hover:bg-slate-100 transition"
|
|
|
|
|
+ >
|
|
|
|
|
+ 取消
|
|
|
</button>
|
|
</button>
|
|
|
<button
|
|
<button
|
|
|
onClick={handleSendMessage}
|
|
onClick={handleSendMessage}
|
|
|
disabled={messageSending}
|
|
disabled={messageSending}
|
|
|
- className="px-5 py-2 bg-slate-900 text-white rounded-lg text-sm font-semibold hover:bg-slate-800 disabled:opacity-60"
|
|
|
|
|
|
|
+ className="px-5 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-xl text-xs font-semibold shadow-md shadow-blue-500/20 disabled:opacity-60 transition flex items-center gap-1.5"
|
|
|
>
|
|
>
|
|
|
- {messageSending ? 'Sending...' : 'Send'}
|
|
|
|
|
|
|
+ {messageSending ? '正在发送...' : '确认发送'}
|
|
|
</button>
|
|
</button>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
@@ -472,92 +843,350 @@ export default function TaskTable({ tasks, loading, onRetry, onManualConfirm, on
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function DataVisualizer({ data, emptyText, isDark = false }: { data: any, emptyText: string, isDark?: boolean }) {
|
|
|
|
|
- if (!data) return <span className={`italic ${isDark ? 'text-slate-500' : 'text-slate-400'}`}>{emptyText}</span>;
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 展开行的 4 个结构化 Tabs 详情面板
|
|
|
|
|
+ */
|
|
|
|
|
+function TaskDetailTabs({
|
|
|
|
|
+ task,
|
|
|
|
|
+ onOpenMessage,
|
|
|
|
|
+ onEdit,
|
|
|
|
|
+}: {
|
|
|
|
|
+ task: VasTask;
|
|
|
|
|
+ onOpenMessage: (task: VasTask, channel: 'sms' | 'whatsapp' | 'email') => void;
|
|
|
|
|
+ onEdit: (task: VasTask) => void;
|
|
|
|
|
+}) {
|
|
|
|
|
+ const [activeTab, setActiveTab] = useState<'history' | 'inputs' | 'config' | 'meta'>('history');
|
|
|
|
|
+ const [copiedKey, setCopiedKey] = useState<string | null>(null);
|
|
|
|
|
|
|
|
- // 1. 对象 Key-Value
|
|
|
|
|
- if (typeof data === 'object' && !Array.isArray(data)) {
|
|
|
|
|
- return (
|
|
|
|
|
- <div className="space-y-1">
|
|
|
|
|
- {Object.entries(data).map(([key, val]) => (
|
|
|
|
|
- <div key={key} className={`flex flex-col border-b pb-1 last:border-0 ${isDark ? 'border-slate-800' : 'border-slate-50'}`}>
|
|
|
|
|
- <span className={`text-[10px] uppercase font-bold ${isDark ? 'text-slate-500' : 'text-slate-400'}`}>{key.replace(/_/g, ' ')}</span>
|
|
|
|
|
- {/* 强制换行 break-all */}
|
|
|
|
|
- <span className={`break-all whitespace-pre-wrap font-medium ${isDark ? 'text-slate-300' : 'text-slate-700'}`}>
|
|
|
|
|
- {typeof val === 'object' ? JSON.stringify(val) : String(val)}
|
|
|
|
|
|
|
+ const copyToClipboard = (text: string, key: string) => {
|
|
|
|
|
+ navigator.clipboard.writeText(typeof text === 'string' ? text : JSON.stringify(text, null, 2));
|
|
|
|
|
+ setCopiedKey(key);
|
|
|
|
|
+ setTimeout(() => setCopiedKey(null), 2000);
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ return (
|
|
|
|
|
+ <div className="bg-white rounded-xl border border-slate-200 overflow-hidden shadow-sm">
|
|
|
|
|
+ {/* Tab Navigation Header */}
|
|
|
|
|
+ <div className="flex items-center justify-between border-b border-slate-200 bg-slate-100/70 px-4 py-2 flex-wrap gap-2">
|
|
|
|
|
+ <div className="flex items-center gap-1.5">
|
|
|
|
|
+ <button
|
|
|
|
|
+ onClick={() => setActiveTab('history')}
|
|
|
|
|
+ className={`px-3 py-1.5 rounded-lg text-xs font-semibold transition flex items-center gap-1.5 ${
|
|
|
|
|
+ activeTab === 'history'
|
|
|
|
|
+ ? 'bg-white text-emerald-700 shadow-sm'
|
|
|
|
|
+ : 'text-slate-600 hover:text-slate-900 hover:bg-slate-200/50'
|
|
|
|
|
+ }`}
|
|
|
|
|
+ >
|
|
|
|
|
+ <History size={14} className="text-emerald-600" />
|
|
|
|
|
+ 业务进度与日志 (History)
|
|
|
|
|
+ </button>
|
|
|
|
|
+
|
|
|
|
|
+ <button
|
|
|
|
|
+ onClick={() => setActiveTab('inputs')}
|
|
|
|
|
+ className={`px-3 py-1.5 rounded-lg text-xs font-semibold transition flex items-center gap-1.5 ${
|
|
|
|
|
+ activeTab === 'inputs'
|
|
|
|
|
+ ? 'bg-white text-blue-700 shadow-sm'
|
|
|
|
|
+ : 'text-slate-600 hover:text-slate-900 hover:bg-slate-200/50'
|
|
|
|
|
+ }`}
|
|
|
|
|
+ >
|
|
|
|
|
+ <User size={14} className="text-blue-600" />
|
|
|
|
|
+ 客户输入与参数 (Inputs)
|
|
|
|
|
+ </button>
|
|
|
|
|
+
|
|
|
|
|
+ <button
|
|
|
|
|
+ onClick={() => setActiveTab('config')}
|
|
|
|
|
+ className={`px-3 py-1.5 rounded-lg text-xs font-semibold transition flex items-center gap-1.5 ${
|
|
|
|
|
+ activeTab === 'config'
|
|
|
|
|
+ ? 'bg-white text-purple-700 shadow-sm'
|
|
|
|
|
+ : 'text-slate-600 hover:text-slate-900 hover:bg-slate-200/50'
|
|
|
|
|
+ }`}
|
|
|
|
|
+ >
|
|
|
|
|
+ <FileJson size={14} className="text-purple-600" />
|
|
|
|
|
+ 调度配置 (Config)
|
|
|
|
|
+ </button>
|
|
|
|
|
+
|
|
|
|
|
+ <button
|
|
|
|
|
+ onClick={() => setActiveTab('meta')}
|
|
|
|
|
+ className={`px-3 py-1.5 rounded-lg text-xs font-semibold transition flex items-center gap-1.5 ${
|
|
|
|
|
+ activeTab === 'meta'
|
|
|
|
|
+ ? 'bg-slate-900 text-slate-100 shadow-sm'
|
|
|
|
|
+ : 'text-slate-600 hover:text-slate-900 hover:bg-slate-200/50'
|
|
|
|
|
+ }`}
|
|
|
|
|
+ >
|
|
|
|
|
+ <Terminal size={14} className="text-amber-500" />
|
|
|
|
|
+ 系统调试日志 (Meta)
|
|
|
|
|
+ </button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <div className="flex items-center gap-2">
|
|
|
|
|
+ <button
|
|
|
|
|
+ onClick={() => onEdit(task)}
|
|
|
|
|
+ className="px-2.5 py-1 bg-indigo-50 text-indigo-600 hover:bg-indigo-100 rounded-lg text-xs font-semibold transition flex items-center gap-1"
|
|
|
|
|
+ >
|
|
|
|
|
+ <Edit size={12} />
|
|
|
|
|
+ 修改配置
|
|
|
|
|
+ </button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ {/* Tab Body Content */}
|
|
|
|
|
+ <div className="p-4">
|
|
|
|
|
+ {/* Tab 1: History / Grabbed */}
|
|
|
|
|
+ {activeTab === 'history' && (
|
|
|
|
|
+ <div className="space-y-3">
|
|
|
|
|
+ <div className="flex items-center justify-between">
|
|
|
|
|
+ <span className="text-xs font-bold text-slate-700 flex items-center gap-1.5">
|
|
|
|
|
+ <Sparkles size={14} className="text-emerald-600" />
|
|
|
|
|
+ 业务抓取进展与状态变更轨迹
|
|
|
|
|
+ </span>
|
|
|
|
|
+ <button
|
|
|
|
|
+ onClick={() => copyToClipboard(JSON.stringify(task.grabbed_history, null, 2), 'history')}
|
|
|
|
|
+ className="text-[11px] text-slate-500 hover:text-slate-800 flex items-center gap-1 transition"
|
|
|
|
|
+ >
|
|
|
|
|
+ {copiedKey === 'history' ? <Check size={12} className="text-emerald-600" /> : <Copy size={12} />}
|
|
|
|
|
+ 复制原始 JSON
|
|
|
|
|
+ </button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <div className="bg-slate-50 rounded-xl p-3.5 border border-slate-200 font-mono text-xs max-h-80 overflow-y-auto">
|
|
|
|
|
+ {!task.grabbed_history ||
|
|
|
|
|
+ (Array.isArray(task.grabbed_history) && task.grabbed_history.length === 0) ||
|
|
|
|
|
+ (typeof task.grabbed_history === 'object' &&
|
|
|
|
|
+ Object.keys(task.grabbed_history).length === 0) ? (
|
|
|
|
|
+ <div className="text-slate-400 py-6 text-center italic">
|
|
|
|
|
+ 暂无业务抓取历史日志 (No history records)
|
|
|
|
|
+ </div>
|
|
|
|
|
+ ) : (
|
|
|
|
|
+ <HistoryVisualizer data={task.grabbed_history} />
|
|
|
|
|
+ )}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ )}
|
|
|
|
|
+
|
|
|
|
|
+ {/* Tab 2: User Inputs */}
|
|
|
|
|
+ {activeTab === 'inputs' && (
|
|
|
|
|
+ <div className="space-y-4">
|
|
|
|
|
+ <div className="flex items-center justify-between">
|
|
|
|
|
+ <span className="text-xs font-bold text-slate-700 flex items-center gap-1.5">
|
|
|
|
|
+ <User size={14} className="text-blue-600" />
|
|
|
|
|
+ 客户提交的关键表单参数与联系方式
|
|
|
|
|
+ </span>
|
|
|
|
|
+ <div className="flex items-center gap-2">
|
|
|
|
|
+ <button
|
|
|
|
|
+ onClick={() => onOpenMessage(task, 'whatsapp')}
|
|
|
|
|
+ className="px-2.5 py-1 rounded bg-emerald-50 text-emerald-700 text-xs font-medium hover:bg-emerald-100 flex items-center gap-1"
|
|
|
|
|
+ >
|
|
|
|
|
+ <MessageCircle size={12} /> WhatsApp
|
|
|
|
|
+ </button>
|
|
|
|
|
+ <button
|
|
|
|
|
+ onClick={() => onOpenMessage(task, 'sms')}
|
|
|
|
|
+ className="px-2.5 py-1 rounded bg-amber-50 text-amber-700 text-xs font-medium hover:bg-amber-100 flex items-center gap-1"
|
|
|
|
|
+ >
|
|
|
|
|
+ <MessageSquare size={12} /> 短信
|
|
|
|
|
+ </button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ {!task.user_inputs ? (
|
|
|
|
|
+ <div className="text-slate-400 py-6 text-center italic text-xs">
|
|
|
|
|
+ 暂无客户输入信息 (No user inputs)
|
|
|
|
|
+ </div>
|
|
|
|
|
+ ) : (
|
|
|
|
|
+ <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3">
|
|
|
|
|
+ {Object.entries(task.user_inputs).map(([key, val]) => (
|
|
|
|
|
+ <div
|
|
|
|
|
+ key={key}
|
|
|
|
|
+ className="p-3 bg-slate-50/80 rounded-xl border border-slate-200/80 flex flex-col justify-between"
|
|
|
|
|
+ >
|
|
|
|
|
+ <div className="flex items-center justify-between mb-1">
|
|
|
|
|
+ <span className="text-[10px] font-bold uppercase text-slate-400 tracking-wider">
|
|
|
|
|
+ {key.replace(/_/g, ' ')}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ <button
|
|
|
|
|
+ onClick={() => copyToClipboard(String(val ?? ''), `input-${key}`)}
|
|
|
|
|
+ className="text-slate-400 hover:text-slate-600"
|
|
|
|
|
+ title="复制"
|
|
|
|
|
+ >
|
|
|
|
|
+ {copiedKey === `input-${key}` ? (
|
|
|
|
|
+ <Check size={11} className="text-emerald-600" />
|
|
|
|
|
+ ) : (
|
|
|
|
|
+ <Copy size={11} />
|
|
|
|
|
+ )}
|
|
|
|
|
+ </button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <span className="text-xs font-mono font-semibold text-slate-800 break-all whitespace-pre-wrap">
|
|
|
|
|
+ {typeof val === 'object' ? JSON.stringify(val) : String(val ?? '—')}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ ))}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ )}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ )}
|
|
|
|
|
+
|
|
|
|
|
+ {/* Tab 3: Config */}
|
|
|
|
|
+ {activeTab === 'config' && (
|
|
|
|
|
+ <div className="space-y-3">
|
|
|
|
|
+ <div className="flex items-center justify-between">
|
|
|
|
|
+ <span className="text-xs font-bold text-slate-700 flex items-center gap-1.5">
|
|
|
|
|
+ <FileJson size={14} className="text-purple-600" />
|
|
|
|
|
+ 任务环境调度与脚本配置
|
|
|
|
|
+ </span>
|
|
|
|
|
+ <button
|
|
|
|
|
+ onClick={() => copyToClipboard(JSON.stringify(task.config, null, 2), 'config')}
|
|
|
|
|
+ className="text-[11px] text-slate-500 hover:text-slate-800 flex items-center gap-1 transition"
|
|
|
|
|
+ >
|
|
|
|
|
+ {copiedKey === 'config' ? <Check size={12} className="text-emerald-600" /> : <Copy size={12} />}
|
|
|
|
|
+ 复制 Config JSON
|
|
|
|
|
+ </button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <div className="grid grid-cols-2 sm:grid-cols-4 gap-3 mb-3">
|
|
|
|
|
+ <div className="p-2.5 rounded-lg bg-purple-50/60 border border-purple-100">
|
|
|
|
|
+ <span className="text-[10px] text-purple-700 font-medium block">Routing Key</span>
|
|
|
|
|
+ <span className="font-mono text-xs font-bold text-purple-900 truncate block">
|
|
|
|
|
+ {task.routing_key}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div className="p-2.5 rounded-lg bg-blue-50/60 border border-blue-100">
|
|
|
|
|
+ <span className="text-[10px] text-blue-700 font-medium block">脚本版本</span>
|
|
|
|
|
+ <span className="font-mono text-xs font-bold text-blue-900">
|
|
|
|
|
+ {task.script_version ? `v${task.script_version}` : 'latest'}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div className="p-2.5 rounded-lg bg-amber-50/60 border border-amber-100">
|
|
|
|
|
+ <span className="text-[10px] text-amber-700 font-medium block">重试 / 通知</span>
|
|
|
|
|
+ <span className="font-mono text-xs font-bold text-amber-900">
|
|
|
|
|
+ {task.attempt_count} 次 / {task.notify_count || 0} 次
|
|
|
|
|
+ </span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div className="p-2.5 rounded-lg bg-slate-100 border border-slate-200">
|
|
|
|
|
+ <span className="text-[10px] text-slate-500 font-medium block">任务过期时间</span>
|
|
|
|
|
+ <span className="font-mono text-xs font-semibold text-slate-700 truncate block">
|
|
|
|
|
+ {task.expire_at || '永久有效'}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <pre className="p-3.5 bg-slate-900 text-slate-200 rounded-xl font-mono text-xs overflow-auto max-h-72 whitespace-pre-wrap break-all">
|
|
|
|
|
+ {JSON.stringify(task.config, null, 2) || '{}'}
|
|
|
|
|
+ </pre>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ )}
|
|
|
|
|
+
|
|
|
|
|
+ {/* Tab 4: Meta / Debug Logs */}
|
|
|
|
|
+ {activeTab === 'meta' && (
|
|
|
|
|
+ <div className="space-y-3">
|
|
|
|
|
+ <div className="flex items-center justify-between">
|
|
|
|
|
+ <span className="text-xs font-bold text-slate-700 flex items-center gap-1.5">
|
|
|
|
|
+ <Terminal size={14} className="text-amber-500" />
|
|
|
|
|
+ 系统底层调试日志 (Debug Meta Logs)
|
|
|
</span>
|
|
</span>
|
|
|
|
|
+ <button
|
|
|
|
|
+ onClick={() => copyToClipboard(JSON.stringify(task.meta, null, 2), 'meta')}
|
|
|
|
|
+ className="text-[11px] text-slate-500 hover:text-slate-800 flex items-center gap-1 transition"
|
|
|
|
|
+ >
|
|
|
|
|
+ {copiedKey === 'meta' ? <Check size={12} className="text-emerald-600" /> : <Copy size={12} />}
|
|
|
|
|
+ 复制 Meta 日志
|
|
|
|
|
+ </button>
|
|
|
</div>
|
|
</div>
|
|
|
- ))}
|
|
|
|
|
|
|
+
|
|
|
|
|
+ <div className="bg-slate-950 text-emerald-400 p-4 rounded-xl font-mono text-xs max-h-80 overflow-y-auto border border-slate-800 space-y-1 shadow-inner">
|
|
|
|
|
+ {!task.meta ||
|
|
|
|
|
+ (typeof task.meta === 'object' && Object.keys(task.meta).length === 0) ? (
|
|
|
|
|
+ <div className="text-slate-600 py-6 text-center italic">
|
|
|
|
|
+ 暂无底层调试日志 (No meta logs)
|
|
|
|
|
+ </div>
|
|
|
|
|
+ ) : (
|
|
|
|
|
+ <DebugMetaVisualizer data={task.meta} />
|
|
|
|
|
+ )}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ )}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ );
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 历史日志/抢单结果结构化解析渲染
|
|
|
|
|
+ */
|
|
|
|
|
+function HistoryVisualizer({ data }: { data: any }) {
|
|
|
|
|
+ if (Array.isArray(data)) {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <div className="space-y-2">
|
|
|
|
|
+ {data.map((item, idx) => (
|
|
|
|
|
+ <div
|
|
|
|
|
+ key={idx}
|
|
|
|
|
+ className="p-2.5 rounded-lg bg-white border border-slate-200/80 shadow-xs flex items-start gap-2.5"
|
|
|
|
|
+ >
|
|
|
|
|
+ <span className="w-5 h-5 rounded-full bg-emerald-100 text-emerald-700 font-bold text-[10px] flex items-center justify-center flex-shrink-0 mt-0.5">
|
|
|
|
|
+ {idx + 1}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ <div className="flex-1 break-all whitespace-pre-wrap text-slate-700 text-xs">
|
|
|
|
|
+ {typeof item === 'object' ? JSON.stringify(item, null, 2) : String(item)}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ ))}
|
|
|
</div>
|
|
</div>
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 2. 数组列表
|
|
|
|
|
- if (Array.isArray(data)) {
|
|
|
|
|
- if (data.length === 0) return <span className={`italic ${isDark ? 'text-slate-500' : 'text-slate-400'}`}>{emptyText}</span>;
|
|
|
|
|
|
|
+ if (typeof data === 'object' && data !== null) {
|
|
|
return (
|
|
return (
|
|
|
- <div className="space-y-1">
|
|
|
|
|
- {data.map((line, i) => (
|
|
|
|
|
- <div key={i} className={`flex gap-2 border-b pb-1 last:border-0 ${isDark ? 'border-slate-800' : 'border-slate-50'}`}>
|
|
|
|
|
- <span className={`select-none w-5 text-right flex-shrink-0 ${isDark ? 'text-slate-600' : 'text-slate-300'}`}>{i + 1}</span>
|
|
|
|
|
- {/* 强制换行 break-all */}
|
|
|
|
|
- <span className="break-all whitespace-pre-wrap">{typeof line === 'object' ? JSON.stringify(line) : String(line)}</span>
|
|
|
|
|
|
|
+ <div className="grid grid-cols-1 sm:grid-cols-2 gap-2">
|
|
|
|
|
+ {Object.entries(data).map(([k, v]) => (
|
|
|
|
|
+ <div key={k} className="p-2.5 bg-white rounded-lg border border-slate-200">
|
|
|
|
|
+ <span className="text-[10px] font-bold text-slate-400 uppercase block mb-0.5">
|
|
|
|
|
+ {k.replace(/_/g, ' ')}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ <span className="text-slate-800 break-all whitespace-pre-wrap text-xs font-semibold">
|
|
|
|
|
+ {typeof v === 'object' ? JSON.stringify(v) : String(v)}
|
|
|
|
|
+ </span>
|
|
|
</div>
|
|
</div>
|
|
|
))}
|
|
))}
|
|
|
</div>
|
|
</div>
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return <span className="break-all whitespace-pre-wrap">{String(data)}</span>;
|
|
|
|
|
|
|
+ return <div className="break-all whitespace-pre-wrap text-slate-700">{String(data)}</div>;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// === 修改点 3:详情布局增加 min-w-0 防止 flex 子项被撑大 ===
|
|
|
|
|
-function TaskDetailContent({ task }: { task: VasTask }) {
|
|
|
|
|
- return (
|
|
|
|
|
- // 添加 w-full 确保在 table cell 内部占满宽度
|
|
|
|
|
- <div className="w-full grid grid-cols-1 lg:grid-cols-3 gap-6 text-xs">
|
|
|
|
|
-
|
|
|
|
|
- {/* Col 1: Config & Inputs - 增加 min-w-0 */}
|
|
|
|
|
- <div className="space-y-4 min-w-0">
|
|
|
|
|
- <div className="bg-white border border-slate-200 rounded-lg overflow-hidden flex flex-col">
|
|
|
|
|
- <div className="px-3 py-2 bg-slate-100 border-b border-slate-200 font-bold text-slate-600 flex items-center gap-2">
|
|
|
|
|
- <FileJson size={14} /> Config
|
|
|
|
|
- </div>
|
|
|
|
|
- {/* 限制最大高度,如果JSON很长则滚动 */}
|
|
|
|
|
- <pre className="p-3 overflow-auto text-slate-600 font-mono max-h-[200px] whitespace-pre-wrap break-all">
|
|
|
|
|
- {JSON.stringify(task.config, null, 2)}
|
|
|
|
|
- </pre>
|
|
|
|
|
- </div>
|
|
|
|
|
- <div className="bg-white border border-slate-200 rounded-lg overflow-hidden flex flex-col">
|
|
|
|
|
- <div className="px-3 py-2 bg-slate-100 border-b border-slate-200 font-bold text-blue-600 flex items-center gap-2">
|
|
|
|
|
- <User size={14} /> User Inputs
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 暗色终端模式调试日志解析渲染
|
|
|
|
|
+ */
|
|
|
|
|
+function DebugMetaVisualizer({ data }: { data: any }) {
|
|
|
|
|
+ if (typeof data === 'object' && !Array.isArray(data) && data !== null) {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <div className="space-y-1.5">
|
|
|
|
|
+ {Object.entries(data).map(([k, v]) => (
|
|
|
|
|
+ <div key={k} className="border-b border-slate-900/80 pb-1.5 last:border-0">
|
|
|
|
|
+ <span className="text-amber-400 font-semibold text-[11px] mr-2">[{k}]:</span>
|
|
|
|
|
+ <span className="text-slate-300 break-all whitespace-pre-wrap">
|
|
|
|
|
+ {typeof v === 'object' ? JSON.stringify(v, null, 2) : String(v)}
|
|
|
|
|
+ </span>
|
|
|
</div>
|
|
</div>
|
|
|
- <pre className="p-3 overflow-auto text-slate-600 font-mono max-h-[200px] whitespace-pre-wrap break-all">
|
|
|
|
|
- {JSON.stringify(task.user_inputs, null, 2)}
|
|
|
|
|
- </pre>
|
|
|
|
|
- </div>
|
|
|
|
|
- </div>
|
|
|
|
|
-
|
|
|
|
|
- {/* Col 2: History - 增加 min-w-0 */}
|
|
|
|
|
- <div className="min-w-0 bg-white border border-slate-200 rounded-lg overflow-hidden flex flex-col h-full max-h-[400px]">
|
|
|
|
|
- <div className="px-3 py-2 bg-green-50 border-b border-green-100 font-bold text-green-800 flex items-center gap-2">
|
|
|
|
|
- <History size={14} /> Grabbed Info / History
|
|
|
|
|
- </div>
|
|
|
|
|
- <div className="p-3 overflow-y-auto flex-1 font-mono">
|
|
|
|
|
- <DataVisualizer data={task.grabbed_history} emptyText="暂无业务日志" isDark={false} />
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ ))}
|
|
|
</div>
|
|
</div>
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- {/* Col 3: Meta - 增加 min-w-0 */}
|
|
|
|
|
- <div className="min-w-0 bg-slate-900 border border-slate-800 rounded-lg overflow-hidden flex flex-col h-full max-h-[400px] text-slate-300">
|
|
|
|
|
- <div className="px-3 py-2 bg-slate-950 border-b border-slate-800 font-bold text-slate-100 flex items-center gap-2">
|
|
|
|
|
- <Terminal size={14} /> Debug Logs (Meta)
|
|
|
|
|
- </div>
|
|
|
|
|
- <div className="p-3 overflow-y-auto flex-1 font-mono text-[11px]">
|
|
|
|
|
- <DataVisualizer data={task.meta} emptyText="暂无调试信息" isDark={true} />
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ if (Array.isArray(data)) {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <div className="space-y-1">
|
|
|
|
|
+ {data.map((item, idx) => (
|
|
|
|
|
+ <div key={idx} className="flex gap-2 border-b border-slate-900 pb-1">
|
|
|
|
|
+ <span className="text-slate-600 select-none w-5 text-right flex-shrink-0">
|
|
|
|
|
+ {idx + 1}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ <span className="text-slate-300 break-all whitespace-pre-wrap">
|
|
|
|
|
+ {typeof item === 'object' ? JSON.stringify(item) : String(item)}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ ))}
|
|
|
</div>
|
|
</div>
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- </div>
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ return <div className="break-all whitespace-pre-wrap text-slate-300">{String(data)}</div>;
|
|
|
}
|
|
}
|