Files
syops/frontend/src/features/chat/components/ShippingBatchProgressPanel.vue
T
hugo 9c036c825b refactor(chat/shipping): 重构发货通知模块为统一UI State驱动模式
- 重构发货通知的状态与动作获取逻辑:移除从聊天文本解析HXOPS_SHIPPING_ACTIONS注释的旧逻辑,改为统一从后端shipping_ui_state获取任务状态、动作按钮与工作流步骤
- 新增SSE实时推送shipping_ui_state事件,支持前端即时更新聊天气泡与工作台的状态与按钮
- 优化路由与登录流程:调整根路径重定向逻辑,退出登录时跳转到登录页;移除chat路由不必要的props传参;将原路由守卫中的根路径判断迁移到路由配置中
- 完善库存RPA与本地导入流程:新增本地库存文件托管接口,优化RPA回调的文件落盘与任务关联逻辑
- 新增多组单元测试覆盖焦点切换、决策处理、SSE同步等核心场景
- 修复多语言显示逻辑,使用te方法判断翻译key是否存在,避免缺失翻译时的渲染异常
- 新增reparse_inventory菜单动作,支持静默重新解析库存且不追加额外聊天消息
- 重构工作流步骤渲染函数,优先使用后端返回的步骤数据, fallback到本地推导的旧逻辑
- 清理后端旧的chat-actions API接口,将相关逻辑迁移到统一的ui_state接口中
2026-07-02 01:55:19 +08:00

240 lines
10 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
/**
* features/chat/components/ShippingBatchProgressPanel.vue
* 用途:发货通知聊天顶部轻量批次状态条,展示当前批次进度与工作台入口。
* 依赖:shipping.api.types、vue-i18n、批次 retry API。
* 逻辑:生成式执行摘要由聊天消息流承载;本组件只提供固定状态 chrome 和明确范围的批次操作。
*/
import { computed, ref } from 'vue';
import { AlertTriangle, List, RefreshCw } from 'lucide-vue-next';
import { useI18n } from 'vue-i18n';
import { retryWorkspaceShippingBatchPending } from '@/features/chat/api/shipping.api';
import { useMessage } from '@/shared/composables/useMessage';
import { resolveShippingWorkflowSteps } from '@/features/chat/shipping';
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;
workspaceOpen: boolean;
}>();
const emit = defineEmits<{
'switch-batch': [batchNo: string];
'toggle-workspace': [];
}>();
const { t } = useI18n();
const msg = useMessage();
const retryingPending = ref(false);
const COMPLETED_PROCESS_STATUSES = new Set(['uploaded', 'completed', 'closed']);
const FAILED_PROCESS_STATUSES = new Set(['rejected', 'upload_failed']);
const workspaceBatches = computed(() => props.conversationWorkspace?.batches || []);
const activeBatchNo = computed(() =>
String(props.activeBatchNo || props.batchSummary?.batch_no || workspaceBatches.value[0]?.batch_no || '').trim(),
);
const focusedTaskNo = computed(() =>
String(
props.activeTaskDetail?.task_no
|| props.batchSummary?.current_focus_task_no
|| props.batchSummary?.process_summary?.current_task_no
|| '',
).trim(),
);
const processSummary = computed(() => {
const summary = props.batchSummary?.process_summary || null;
const total = Number(summary?.total || props.batchSummary?.file_count || props.batchTasks.length || 0);
const completed = Number(
summary?.completed
|| props.batchTasks.filter((task) => COMPLETED_PROCESS_STATUSES.has(String(task.process_status || '').trim())).length
|| 0,
);
const runningFallback = props.batchTasks.some(
(task) => !COMPLETED_PROCESS_STATUSES.has(String(task.process_status || '').trim()),
) ? 1 : 0;
const running = Number(summary?.running || runningFallback || 0);
const taskAbnormal = props.batchTasks.filter((task) => {
const status = String(task.process_status || '').trim();
return FAILED_PROCESS_STATUSES.has(status)
|| task.upload_status === 'failed'
|| Boolean(task.review_status || task.pending_human_reason);
}).length;
const summaryAbnormal = Number(summary?.failed || 0) + Number((summary as { needs_human?: number })?.needs_human || 0);
const abnormal = Math.max(taskAbnormal, summaryAbnormal);
const pending = Math.max(0, Number(summary?.pending ?? (total - completed - running - abnormal)));
return { total, completed, running, pending, abnormal };
});
const abnormalCount = computed(() => processSummary.value.abnormal);
const progressPercent = computed(() =>
processSummary.value.total
? Math.round((processSummary.value.completed / processSummary.value.total) * 100)
: 0,
);
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 {
text: t('chat.shippingNoticeUi.completedState'),
className: 'border-emerald-100 bg-emerald-50 text-emerald-700',
};
});
const activeTaskSteps = computed(() => (
resolveShippingWorkflowSteps(props.activeTaskDetail)
));
const activeStepIndex = computed(() => {
const index = activeTaskSteps.value.findIndex((step) => step.status === 'current' || step.status === 'blocked');
return index >= 0 ? index : Math.max(0, activeTaskSteps.value.length - 1);
});
const activeStepLabel = computed(() => {
const step = activeTaskSteps.value[activeStepIndex.value];
return step ? t('chat.shippingNoticeUi.stepHeadline', {
current: activeStepIndex.value + 1,
total: activeTaskSteps.value.length,
label: step.label.startsWith('chat.') ? t(step.label) : step.label,
}) : '--';
});
const blockingMeta = computed(() => {
const task = props.activeTaskDetail;
if (!task) return null;
const reason = String(task.pending_human_reason || '').trim();
const reviewStatus = String(task.review_status || '').trim();
const processStatus = String(task.process_status || '').trim();
if (processStatus === 'upload_failed' || task.upload_status === 'failed') {
return {
text: t('chat.shippingNoticeUi.blockedUploadRetryable'),
className: 'border-rose-200 bg-rose-50 text-rose-700',
};
}
if (reason === 'shortage' || reason === 'shortage_review' || reviewStatus === 'shortage_review') {
return {
text: t('chat.shippingNoticeUi.blockedShortage'),
className: 'border-amber-200 bg-amber-50 text-amber-700',
};
}
if (reason === 'low_confidence' || reviewStatus === 'parse_review') {
return {
text: t('chat.shippingNoticeUi.blockedParseReview'),
className: 'border-amber-200 bg-amber-50 text-amber-700',
};
}
if (reason || reviewStatus) {
return {
text: t('chat.shippingNoticeUi.blockedWaitingHuman'),
className: 'border-amber-200 bg-amber-50 text-amber-700',
};
}
return null;
});
const handleRetryPending = async () => {
const batchNo = String(props.batchSummary?.batch_no || '').trim();
if (!batchNo || retryingPending.value) return;
retryingPending.value = true;
try {
const result = await retryWorkspaceShippingBatchPending(batchNo);
msg.success(result.message || t('chat.shippingNoticeUi.retryPendingDone'));
} catch (error) {
msg.error(error instanceof Error ? error.message : t('chat.shippingNoticeUi.retryFailed'));
} finally {
retryingPending.value = false;
}
};
</script>
<template>
<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-start 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.fileCount') }} {{ processSummary.total }}</span>
<span>{{ t('chat.shippingNoticeUi.completedCount') }} {{ processSummary.completed }}</span>
<span>{{ t('chat.shippingNoticeUi.runningCount') }} {{ processSummary.running }}</span>
<span>{{ t('chat.shippingNoticeUi.pendingCount') }} {{ processSummary.pending }}</span>
<span>{{ t('chat.shippingNoticeUi.needsIntervention') }} {{ abnormalCount }}</span>
<span
class="rounded-full border px-2 py-0.5 text-[11px] font-semibold"
:class="executionStateMeta.className"
>
{{ executionStateMeta.text }}
</span>
<span
v-if="blockingMeta"
class="inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[11px] font-semibold"
:class="blockingMeta.className"
>
<AlertTriangle class="h-3 w-3" />
{{ blockingMeta.text }}
</span>
</div>
<div class="mt-2 flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-secondary">
<span>
<span class="text-muted">{{ t('chat.shippingNoticeUi.currentFocus') }}</span>
<span class="font-mono font-semibold text-primary">{{ focusedTaskNo || '--' }}</span>
</span>
<span>
<span class="text-muted">{{ t('chat.shippingNoticeUi.currentStepLabel') }}:</span>
<span class="font-medium text-primary">{{ activeStepLabel }}</span>
</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 shrink-0 items-center gap-2">
<button
v-if="batchSummary?.batch_no"
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 disabled:cursor-not-allowed disabled:opacity-60"
: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="emit('toggle-workspace')"
>
<List class="h-3.5 w-3.5" />
{{ workspaceOpen ? t('chat.shippingNoticeUi.collapseTaskList') : t('chat.shippingNoticeUi.expandTaskList') }}
<span class="text-brand-600">{{ workspaceOpen ? '▲' : '▼' }}</span>
</button>
</div>
</div>
</div>
</section>
</template>