Files
syops/frontend/src/features/chat/components/ShippingBatchWorkspaceDrawer.vue
T
hugo 1fc9976ca3 feat(chat): 更新发货任务处理逻辑和界面文本
- 移除不必要的状态引用
- 更新上传处理提示文本,使用国际化支持
- 扩展发货任务摘要接口,增加错误信息和短缺信息
- 更新多语言支持的文本,改善用户体验
- 增加批次工作区的汇总信息和操作提示
2026-06-29 14:43:27 +08:00

510 lines
20 KiB
Vue

<script setup lang="ts">
/**
* features/chat/components/ShippingBatchWorkspaceDrawer.vue
* 用途:发货通知 Agent 的右侧批次工作台抽屉,承载多批次切换、任务筛选、步骤诊断与恢复动作。
* 依赖:shippingStepper、shipping.api.types、vue-i18n、lucide-vue-next。
* 逻辑:上游传入会话级 workspace 与当前批次任务;本组件只做展示、筛选和事件抛出,执行动作仍由 useChatShipping 接管。
*/
import { computed, ref } from 'vue';
import { RefreshCw, Target, X } from 'lucide-vue-next';
import { useI18n } from 'vue-i18n';
import { buildShippingWorkflowSteps, type ShippingWorkflowStepItem } from '@/features/chat/shipping';
import { hasShortageLines } from '@/features/chat/shipping/shippingShortageDetails';
import type {
ShippingBatchSummary,
ShippingConversationWorkspace,
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;
}>();
const emit = defineEmits<{
'update:open': [value: boolean];
'switch-batch': [batchNo: string];
'focus-task': [taskNo: string];
'resume-task': [taskNo: string];
'query-shortage': [taskNo: string];
'retry-pending': [];
}>();
const { t } = useI18n();
const activeFilter = ref<'all' | 'abnormal' | 'completed'>('all');
const COMPLETED_PROCESS_STATUSES = new Set(['uploaded', 'completed', 'closed']);
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) =>
COMPLETED_PROCESS_STATUSES.has(String(task.process_status || '').trim());
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 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;
return {
total: tasks.length,
abnormal,
completed,
};
});
const filteredTasks = computed(() => {
const tasks = props.batchTasks || [];
if (activeFilter.value === 'abnormal') return tasks.filter(isAbnormalTask);
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 taskStepNumber = (task: ShippingTaskSummary | ShippingTaskDetail) =>
resolveActiveStep(buildShippingWorkflowSteps(task)) + 1;
const currentStepProgress = (task: ShippingTaskSummary | ShippingTaskDetail) =>
task.step_payload?.current_step_progress || null;
const resolveTaskDiagnosis = (task: ShippingTaskSummary | ShippingTaskDetail) => {
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: progressMessage,
advice: progressDetail || t('chat.shippingNoticeUi.diagnosisInventoryRpaAdvice'),
};
}
if (explicitError) {
return {
title: explicitError,
advice: progressDetail || t('chat.shippingNoticeUi.diagnosisAdviceRetryOrFocus'),
};
}
if (progressMessage && (isAbnormalTask(task) || progress?.status === 'needs_human')) {
return {
title: progressMessage,
advice: 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 === '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 resolveActiveStep = (steps: ShippingWorkflowStepItem[]) => {
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)] xl: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-2xl border border-default bg-surface p-4 shadow-sm">
<h3 class="text-sm font-bold text-primary">{{ t('chat.shippingNoticeUi.batchActionsTitle') }}</h3>
<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"
@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 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 === '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-4">
<article
v-for="task in filteredTasks"
:key="task.task_no"
class="relative overflow-hidden rounded-2xl border bg-white p-4 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="mb-4 flex items-start justify-between gap-3">
<div class="min-w-0">
<div class="truncate font-mono text-sm font-bold text-primary">{{ 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>
<span class="rounded border px-2 py-1 text-[10px] font-bold" :class="resolveTaskStateMeta(task).className">
{{ resolveTaskStateMeta(task).text }}
</span>
</div>
<div class="mb-5 mt-4">
<div class="scheme-stepper">
<template v-for="(step, index) in buildShippingWorkflowSteps(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">{{ t(step.label) }}</div>
</div>
</template>
</div>
</div>
<div
class="mb-3 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">{{ resolveTaskDiagnosis(task).title }}</div>
<div class="mt-1 font-normal text-slate-600">{{ resolveTaskDiagnosis(task).advice }}</div>
</div>
<div class="flex gap-2">
<button
v-if="hasShortageLines(task)"
type="button"
class="flex flex-1 items-center justify-center gap-1.5 rounded-lg border border-amber-100 bg-amber-50 py-1.5 text-xs font-medium text-amber-700 transition-colors hover:bg-amber-100"
@click="emit('query-shortage', task.task_no)"
>
{{ t('chat.shippingNoticeUi.queryShortageDetails') }}
</button>
<button
type="button"
class="flex flex-1 items-center justify-center gap-1.5 rounded-lg border border-transparent bg-surface-soft py-1.5 text-xs font-medium text-secondary transition-colors hover:border-brand-200 hover:bg-brand-50 hover:text-brand-600"
@click="emit('focus-task', task.task_no)"
>
<Target class="h-3.5 w-3.5" />
{{ t('chat.shippingNoticeUi.focusRepair') }}
</button>
<button
type="button"
class="flex-1 rounded-lg border border-default bg-white py-1.5 text-xs font-medium text-secondary transition-colors hover:border-brand-300 hover:text-brand-700"
@click="emit('resume-task', task.task_no)"
>
{{ isCompletedTask(task) ? t('chat.shippingNoticeUi.viewDetail') : t('chat.shippingNoticeUi.retrySingleTask') }}
</button>
</div>
</article>
</div>
</section>
</div>
</aside>
<div
v-if="open"
class="fixed inset-0 z-[90] bg-slate-900/30 backdrop-blur-sm xl: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>