feat(shipping): 新增货代发货批量自动处理与任务重试功能
本次提交完整实现货代发货通知的自动化批量处理能力: 1. 新增发货单票后台任务类型与专用worker队列,实现任务持久化调度 2. 实现发货批次后台编排器,支持上传后自动逐票推进解析、匹配、导出全流程 3. 新增单票重试、批次待处理重试的API与前端操作界面 4. 补充全量多语言翻译,新增重试、任务列表、状态展示相关文案 5. 优化上传交互逻辑,改为后台自动处理任务,无需手动触发解析指令 6. 修复文件检核工具无数据预检逻辑,避免创建空检核批次 7. 调整发货工作流细节,优化Excel生成幂等性与任务状态同步 8. 更新环境配置与API文档,修正货代工具接口地址端口
This commit is contained in:
1 parent
70e8f700ff
commit
08360a4142
40 files changed
+2515
-371
No files matched your search
@@ -214,6 +214,49 @@ export async function switchWorkspaceShippingBatchFocusTask(batchNo: string, tas
|
||||
return body;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重试当前发货任务。
|
||||
* @param taskNo - 发货任务编号
|
||||
* @param comment - 可选重试备注
|
||||
* @returns 重试结果
|
||||
*/
|
||||
export async function retryWorkspaceShippingTask(taskNo: string, comment?: string) {
|
||||
const res = await fetch(
|
||||
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/retry`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(comment ? { comment } : {}),
|
||||
},
|
||||
);
|
||||
const body = (await res.json().catch(() => ({}))) as ShippingDecisionResponse & { error?: string };
|
||||
if (!res.ok || body.status === 'failed') {
|
||||
throw new Error(body.error || body.message || res.statusText);
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重试批次中仍可自动推进的任务。
|
||||
* @param batchNo - 批次编号
|
||||
* @returns 批次重试结果
|
||||
*/
|
||||
export async function retryWorkspaceShippingBatchPending(batchNo: string) {
|
||||
const res = await fetch(
|
||||
`/api/workspace/shipping-batches/${encodeURIComponent(batchNo)}/retry-pending`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({}),
|
||||
},
|
||||
);
|
||||
const body = (await res.json().catch(() => ({}))) as { status?: string; message?: string; error?: string };
|
||||
if (!res.ok || body.status === 'failed') {
|
||||
throw new Error(body.error || body.message || res.statusText);
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交人工决策。
|
||||
* @param taskNo - 发货任务编号
|
||||
@@ -390,6 +433,28 @@ export async function autoProgressWorkspaceShippingTask(taskNo: string, lang?: s
|
||||
return body;
|
||||
}
|
||||
|
||||
/**
|
||||
* 以用户态触发通知解析,供批量上传后逐任务补齐首轮解析。
|
||||
* @param taskNo - 发货任务编号
|
||||
* @param lang - 可选语言代码
|
||||
* @returns 解析与可能的自动推进结果
|
||||
*/
|
||||
export async function parseWorkspaceShippingNotice(taskNo: string, lang?: string) {
|
||||
const res = await fetch(
|
||||
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/parse-notice`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(lang ? { lang } : {}),
|
||||
},
|
||||
);
|
||||
const body = (await res.json().catch(() => ({}))) as ShippingDecisionResponse & { error?: string };
|
||||
if (!res.ok || body.status === 'failed') {
|
||||
throw new Error(body.error || body.message || res.statusText);
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
/**
|
||||
* 标记货代系统已人工上传完成。
|
||||
* @param taskNo - 发货任务编号
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
/**
|
||||
* features/chat/components/ChatViewContent.vue
|
||||
* 对话页主区域:侧栏、消息列表、输入栏与内置浏览器。
|
||||
* 用途:对话页主区域,组合侧栏、发货批次进度区、消息列表、输入栏与内置浏览器。
|
||||
* 依赖:ChatSidebar、ChatMessageList、ChatInputBar、ShippingBatchProgressPanel、chat.context。
|
||||
* 逻辑:本文件只做页面结构编排;发货批次进度样式与任务续办交互下沉到独立面板组件。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { Loader2 } from 'lucide-vue-next';
|
||||
import ChatShell from '@/shared/layouts/ChatShell.vue';
|
||||
import ChatSidebar from '@/features/chat/components/ChatSidebar.vue';
|
||||
@@ -12,91 +12,10 @@ import ChatInputBar from '@/features/chat/components/ChatInputBar.vue';
|
||||
import ChatMessageList from '@/features/chat/components/ChatMessageList.vue';
|
||||
import ChatMobileHeader from '@/features/chat/components/ChatMobileHeader.vue';
|
||||
import ChatBrowserPanel from '@/features/chat/components/ChatBrowserPanel.vue';
|
||||
import ShippingWorkflowStepper from '@/features/chat/components/ShippingWorkflowStepper.vue';
|
||||
import ShippingBatchProgressPanel from '@/features/chat/components/ShippingBatchProgressPanel.vue';
|
||||
import { useChatPageContext } from '@/features/chat/composables/chat.context';
|
||||
import { buildShippingWorkflowSteps } from '@/features/chat/shipping';
|
||||
import type { ShippingCurrentStepProgress, ShippingTaskSummary } from '@/features/chat/types/shipping.api.types';
|
||||
|
||||
const page = useChatPageContext();
|
||||
const { t } = useI18n();
|
||||
|
||||
const statusMeta = (status?: string | null) => {
|
||||
const map: Record<string, { label: string; chip: string }> = {
|
||||
created: { label: t('chat.shippingNoticeUi.status.created'), chip: 'bg-slate-100 text-slate-700' },
|
||||
waiting_inventory: { label: t('chat.shippingNoticeUi.status.waitingInventory'), chip: 'bg-amber-100 text-amber-700' },
|
||||
inventory_ready: { label: t('chat.shippingNoticeUi.status.inventoryReady'), chip: 'bg-sky-100 text-sky-700' },
|
||||
matched: { label: t('chat.shippingNoticeUi.status.matched'), chip: 'bg-emerald-100 text-emerald-700' },
|
||||
waiting_upload: { label: t('chat.shippingNoticeUi.status.waitingUpload'), chip: 'bg-orange-100 text-orange-700' },
|
||||
uploaded: { label: t('chat.shippingNoticeUi.status.uploaded'), chip: 'bg-emerald-100 text-emerald-700' },
|
||||
upload_failed: { label: t('chat.shippingNoticeUi.status.uploadFailed'), chip: 'bg-rose-100 text-rose-700' },
|
||||
rejected: { label: t('chat.shippingNoticeUi.status.rejected'), chip: 'bg-rose-100 text-rose-700' },
|
||||
closed: { label: t('chat.shippingNoticeUi.status.closed'), chip: 'bg-slate-100 text-slate-700' },
|
||||
};
|
||||
return map[String(status || '').trim()] || { label: String(status || t('chat.shippingNoticeUi.processing')), chip: 'bg-slate-100 text-slate-700' };
|
||||
};
|
||||
|
||||
const stepLabel = (step?: string | null) => {
|
||||
const map: Record<string, string> = {
|
||||
step1_notice_submit: t('chat.shippingNoticeUi.currentStep.noticeParse'),
|
||||
step2_parse_confirm: t('chat.shippingNoticeUi.currentStep.parseConfirm'),
|
||||
step3_inventory_prepare: t('chat.shippingNoticeUi.currentStep.inventoryPrepare'),
|
||||
step4_align_confirm: t('chat.shippingNoticeUi.currentStep.alignConfirm'),
|
||||
step5_match_inventory: t('chat.shippingNoticeUi.currentStep.inventoryMatch'),
|
||||
step6_generate_file: t('chat.shippingNoticeUi.currentStep.generateExcel'),
|
||||
step7_upload_freight: t('chat.shippingNoticeUi.currentStep.uploadFreight'),
|
||||
step2_inventory_prepare: t('chat.shippingNoticeUi.currentStep.inventoryPrepare'),
|
||||
step3_inventory_match: t('chat.shippingNoticeUi.currentStep.inventoryMatch'),
|
||||
step4_shortage_review: t('chat.shippingNoticeUi.currentStep.shortageHandle'),
|
||||
step5_export_excel: t('chat.shippingNoticeUi.currentStep.generateExcel'),
|
||||
step6_upload_freight: t('chat.shippingNoticeUi.currentStep.uploadFreight'),
|
||||
step7_finish: t('chat.shippingNoticeUi.currentStep.finishArchive'),
|
||||
};
|
||||
return map[String(step || '').trim()] || t('chat.shippingNoticeUi.processing');
|
||||
};
|
||||
|
||||
const currentShippingTask = computed<ShippingTaskSummary | null>(() => {
|
||||
const focusTaskNo = String(page.shippingBatchSummary?.current_focus_task_no || '').trim();
|
||||
if (!focusTaskNo || !Array.isArray(page.shippingBatchTasks)) return null;
|
||||
return page.shippingBatchTasks.find((task: ShippingTaskSummary) => task.task_no === focusTaskNo) || null;
|
||||
});
|
||||
|
||||
const currentShippingTaskSource = computed(() => currentShippingTask.value || page.activeShippingTaskDetail || null);
|
||||
const currentShippingSteps = computed(() => buildShippingWorkflowSteps(currentShippingTaskSource.value));
|
||||
const currentShippingStepProgress = computed<ShippingCurrentStepProgress | null>(() => {
|
||||
const payload = currentShippingTaskSource.value?.step_payload;
|
||||
if (!payload || typeof payload !== 'object') return null;
|
||||
const progress = (payload as Record<string, unknown>).current_step_progress;
|
||||
return progress && typeof progress === 'object' ? progress as ShippingCurrentStepProgress : null;
|
||||
});
|
||||
const currentShippingBatchProgress = computed(() => {
|
||||
const task = currentShippingTask.value;
|
||||
if (!task?.batch_index || !task?.batch_total) return '';
|
||||
return t('chat.shippingNoticeUi.batchProgress', { index: task.batch_index, total: task.batch_total });
|
||||
});
|
||||
const batchCompletedCount = computed(() =>
|
||||
Number(page.shippingBatchSummary?.process_summary?.completed || 0),
|
||||
);
|
||||
const batchRunningCount = computed(() =>
|
||||
Number(page.shippingBatchSummary?.process_summary?.running || 0),
|
||||
);
|
||||
const batchPendingCount = computed(() =>
|
||||
Number(page.shippingBatchSummary?.process_summary?.pending || 0),
|
||||
);
|
||||
const batchFileCount = computed(() =>
|
||||
Number(page.shippingBatchSummary?.file_count || 0),
|
||||
);
|
||||
const batchCurrentIndex = computed(() =>
|
||||
Number(
|
||||
currentShippingTask.value?.batch_index
|
||||
|| page.activeShippingTaskDetail?.batch_index
|
||||
|| page.shippingBatchSummary?.process_summary?.current_index
|
||||
|| 0,
|
||||
),
|
||||
);
|
||||
const batchCompletionPercent = computed(() => {
|
||||
if (!batchFileCount.value) return 0;
|
||||
return Math.min(100, Math.max(0, Math.round((batchCompletedCount.value / batchFileCount.value) * 100)));
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -164,230 +83,17 @@ const batchCompletionPercent = computed(() => {
|
||||
<template v-else>
|
||||
<div class="flex min-h-0 flex-1">
|
||||
<div class="flex min-h-0 flex-1 flex-col">
|
||||
<div
|
||||
v-if="page.isShippingNoticeAgent && (page.shippingBatchSummary || currentShippingTaskSource)"
|
||||
class="mx-4 mt-4 rounded-3xl border border-default/80 bg-[linear-gradient(135deg,rgba(255,255,255,0.96),rgba(246,248,251,0.92))] px-4 py-3 shadow-sm"
|
||||
>
|
||||
<div class="flex flex-wrap items-start justify-between gap-3">
|
||||
<div class="space-y-1">
|
||||
<div class="text-[11px] font-semibold uppercase tracking-[0.18em] text-muted">
|
||||
{{ page.shippingBatchSummary ? t('chat.shippingNoticeUi.batchTitle') : t('chat.shippingNoticeUi.taskTitle') }}
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<span
|
||||
v-if="page.shippingBatchSummary"
|
||||
class="font-mono text-sm font-semibold text-primary"
|
||||
>
|
||||
{{ page.shippingBatchSummary.batch_no }}
|
||||
</span>
|
||||
<span
|
||||
v-else-if="currentShippingTaskSource"
|
||||
class="font-mono text-sm font-semibold text-primary"
|
||||
>
|
||||
{{ currentShippingTaskSource.task_no }}
|
||||
</span>
|
||||
<span
|
||||
v-if="page.shippingBatchSummary?.current_focus_task_no"
|
||||
class="rounded-full bg-brand-50 px-2.5 py-1 text-xs font-medium text-brand-700"
|
||||
>
|
||||
{{ t('chat.shippingNoticeUi.currentTask', { taskId: page.shippingBatchSummary.current_focus_task_no }) }}
|
||||
</span>
|
||||
<span
|
||||
v-if="currentShippingBatchProgress"
|
||||
class="rounded-full bg-sky-50 px-2.5 py-1 text-xs font-medium text-sky-700"
|
||||
>
|
||||
{{ currentShippingBatchProgress }}
|
||||
</span>
|
||||
<span
|
||||
v-if="batchCurrentIndex"
|
||||
class="rounded-full bg-amber-50 px-2.5 py-1 text-xs font-medium text-amber-700"
|
||||
>
|
||||
{{ t('chat.shippingNoticeUi.batchCurrentIndex', { index: batchCurrentIndex, total: batchFileCount }) }}
|
||||
</span>
|
||||
</div>
|
||||
<div v-if="currentShippingTaskSource" class="flex flex-wrap items-center gap-2 text-xs text-secondary">
|
||||
<span class="truncate font-medium text-primary">
|
||||
{{ currentShippingTaskSource.customer_name || currentShippingTaskSource.source_file_name || t('chat.shippingNoticeUi.currentNotice') }}
|
||||
</span>
|
||||
<span
|
||||
class="rounded-full px-2 py-0.5 font-medium"
|
||||
:class="statusMeta(currentShippingTaskSource.process_status).chip"
|
||||
>
|
||||
{{ statusMeta(currentShippingTaskSource.process_status).label }}
|
||||
</span>
|
||||
<span class="text-muted">{{ t('chat.shippingNoticeUi.stepperTitle') }}:{{ stepLabel(currentShippingTaskSource.current_step) }}</span>
|
||||
</div>
|
||||
<ShippingWorkflowStepper
|
||||
v-if="currentShippingTaskSource"
|
||||
:steps="currentShippingSteps"
|
||||
compact
|
||||
class="pt-2"
|
||||
/>
|
||||
<div
|
||||
v-if="currentShippingStepProgress"
|
||||
class="mt-3 rounded-2xl border border-default/80 bg-surface/80 px-3 py-3"
|
||||
>
|
||||
<div class="flex items-center justify-between gap-3 text-xs">
|
||||
<div class="font-medium text-primary">
|
||||
{{ currentShippingStepProgress.step_title || t('chat.shippingNoticeUi.stepDetail.title') }}
|
||||
</div>
|
||||
<div class="text-muted">
|
||||
{{ currentShippingStepProgress.progress_percent ?? 0 }}%
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-1 text-sm text-secondary">
|
||||
{{ currentShippingStepProgress.message || t('chat.shippingNoticeUi.processing') }}
|
||||
</div>
|
||||
<div
|
||||
v-if="currentShippingStepProgress.detail"
|
||||
class="mt-1 text-xs text-muted"
|
||||
>
|
||||
{{ currentShippingStepProgress.detail }}
|
||||
</div>
|
||||
<div
|
||||
v-if="currentShippingStepProgress.current && currentShippingStepProgress.total"
|
||||
class="mt-1 text-xs text-muted"
|
||||
>
|
||||
{{ t('chat.shippingNoticeUi.stepDetail.counter', { current: currentShippingStepProgress.current, total: currentShippingStepProgress.total }) }}
|
||||
</div>
|
||||
<div class="mt-2 h-2 overflow-hidden rounded-full bg-slate-200">
|
||||
<div
|
||||
class="h-full rounded-full bg-sky-500 transition-all"
|
||||
:style="{ width: `${currentShippingStepProgress.progress_percent ?? 0}%` }"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-wrap gap-2 pt-1 text-xs">
|
||||
<button
|
||||
v-if="page.shippingBatchSummary"
|
||||
type="button"
|
||||
class="rounded-full border border-default px-2.5 py-1 text-secondary transition hover:bg-surface-soft"
|
||||
@click="page.input = '上一票'"
|
||||
>
|
||||
{{ t('chat.shippingNoticeUi.prevTask') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="page.shippingBatchSummary"
|
||||
type="button"
|
||||
class="rounded-full border border-default px-2.5 py-1 text-secondary transition hover:bg-surface-soft"
|
||||
@click="page.input = '下一票'"
|
||||
>
|
||||
{{ t('chat.shippingNoticeUi.nextTask') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="page.shippingBatchTasks?.length > 1"
|
||||
type="button"
|
||||
class="rounded-full border border-default px-2.5 py-1 text-secondary transition hover:bg-surface-soft"
|
||||
@click="page.shippingBatchTasksExpanded = !page.shippingBatchTasksExpanded"
|
||||
>
|
||||
{{ page.shippingBatchTasksExpanded ? t('chat.shippingNoticeUi.collapseTasks') : t('chat.shippingNoticeUi.viewTasks') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="page.shippingBatchSummary" class="grid grid-cols-4 gap-2 text-right text-xs">
|
||||
<div class="rounded-2xl bg-surface px-3 py-2">
|
||||
<div class="text-muted">{{ t('chat.shippingNoticeUi.fileCount') }}</div>
|
||||
<div class="mt-1 text-sm font-semibold text-primary">{{ batchFileCount }}</div>
|
||||
</div>
|
||||
<div class="rounded-2xl bg-surface px-3 py-2">
|
||||
<div class="text-muted">{{ t('chat.shippingNoticeUi.runningCount') }}</div>
|
||||
<div class="mt-1 text-sm font-semibold text-primary">{{ batchRunningCount }}</div>
|
||||
</div>
|
||||
<div class="rounded-2xl bg-surface px-3 py-2">
|
||||
<div class="text-muted">{{ t('chat.shippingNoticeUi.completedCount') }}</div>
|
||||
<div class="mt-1 text-sm font-semibold text-primary">{{ batchCompletedCount }}</div>
|
||||
</div>
|
||||
<div class="rounded-2xl bg-surface px-3 py-2">
|
||||
<div class="text-muted">{{ t('chat.shippingNoticeUi.pendingCount') }}</div>
|
||||
<div class="mt-1 text-sm font-semibold text-primary">{{ batchPendingCount }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-if="page.shippingBatchSummary"
|
||||
class="mt-3 space-y-1 border-t border-default/70 pt-3"
|
||||
>
|
||||
<div class="flex items-center justify-between text-[11px] text-muted">
|
||||
<span>{{ t('chat.shippingNoticeUi.batchProgressTitle') }}</span>
|
||||
<span>{{ batchCompletedCount }}/{{ batchFileCount }} · {{ batchCompletionPercent }}%</span>
|
||||
</div>
|
||||
<div class="h-2 overflow-hidden rounded-full bg-slate-200">
|
||||
<div
|
||||
class="h-full rounded-full bg-brand-500 transition-all"
|
||||
:style="{ width: `${batchCompletionPercent}%` }"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-if="page.shippingInventorySelectionActive && page.shippingBatchTasks?.length > 1"
|
||||
class="mt-3 flex flex-wrap items-center justify-between gap-3 rounded-2xl border border-amber-200 bg-amber-50/90 px-3 py-3 text-sm text-amber-900"
|
||||
>
|
||||
<div class="space-y-1">
|
||||
<div class="font-semibold">{{ t('chat.shippingNoticeUi.inventoryTaskPickTitle') }}</div>
|
||||
<div class="text-xs text-amber-800">
|
||||
{{ t('chat.shippingNoticeUi.inventoryTaskPickHint') }}
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-full border border-amber-300 px-3 py-1 text-xs font-medium text-amber-800 transition hover:bg-amber-100"
|
||||
@click="page.cancelShippingInventoryTaskSelection()"
|
||||
>
|
||||
{{ t('chat.shippingNoticeUi.cancelInventoryTaskPick') }}
|
||||
</button>
|
||||
</div>
|
||||
<div
|
||||
v-if="page.shippingBatchTasksExpanded && page.shippingBatchTasks?.length"
|
||||
class="mt-3 grid gap-2 border-t border-default/70 pt-3 sm:grid-cols-2 xl:grid-cols-3"
|
||||
>
|
||||
<button
|
||||
v-for="task in page.shippingBatchTasks"
|
||||
:key="task.task_no"
|
||||
type="button"
|
||||
class="rounded-2xl border px-3 py-3 text-left transition"
|
||||
:class="task.task_no === page.shippingBatchSummary?.current_focus_task_no ? 'border-brand-300 bg-brand-50/80 shadow-sm' : 'border-default bg-surface hover:bg-surface-soft'"
|
||||
@click="page.switchShippingFocusTask(task.task_no)"
|
||||
>
|
||||
<div class="flex items-start justify-between gap-2">
|
||||
<div class="font-mono text-xs font-semibold text-primary">{{ task.task_no }}</div>
|
||||
<span
|
||||
class="rounded-full px-2 py-0.5 text-[11px] font-medium"
|
||||
:class="statusMeta(task.process_status).chip"
|
||||
>
|
||||
{{ statusMeta(task.process_status).label }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="mt-2 truncate text-sm font-medium text-secondary">{{ task.customer_name || task.source_file_name || '未命名通知' }}</div>
|
||||
<div class="mt-1 text-[11px] text-muted">
|
||||
{{ stepLabel(task.current_step) }}
|
||||
<span v-if="task.batch_index && task.batch_total">
|
||||
· {{ t('chat.shippingNoticeUi.batchProgress', { index: task.batch_index, total: task.batch_total }) }}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
v-if="page.shippingInventorySelectionActive"
|
||||
class="mt-3 flex items-center justify-between gap-2"
|
||||
>
|
||||
<span
|
||||
v-if="page.shippingInventorySelectionTaskId === task.task_no"
|
||||
class="rounded-full bg-brand-50 px-2 py-1 text-[11px] font-medium text-brand-700"
|
||||
>
|
||||
{{ t('chat.shippingNoticeUi.inventoryTargetTask', { taskId: task.task_no }) }}
|
||||
</span>
|
||||
<span v-else class="text-[11px] text-muted">
|
||||
{{ t('chat.shippingNoticeUi.inventoryTargetIdle') }}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-full border border-brand-200 px-2.5 py-1 text-[11px] font-medium text-brand-700 transition hover:bg-brand-50"
|
||||
@click.stop="page.selectShippingInventoryUploadTask(task.task_no)"
|
||||
>
|
||||
{{ t('chat.shippingNoticeUi.uploadInventoryToTask') }}
|
||||
</button>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<ShippingBatchProgressPanel
|
||||
v-if="page.isShippingNoticeAgent && (page.shippingBatchSummary || page.activeShippingTaskDetail)"
|
||||
:batch-summary="page.shippingBatchSummary"
|
||||
:batch-tasks="page.shippingBatchTasks"
|
||||
:active-task-detail="page.activeShippingTaskDetail"
|
||||
:tasks-expanded="page.shippingBatchTasksExpanded"
|
||||
:inventory-selection-active="page.shippingInventorySelectionActive && page.shippingBatchTasks?.length > 1"
|
||||
@update:tasks-expanded="page.shippingBatchTasksExpanded = $event"
|
||||
@focus-task="page.switchShippingFocusTask"
|
||||
@resume-task="page.resumeShippingTask"
|
||||
/>
|
||||
|
||||
<ChatMessageList
|
||||
:messages="page.messages"
|
||||
|
||||
@@ -0,0 +1,443 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/chat/components/ShippingBatchProgressPanel.vue
|
||||
* 用途:发货通知聊天顶部批次进度卡片,按原型方案 C 展示批次概览、任务切换列表、七步进度与续办弹层。
|
||||
* 依赖:shippingStepper、shipping.api.types、vue-i18n、lucide-vue-next。
|
||||
* 逻辑:上游由 ChatViewContent 传入批次/任务状态;本组件只负责展示与抛出 focus/resume 事件,不直接请求后端。
|
||||
*/
|
||||
import { computed, ref } from 'vue';
|
||||
import { List, PlayCircle, X } 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,
|
||||
ShippingTaskDetail,
|
||||
ShippingTaskSummary,
|
||||
} from '@/features/chat/api/shipping.api';
|
||||
|
||||
const props = defineProps<{
|
||||
batchSummary: ShippingBatchSummary | null;
|
||||
batchTasks: ShippingTaskSummary[];
|
||||
activeTaskDetail: ShippingTaskDetail | null;
|
||||
tasksExpanded: boolean;
|
||||
inventorySelectionActive: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:tasksExpanded': [value: boolean];
|
||||
'focus-task': [taskNo: string];
|
||||
'resume-task': [taskNo: string];
|
||||
}>();
|
||||
|
||||
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 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 pending = Math.max(0, Number(summary?.pending ?? (total - completed - running)));
|
||||
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 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 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;
|
||||
return {
|
||||
index: safeIndex + 1,
|
||||
label: t(steps[safeIndex]?.label || 'chat.shippingNoticeUi.processing'),
|
||||
};
|
||||
});
|
||||
|
||||
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;
|
||||
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="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 }}
|
||||
</div>
|
||||
<div class="flex 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"
|
||||
>
|
||||
{{ 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"
|
||||
>
|
||||
<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')} ▼` }}
|
||||
</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>
|
||||
@@ -87,9 +87,12 @@ export function useChatPage() {
|
||||
const scroll = useChatScroll({ container: chatScrollContainer, messages });
|
||||
scroll.setupThinkingScrollWatch(isThinking, conversationId);
|
||||
|
||||
let resetShippingConversationState = () => {};
|
||||
|
||||
const resetPeripheralState = () => {
|
||||
browser.close();
|
||||
queryPreview.close();
|
||||
resetShippingConversationState();
|
||||
};
|
||||
|
||||
const disposePeripherals = () => {
|
||||
@@ -204,6 +207,7 @@ export function useChatPage() {
|
||||
loadConversation: (id, opts) => loadConversation(id, opts),
|
||||
createNewChatView,
|
||||
});
|
||||
resetShippingConversationState = shipping.resetShippingConversationState;
|
||||
|
||||
const conversationApi = createChatPageConversationApi({
|
||||
deps,
|
||||
@@ -416,6 +420,7 @@ export function useChatPage() {
|
||||
shippingInventorySelectionActive: shipping.shippingInventorySelectionActive,
|
||||
shippingInventorySelectionTaskId: shipping.shippingInventorySelectionTaskId,
|
||||
switchShippingFocusTask: shipping.switchShippingFocusTask,
|
||||
resumeShippingTask: shipping.resumeShippingTask,
|
||||
selectShippingInventoryUploadTask: shipping.selectShippingInventoryUploadTask,
|
||||
cancelShippingInventoryTaskSelection: shipping.cancelShippingInventoryTaskSelection,
|
||||
shippingSuggestedPrompt: shipping.shippingSuggestedPrompt,
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
import {
|
||||
computed,
|
||||
onBeforeUnmount,
|
||||
ref,
|
||||
watch,
|
||||
type ComputedRef,
|
||||
@@ -48,6 +49,7 @@ import {
|
||||
import type { ChatMessage, ChatSessionItem } from '../types/chat.types';
|
||||
import type { ChatUploadFileSpec, PendingAttachment } from '../types/shipping.types';
|
||||
import type { ChatDeps } from './chat.deps';
|
||||
import { listChatMessages } from '../api/chat.api';
|
||||
|
||||
export interface UseChatShippingOptions {
|
||||
deps: ChatDeps;
|
||||
@@ -152,6 +154,8 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
const shippingConversationTaskIdCache = ref<Record<string, string>>({});
|
||||
const shippingInventorySchemaPreviewCache = ref<Record<string, unknown>>({});
|
||||
const autoResumedShippingTasks = ref<Record<string, boolean>>({});
|
||||
const lastConversationSyncKey = ref('');
|
||||
let shippingStatusPollTimer: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
const syncShippingBatchSummary = async (batchNo: string) => {
|
||||
const normalized = String(batchNo || '').trim();
|
||||
@@ -174,8 +178,14 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
created_at: detail.created_at,
|
||||
updated_at: detail.updated_at,
|
||||
};
|
||||
if (detail.focus_task?.task_no) {
|
||||
resolvedShippingTaskId.value = String(detail.focus_task.task_no).trim();
|
||||
const preferredTaskNo = String(
|
||||
detail.focus_task?.task_no
|
||||
|| detail.process_summary?.current_task_no
|
||||
|| detail.current_focus_task_no
|
||||
|| '',
|
||||
).trim();
|
||||
if (preferredTaskNo) {
|
||||
resolvedShippingTaskId.value = preferredTaskNo;
|
||||
}
|
||||
} catch {
|
||||
// ignore summary refresh failure in chat flow
|
||||
@@ -195,9 +205,34 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
};
|
||||
}
|
||||
await syncShippingBatchSummary(batchNo);
|
||||
await syncActiveShippingTaskDetail(normalizedTaskNo);
|
||||
await refreshShippingActions();
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* 清空当前聊天页绑定的发货任务上下文。
|
||||
*
|
||||
* 核心逻辑:在新建对话、切换 Agent 或离开发货任务场景时,主动清掉批次/任务/上传缓存,
|
||||
* 避免顶部 Stepper、列表展开态和待上传库存文件残留到下一次新会话。
|
||||
*/
|
||||
const resetShippingConversationState = () => {
|
||||
shippingAutoFlowRequested.value = false;
|
||||
pendingShippingUploadTaskId.value = '';
|
||||
pendingShippingInventoryFile.value = null;
|
||||
shippingInventorySelectionActive.value = false;
|
||||
shippingInventorySelectionTaskId.value = '';
|
||||
resolvedShippingTaskId.value = '';
|
||||
resolvedShippingBatchNo.value = '';
|
||||
shippingBatchSummary.value = null;
|
||||
shippingBatchTasks.value = [];
|
||||
shippingBatchTasksExpanded.value = false;
|
||||
activeShippingTaskDetail.value = null;
|
||||
shippingConversationTaskIdCache.value = {};
|
||||
shippingInventorySchemaPreviewCache.value = {};
|
||||
lastConversationSyncKey.value = '';
|
||||
};
|
||||
|
||||
const getActiveShippingTaskId = () =>
|
||||
findLatestShippingTaskId(messages.value)
|
||||
|| resolvedShippingTaskId.value
|
||||
@@ -215,6 +250,17 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
batch_no: getActiveShippingBatchNo(),
|
||||
});
|
||||
|
||||
const hasRunningShippingBatchTasks = () =>
|
||||
shippingBatchTasks.value.some(
|
||||
(task) => !['uploaded', 'completed', 'closed', 'rejected'].includes(String(task.process_status || '').trim()),
|
||||
);
|
||||
|
||||
/**
|
||||
* 同步当前焦点任务详情,并在仅恢复 `task_no` 的场景下补齐 `batch_no` 上下文。
|
||||
*
|
||||
* 核心逻辑:先拉取任务详情,再把详情里的批次号回填到聊天状态,确保会话恢复后仍能继续按批次模式加载 2 票/多票摘要。
|
||||
* @param taskId - 可选任务编号;未传时回退到当前激活任务
|
||||
*/
|
||||
const syncActiveShippingTaskDetail = async (taskId?: string) => {
|
||||
const normalized = String(taskId || getActiveShippingTaskId() || '').trim().toUpperCase();
|
||||
if (!normalized) {
|
||||
@@ -222,12 +268,43 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
activeShippingTaskDetail.value = await getWorkspaceShippingTask(normalized);
|
||||
const detail = await getWorkspaceShippingTask(normalized);
|
||||
activeShippingTaskDetail.value = detail;
|
||||
const batchNo = String(detail.batch_no || '').trim();
|
||||
if (batchNo && resolvedShippingBatchNo.value !== batchNo) {
|
||||
resolvedShippingBatchNo.value = batchNo;
|
||||
}
|
||||
} catch {
|
||||
activeShippingTaskDetail.value = null;
|
||||
}
|
||||
};
|
||||
|
||||
const syncConversationMessagesIfNeeded = async (taskId?: string) => {
|
||||
const conversationKey = String(conversationId.value || '').trim();
|
||||
const normalizedTaskId = String(taskId || getActiveShippingTaskId() || '').trim().toUpperCase();
|
||||
if (!conversationKey || !normalizedTaskId || !isShippingNoticeAgent.value || isThinking.value) return;
|
||||
const detail = activeShippingTaskDetail.value;
|
||||
// 任务详情接口当前不返回顶层 checkpoint,parse_review 需从详情状态字段回推。
|
||||
const checkpoint = String(
|
||||
(detail?.step_payload as Record<string, unknown> | undefined)?.checkpoint
|
||||
|| detail?.review_status
|
||||
|| '',
|
||||
).trim();
|
||||
if (checkpoint !== 'parse_review') return;
|
||||
const exists = messages.value.some((msg) => {
|
||||
if (msg.type !== 'shipping-parse-review' || !msg.payload || typeof msg.payload !== 'object') return false;
|
||||
return String((msg.payload as { taskId?: string }).taskId || '').trim().toUpperCase() === normalizedTaskId;
|
||||
});
|
||||
if (exists) return;
|
||||
const syncKey = `${conversationKey}|${normalizedTaskId}|parse_review`;
|
||||
if (lastConversationSyncKey.value === syncKey) return;
|
||||
const loaded = await listChatMessages(conversationKey, currentAgentId.value);
|
||||
if (Array.isArray(loaded) && loaded.length > 0) {
|
||||
messages.value = loaded;
|
||||
lastConversationSyncKey.value = syncKey;
|
||||
}
|
||||
};
|
||||
|
||||
const lastAssistantMessageContent = () => {
|
||||
for (let i = messages.value.length - 1; i >= 0; i -= 1) {
|
||||
const item = messages.value[i];
|
||||
@@ -422,9 +499,32 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
const onConversationIdChanging = (nextId: string, prevId: string | null | undefined) => {
|
||||
if (prevId !== nextId) {
|
||||
resolvedShippingTaskId.value = '';
|
||||
if (!shippingBatchNoFromQuery.value) {
|
||||
resolvedShippingBatchNo.value = '';
|
||||
shippingBatchSummary.value = null;
|
||||
shippingBatchTasks.value = [];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 续办指定任务,并把聊天上下文切到该任务继续推进。
|
||||
*
|
||||
* 核心逻辑:先切换批次焦点任务,再复用既有“请继续处理发货任务”提示词触发一次发送,
|
||||
* 让 Agent 基于最新 task_id/batch_no 返回下一步动作。
|
||||
* @param taskNo - 需要续办的任务编号
|
||||
* @returns 是否已成功触发续办
|
||||
*/
|
||||
const resumeShippingTask = async (taskNo: string) => {
|
||||
const normalizedTaskNo = String(taskNo || '').trim().toUpperCase();
|
||||
if (!normalizedTaskNo || !isShippingNoticeAgent.value || isThinking.value) return false;
|
||||
const switched = await switchShippingFocusTask(normalizedTaskNo);
|
||||
if (!switched) return false;
|
||||
input.value = t('chat.shippingNoticeContinue', { taskId: normalizedTaskNo });
|
||||
await invokeHandleSend?.();
|
||||
return true;
|
||||
};
|
||||
|
||||
const onConversationLoadedEmpty = async () => {
|
||||
if (!isShippingNoticeAgent.value || !shippingTaskIdFromQuery.value || isThinking.value) return;
|
||||
const nextQuery: Record<string, string> = { task_id: shippingTaskIdFromQuery.value };
|
||||
@@ -442,6 +542,42 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
await invokeHandleSend?.();
|
||||
};
|
||||
|
||||
/**
|
||||
* 启停发货批次状态短轮询。
|
||||
*
|
||||
* 核心逻辑:聊天流当前没有 shipping 专属 SSE;因此在存在任务/批次上下文时每 3 秒补拉一次,
|
||||
* 让顶部 Stepper、批次统计和动作按钮能在后端异步状态变化后自动更新。
|
||||
*/
|
||||
const restartShippingStatusPolling = () => {
|
||||
if (shippingStatusPollTimer) {
|
||||
clearInterval(shippingStatusPollTimer);
|
||||
shippingStatusPollTimer = null;
|
||||
}
|
||||
if (!isShippingNoticeAgent.value) return;
|
||||
const batchNo = getActiveShippingBatchNo();
|
||||
const taskId = getActiveShippingTaskId();
|
||||
if (!batchNo && !taskId) return;
|
||||
|
||||
shippingStatusPollTimer = setInterval(() => {
|
||||
if (!isShippingNoticeAgent.value) return;
|
||||
const nextBatchNo = getActiveShippingBatchNo();
|
||||
const nextTaskId = getActiveShippingTaskId();
|
||||
if (!nextBatchNo && !nextTaskId) return;
|
||||
void (async () => {
|
||||
if (nextBatchNo) await syncShippingBatchSummary(nextBatchNo);
|
||||
if (nextTaskId) {
|
||||
await syncActiveShippingTaskDetail(nextTaskId);
|
||||
await syncConversationMessagesIfNeeded(nextTaskId);
|
||||
}
|
||||
await refreshShippingActions();
|
||||
if (!hasRunningShippingBatchTasks() && !isThinking.value && shippingStatusPollTimer) {
|
||||
clearInterval(shippingStatusPollTimer);
|
||||
shippingStatusPollTimer = null;
|
||||
}
|
||||
})();
|
||||
}, 3000);
|
||||
};
|
||||
|
||||
// ── 动作按钮 watch ────────────────────────────────────────
|
||||
const shippingActionsWatchKey = computed(() => {
|
||||
const msgs = messages.value;
|
||||
@@ -460,6 +596,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
syncShippingParseReviewCard(taskId),
|
||||
syncActiveShippingTaskDetail(taskId),
|
||||
]);
|
||||
await syncConversationMessagesIfNeeded(taskId);
|
||||
});
|
||||
});
|
||||
watch([resolvedShippingBatchNo, shippingBatchNoFromQuery], ([batchNo, queryBatchNo]) => {
|
||||
@@ -470,6 +607,19 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
}
|
||||
void syncShippingBatchSummary(nextBatchNo);
|
||||
}, { immediate: true });
|
||||
watch(
|
||||
[isShippingNoticeAgent, conversationId, resolvedShippingBatchNo, shippingBatchNoFromQuery, resolvedShippingTaskId, shippingTaskIdFromQuery, isThinking],
|
||||
() => {
|
||||
restartShippingStatusPolling();
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
onBeforeUnmount(() => {
|
||||
if (shippingStatusPollTimer) {
|
||||
clearInterval(shippingStatusPollTimer);
|
||||
shippingStatusPollTimer = null;
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
shippingBindSend,
|
||||
@@ -491,6 +641,8 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
getCurrentShippingChatContext,
|
||||
getActiveShippingBatchNo,
|
||||
switchShippingFocusTask,
|
||||
resumeShippingTask,
|
||||
resetShippingConversationState,
|
||||
resumeShippingTaskFromQuery,
|
||||
normalizeShippingHeaderForDisplay,
|
||||
getShippingInventoryMappingPayload,
|
||||
|
||||
@@ -65,6 +65,12 @@ export function createChatPageConversationApi(ctx: ChatPageConversationContext)
|
||||
|
||||
const startNewChat = () => {
|
||||
ctx.createNewChatView();
|
||||
ctx.clearAttachments();
|
||||
ctx.input.value = '';
|
||||
ctx.copiedIndex.value = null;
|
||||
ctx.resetPeripheralState();
|
||||
ctx.filePreviewVisible.value = false;
|
||||
ctx.previewFile.value = null;
|
||||
void ctx.router.replace({ path: ctx.route.path, query: {} });
|
||||
};
|
||||
|
||||
|
||||
@@ -45,6 +45,8 @@ const CURRENT_STEP_INDEX_MAP: Record<string, number> = {
|
||||
step7_finish: 6,
|
||||
};
|
||||
|
||||
const TERMINAL_PROCESS_STATUSES = new Set(['uploaded', 'closed']);
|
||||
|
||||
function deriveCurrentIndex(task: ShippingTaskStepperSource | null | undefined): number {
|
||||
const currentStep = String(task?.current_step || '').trim();
|
||||
const processStatus = String(task?.process_status || '').trim();
|
||||
@@ -60,7 +62,7 @@ function deriveCurrentIndex(task: ShippingTaskStepperSource | null | undefined):
|
||||
}
|
||||
}
|
||||
|
||||
if (processStatus === 'uploaded' || processStatus === 'closed') return 6;
|
||||
if (TERMINAL_PROCESS_STATUSES.has(processStatus)) return 6;
|
||||
if (processStatus === 'waiting_upload' || processStatus === 'upload_failed' || hasExport) return 5;
|
||||
if (processStatus === 'matched') return 4;
|
||||
if (reviewStatus === 'shortage_review' || pendingReason === 'shortage_review' || pendingReason === 'shortage') return 4;
|
||||
@@ -102,7 +104,10 @@ export function buildShippingWorkflowSteps(
|
||||
|
||||
return SHIPPING_WORKFLOW_STEP_LABELS.map((label, index) => {
|
||||
let status: ShippingWorkflowStepItem['status'] = 'pending';
|
||||
if (index < currentIndex) {
|
||||
// [STEP 1] uploaded/closed 是整票已完成的终态,不能再被 current_step 渲染成“第 7 步进行中”。
|
||||
if (TERMINAL_PROCESS_STATUSES.has(processStatus)) {
|
||||
status = 'completed';
|
||||
} else if (index < currentIndex) {
|
||||
status = 'completed';
|
||||
} else if (index === currentIndex) {
|
||||
status = 'current';
|
||||
|
||||
@@ -47,6 +47,11 @@ export function buildShippingNoticeUploadPrompt(
|
||||
|| ((result?.data as { tasks?: Array<{ task_id?: string }> } | undefined)?.tasks?.[0]?.task_id)
|
||||
|| '',
|
||||
).trim();
|
||||
const taskIds = Array.isArray((result?.data as { tasks?: unknown[] } | undefined)?.tasks)
|
||||
? ((result?.data as { tasks?: Array<{ task_id?: string }> }).tasks || [])
|
||||
.map((task) => String(task?.task_id || '').trim())
|
||||
.filter(Boolean)
|
||||
: [];
|
||||
const fileCount = Number(options?.fileCount || 0);
|
||||
const fileLabel = options?.fileName
|
||||
? `《${options.fileName}》`
|
||||
@@ -54,7 +59,11 @@ export function buildShippingNoticeUploadPrompt(
|
||||
const parts = [`我已上传${fileLabel}`];
|
||||
if (batchNo) parts.push(`批次 ${batchNo}`);
|
||||
if (taskId) parts.push(`当前任务 ${taskId}`);
|
||||
return `${parts.join(',')}。请读取任务 raw_text,用 LLM 抽取结构化字段后调用 parse_notice(structured=...) 落库;若抽取失败可仅传 raw_text 走后端规则兜底,并展示解析结果供我确认。`;
|
||||
if (fileCount > 1 || taskIds.length > 1) {
|
||||
const taskListText = taskIds.length ? `任务列表:${taskIds.join('、')}。` : '';
|
||||
return `${parts.join(',')}。${taskListText}请立即开始整批处理,不要只处理当前任务。先调用 get_batch_status 查看整批状态,再按批次顺序逐票处理:必要时调用 switch_focus_task 切到对应任务,然后读取该任务 raw_text,用 LLM 抽取结构化字段并调用 parse_notice(structured=...) 落库;若抽取失败可仅传 task_id 让后端用 raw_text 兜底。每处理完一票,都继续切到下一票,直到本批每一票都进入各自下一阶段(待确认、待上传库存、自动推进中的任一状态)。禁止再次询问我“是否开始解析”或只停在第一票。`;
|
||||
}
|
||||
return `${parts.join(',')}。请立即读取任务 raw_text,用 LLM 抽取结构化字段后直接调用 parse_notice(structured=...) 落库;若抽取失败可仅传 raw_text 走后端规则兜底。禁止再次询问我“是否开始解析”或“是否现在开始解析”。解析完成后,请直接展示解析结果供我确认。`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -107,12 +107,11 @@ export function createShippingMenuHandlers(ctx: ShippingMenuHandlerContext) {
|
||||
};
|
||||
const assistantMsg: ChatMessage = {
|
||||
role: 'assistant',
|
||||
type: 'shipping-match-result',
|
||||
type: 'text',
|
||||
content: [
|
||||
String(result.message || '').trim(),
|
||||
`任务编号:${taskId}`,
|
||||
].filter(Boolean).join('\n'),
|
||||
payload: buildMatchResultPayload(taskId, result),
|
||||
local_id: ctx.newLocalMessageId('shipping-assistant'),
|
||||
local_only: true,
|
||||
};
|
||||
@@ -158,11 +157,9 @@ export function createShippingMenuHandlers(ctx: ShippingMenuHandlerContext) {
|
||||
};
|
||||
const assistantMsg: ChatMessage = {
|
||||
role: 'assistant',
|
||||
type: 'text',
|
||||
content: [
|
||||
String(result.message || '').trim(),
|
||||
`任务编号:${taskId}`,
|
||||
].filter(Boolean).join('\n'),
|
||||
type: 'shipping-match-result',
|
||||
content: String(result.message || '').trim(),
|
||||
payload: buildMatchResultPayload(taskId, result),
|
||||
local_id: ctx.newLocalMessageId('shipping-assistant'),
|
||||
local_only: true,
|
||||
};
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
type ShippingTaskSummary,
|
||||
} from '@/features/chat/api/shipping.api';
|
||||
import { extractExt } from '../constants/shipping';
|
||||
import { buildShippingInventoryUploadPrompt, buildShippingNoticeUploadPrompt, classifyShippingUploadFile } from './shippingUploadPrompt';
|
||||
import { buildShippingInventoryUploadPrompt, classifyShippingUploadFile } from './shippingUploadPrompt';
|
||||
import type { PendingAttachment } from '../types/shipping.types';
|
||||
import type { Ref } from 'vue';
|
||||
|
||||
@@ -184,18 +184,19 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
|
||||
).trim();
|
||||
const hint = String(result.message || '').trim();
|
||||
const status = String((result as { status?: string }).status || '').trim();
|
||||
const orchestratorStarted = Boolean(
|
||||
(result.data as { orchestrator_started?: boolean } | undefined)?.orchestrator_started,
|
||||
);
|
||||
const tail = status === 'needs_human' ? '请根据提示进行确认/驳回。' : '';
|
||||
await ctx.pushShippingLocalAssistantMessage(
|
||||
[
|
||||
hint || `已处理发货通知附件:${file.name}`,
|
||||
batchNo ? `批次编号:${batchNo}` : '',
|
||||
taskId ? `任务编号:${taskId}` : '',
|
||||
orchestratorStarted ? '后台已开始按票处理,请稍后查看进度自动刷新。' : '',
|
||||
tail,
|
||||
].filter(Boolean).join('\n'),
|
||||
);
|
||||
await ctx.sendShippingMenuMessage(
|
||||
buildShippingNoticeUploadPrompt(result as unknown as Record<string, unknown>, { fileName: file.name }),
|
||||
);
|
||||
void ctx.refreshShippingActions();
|
||||
};
|
||||
|
||||
@@ -231,6 +232,9 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
|
||||
const fileCount = Number(batch?.file_count || noticeFiles.length || 0);
|
||||
const hint = String(result.message || '').trim();
|
||||
const status = String((result as { status?: string }).status || '').trim();
|
||||
const orchestratorStarted = Boolean(
|
||||
(result.data as { orchestrator_started?: boolean } | undefined)?.orchestrator_started,
|
||||
);
|
||||
const tail = status === 'needs_human' ? '请根据提示进行确认/驳回。' : '';
|
||||
await ctx.pushShippingLocalAssistantMessage(
|
||||
[
|
||||
@@ -238,12 +242,10 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
|
||||
batchNo ? `批次编号:${batchNo}` : '',
|
||||
taskId ? `当前任务:${taskId}` : '',
|
||||
focusProgress,
|
||||
orchestratorStarted ? `后台已开始按票拆分处理,本批 ${fileCount} 票会逐步更新状态。` : '',
|
||||
tail,
|
||||
].filter(Boolean).join('\n'),
|
||||
);
|
||||
await ctx.sendShippingMenuMessage(
|
||||
buildShippingNoticeUploadPrompt(result as unknown as Record<string, unknown>, { fileCount }),
|
||||
);
|
||||
void ctx.refreshShippingActions();
|
||||
};
|
||||
|
||||
|
||||
@@ -157,6 +157,7 @@ export interface ShippingNoticeUploadResponse {
|
||||
batch?: ShippingBatchSummary;
|
||||
focus_task?: ShippingTaskSummary | null;
|
||||
tasks?: Array<Record<string, unknown>>;
|
||||
orchestrator_started?: boolean;
|
||||
};
|
||||
human_options?: string[];
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
markWorkspaceShippingManualUploaded,
|
||||
matchWorkspaceShippingInventory,
|
||||
removeWorkspaceShippingNoticeLine,
|
||||
retryWorkspaceShippingTask,
|
||||
SHIPPING_NOTICE_AGENT_NAME,
|
||||
submitWorkspaceShippingDecision,
|
||||
updateWorkspaceShippingNoticeFields,
|
||||
@@ -39,6 +40,7 @@ import {
|
||||
import type { ChatMessage } from '@/features/chat/types/chat.types';
|
||||
import type { ShippingParseReviewPayload } from '@/features/chat/types/shipping.types';
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import { buildShippingWorkflowSteps, shippingActionButtonClass } from '@/features/chat/shipping';
|
||||
|
||||
const props = defineProps<{
|
||||
@@ -47,6 +49,7 @@ const props = defineProps<{
|
||||
|
||||
const router = useRouter();
|
||||
const { t } = useI18n();
|
||||
const msg = useMessage();
|
||||
|
||||
const loading = ref(false);
|
||||
const detailLoading = ref(false);
|
||||
@@ -55,6 +58,7 @@ const selectedTaskNo = ref<string | null>(null);
|
||||
const detail = ref<ShippingTaskDetail | null>(null);
|
||||
const detailSaving = ref(false);
|
||||
const detailActionBusy = ref(false);
|
||||
const detailRetrying = ref(false);
|
||||
const detailActionButtons = ref<ShippingChatAction[]>([]);
|
||||
const statusFilter = ref('all');
|
||||
const chatAgentId = ref<number | null>(null);
|
||||
@@ -97,6 +101,9 @@ const detailStepProgress = computed<ShippingCurrentStepProgress | null>(() => {
|
||||
const progress = (payload as Record<string, unknown>).current_step_progress;
|
||||
return progress && typeof progress === 'object' ? progress as ShippingCurrentStepProgress : null;
|
||||
});
|
||||
const detailStepHasPercent = computed(() =>
|
||||
typeof detailStepProgress.value?.progress_percent === 'number',
|
||||
);
|
||||
|
||||
const loadCases = async () => {
|
||||
loading.value = true;
|
||||
@@ -290,6 +297,20 @@ const handleWorkspaceAction = async (action: ShippingChatAction) => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleRetryCurrentTask = async () => {
|
||||
if (!detail.value || detailRetrying.value) return;
|
||||
detailRetrying.value = true;
|
||||
try {
|
||||
const result = await retryWorkspaceShippingTask(detail.value.task_no, '工作台重试当前票');
|
||||
msg.success(result.message || t('workspace.shippingNotice.retryCurrentDone'));
|
||||
await Promise.all([loadDetail(detail.value.task_no), loadCases()]);
|
||||
} catch (error) {
|
||||
msg.error(error instanceof Error ? error.message : t('workspace.shippingNotice.retryFailed'));
|
||||
} finally {
|
||||
detailRetrying.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
watch(selectedTaskNo, (val) => {
|
||||
if (val) loadDetail(val);
|
||||
else detail.value = null;
|
||||
@@ -397,6 +418,15 @@ onMounted(async () => {
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 rounded-xl border border-default px-3 py-1.5 text-sm font-medium text-secondary hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-60"
|
||||
:disabled="detailRetrying"
|
||||
@click="handleRetryCurrentTask"
|
||||
>
|
||||
<RefreshCw class="h-3.5 w-3.5" />
|
||||
{{ detailRetrying ? $t('workspace.shippingNotice.retrying') : $t('workspace.shippingNotice.retryCurrentTask') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="chatAgentId"
|
||||
type="button"
|
||||
@@ -428,8 +458,8 @@ onMounted(async () => {
|
||||
<div class="font-medium text-primary">
|
||||
{{ detailStepProgress.step_title || t('chat.shippingNoticeUi.stepDetail.title') }}
|
||||
</div>
|
||||
<div class="text-muted">
|
||||
{{ detailStepProgress.progress_percent ?? 0 }}%
|
||||
<div v-if="detailStepHasPercent" class="text-muted">
|
||||
{{ detailStepProgress.progress_percent }}%
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-1 text-sm text-secondary">
|
||||
@@ -444,10 +474,13 @@ onMounted(async () => {
|
||||
>
|
||||
{{ t('chat.shippingNoticeUi.stepDetail.counter', { current: detailStepProgress.current, total: detailStepProgress.total }) }}
|
||||
</div>
|
||||
<div class="mt-2 h-2 overflow-hidden rounded-full bg-slate-200">
|
||||
<div
|
||||
v-if="detailStepHasPercent"
|
||||
class="mt-2 h-2 overflow-hidden rounded-full bg-slate-200"
|
||||
>
|
||||
<div
|
||||
class="h-full rounded-full bg-sky-500 transition-all"
|
||||
:style="{ width: `${detailStepProgress.progress_percent ?? 0}%` }"
|
||||
:style="{ width: `${detailStepProgress.progress_percent}%` }"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user