feat(chat): 更新发货任务处理逻辑和界面文本

- 移除不必要的状态引用
- 更新上传处理提示文本,使用国际化支持
- 扩展发货任务摘要接口,增加错误信息和短缺信息
- 更新多语言支持的文本,改善用户体验
- 增加批次工作区的汇总信息和操作提示
This commit is contained in:
hugo committed 2026-06-29 14:43:27 +08:00
1 parent 0b083cfdbd
commit 1fc9976ca3
60 files changed
+3876 -639

No files matched your search

@@ -1,43 +1,45 @@
<script setup lang="ts">
/**
* features/chat/components/ShippingBatchProgressPanel.vue
* 用途:发货通知聊天顶部批次进度卡片,按原型方案 C 展示批次概览、任务切换列表、七步进度与续办弹层。
* 依赖:shippingStepper、shipping.api.types、vue-i18n、lucide-vue-next。
* 逻辑:上游由 ChatViewContent 传入批次/任务状态;本组件只负责展示与抛出 focus/resume 事件,不直接请求后端。
* 用途:发货通知聊天顶部轻量批次状态条,展示当前批次进度与工作台入口。
* 依赖:shipping.api.types、vue-i18n、批次 retry API。
* 逻辑:生成式执行摘要由聊天消息流承载;本组件只提供固定状态 chrome 和明确范围的批次操作。
*/
import { computed, ref } from 'vue';
import { List, PlayCircle, X } from 'lucide-vue-next';
import { List, RefreshCw } from 'lucide-vue-next';
import { useI18n } from 'vue-i18n';
import { buildShippingWorkflowSteps, type ShippingWorkflowStepItem } from '@/features/chat/shipping';
import { retryWorkspaceShippingBatchPending } from '@/features/chat/api/shipping.api';
import { useMessage } from '@/shared/composables/useMessage';
import type {
ShippingBatchSummary,
ShippingConversationWorkspace,
ShippingTaskDetail,
ShippingTaskSummary,
} from '@/features/chat/api/shipping.api';
const props = defineProps<{
conversationWorkspace: ShippingConversationWorkspace | null;
activeBatchNo: string;
batchSummary: ShippingBatchSummary | null;
batchTasks: ShippingTaskSummary[];
activeTaskDetail: ShippingTaskDetail | null;
tasksExpanded: boolean;
inventorySelectionActive: boolean;
workspaceOpen: boolean;
}>();
const emit = defineEmits<{
'update:tasksExpanded': [value: boolean];
'focus-task': [taskNo: string];
'resume-task': [taskNo: string];
'switch-batch': [batchNo: string];
'toggle-workspace': [];
}>();
const { t } = useI18n();
const msg = useMessage();
const showTaskDialog = ref(false);
const retryingPending = ref(false);
const COMPLETED_PROCESS_STATUSES = new Set(['uploaded', 'closed']);
const CIRCLED_NUMBERS = ['①', '②', '③', '④', '⑤', '⑥', '⑦', '⑧', '⑨'];
const workspaceBatches = computed(() => props.conversationWorkspace?.batches || []);
const activeBatchNo = computed(() =>
String(props.activeBatchNo || props.batchSummary?.batch_no || workspaceBatches.value[0]?.batch_no || '').trim(),
);
const processSummary = computed(() => {
const summary = props.batchSummary?.process_summary || null;
@@ -55,121 +57,36 @@ const processSummary = computed(() => {
return { total, completed, running, pending };
});
const currentTask = computed<ShippingTaskSummary | ShippingTaskDetail | null>(() => {
const focusTaskNo = String(props.batchSummary?.current_focus_task_no || '').trim().toUpperCase();
if (focusTaskNo) {
return props.batchTasks.find((task) => String(task.task_no || '').trim().toUpperCase() === focusTaskNo)
|| props.activeTaskDetail
|| null;
}
return props.activeTaskDetail || props.batchTasks[0] || null;
const abnormalCount = computed(() => {
const batchSummary = props.batchSummary?.process_summary || {};
return Number(batchSummary.failed || 0) + Number((batchSummary as { needs_human?: number }).needs_human || 0);
});
const currentTaskNo = computed(() => String(currentTask.value?.task_no || '').trim().toUpperCase());
const currentTaskName = computed(() =>
String(
currentTask.value?.source_file_name
|| currentTask.value?.customer_name
|| t('chat.shippingNoticeUi.currentNotice'),
).trim(),
const progressPercent = computed(() =>
processSummary.value.total
? Math.round((processSummary.value.completed / processSummary.value.total) * 100)
: 0,
);
const currentTaskIndex = computed(() =>
Number(
currentTask.value?.batch_index
|| props.batchSummary?.process_summary?.current_index
|| 0,
),
);
const currentTaskTotal = computed(() =>
Number(
currentTask.value?.batch_total
|| props.batchSummary?.file_count
|| processSummary.value.total
|| 0,
),
);
const currentSteps = computed(() => buildShippingWorkflowSteps(currentTask.value));
const resolveActiveStep = (steps: ShippingWorkflowStepItem[]) =>
steps.findIndex((step) => step.status === 'current' || step.status === 'blocked');
const currentStepMeta = computed(() => {
const steps = currentSteps.value;
if (!steps.length) return { index: 0, label: t('chat.shippingNoticeUi.processing') };
const activeIndex = resolveActiveStep(steps);
const safeIndex = activeIndex >= 0 ? activeIndex : steps.length - 1;
const executionStateMeta = computed(() => {
if (abnormalCount.value > 0) {
return {
text: t('chat.shippingNoticeUi.needsIntervention'),
className: 'border-amber-100 bg-amber-50 text-amber-700',
};
}
if (processSummary.value.running > 0 || processSummary.value.pending > 0) {
return {
text: t('chat.shippingNoticeUi.runningState'),
className: 'border-sky-100 bg-sky-50 text-brand-700',
};
}
return {
index: safeIndex + 1,
label: t(steps[safeIndex]?.label || 'chat.shippingNoticeUi.processing'),
text: t('chat.shippingNoticeUi.completedState'),
className: 'border-emerald-100 bg-emerald-50 text-emerald-700',
};
});
const summaryLine = computed(() => t('chat.shippingNoticeUi.batchSummaryLine', {
total: processSummary.value.total,
completed: processSummary.value.completed,
running: processSummary.value.running,
pending: processSummary.value.pending,
}));
/**
* 将任务状态映射为原型中列表右侧的紧凑状态文案。
*
* 核心逻辑:完成态显示“已完成”,阻塞态显示“步骤 X 待确认”,运行态显示“步骤 X/Y”,
* 其余回退到“排队中”,以匹配原型中批次队列的短标签风格。
* @param task - 任务摘要或详情
* @returns 原型列表使用的短文案与颜色类
*/
const resolveTaskStateMeta = (task: ShippingTaskSummary | ShippingTaskDetail | null) => {
if (!task) {
return { text: t('chat.shippingNoticeUi.queuedState'), tone: 'text-muted' };
}
if (COMPLETED_PROCESS_STATUSES.has(String(task.process_status || '').trim())) {
return { text: t('chat.shippingNoticeUi.completedState'), tone: 'text-emerald-700' };
}
const steps = buildShippingWorkflowSteps(task);
const blockedIndex = steps.findIndex((step) => step.status === 'blocked');
if (blockedIndex >= 0) {
return {
text: t('chat.shippingNoticeUi.stepNeedsConfirm', { step: blockedIndex + 1 }),
tone: 'text-amber-700',
};
}
const activeIndex = resolveActiveStep(steps);
if (activeIndex >= 0) {
return {
text: t('chat.shippingNoticeUi.stepFraction', { current: activeIndex + 1, total: steps.length }),
tone: 'text-brand-600',
};
}
return { text: t('chat.shippingNoticeUi.queuedState'), tone: 'text-muted' };
};
const shortTaskNo = (taskNo?: string | null) => {
const value = String(taskNo || '').trim();
if (value.length <= 10) return value || '--';
return `${value.slice(0, 5)}...${value.slice(-3)}`;
};
const isCurrentTask = (taskNo?: string | null) =>
String(taskNo || '').trim().toUpperCase() === currentTaskNo.value;
const openTaskDialog = () => {
if (!props.batchTasks.length) return;
showTaskDialog.value = true;
};
const handleFocusTask = (taskNo: string) => {
emit('focus-task', taskNo);
};
const handleResumeTask = (taskNo: string) => {
showTaskDialog.value = false;
emit('resume-task', taskNo);
};
const handleRetryPending = async () => {
const batchNo = String(props.batchSummary?.batch_no || '').trim();
if (!batchNo || retryingPending.value) return;
@@ -186,15 +103,37 @@ const handleRetryPending = async () => {
</script>
<template>
<section
class="mx-auto mt-4 w-full max-w-4xl overflow-hidden rounded-2xl border border-sky-100 bg-gradient-to-br from-sky-50 via-white to-emerald-50 shadow-sm"
>
<div class="border-b border-sky-100/80 px-4 py-3">
<div class="flex flex-wrap items-center justify-between gap-2">
<div class="text-xs text-slate-500">
{{ summaryLine }}
<section class="w-full px-3 pt-3 md:px-8 md:pr-10">
<div
class="mx-auto w-full max-w-4xl rounded-2xl border border-default bg-gradient-to-r from-sky-50 via-white to-emerald-50 px-6 py-4 shadow-sm"
>
<div class="flex flex-wrap items-center justify-between gap-3">
<div class="min-w-0 flex-1">
<div class="flex flex-wrap items-center gap-2 text-xs text-slate-500">
<span class="font-mono font-semibold text-brand-700">{{ activeBatchNo || '--' }}</span>
<span>
{{ t('chat.shippingNoticeUi.batchChromeSummary', {
total: processSummary.total,
completed: processSummary.completed,
running: processSummary.running,
abnormal: abnormalCount,
}) }}
</span>
<span
class="rounded-full border px-2 py-0.5 text-[11px] font-semibold"
:class="executionStateMeta.className"
>
{{ executionStateMeta.text }}
</span>
</div>
<div class="mt-2 h-1.5 max-w-md overflow-hidden rounded-full bg-slate-200">
<div
class="h-full rounded-full bg-brand-500 transition-all"
:style="{ width: `${progressPercent}%` }"
></div>
</div>
</div>
<div class="flex items-center gap-2">
<div class="flex shrink-0 items-center gap-2">
<button
v-if="batchSummary?.batch_no"
type="button"
@@ -202,242 +141,20 @@ const handleRetryPending = async () => {
:disabled="retryingPending"
@click="handleRetryPending"
>
<RefreshCw class="h-3.5 w-3.5" :class="retryingPending ? 'animate-spin' : ''" />
{{ retryingPending ? t('chat.shippingNoticeUi.retrying') : t('chat.shippingNoticeUi.retryPendingTasks') }}
</button>
<button
type="button"
class="inline-flex items-center gap-1 rounded-lg border border-default bg-white/80 px-2.5 py-1 text-xs font-medium text-secondary transition hover:border-brand-300 hover:bg-brand-50 hover:text-brand-700"
@click="openTaskDialog"
@click="emit('toggle-workspace')"
>
<List class="h-3.5 w-3.5" />
{{ t('chat.shippingNoticeUi.taskListResume') }}
</button>
<button
v-if="batchTasks.length > 1"
type="button"
class="text-xs font-medium text-brand-600 transition hover:text-brand-700"
@click="emit('update:tasksExpanded', !tasksExpanded)"
>
{{ tasksExpanded ? `${t('chat.shippingNoticeUi.collapseTaskList')} ▲` : `${t('chat.shippingNoticeUi.expandTaskList')} ▼` }}
{{ workspaceOpen ? t('chat.shippingNoticeUi.collapseTaskList') : t('chat.shippingNoticeUi.expandTaskList') }}
<span class="text-brand-600">{{ workspaceOpen ? '▲' : '▼' }}</span>
</button>
</div>
</div>
<div
v-if="tasksExpanded && batchTasks.length"
class="mt-2 space-y-1 border-t border-dashed border-sky-100 pt-2"
>
<button
v-for="(task, index) in batchTasks"
:key="task.task_no"
type="button"
class="flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-left text-xs transition hover:bg-white/70"
:class="isCurrentTask(task.task_no) ? 'bg-white/80 ring-1 ring-brand-200' : ''"
@click="handleFocusTask(task.task_no)"
>
<span class="text-muted">{{ CIRCLED_NUMBERS[index] || `${index + 1}` }}</span>
<span class="flex-1 truncate" :class="isCurrentTask(task.task_no) ? 'font-medium text-secondary' : ''">
{{ task.source_file_name || task.customer_name || t('chat.shippingNoticeUi.currentNotice') }}
</span>
<span class="font-mono text-brand-600">{{ shortTaskNo(task.task_no) }}</span>
<span
class="rounded-full px-1.5 py-0.5"
:class="isCurrentTask(task.task_no) ? 'text-brand-600' : resolveTaskStateMeta(task).tone"
>
{{ resolveTaskStateMeta(task).text }}
</span>
</button>
</div>
</div>
<div class="space-y-3 px-4 py-4">
<div class="flex flex-wrap items-baseline justify-between gap-2">
<div>
<div class="font-mono text-sm font-semibold text-brand-700">
{{ currentTaskNo || batchSummary?.batch_no || '--' }}
</div>
<div class="mt-0.5 text-xs text-muted">
当前 · 第 {{ currentTaskIndex || 0 }}/{{ currentTaskTotal || 0 }} 笔 ·
<em class="not-italic text-secondary">{{ currentTaskName }}</em>
</div>
</div>
<div class="text-xs text-muted">
步骤 <strong class="text-secondary">{{ currentStepMeta.index }}</strong>/{{ currentSteps.length || 7 }} · {{ currentStepMeta.label }}
</div>
</div>
<div class="scheme-stepper">
<template v-for="(step, index) in currentSteps" :key="step.id">
<div
class="scheme-step-node"
:class="{
done: step.status === 'completed',
active: step.status === 'current' || step.status === 'blocked',
}"
>
<div class="scheme-step-dot">
{{ step.status === 'completed' ? '✓' : index + 1 }}
</div>
<div class="scheme-step-label">{{ t(step.label) }}</div>
</div>
</template>
</div>
<div
v-if="inventorySelectionActive"
class="rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-800"
>
{{ t('chat.shippingNoticeUi.inventoryTaskPickHint') }}
</div>
</div>
<Teleport to="body">
<div
v-if="showTaskDialog"
class="fixed inset-0 z-[120] flex items-center justify-center bg-slate-900/30 px-4"
@click.self="showTaskDialog = false"
>
<div class="w-full max-w-[620px] rounded-[28px] bg-white p-5 shadow-[0_24px_80px_rgba(15,23,42,0.22)]">
<div class="flex items-start justify-between gap-4">
<div>
<div class="text-[32px] font-semibold tracking-tight text-slate-800">
{{ t('chat.shippingNoticeUi.taskListTitle') }}
</div>
<div class="mt-1 text-sm text-slate-500">
{{ t('chat.shippingNoticeUi.taskListHint') }}
</div>
</div>
<button
type="button"
class="rounded-full p-2 text-slate-400 transition hover:bg-slate-100 hover:text-slate-600"
@click="showTaskDialog = false"
>
<X class="h-5 w-5" />
</button>
</div>
<div class="mt-5 space-y-3">
<button
v-for="task in batchTasks"
:key="task.task_no"
type="button"
class="w-full rounded-3xl border px-4 py-4 text-left transition hover:border-[#8bc8f5] hover:bg-[#f8fbff]"
:class="isCurrentTask(task.task_no) ? 'border-[#8bc8f5] bg-[#f5fbff]' : 'border-[#e5edf5] bg-white'"
@click="handleResumeTask(task.task_no)"
>
<div class="flex items-start justify-between gap-3">
<div class="min-w-0">
<div class="font-mono text-lg font-semibold text-[#1277c8]">
{{ task.task_no }}
</div>
<div class="mt-1 truncate text-[15px] text-slate-700">
{{ task.source_file_name || task.customer_name || t('chat.shippingNoticeUi.currentNotice') }}
</div>
<div class="mt-1 text-sm text-slate-500">
{{ resolveTaskStateMeta(task).text }}
</div>
<div
v-if="isCurrentTask(task.task_no)"
class="mt-2 inline-flex items-center gap-1 text-sm font-medium text-[#1277c8]"
>
{{ t('chat.shippingNoticeUi.currentFocus') }}
</div>
</div>
<div class="flex shrink-0 items-center gap-2">
<span
class="rounded-full px-3 py-1 text-sm font-medium"
:class="COMPLETED_PROCESS_STATUSES.has(String(task.process_status || '').trim())
? 'bg-emerald-100 text-emerald-700'
: isCurrentTask(task.task_no)
? 'bg-sky-100 text-sky-700'
: 'bg-amber-100 text-amber-700'"
>
{{ COMPLETED_PROCESS_STATUSES.has(String(task.process_status || '').trim())
? t('chat.shippingNoticeUi.completedState')
: isCurrentTask(task.task_no)
? t('chat.shippingNoticeUi.runningState')
: t('chat.shippingNoticeUi.pendingState') }}
</span>
<PlayCircle class="h-5 w-5 text-[#1492df]" />
</div>
</div>
</button>
</div>
</div>
</div>
</Teleport>
</section>
</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-label {
color: #64748b;
font-size: 0.58rem;
line-height: 1.2;
}
.scheme-step-node.active .scheme-step-label {
color: #0284c7;
font-weight: 600;
}
</style>