789 lines
34 KiB
Vue
789 lines
34 KiB
Vue
<script setup lang="ts">
|
||
/**
|
||
* features/chat/components/ShippingBatchWorkspaceDrawer.vue
|
||
* 用途:发货通知 Agent 的右侧批次工作台抽屉,承载多批次切换、任务筛选、步骤诊断与统一动作入口。
|
||
* 依赖:shippingStepper、shippingMenu、shipping.api.types、vue-i18n、lucide-vue-next。
|
||
* 逻辑:上游传入会话级 workspace 与当前批次任务;本组件只渲染后端 `ui_state.action_buttons` 和查看类辅助入口。
|
||
* 解析阶段诊断优先展示 `ui_state.summary.issues` 完整问题列表;「重试所有失败」仅 emit `retry-pending`,由父级打开确认弹窗后再调用 useChatShipping 执行。
|
||
*/
|
||
import { computed, ref, watch } from 'vue';
|
||
import { RefreshCw, Target, X } from 'lucide-vue-next';
|
||
import { useI18n } from 'vue-i18n';
|
||
import {
|
||
resolveShippingWorkflowSteps,
|
||
type ShippingWorkflowStepItem,
|
||
} from '@/features/chat/shipping';
|
||
import { sanitizeShippingRuntimeStatusText } from '@/features/chat/shipping/shippingText';
|
||
import { reportShippingDebugEvent } from '@/features/chat/shipping/shippingDebugReporter';
|
||
import {
|
||
isShippingWorkspaceTerminalTask,
|
||
resolveShippingWorkspaceActionButtons,
|
||
} from '@/features/chat/shipping/shippingWorkspaceActions';
|
||
import { hasShortageLines } from '@/features/chat/shipping/shippingShortageDetails';
|
||
import type {
|
||
ShippingBatchSummary,
|
||
ShippingConversationWorkspace,
|
||
ShippingChatAction,
|
||
ShippingTaskDetail,
|
||
ShippingTaskSummary,
|
||
} from '@/features/chat/api/shipping.api';
|
||
|
||
const props = defineProps<{
|
||
open: boolean;
|
||
conversationWorkspace: ShippingConversationWorkspace | null;
|
||
activeBatchNo: string;
|
||
focusedTaskNo: string;
|
||
batchSummary: ShippingBatchSummary | null;
|
||
batchTasks: ShippingTaskSummary[];
|
||
activeTaskDetail: ShippingTaskDetail | null;
|
||
retryingPending?: boolean;
|
||
actionBusy?: boolean;
|
||
}>();
|
||
|
||
const emit = defineEmits<{
|
||
'update:open': [value: boolean];
|
||
'switch-batch': [batchNo: string];
|
||
'focus-task': [taskNo: string];
|
||
'workspace-action': [taskNo: string, action: ShippingChatAction];
|
||
'query-shortage': [taskNo: string];
|
||
'retry-pending': [];
|
||
}>();
|
||
|
||
const { t } = useI18n();
|
||
const activeFilter = ref<'all' | 'abnormal' | 'waitingHuman' | 'resumable' | 'completed'>('all');
|
||
|
||
// #region debug-point A:workspace-click
|
||
const reportRetryRpaDebug = (hypothesisId: string, msg: string, data: Record<string, unknown>) =>
|
||
reportShippingDebugEvent('ShippingBatchWorkspaceDrawer.vue', hypothesisId, msg, data);
|
||
// #endregion
|
||
|
||
const workspaceBatches = computed(() => props.conversationWorkspace?.batches || []);
|
||
const activeBatchNo = computed(() =>
|
||
String(props.activeBatchNo || props.batchSummary?.batch_no || workspaceBatches.value[0]?.batch_no || '').trim(),
|
||
);
|
||
|
||
const isFailedTask = (task: ShippingTaskSummary | ShippingTaskDetail) =>
|
||
task.upload_status === 'failed' || String(task.process_status || '').trim() === 'upload_failed';
|
||
|
||
const isCompletedTask = (task: ShippingTaskSummary | ShippingTaskDetail) =>
|
||
isShippingWorkspaceTerminalTask(task);
|
||
|
||
const isAbnormalTask = (task: ShippingTaskSummary | ShippingTaskDetail) =>
|
||
!isCompletedTask(task)
|
||
&& (isFailedTask(task)
|
||
|| Boolean(task.review_status || task.pending_human_reason)
|
||
|| String(task.process_status || '').trim() === 'waiting_inventory');
|
||
|
||
const isWaitingHumanTask = (task: ShippingTaskSummary | ShippingTaskDetail) =>
|
||
!isCompletedTask(task) && !isFailedTask(task) && Boolean(task.review_status || task.pending_human_reason);
|
||
|
||
const isResumableTask = (task: ShippingTaskSummary | ShippingTaskDetail) =>
|
||
!isCompletedTask(task) && !isWaitingHumanTask(task) && (
|
||
isFailedTask(task)
|
||
|| ['created', 'parsed', 'inventory_ready', 'matched', 'waiting_upload'].includes(String(task.process_status || '').trim())
|
||
);
|
||
|
||
const resolveWorkspaceActionButtons = (task: ShippingTaskSummary | ShippingTaskDetail): ShippingChatAction[] =>
|
||
resolveShippingWorkspaceActionButtons(task);
|
||
|
||
const rpaRuntimeMode = (task: ShippingTaskSummary | ShippingTaskDetail) =>
|
||
String(task.rpa_runtime?.mode || '').trim().toLowerCase();
|
||
|
||
const rpaRuntimeLabel = (task: ShippingTaskSummary | ShippingTaskDetail) => {
|
||
const mode = rpaRuntimeMode(task);
|
||
if (mode === 'mock') return t('chat.shippingNoticeUi.rpaModeMock');
|
||
if (mode === 'browser') return t('chat.shippingNoticeUi.rpaModeBrowser');
|
||
return String(task.rpa_runtime?.label || '').trim() || t('chat.shippingNoticeUi.rpaModeUnknown');
|
||
};
|
||
|
||
const rpaRuntimeBadgeClass = (task: ShippingTaskSummary | ShippingTaskDetail) =>
|
||
rpaRuntimeMode(task) === 'mock'
|
||
? 'border-amber-200 bg-amber-50 text-amber-700'
|
||
: 'border-emerald-200 bg-emerald-50 text-emerald-700';
|
||
|
||
/**
|
||
* 渲染工作台任务卡中的辅助动作按钮样式。
|
||
* 核心逻辑:把“聚焦当前任务 / 查询缺口明细”降级成轻量辅助入口,避免与后端主业务动作抢视觉权重。
|
||
* @param kind - 当前辅助动作的视觉类型
|
||
* @returns 对应的 Tailwind class 字符串
|
||
*/
|
||
const resolveWorkspaceAssistButtonClass = (kind: 'focus' | 'shortage') => {
|
||
if (kind === 'shortage') {
|
||
return 'inline-flex min-h-[32px] items-center justify-center gap-1.5 rounded-lg border border-amber-200 bg-amber-50/90 px-2.5 py-1.5 text-xs font-semibold text-amber-700 transition-all hover:border-amber-300 hover:bg-amber-100 disabled:cursor-not-allowed disabled:opacity-60';
|
||
}
|
||
return 'inline-flex min-h-[32px] items-center justify-center gap-1.5 rounded-lg border border-slate-200 bg-slate-50/90 px-2.5 py-1.5 text-xs font-semibold text-slate-700 transition-all hover:border-brand-200 hover:bg-white hover:text-brand-700 disabled:cursor-not-allowed disabled:opacity-60';
|
||
};
|
||
|
||
/**
|
||
* 渲染工作台任务卡中的业务动作按钮样式。
|
||
* 核心逻辑:主动作在右侧工作台里使用更强的卡片式按钮承载,优先突出 primary,secondary/danger 维持次级密度。
|
||
* @param action - 后端返回的结构化动作按钮
|
||
* @param total - 当前任务业务动作总数,用于控制按钮跨列布局
|
||
* @returns 对应的 Tailwind class 字符串
|
||
*/
|
||
const resolveWorkspaceTaskActionClass = (action: ShippingChatAction, total: number) => {
|
||
const spanClass = action.variant === 'primary' || total === 1 ? 'col-span-2' : 'col-span-1';
|
||
if (action.variant === 'primary') {
|
||
return `${spanClass} inline-flex min-h-[36px] items-center justify-center rounded-lg bg-gradient-to-r from-brand-600 to-sky-500 px-3 py-1.5 text-sm font-semibold text-white shadow-sm transition-all hover:-translate-y-[1px] hover:from-brand-700 hover:to-sky-600 disabled:cursor-not-allowed disabled:opacity-60`;
|
||
}
|
||
if (action.variant === 'danger') {
|
||
return `${spanClass} inline-flex min-h-[36px] items-center justify-center rounded-lg border border-rose-200 bg-rose-50 px-3 py-1.5 text-sm font-semibold text-rose-700 transition-all hover:border-rose-300 hover:bg-rose-100 disabled:cursor-not-allowed disabled:opacity-60`;
|
||
}
|
||
return `${spanClass} inline-flex min-h-[36px] items-center justify-center rounded-lg border border-slate-200 bg-white px-3 py-1.5 text-sm font-semibold text-slate-700 shadow-sm transition-all hover:border-brand-200 hover:bg-brand-50 hover:text-brand-700 disabled:cursor-not-allowed disabled:opacity-60`;
|
||
};
|
||
|
||
// #region debug-point A:workspace-action
|
||
const emitWorkspaceAction = (
|
||
task: ShippingTaskSummary | ShippingTaskDetail,
|
||
action: ShippingChatAction,
|
||
) => {
|
||
void reportRetryRpaDebug('A', 'workspace action clicked', {
|
||
actionId: String(action.id || ''),
|
||
actionBusy: Boolean(props.actionBusy),
|
||
taskNo: String(task.task_no || '').trim().toUpperCase(),
|
||
processStatus: String(task.process_status || ''),
|
||
pendingHumanReason: String(task.pending_human_reason || ''),
|
||
focusedTaskNo: String(props.focusedTaskNo || props.activeTaskDetail?.task_no || '').trim().toUpperCase(),
|
||
});
|
||
emit('workspace-action', task.task_no, action);
|
||
};
|
||
// #endregion
|
||
|
||
// #region debug-point A:workspace-busy-state
|
||
watch(
|
||
() => [Boolean(props.actionBusy), String(props.focusedTaskNo || ''), String(props.activeTaskDetail?.task_no || '')].join('|'),
|
||
() => {
|
||
void reportRetryRpaDebug('A', 'workspace busy state snapshot', {
|
||
actionBusy: Boolean(props.actionBusy),
|
||
focusedTaskNo: String(props.focusedTaskNo || '').trim().toUpperCase(),
|
||
activeDetailTaskNo: String(props.activeTaskDetail?.task_no || '').trim().toUpperCase(),
|
||
activeDetailStatus: String(props.activeTaskDetail?.process_status || ''),
|
||
activeDetailPendingReason: String(props.activeTaskDetail?.pending_human_reason || ''),
|
||
open: props.open,
|
||
});
|
||
},
|
||
{ immediate: true },
|
||
);
|
||
// #endregion
|
||
|
||
const batchAbnormalCount = (batch: ShippingBatchSummary) => {
|
||
const summary = batch.process_summary || {};
|
||
return Number(summary.failed || 0) + Number((summary as { needs_human?: number }).needs_human || 0);
|
||
};
|
||
|
||
const batchCompletedCount = (batch: ShippingBatchSummary) =>
|
||
Number(batch.process_summary?.completed || 0);
|
||
|
||
const batchTotalCount = (batch: ShippingBatchSummary) =>
|
||
Number(batch.process_summary?.total || batch.file_count || 0);
|
||
|
||
const taskCounts = computed(() => {
|
||
const tasks = props.batchTasks || [];
|
||
const completed = tasks.filter(isCompletedTask).length;
|
||
const abnormal = tasks.filter(isAbnormalTask).length;
|
||
const waitingHuman = tasks.filter(isWaitingHumanTask).length;
|
||
const resumable = tasks.filter(isResumableTask).length;
|
||
return {
|
||
total: tasks.length,
|
||
abnormal,
|
||
waitingHuman,
|
||
resumable,
|
||
completed,
|
||
};
|
||
});
|
||
|
||
const filteredTasks = computed(() => {
|
||
const tasks = props.batchTasks || [];
|
||
if (activeFilter.value === 'abnormal') return tasks.filter(isAbnormalTask);
|
||
if (activeFilter.value === 'waitingHuman') return tasks.filter(isWaitingHumanTask);
|
||
if (activeFilter.value === 'resumable') return tasks.filter(isResumableTask);
|
||
if (activeFilter.value === 'completed') return tasks.filter(isCompletedTask);
|
||
return tasks;
|
||
});
|
||
|
||
const isCurrentTask = (taskNo?: string | null) =>
|
||
String(taskNo || '').trim().toUpperCase() === String(props.focusedTaskNo || props.activeTaskDetail?.task_no || '').trim().toUpperCase();
|
||
|
||
const resolveTaskStateMeta = (task: ShippingTaskSummary | ShippingTaskDetail) => {
|
||
if (isCompletedTask(task)) {
|
||
return { text: t('chat.shippingNoticeUi.completedState'), className: 'border-emerald-100 bg-emerald-50 text-emerald-700' };
|
||
}
|
||
if (isFailedTask(task)) {
|
||
return { text: t('chat.shippingNoticeUi.status.uploadFailed'), className: 'border-rose-100 bg-rose-50 text-rose-700' };
|
||
}
|
||
if (isAbnormalTask(task)) {
|
||
return { text: t('chat.shippingNoticeUi.pendingState'), className: 'border-amber-100 bg-amber-50 text-amber-700' };
|
||
}
|
||
return { text: t('chat.shippingNoticeUi.runningState'), className: 'border-sky-100 bg-sky-50 text-brand-700' };
|
||
};
|
||
|
||
const taskWorkflowSteps = (task: ShippingTaskSummary | ShippingTaskDetail) => (
|
||
resolveShippingWorkflowSteps(task)
|
||
);
|
||
|
||
const taskStepNumber = (task: ShippingTaskSummary | ShippingTaskDetail) =>
|
||
resolveActiveStep(taskWorkflowSteps(task)) + 1;
|
||
|
||
const taskStepHeadline = (task: ShippingTaskSummary | ShippingTaskDetail) => {
|
||
const steps = taskWorkflowSteps(task);
|
||
const index = resolveActiveStep(steps);
|
||
const step = steps[index];
|
||
return step ? t('chat.shippingNoticeUi.stepHeadline', {
|
||
current: index + 1,
|
||
total: steps.length,
|
||
label: step.label.startsWith('chat.') ? t(step.label) : step.label,
|
||
}) : t('chat.shippingNoticeUi.stepFraction', { current: index + 1, total: steps.length });
|
||
};
|
||
|
||
const currentStepProgress = (task: ShippingTaskSummary | ShippingTaskDetail) =>
|
||
task.step_payload?.current_step_progress || null;
|
||
|
||
/**
|
||
* 规范化工作台中的运行态诊断文案。
|
||
* 核心逻辑:右侧工作台属于业务操作面,不展示“第几次重试”这类过程计数,只保留状态与建议。
|
||
* @param text - 后端返回的 summary / progress / error 文本
|
||
* @returns 面向业务用户的净化后文案
|
||
*/
|
||
const sanitizeDiagnosisCopy = (text: string | null | undefined) =>
|
||
sanitizeShippingRuntimeStatusText(String(text || '').trim());
|
||
|
||
/**
|
||
* 读取任务诊断卡要展示的全部问题列表。
|
||
* 核心逻辑:优先消费后端 `ui_state.summary.issues`(解析阶段已汇总库存源+warnings);
|
||
* 若缺失则回退到单一 error_message,保证旧数据仍有可读文案。
|
||
*/
|
||
const resolveTaskDiagnosisIssues = (task: ShippingTaskSummary | ShippingTaskDetail): string[] => {
|
||
const uiIssues = task.ui_state?.summary?.issues;
|
||
if (Array.isArray(uiIssues) && uiIssues.length) {
|
||
return uiIssues
|
||
.map((item) => sanitizeDiagnosisCopy(item))
|
||
.filter(Boolean);
|
||
}
|
||
const fallback = sanitizeDiagnosisCopy(task.ui_state?.summary?.error_message || task.error_message);
|
||
return fallback ? [fallback] : [];
|
||
};
|
||
|
||
/**
|
||
* 解析右侧工作台诊断标题/建议/问题列表。
|
||
* 核心逻辑:解析阶段若 issues 多于 1 条,使用「发现问题」标题并列出全部条目,避免只显示库存源一条。
|
||
*/
|
||
const resolveTaskDiagnosis = (task: ShippingTaskSummary | ShippingTaskDetail) => {
|
||
const uiSummary = task.ui_state?.summary;
|
||
const issues = resolveTaskDiagnosisIssues(task);
|
||
if (uiSummary?.title || uiSummary?.message || uiSummary?.error_message || issues.length) {
|
||
const multiIssue = issues.length > 1;
|
||
return {
|
||
title: multiIssue
|
||
? t('chat.shippingNoticeUi.diagnosisIssuesTitle', { count: issues.length })
|
||
: (
|
||
sanitizeDiagnosisCopy(issues[0] || uiSummary?.error_message || uiSummary?.title)
|
||
|| t('chat.shippingNoticeUi.diagnosisStepWaitingTitle', { step: taskStepNumber(task) })
|
||
),
|
||
advice: multiIssue
|
||
? t('chat.shippingNoticeUi.diagnosisIssuesAdvice')
|
||
: (sanitizeDiagnosisCopy(uiSummary?.message) || t('chat.shippingNoticeUi.diagnosisStepWaitingAdvice')),
|
||
issues: multiIssue ? issues : [],
|
||
};
|
||
}
|
||
const reason = String(task.pending_human_reason || '').trim();
|
||
const reviewStatus = String(task.review_status || '').trim();
|
||
const processStatus = String(task.process_status || '').trim();
|
||
const explicitError = String(task.error_message || '').trim();
|
||
const progress = currentStepProgress(task);
|
||
const progressMessage = String(progress?.message || '').trim();
|
||
const progressDetail = String(progress?.detail || '').trim();
|
||
const step = taskStepNumber(task);
|
||
|
||
if (isCompletedTask(task)) {
|
||
return {
|
||
title: t('chat.shippingNoticeUi.diagnosisCompletedTitle'),
|
||
advice: t('chat.shippingNoticeUi.diagnosisCompletedAdvice'),
|
||
};
|
||
}
|
||
if (progressMessage && reason === 'rpa_pending') {
|
||
return {
|
||
title: sanitizeDiagnosisCopy(progressMessage),
|
||
advice: sanitizeDiagnosisCopy(progressDetail) || t('chat.shippingNoticeUi.diagnosisInventoryRpaAdvice'),
|
||
};
|
||
}
|
||
if (explicitError) {
|
||
return {
|
||
title: sanitizeDiagnosisCopy(explicitError),
|
||
advice: sanitizeDiagnosisCopy(progressDetail) || t('chat.shippingNoticeUi.diagnosisAdviceRetryOrFocus'),
|
||
};
|
||
}
|
||
if (progressMessage && (isAbnormalTask(task) || progress?.status === 'needs_human')) {
|
||
return {
|
||
title: sanitizeDiagnosisCopy(progressMessage),
|
||
advice: sanitizeDiagnosisCopy(progressDetail) || t('chat.shippingNoticeUi.diagnosisStepWaitingAdvice'),
|
||
};
|
||
}
|
||
if (isFailedTask(task) || reason === 'upload_rpa_failed') {
|
||
return {
|
||
title: t('chat.shippingNoticeUi.diagnosisUploadFailedTitle'),
|
||
advice: t('chat.shippingNoticeUi.diagnosisUploadFailedAdvice'),
|
||
};
|
||
}
|
||
if (reason === 'shortage' || reason === 'shortage_review' || reviewStatus === 'shortage_review') {
|
||
return {
|
||
title: t('chat.shippingNoticeUi.diagnosisShortageTitle'),
|
||
advice: t('chat.shippingNoticeUi.diagnosisShortageAdvice'),
|
||
};
|
||
}
|
||
if (reason === 'rpa_exhausted' || reason === 'rpa_pending' || reason === 'inv_unavail') {
|
||
return {
|
||
title: t('chat.shippingNoticeUi.diagnosisInventoryRpaTitle'),
|
||
advice: t('chat.shippingNoticeUi.diagnosisInventoryRpaAdvice'),
|
||
};
|
||
}
|
||
if (reason === 'align_review' || reviewStatus === 'align_review') {
|
||
return {
|
||
title: t('chat.shippingNoticeUi.diagnosisAlignReviewTitle'),
|
||
advice: t('chat.shippingNoticeUi.diagnosisAlignReviewAdvice'),
|
||
};
|
||
}
|
||
if (reason === 'low_confidence' || reviewStatus === 'parse_review') {
|
||
return {
|
||
title: t('chat.shippingNoticeUi.diagnosisParseReviewTitle'),
|
||
advice: t('chat.shippingNoticeUi.diagnosisParseReviewAdvice'),
|
||
};
|
||
}
|
||
if (reason === 'rsv_required' || reviewStatus === 'rsv_required') {
|
||
return {
|
||
title: t('chat.shippingNoticeUi.diagnosisReservationRequiredTitle'),
|
||
advice: t('chat.shippingNoticeUi.diagnosisReservationRequiredAdvice'),
|
||
};
|
||
}
|
||
if (reason === 'inventory_source_unresolved') {
|
||
const resolution = (task as ShippingTaskDetail).inventory_source_resolution;
|
||
const status = resolution && typeof resolution === 'object'
|
||
? String((resolution as { status?: unknown }).status || '').trim()
|
||
: '';
|
||
const isAmbiguous = status === 'ambiguous';
|
||
return {
|
||
title: t(isAmbiguous
|
||
? 'chat.shippingNoticeUi.diagnosisInventorySourceAmbiguousTitle'
|
||
: 'chat.shippingNoticeUi.diagnosisInventorySourceTitle'),
|
||
advice: t(isAmbiguous
|
||
? 'chat.shippingNoticeUi.diagnosisInventorySourceAmbiguousAdvice'
|
||
: 'chat.shippingNoticeUi.diagnosisInventorySourceAdvice'),
|
||
};
|
||
}
|
||
if (reason === 'map_infer' || processStatus === 'waiting_inventory') {
|
||
return {
|
||
title: t('chat.shippingNoticeUi.diagnosisInventoryWaitingTitle'),
|
||
advice: t('chat.shippingNoticeUi.diagnosisInventoryWaitingAdvice'),
|
||
};
|
||
}
|
||
return {
|
||
title: t('chat.shippingNoticeUi.diagnosisStepWaitingTitle', { step }),
|
||
advice: t('chat.shippingNoticeUi.diagnosisStepWaitingAdvice'),
|
||
};
|
||
};
|
||
|
||
const resolveSuggestedAction = (task: ShippingTaskSummary | ShippingTaskDetail) => {
|
||
const actions = resolveWorkspaceActionButtons(task);
|
||
if (actions.length) {
|
||
return actions.map((action) => action.label).join(' / ');
|
||
}
|
||
const reason = String(task.pending_human_reason || '').trim();
|
||
const reviewStatus = String(task.review_status || '').trim();
|
||
if (hasShortageLines(task) || reason === 'shortage' || reviewStatus === 'shortage_review') {
|
||
return t('chat.shippingNoticeUi.suggestShortageActions');
|
||
}
|
||
if (reason === 'align_review' || reviewStatus === 'align_review') {
|
||
return t('chat.shippingNoticeUi.suggestConfirmMapping');
|
||
}
|
||
if (reason === 'low_confidence' || reviewStatus === 'parse_review') {
|
||
return t('chat.shippingNoticeUi.suggestReviewParse');
|
||
}
|
||
if (reason === 'inventory_source_unresolved') {
|
||
return t('chat.shippingNoticeUi.suggestConfirmInventorySource');
|
||
}
|
||
if (isFailedTask(task)) {
|
||
return t('chat.shippingNoticeUi.suggestRetryStep');
|
||
}
|
||
if (isCompletedTask(task)) {
|
||
return t('chat.shippingNoticeUi.suggestViewOnly');
|
||
}
|
||
return t('chat.shippingNoticeUi.suggestContinue');
|
||
};
|
||
|
||
const resolveActiveStep = (steps: Array<ShippingWorkflowStepItem | { status: string }>) => {
|
||
const activeIndex = steps.findIndex((step) => step.status === 'current' || step.status === 'blocked');
|
||
return activeIndex >= 0 ? activeIndex : Math.max(0, steps.length - 1);
|
||
};
|
||
|
||
const handleSwitchBatch = (batchNo: string) => {
|
||
if (!batchNo || batchNo === activeBatchNo.value) return;
|
||
activeFilter.value = 'all';
|
||
emit('switch-batch', batchNo);
|
||
};
|
||
</script>
|
||
|
||
<template>
|
||
<aside
|
||
v-if="open"
|
||
class="hidden h-full w-[520px] shrink-0 flex-col border-l border-default bg-surface shadow-[-12px_0_40px_rgba(15,23,42,0.08)] lg:flex"
|
||
>
|
||
<header class="flex h-[92px] shrink-0 items-center justify-between border-b border-default px-6">
|
||
<div>
|
||
<div class="flex items-center gap-2 text-lg font-bold text-primary">
|
||
<span class="grid h-5 w-5 grid-cols-2 gap-0.5 text-brand-500">
|
||
<span class="rounded-sm bg-current"></span>
|
||
<span class="rounded-sm border border-current"></span>
|
||
<span class="rounded-sm border border-current"></span>
|
||
<span class="rounded-sm bg-current"></span>
|
||
</span>
|
||
{{ t('chat.shippingNoticeUi.batchWorkspaceTitle') }}
|
||
</div>
|
||
<p class="mt-1 text-[11px] text-muted">{{ t('chat.shippingNoticeUi.batchWorkspaceSubtitle') }}</p>
|
||
</div>
|
||
<button
|
||
type="button"
|
||
class="flex h-9 w-9 items-center justify-center rounded-full text-muted transition hover:bg-surface-soft hover:text-primary"
|
||
@click="emit('update:open', false)"
|
||
>
|
||
<X class="h-5 w-5" />
|
||
</button>
|
||
</header>
|
||
|
||
<div class="border-b border-default px-6 py-5">
|
||
<div class="flex gap-3 overflow-x-auto pb-1">
|
||
<button
|
||
v-for="batch in workspaceBatches"
|
||
:key="batch.batch_no"
|
||
type="button"
|
||
class="relative w-44 shrink-0 overflow-hidden rounded-xl border p-3 text-left transition-colors"
|
||
:class="batch.batch_no === activeBatchNo ? 'border-brand-300 bg-surface shadow-sm ring-1 ring-brand-100' : 'border-default bg-transparent hover:bg-surface-soft'"
|
||
@click="handleSwitchBatch(batch.batch_no)"
|
||
>
|
||
<div
|
||
v-if="batch.batch_no === activeBatchNo"
|
||
class="absolute left-0 top-0 h-1 w-full bg-brand-500"
|
||
></div>
|
||
<div class="mb-1 truncate font-mono text-xs font-bold text-primary">{{ batch.batch_no }}</div>
|
||
<div class="text-[10px] font-medium text-muted">
|
||
{{
|
||
batchAbnormalCount(batch) > 0
|
||
? t('chat.shippingNoticeUi.batchTabAbnormal', { completed: batchCompletedCount(batch), abnormal: batchAbnormalCount(batch) })
|
||
: t('chat.shippingNoticeUi.batchTabNormal', { total: batchTotalCount(batch) })
|
||
}}
|
||
</div>
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="flex-1 overflow-y-auto px-6 py-6">
|
||
<section class="rounded-lg border border-default bg-surface p-4 shadow-sm">
|
||
<h3 class="text-sm font-bold text-primary">{{ t('chat.shippingNoticeUi.taskQueueTitle') }}</h3>
|
||
<p class="mt-1 text-xs leading-5 text-muted">{{ t('chat.shippingNoticeUi.taskQueueHint') }}</p>
|
||
<div class="mt-4">
|
||
<button
|
||
type="button"
|
||
class="inline-flex w-full items-center justify-center gap-2 rounded-lg border border-default bg-white py-2 text-xs font-medium text-secondary transition hover:border-brand-300 hover:bg-brand-50 hover:text-brand-700 disabled:cursor-not-allowed disabled:opacity-60"
|
||
:disabled="retryingPending || actionBusy"
|
||
@click="emit('retry-pending')"
|
||
>
|
||
<RefreshCw class="h-3.5 w-3.5" :class="retryingPending ? 'animate-spin' : ''" />
|
||
{{ retryingPending ? t('chat.shippingNoticeUi.retrying') : t('chat.shippingNoticeUi.retryFailedTasks') }}
|
||
</button>
|
||
</div>
|
||
<div class="mt-3 rounded-lg border border-indigo-100 bg-indigo-50 p-3 text-xs leading-5 text-indigo-900/80">
|
||
{{ t('chat.shippingNoticeUi.batchActionSafetyNotice') }}
|
||
</div>
|
||
</section>
|
||
|
||
<section class="mt-6">
|
||
<div class="mb-3 flex items-center justify-between gap-3">
|
||
<h3 class="text-sm font-bold text-primary">
|
||
{{ t('chat.shippingNoticeUi.taskDetailCount', { count: filteredTasks.length }) }}
|
||
</h3>
|
||
<div class="flex flex-wrap rounded-lg bg-slate-100 p-1 text-xs">
|
||
<button
|
||
type="button"
|
||
class="rounded px-3 py-1 transition-colors"
|
||
:class="activeFilter === 'all' ? 'bg-white text-primary shadow-sm' : 'text-muted hover:text-secondary'"
|
||
@click="activeFilter = 'all'"
|
||
>
|
||
{{ t('chat.shippingNoticeUi.filterAll') }}
|
||
</button>
|
||
<button
|
||
type="button"
|
||
class="rounded px-3 py-1 transition-colors"
|
||
:class="activeFilter === 'abnormal' ? 'bg-white text-primary shadow-sm' : 'text-muted hover:text-secondary'"
|
||
@click="activeFilter = 'abnormal'"
|
||
>
|
||
{{ t('chat.shippingNoticeUi.filterAbnormal', { count: taskCounts.abnormal }) }}
|
||
</button>
|
||
<button
|
||
type="button"
|
||
class="rounded px-3 py-1 transition-colors"
|
||
:class="activeFilter === 'waitingHuman' ? 'bg-white text-primary shadow-sm' : 'text-muted hover:text-secondary'"
|
||
@click="activeFilter = 'waitingHuman'"
|
||
>
|
||
{{ t('chat.shippingNoticeUi.filterWaitingHuman', { count: taskCounts.waitingHuman }) }}
|
||
</button>
|
||
<button
|
||
type="button"
|
||
class="rounded px-3 py-1 transition-colors"
|
||
:class="activeFilter === 'resumable' ? 'bg-white text-primary shadow-sm' : 'text-muted hover:text-secondary'"
|
||
@click="activeFilter = 'resumable'"
|
||
>
|
||
{{ t('chat.shippingNoticeUi.filterResumable', { count: taskCounts.resumable }) }}
|
||
</button>
|
||
<button
|
||
type="button"
|
||
class="rounded px-3 py-1 transition-colors"
|
||
:class="activeFilter === 'completed' ? 'bg-white text-primary shadow-sm' : 'text-muted hover:text-secondary'"
|
||
@click="activeFilter = 'completed'"
|
||
>
|
||
{{ t('chat.shippingNoticeUi.filterCompleted', { count: taskCounts.completed }) }}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<div v-if="!filteredTasks.length" class="py-10 text-center text-sm text-muted">
|
||
{{ t('chat.shippingNoticeUi.emptyFilteredTasks') }}
|
||
</div>
|
||
|
||
<div v-else class="space-y-3">
|
||
<article
|
||
v-for="task in filteredTasks"
|
||
:key="task.task_no"
|
||
class="relative overflow-hidden rounded-lg border bg-white p-3 shadow-sm transition-colors"
|
||
:class="[
|
||
isFailedTask(task) ? 'border-rose-100' : isAbnormalTask(task) ? 'border-amber-100' : 'border-default',
|
||
isCurrentTask(task.task_no) ? 'ring-1 ring-brand-200' : '',
|
||
]"
|
||
>
|
||
<div
|
||
class="absolute left-0 top-0 h-full w-1"
|
||
:class="isFailedTask(task) ? 'bg-rose-500' : isAbnormalTask(task) ? 'bg-amber-500' : 'bg-emerald-500'"
|
||
></div>
|
||
<div class="flex items-start justify-between gap-3">
|
||
<div class="min-w-0">
|
||
<div class="truncate font-mono text-sm font-bold text-primary">
|
||
{{ task.business_no || task.task_no }}
|
||
</div>
|
||
<div v-if="task.business_no" class="mt-0.5 truncate font-mono text-[10px] text-muted">
|
||
{{ t('chat.shippingNoticeUi.technicalTaskNo', { taskNo: task.task_no }) }}
|
||
</div>
|
||
<div class="mt-0.5 truncate text-xs text-muted">
|
||
{{ task.source_file_name || task.customer_name || t('chat.shippingNoticeUi.currentNotice') }}
|
||
</div>
|
||
<div class="mt-1 flex flex-wrap items-center gap-1.5 text-xs font-medium text-secondary">
|
||
<span>{{ taskStepHeadline(task) }}</span>
|
||
<span
|
||
v-if="task.rpa_runtime"
|
||
class="rounded border px-1.5 py-0.5 text-[10px] font-bold leading-none"
|
||
:class="rpaRuntimeBadgeClass(task)"
|
||
>
|
||
{{ rpaRuntimeLabel(task) }}
|
||
</span>
|
||
</div>
|
||
</div>
|
||
<span class="rounded border px-2 py-1 text-[10px] font-bold" :class="resolveTaskStateMeta(task).className">
|
||
{{ resolveTaskStateMeta(task).text }}
|
||
</span>
|
||
</div>
|
||
|
||
<div class="my-3">
|
||
<div class="scheme-stepper">
|
||
<template v-for="(step, index) in taskWorkflowSteps(task)" :key="step.id">
|
||
<div
|
||
class="scheme-step-node"
|
||
:class="{
|
||
done: step.status === 'completed',
|
||
active: step.status === 'current',
|
||
blocked: step.status === 'blocked',
|
||
}"
|
||
>
|
||
<div class="scheme-step-dot">
|
||
<span v-if="step.status === 'completed'">✓</span>
|
||
<X v-else-if="step.status === 'blocked' && isFailedTask(task)" class="h-3 w-3" />
|
||
<span v-else-if="step.status === 'blocked'">!</span>
|
||
<span v-else>{{ index + 1 }}</span>
|
||
</div>
|
||
<div class="scheme-step-label">{{ step.label.startsWith('chat.') ? t(step.label) : step.label }}</div>
|
||
</div>
|
||
</template>
|
||
</div>
|
||
</div>
|
||
|
||
<div
|
||
v-for="diagnosis in [resolveTaskDiagnosis(task)]"
|
||
:key="`${task.task_no}-diagnosis`"
|
||
class="mb-2 rounded-lg border p-2.5 text-xs font-medium leading-5"
|
||
:class="isFailedTask(task) ? 'border-rose-100 bg-rose-50 text-rose-700' : isAbnormalTask(task) ? 'border-amber-100 bg-amber-50 text-amber-700' : 'border-emerald-100 bg-emerald-50 text-emerald-700'"
|
||
>
|
||
<div class="font-semibold">{{ diagnosis.title }}</div>
|
||
<ul
|
||
v-if="(diagnosis.issues || []).length"
|
||
class="mt-1.5 list-disc space-y-1 pl-4 font-normal text-slate-700"
|
||
>
|
||
<li
|
||
v-for="(issue, issueIndex) in diagnosis.issues"
|
||
:key="`${task.task_no}-issue-${issueIndex}`"
|
||
>
|
||
{{ issue }}
|
||
</li>
|
||
</ul>
|
||
<div class="mt-1 font-normal text-slate-600">{{ diagnosis.advice }}</div>
|
||
</div>
|
||
<div v-if="!resolveWorkspaceActionButtons(task).length" class="mb-3 text-xs leading-5 text-muted">
|
||
<span class="font-semibold text-secondary">{{ t('chat.shippingNoticeUi.suggestedAction') }}</span>
|
||
{{ resolveSuggestedAction(task) }}
|
||
</div>
|
||
|
||
<div class="grid grid-cols-2 gap-1.5">
|
||
<button
|
||
v-if="hasShortageLines(task)"
|
||
type="button"
|
||
:class="`${resolveWorkspaceAssistButtonClass('shortage')} col-span-2`"
|
||
:disabled="actionBusy"
|
||
@click="emit('query-shortage', task.task_no)"
|
||
>
|
||
{{ t('chat.shippingNoticeUi.queryShortageDetails') }}
|
||
</button>
|
||
<button
|
||
type="button"
|
||
:class="`${resolveWorkspaceAssistButtonClass('focus')} col-span-2`"
|
||
:disabled="actionBusy"
|
||
@click="emit('focus-task', task.task_no)"
|
||
>
|
||
<Target class="h-3.5 w-3.5" />
|
||
{{ isCompletedTask(task) ? t('chat.shippingNoticeUi.viewDetail') : t('chat.shippingNoticeUi.switchCurrentTask') }}
|
||
</button>
|
||
</div>
|
||
|
||
<div v-if="resolveWorkspaceActionButtons(task).length" class="mt-2 rounded-xl border border-slate-200/80 bg-slate-50/70 p-2">
|
||
<div class="mb-1.5 px-1 text-[10px] font-semibold uppercase tracking-[0.08em] text-slate-500">
|
||
{{ t('chat.shippingNoticeActionsHint') }}
|
||
</div>
|
||
<div class="grid grid-cols-2 gap-1.5">
|
||
<button
|
||
v-for="action in resolveWorkspaceActionButtons(task)"
|
||
:key="`${task.task_no}-workspace-action-${action.id}-${action.source_code || ''}`"
|
||
type="button"
|
||
:class="resolveWorkspaceTaskActionClass(action, resolveWorkspaceActionButtons(task).length)"
|
||
:disabled="actionBusy"
|
||
@click="emitWorkspaceAction(task, action)"
|
||
>
|
||
{{ action.label }}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</article>
|
||
</div>
|
||
</section>
|
||
</div>
|
||
</aside>
|
||
|
||
<div
|
||
v-if="open"
|
||
class="fixed inset-0 z-[90] bg-slate-900/30 backdrop-blur-sm lg:hidden"
|
||
@click="emit('update:open', false)"
|
||
>
|
||
<aside
|
||
class="ml-auto flex h-full w-[min(92vw,520px)] flex-col border-l border-default bg-surface shadow-2xl"
|
||
@click.stop
|
||
>
|
||
<header class="flex h-16 shrink-0 items-center justify-between border-b border-default px-4">
|
||
<div class="font-bold text-primary">{{ t('chat.shippingNoticeUi.batchWorkspaceTitle') }}</div>
|
||
<button type="button" class="rounded-full p-2 text-muted hover:bg-surface-soft" @click="emit('update:open', false)">
|
||
<X class="h-5 w-5" />
|
||
</button>
|
||
</header>
|
||
<div class="flex-1 overflow-y-auto p-4 text-sm text-muted">
|
||
{{ t('chat.shippingNoticeUi.mobileWorkspaceHint') }}
|
||
</div>
|
||
</aside>
|
||
</div>
|
||
</template>
|
||
|
||
<style scoped>
|
||
.scheme-stepper {
|
||
display: flex;
|
||
overflow-x: auto;
|
||
padding-bottom: 0.25rem;
|
||
}
|
||
|
||
.scheme-step-node {
|
||
position: relative;
|
||
flex: 1;
|
||
min-width: 52px;
|
||
text-align: center;
|
||
}
|
||
|
||
.scheme-step-node:not(:last-child)::after {
|
||
content: '';
|
||
position: absolute;
|
||
top: 10px;
|
||
left: calc(50% + 11px);
|
||
width: calc(100% - 22px);
|
||
height: 2px;
|
||
background: #e2e8f0;
|
||
z-index: 0;
|
||
}
|
||
|
||
.scheme-step-node.done:not(:last-child)::after {
|
||
background: #0284c7;
|
||
}
|
||
|
||
.scheme-step-node.active:not(:last-child)::after {
|
||
background: linear-gradient(90deg, #0284c7 50%, #e2e8f0 50%);
|
||
}
|
||
|
||
.scheme-step-dot {
|
||
position: relative;
|
||
z-index: 1;
|
||
display: grid;
|
||
place-items: center;
|
||
width: 20px;
|
||
height: 20px;
|
||
margin: 0 auto 0.25rem;
|
||
border: 2px solid #e2e8f0;
|
||
border-radius: 9999px;
|
||
background: #fff;
|
||
color: #64748b;
|
||
font-size: 0.55rem;
|
||
font-weight: 700;
|
||
}
|
||
|
||
.scheme-step-node.done .scheme-step-dot {
|
||
border-color: #0284c7;
|
||
background: #0284c7;
|
||
color: #fff;
|
||
}
|
||
|
||
.scheme-step-node.active .scheme-step-dot {
|
||
border-color: #0284c7;
|
||
box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.18);
|
||
color: #0284c7;
|
||
}
|
||
|
||
.scheme-step-node.blocked .scheme-step-dot {
|
||
border-color: #f59e0b;
|
||
background: #fff;
|
||
color: #f59e0b;
|
||
box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18);
|
||
}
|
||
|
||
.scheme-step-node.blocked .scheme-step-label {
|
||
color: #d97706;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.scheme-step-label {
|
||
color: #64748b;
|
||
font-size: 0.58rem;
|
||
line-height: 1.2;
|
||
}
|
||
|
||
.scheme-step-node.active .scheme-step-label {
|
||
color: #0284c7;
|
||
font-weight: 600;
|
||
}
|
||
</style>
|