feat(shipping-notice): 落地 XFA 拆分、版面签名、统一进度与处理域履约
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
3a9fbac2fc
commit
d2b3d74def
571 files changed
+78064
-24681
No files matched your search
+318
@@ -0,0 +1,318 @@
|
||||
/**
|
||||
* features/chat/components/shipping/ShippingConversationProcessingCard.spec.ts
|
||||
* 用途:验收右侧任务分组卡——needs_action/processing 与短时反馈标签。
|
||||
* 依赖:Vitest、Vue Test Utils、vue-i18n、ShippingConversationProcessingCard。
|
||||
* 逻辑:构造 ConversationProcessingProjection;断言分组、焦点 emit;右侧不渲染 history。
|
||||
*/
|
||||
import { mount, flushPromises } from '@vue/test-utils';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { createI18n } from 'vue-i18n';
|
||||
import chatZhCn from '@/locales/zh-CN/chat.json';
|
||||
import type { ConversationProcessingProjection } from '@/features/chat/types/shipping.api.types';
|
||||
import ShippingConversationProcessingCard from './ShippingConversationProcessingCard.vue';
|
||||
|
||||
const i18n = createI18n({
|
||||
legacy: false,
|
||||
locale: 'zh-CN',
|
||||
messages: { 'zh-CN': { chat: chatZhCn } },
|
||||
});
|
||||
|
||||
function buildProjection(): ConversationProcessingProjection {
|
||||
return {
|
||||
summary: { total_tasks: 3, processing: 1, needs_action: 1, completed: 1, history: 0 },
|
||||
focused_task_no: 'OT-PROC',
|
||||
recent_task_no: 'OT-PROC',
|
||||
needs_action: [{
|
||||
user_task_no: 'OT-NEED',
|
||||
group: 'needs_action',
|
||||
status_label: 'pending_review',
|
||||
file_count: 2,
|
||||
run_no: 'RUN-NEED',
|
||||
can_append: false,
|
||||
recently_created: false,
|
||||
}],
|
||||
processing: [{
|
||||
user_task_no: 'OT-PROC',
|
||||
submission_ordinal: 2,
|
||||
group: 'processing',
|
||||
status_label: 'extracting',
|
||||
file_count: 1,
|
||||
run_no: 'RUN-PROC',
|
||||
can_append: true,
|
||||
recently_created: true,
|
||||
focused: true,
|
||||
}],
|
||||
completed: [{
|
||||
user_task_no: 'OT-DONE',
|
||||
group: 'completed',
|
||||
status_label: 'completed',
|
||||
title: 'done.pdf',
|
||||
file_count: 1,
|
||||
run_no: 'RUN-DONE',
|
||||
can_append: false,
|
||||
available_actions: ['view_details'],
|
||||
}],
|
||||
history: [{
|
||||
user_task_no: 'OT-HIST',
|
||||
group: 'history',
|
||||
status_label: 'completed',
|
||||
file_count: 1,
|
||||
run_no: 'RUN-HIST',
|
||||
can_append: false,
|
||||
viewed: true,
|
||||
}],
|
||||
};
|
||||
}
|
||||
|
||||
describe('ShippingConversationProcessingCard', () => {
|
||||
it('renders needs_action / processing / completed groups, hides history on the right panel', async () => {
|
||||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||||
props: { projection: buildProjection() },
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
await flushPromises();
|
||||
|
||||
expect(wrapper.find('[data-testid="shipping-conversation-processing-card"]').exists()).toBe(true);
|
||||
expect(wrapper.find('[data-testid="shipping-processing-group-needs_action"]').exists()).toBe(true);
|
||||
expect(wrapper.find('[data-testid="shipping-processing-group-processing"]').exists()).toBe(true);
|
||||
expect(wrapper.find('[data-testid="shipping-processing-group-completed"]').exists()).toBe(true);
|
||||
expect(wrapper.find('[data-testid="shipping-processing-task-OT-NEED"]').exists()).toBe(true);
|
||||
expect(wrapper.find('[data-testid="shipping-processing-task-OT-PROC"]').exists()).toBe(true);
|
||||
expect(wrapper.find('[data-testid="shipping-processing-task-OT-DONE"]').exists()).toBe(true);
|
||||
expect(wrapper.text()).toContain('刚刚创建');
|
||||
expect(wrapper.text()).toContain('已完成');
|
||||
// UI-04:右侧不展示处理记录分组。
|
||||
expect(wrapper.find('[data-testid="shipping-processing-group-history"]').exists()).toBe(false);
|
||||
expect(wrapper.find('[data-testid="shipping-processing-task-OT-HIST"]').exists()).toBe(false);
|
||||
});
|
||||
|
||||
it('renders multi-PDF task title instead of first filename', async () => {
|
||||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||||
props: {
|
||||
projection: {
|
||||
summary: { total_tasks: 1, processing: 0, needs_action: 1, completed: 0, history: 0 },
|
||||
needs_action: [{
|
||||
user_task_no: 'OT-MULTI',
|
||||
group: 'needs_action',
|
||||
status_label: 'pending_review',
|
||||
title: null,
|
||||
display_kind: 'multi_document_task',
|
||||
document_names: ['4518838152.pdf', '4518838154.pdf'],
|
||||
file_count: 2,
|
||||
run_no: 'RUN-MULTI',
|
||||
can_append: false,
|
||||
available_actions: ['view_details', 'cancel_task'],
|
||||
}],
|
||||
processing: [],
|
||||
completed: [],
|
||||
history: [],
|
||||
},
|
||||
},
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
await flushPromises();
|
||||
expect(wrapper.text()).toContain('订单识别任务');
|
||||
expect(wrapper.text()).toContain('2 个 PDF');
|
||||
expect(wrapper.text()).toContain('4518838152.pdf、4518838154.pdf');
|
||||
expect(wrapper.text()).toContain('取消整个任务');
|
||||
// 主标题不得单独伪装成首个 PDF 文件名任务。
|
||||
const titleEl = wrapper.find('[data-testid="shipping-processing-task-OT-MULTI"] .text-sm.font-semibold');
|
||||
expect(titleEl.text()).toContain('订单识别任务');
|
||||
expect(titleEl.text()).not.toContain('4518838152.pdf');
|
||||
});
|
||||
|
||||
it('shows multi-document title from authoritative projection without workflow fallback', async () => {
|
||||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||||
props: {
|
||||
projection: {
|
||||
summary: { total_tasks: 1, total_files: 2, processing: 0, needs_action: 1, completed: 0, history: 0 },
|
||||
needs_action: [{
|
||||
user_task_no: 'OT-MULTI',
|
||||
group: 'needs_action',
|
||||
status_label: 'pending_review',
|
||||
title: null,
|
||||
display_kind: 'multi_document_task',
|
||||
document_names: ['4518838152.pdf', '4518838154.pdf'],
|
||||
file_count: 2,
|
||||
run_no: 'RUN-MULTI',
|
||||
can_append: false,
|
||||
available_actions: ['view_details', 'cancel_task'],
|
||||
objects: [],
|
||||
}],
|
||||
processing: [],
|
||||
completed: [],
|
||||
history: [],
|
||||
},
|
||||
},
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
await flushPromises();
|
||||
expect(wrapper.text()).toContain('订单识别任务');
|
||||
expect(wrapper.text()).toContain('2 个 PDF');
|
||||
const titleEl = wrapper.find('[data-testid="shipping-processing-task-OT-MULTI"] .text-sm.font-semibold');
|
||||
expect(titleEl.text()).toContain('订单识别任务');
|
||||
expect(titleEl.text()).not.toContain('4518838152.pdf');
|
||||
});
|
||||
|
||||
it('falls back to unnamed PDF instead of internal OT number', async () => {
|
||||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||||
props: {
|
||||
projection: {
|
||||
summary: { total_tasks: 1, processing: 1, needs_action: 0, completed: 0, history: 0 },
|
||||
needs_action: [],
|
||||
processing: [{
|
||||
user_task_no: 'OT-20260803-A13F95D2',
|
||||
group: 'processing',
|
||||
status_label: 'processing',
|
||||
title: null,
|
||||
file_count: 1,
|
||||
run_no: 'SNER-X',
|
||||
can_append: false,
|
||||
}],
|
||||
completed: [],
|
||||
history: [],
|
||||
},
|
||||
},
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
await flushPromises();
|
||||
expect(wrapper.text()).toContain('未命名 PDF');
|
||||
expect(wrapper.text()).not.toContain('20260803-A13F95D2');
|
||||
});
|
||||
|
||||
it('emits focus only when selecting a task (not viewed)', async () => {
|
||||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||||
props: { projection: buildProjection() },
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
await flushPromises();
|
||||
await wrapper.find('[data-testid="shipping-processing-task-OT-NEED"] button').trigger('click');
|
||||
expect(wrapper.emitted('focus')?.[0]).toEqual(['OT-NEED']);
|
||||
expect(wrapper.emitted('viewed')).toBeUndefined();
|
||||
expect(wrapper.emitted('expandFiles')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('applies visible focus ring on needs_action card when focused', async () => {
|
||||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||||
props: {
|
||||
projection: {
|
||||
...buildProjection(),
|
||||
focused_task_no: 'OT-NEED',
|
||||
},
|
||||
},
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
await flushPromises();
|
||||
const needCard = wrapper.find('[data-testid="shipping-processing-task-OT-NEED"]');
|
||||
// 关键断言:待操作聚焦卡必须有用户可见 ring,不能只写 data-focused。
|
||||
expect(needCard.attributes('data-focused')).toBe('1');
|
||||
expect(needCard.classes().join(' ')).toContain('ring-brand-400');
|
||||
const other = wrapper.find('[data-testid="shipping-processing-task-OT-PROC"]');
|
||||
expect(other.attributes('data-focused')).toBe('0');
|
||||
expect(other.classes().join(' ')).not.toContain('ring-brand-400');
|
||||
});
|
||||
|
||||
it('emits expandFiles / collapseFiles when toggling file details', async () => {
|
||||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||||
props: {
|
||||
projection: {
|
||||
...buildProjection(),
|
||||
needs_action: [{
|
||||
...buildProjection().needs_action[0],
|
||||
available_actions: ['view_details', 'open_review', 'cancel_task'],
|
||||
}],
|
||||
},
|
||||
},
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
await flushPromises();
|
||||
const taskRoot = wrapper.find('[data-testid="shipping-processing-task-OT-NEED"]');
|
||||
const buttons = taskRoot.findAll('button');
|
||||
// 最后一个按钮是展开/收起文件详情
|
||||
await buttons[buttons.length - 1].trigger('click');
|
||||
expect(wrapper.emitted('expandFiles')?.[0]?.[0]).toMatchObject({ user_task_no: 'OT-NEED' });
|
||||
await buttons[buttons.length - 1].trigger('click');
|
||||
expect(wrapper.emitted('collapseFiles')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('renders twenty processing tasks in one top-level container', async () => {
|
||||
const processing = Array.from({ length: 20 }, (_, index) => ({
|
||||
user_task_no: `OT-${index}`,
|
||||
group: 'processing' as const,
|
||||
status_label: 'extracting',
|
||||
file_count: 1,
|
||||
run_no: `RUN-${index}`,
|
||||
can_append: false,
|
||||
}));
|
||||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||||
props: {
|
||||
projection: {
|
||||
summary: { total_tasks: 20, processing: 20, needs_action: 0, history: 0 },
|
||||
needs_action: [],
|
||||
processing,
|
||||
history: [],
|
||||
},
|
||||
},
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
await flushPromises();
|
||||
expect(wrapper.findAll('[data-testid^="shipping-processing-task-"]')).toHaveLength(20);
|
||||
expect(wrapper.findAll('[data-testid="shipping-conversation-processing-card"]')).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('renders pending order_intake work items above task groups', async () => {
|
||||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||||
props: {
|
||||
projection: null,
|
||||
workItems: [{
|
||||
workItemType: 'order_intake',
|
||||
workItemNo: 'SNI-1',
|
||||
sourceType: 'direct_pdf',
|
||||
rootOrderTaskNo: null,
|
||||
shippingNoticeNo: null,
|
||||
conversationId: 'conv-1',
|
||||
submissionNo: 'SOS-1',
|
||||
intakeNo: 'SNI-1',
|
||||
status: 'failed',
|
||||
stage: 'document_parsing',
|
||||
progressVersion: 1,
|
||||
lastActivityAt: '2026-08-04T12:00:00Z',
|
||||
currentGate: {
|
||||
gateCode: 'intake_document_parse',
|
||||
status: 'blocked',
|
||||
nextActionCode: 'retry_parse',
|
||||
blockingReasonCode: 'SHIPPING_NOTICE.INTAKE_PARSE_FAILED',
|
||||
attemptNo: 2,
|
||||
},
|
||||
availableActions: ['view_details', 'retry_parse'],
|
||||
sourceSummary: {
|
||||
emailSubject: null,
|
||||
filename: 'po.pdf',
|
||||
documentCount: 1,
|
||||
parsedDocumentCount: 0,
|
||||
candidateCount: 0,
|
||||
customerName: null,
|
||||
poNumber: null,
|
||||
failureReasonCode: 'SHIPPING_NOTICE.INTAKE_PARSE_FAILED',
|
||||
parseAttemptCount: 2,
|
||||
assetStatus: 'ready',
|
||||
},
|
||||
childOrderTasks: [],
|
||||
}],
|
||||
},
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
await flushPromises();
|
||||
expect(wrapper.find('[data-testid="shipping-processing-group-order-intake"]').exists()).toBe(true);
|
||||
expect(wrapper.find('[data-testid="shipping-processing-intake-SNI-1"]').exists()).toBe(true);
|
||||
expect(wrapper.text()).toContain('po.pdf');
|
||||
// 关键断言:失败恢复元信息(原因 / Attempt / 资产)出现在材料卡。
|
||||
expect(wrapper.find('[data-testid="shipping-processing-intake-recovery"]').exists()).toBe(true);
|
||||
expect(wrapper.text()).toContain('SHIPPING_NOTICE.INTAKE_PARSE_FAILED');
|
||||
await wrapper.find('[data-testid="shipping-processing-intake-action-retry_parse"]').trigger('click');
|
||||
expect(wrapper.emitted('intakeAction')?.[0]?.[0]).toMatchObject({
|
||||
action: 'retry_parse',
|
||||
item: { workItemNo: 'SNI-1' },
|
||||
});
|
||||
});
|
||||
});
|
||||
+686
@@ -0,0 +1,686 @@
|
||||
/**
|
||||
* features/chat/components/shipping/ShippingConversationProcessingCard.vue
|
||||
* 用途:右侧「本次处理中」顶层任务卡——按 needs_action / processing / completed 展示。
|
||||
* 依赖:vue-i18n、ConversationProcessingProjection、conversationProcessingState、
|
||||
* shippingProcessingLabels。
|
||||
* 逻辑:由 ShippingWorkflowTimeline 嵌入;只消费统一 projection / workItems,禁止 Workflow fallback;
|
||||
* 单 PDF 主标题用文件名,多 PDF 用「订单识别任务」;右侧不渲染 history;
|
||||
* 任务级操作只消费后端 available_actions;另渲染尚未建 OT 的 order_intake 材料卡。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ChevronDown, ChevronRight } from 'lucide-vue-next';
|
||||
import type {
|
||||
ConversationProcessingProjection,
|
||||
ConversationProcessingUserTask,
|
||||
ShippingProcessingProjection,
|
||||
} from '@/features/chat/types/shipping.api.types';
|
||||
import {
|
||||
createConversationProcessingUiState,
|
||||
focusTaskManually,
|
||||
markTaskViewed,
|
||||
resetConversationProcessingUiState,
|
||||
resolveFocusedTask,
|
||||
shouldExpandTaskDetails,
|
||||
toggleTaskDetails,
|
||||
} from '@/features/chat/shipping/conversationProcessingState';
|
||||
import {
|
||||
resolveShippingProcessingMessage,
|
||||
resolveShippingProcessingStatusLabel,
|
||||
shippingProcessingSourceTypeKey,
|
||||
shippingProcessingStageKey,
|
||||
} from '@/features/chat/shipping/shippingProcessingLabels';
|
||||
|
||||
const props = defineProps<{
|
||||
projection: ConversationProcessingProjection | null;
|
||||
/** 统一 ShippingProcessing work_items(含 order_intake) */
|
||||
workItems?: ShippingProcessingProjection[] | null;
|
||||
/** 当前会话 ID;切换时重置本地焦点/展开状态 */
|
||||
conversationId?: string | null;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
focus: [taskNo: string];
|
||||
viewed: [taskNo: string];
|
||||
/** 请求展开某任务下的文件列表(由 Timeline 按 OT objects 合成) */
|
||||
expandFiles: [task: ConversationProcessingUserTask];
|
||||
/** 收起文件详情:父级应清空过滤并隐藏文件列表 */
|
||||
collapseFiles: [];
|
||||
/** 任务级权威操作(后端 available_actions) */
|
||||
taskAction: [payload: { task: ConversationProcessingUserTask; action: string }];
|
||||
/** Intake 级统一投影动作(如 retry_parse) */
|
||||
intakeAction: [payload: { item: ShippingProcessingProjection; action: string }];
|
||||
}>();
|
||||
|
||||
const { t, te } = useI18n();
|
||||
const uiState = createConversationProcessingUiState();
|
||||
|
||||
/** 唯一进度源:统一 conversation_processing / work_items 合成投影。 */
|
||||
const activeProjection = computed((): ConversationProcessingProjection | null => (
|
||||
props.projection || null
|
||||
));
|
||||
|
||||
/** 尚未建 OT、仍应展示在「待处理材料」的 Intake 工作项。 */
|
||||
const pendingIntakeItems = computed((): ShippingProcessingProjection[] => {
|
||||
const items = Array.isArray(props.workItems) ? props.workItems : [];
|
||||
return items.filter((item) => {
|
||||
if (item.workItemType !== 'order_intake') return false;
|
||||
return !['completed', 'cancelled'].includes(String(item.status || ''));
|
||||
});
|
||||
});
|
||||
|
||||
const hasContent = computed(() => Boolean(
|
||||
activeProjection.value
|
||||
|| pendingIntakeItems.value.length,
|
||||
));
|
||||
|
||||
const completedTasks = computed(() => activeProjection.value?.completed || []);
|
||||
|
||||
const focusedTaskNo = computed(() => resolveFocusedTask(uiState, {
|
||||
serverFocusedTaskNo: activeProjection.value?.focused_task_no,
|
||||
recentTaskNo: activeProjection.value?.recent_task_no,
|
||||
}));
|
||||
|
||||
/**
|
||||
* 切会话时重置本地焦点/展开,避免跨会话残留。
|
||||
*/
|
||||
watch(
|
||||
() => String(props.conversationId || '').trim(),
|
||||
(next, prev) => {
|
||||
if (next === prev) return;
|
||||
resetConversationProcessingUiState(uiState);
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* 点击任务卡:只聚焦,不标记正式 viewed、不强制展开文件。
|
||||
* 非权威任务号仅更新本地 UI 焦点,不向后端 focus 写接口。
|
||||
*/
|
||||
function onSelectTask(task: ConversationProcessingUserTask) {
|
||||
const taskNo = String(task.user_task_no || '').trim();
|
||||
if (!taskNo) return;
|
||||
focusTaskManually(uiState, taskNo, { expandDetails: false });
|
||||
if (task.user_task_authoritative === false) return;
|
||||
emit('focus', taskNo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换文件详情展开;展开时通知父级过滤,收起时清空过滤。
|
||||
*/
|
||||
function onToggleDetails(task: ConversationProcessingUserTask) {
|
||||
const taskNo = String(task.user_task_no || '').trim();
|
||||
if (!taskNo) return;
|
||||
toggleTaskDetails(uiState, taskNo);
|
||||
if (uiState.expandedDetailTaskNo === taskNo) {
|
||||
markTaskViewed(uiState, taskNo);
|
||||
emit('expandFiles', task);
|
||||
} else {
|
||||
emit('collapseFiles');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为多 PDF 任务卡(禁止用首个文件名伪装单文件任务)。
|
||||
*/
|
||||
function isMultiDocumentTask(task: ConversationProcessingUserTask): boolean {
|
||||
if (String(task.display_kind || '').trim() === 'multi_document_task') return true;
|
||||
if (Number(task.file_count || 0) > 1) return true;
|
||||
return Array.isArray(task.document_names) && task.document_names.length > 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 任务主标题:单 PDF 用文件名;多 PDF 用 i18n「订单识别任务」;禁止 OT/Run 编号。
|
||||
*/
|
||||
function taskLabel(task: ConversationProcessingUserTask): string {
|
||||
if (isMultiDocumentTask(task)) {
|
||||
return t('chat.shippingProcessing.multiPdfTaskTitle');
|
||||
}
|
||||
const title = String(task.title || '').trim();
|
||||
if (title) return title;
|
||||
return t('chat.shippingProcessing.unnamedPdf');
|
||||
}
|
||||
|
||||
/**
|
||||
* 多 PDF 副标题:前两个文件名;超过两个时追加「等 N 个 PDF」。
|
||||
*/
|
||||
function documentNamesPreview(task: ConversationProcessingUserTask): string {
|
||||
const names = (Array.isArray(task.document_names) ? task.document_names : [])
|
||||
.map((name) => String(name || '').trim())
|
||||
.filter(Boolean);
|
||||
if (names.length <= 1) return '';
|
||||
const head = names.slice(0, 2).join(t('chat.shippingProcessing.multiPdfNameSeparator'));
|
||||
if (names.length === 2) return head;
|
||||
return t('chat.shippingProcessing.multiPdfNamesMore', {
|
||||
names: head,
|
||||
count: names.length,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件数量文案:多 PDF 用「N 个 PDF」,单文件仍用「N 个文件」。
|
||||
*/
|
||||
function fileCountLabel(task: ConversationProcessingUserTask): string {
|
||||
const count = Number(task.file_count || 0);
|
||||
if (count <= 0) return '';
|
||||
if (isMultiDocumentTask(task)) {
|
||||
return t('chat.shippingProcessing.taskPdfCount', { count });
|
||||
}
|
||||
return t('chat.shippingProcessing.taskFiles', { count });
|
||||
}
|
||||
|
||||
/**
|
||||
* 任务状态文案:优先统一 shippingProcessing,回退 shippingWorkflow。
|
||||
*/
|
||||
function statusLabel(task: ConversationProcessingUserTask): string {
|
||||
return resolveShippingProcessingStatusLabel(String(task.status_label || ''), te, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* 最近活动时间:当天仅时分;昨天带「昨天」;更早带月日。
|
||||
*/
|
||||
function activityLabel(task: ConversationProcessingUserTask): string {
|
||||
const raw = String(task.last_activity_at || '').trim();
|
||||
if (!raw) return '';
|
||||
const date = new Date(raw);
|
||||
if (Number.isNaN(date.getTime())) return '';
|
||||
const hh = String(date.getHours()).padStart(2, '0');
|
||||
const mm = String(date.getMinutes()).padStart(2, '0');
|
||||
const time = `${hh}:${mm}`;
|
||||
const now = new Date();
|
||||
const startOfToday = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
||||
const startOfTarget = new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
||||
const dayDiff = Math.round((startOfToday.getTime() - startOfTarget.getTime()) / 86400000);
|
||||
if (dayDiff === 0) {
|
||||
return t('chat.shippingProcessing.updatedAt', { time });
|
||||
}
|
||||
if (dayDiff === 1) {
|
||||
return t('chat.shippingProcessing.updatedYesterday', { time });
|
||||
}
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
return t('chat.shippingProcessing.updatedOnDate', { date: `${month}-${day}`, time });
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否高亮 needs_action 任务。
|
||||
*/
|
||||
function isNeedsActionHighlight(task: ConversationProcessingUserTask): boolean {
|
||||
return task.group === 'needs_action';
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否展开该任务的文件详情区。
|
||||
*/
|
||||
function isDetailsExpanded(task: ConversationProcessingUserTask): boolean {
|
||||
return shouldExpandTaskDetails(uiState, task.user_task_no, {
|
||||
focusedTaskNo: focusedTaskNo.value,
|
||||
forceExpand: false,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 任务级可见操作:只展示后端权威动作中的业务入口。
|
||||
*/
|
||||
function visibleTaskActions(task: ConversationProcessingUserTask): string[] {
|
||||
const actions = Array.isArray(task.available_actions) ? task.available_actions : [];
|
||||
const preferred = [
|
||||
'view_details',
|
||||
'open_review',
|
||||
'enter_manual_review',
|
||||
'retry_failed_documents',
|
||||
'retry_failed_attachments',
|
||||
'cancel_task',
|
||||
'cancel_run',
|
||||
];
|
||||
const seen = new Set<string>();
|
||||
const result: string[] = [];
|
||||
for (const code of preferred) {
|
||||
if (!actions.includes(code) || seen.has(code)) continue;
|
||||
// 别名去重:只保留一套展示
|
||||
if (code === 'open_review' && seen.has('enter_manual_review')) continue;
|
||||
if (code === 'enter_manual_review' && seen.has('open_review')) continue;
|
||||
if (code === 'retry_failed_documents' && seen.has('retry_failed_attachments')) continue;
|
||||
if (code === 'retry_failed_attachments' && seen.has('retry_failed_documents')) continue;
|
||||
if (code === 'cancel_task' && seen.has('cancel_run')) continue;
|
||||
if (code === 'cancel_run' && seen.has('cancel_task')) continue;
|
||||
seen.add(code);
|
||||
result.push(code);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 动作按钮文案:任务级取消在多 PDF 时明确为「取消整个任务」。
|
||||
*/
|
||||
function actionLabel(task: ConversationProcessingUserTask, action: string): string {
|
||||
const code = String(action || '').trim();
|
||||
if (
|
||||
(code === 'cancel_task' || code === 'cancel_run')
|
||||
&& isMultiDocumentTask(task)
|
||||
) {
|
||||
return t('chat.shippingProcessing.cancelEntireTask');
|
||||
}
|
||||
if (code === 'cancel_task' || code === 'cancel_run') {
|
||||
return t('chat.shippingProcessing.cancelEntireTaskSingle');
|
||||
}
|
||||
const extractionKey = `chat.shippingOrderExtractionAction.${code}`;
|
||||
if (te(extractionKey)) return t(extractionKey);
|
||||
const aliases: Record<string, string> = {
|
||||
open_review: 'chat.shippingOrderExtractionAction.enter_manual_review',
|
||||
retry_failed_documents: 'chat.shippingOrderExtractionAction.retry_failed_attachments',
|
||||
};
|
||||
const alias = aliases[code];
|
||||
if (alias && te(alias)) return t(alias);
|
||||
return code;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行任务级动作:view_details 展开文件;其余交给父级。
|
||||
* 非权威任务号禁止向后端 focus/viewed 写接口。
|
||||
*/
|
||||
function onTaskAction(task: ConversationProcessingUserTask, action: string) {
|
||||
const code = String(action || '').trim();
|
||||
if (!code) return;
|
||||
if (code === 'view_details') {
|
||||
focusTaskManually(uiState, task.user_task_no, { expandDetails: true });
|
||||
markTaskViewed(uiState, task.user_task_no);
|
||||
emit('expandFiles', task);
|
||||
if (task.user_task_authoritative !== false) {
|
||||
emit('focus', task.user_task_no);
|
||||
emit('viewed', task.user_task_no);
|
||||
}
|
||||
return;
|
||||
}
|
||||
emit('taskAction', { task, action: code });
|
||||
}
|
||||
|
||||
/**
|
||||
* Intake 材料标题:文件名 / 邮件主题 / Intake 编号。
|
||||
*/
|
||||
function intakeTitle(item: ShippingProcessingProjection): string {
|
||||
return String(
|
||||
item.sourceSummary?.filename
|
||||
|| item.sourceSummary?.emailSubject
|
||||
|| item.workItemNo
|
||||
|| '',
|
||||
).trim() || item.workItemNo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Intake 状态文案。
|
||||
*/
|
||||
function intakeStatusLabel(item: ShippingProcessingProjection): string {
|
||||
return resolveShippingProcessingStatusLabel(item.status, te, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Intake 阶段文案。
|
||||
*/
|
||||
function intakeStageLabel(item: ShippingProcessingProjection): string {
|
||||
const key = shippingProcessingStageKey(item.stage);
|
||||
return te(key) ? t(key) : String(item.stage || '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Intake 来源类型文案。
|
||||
*/
|
||||
function intakeSourceLabel(item: ShippingProcessingProjection): string {
|
||||
const key = shippingProcessingSourceTypeKey(item.sourceType);
|
||||
return te(key) ? t(key) : String(item.sourceType || '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Intake / OT 门禁与失败恢复元信息(Gate / Attempt / 资产状态)。
|
||||
*/
|
||||
function intakeRecoveryMeta(item: ShippingProcessingProjection): string[] {
|
||||
const parts: string[] = [];
|
||||
const gate = item.currentGate;
|
||||
const reason = String(
|
||||
gate?.blockingReasonCode
|
||||
|| item.sourceSummary?.failureReasonCode
|
||||
|| '',
|
||||
).trim();
|
||||
if (reason) {
|
||||
parts.push(t('chat.shippingProcessing.failureReason', { code: reason }));
|
||||
}
|
||||
const attempt = gate?.attemptNo ?? item.sourceSummary?.parseAttemptCount;
|
||||
if (attempt != null && Number(attempt) > 0) {
|
||||
parts.push(t('chat.shippingProcessing.parseAttempt', { count: Number(attempt) }));
|
||||
}
|
||||
const assetStatus = String(item.sourceSummary?.assetStatus || '').trim();
|
||||
if (assetStatus) {
|
||||
const key = `chat.shippingProcessing.assetStatus.${assetStatus}`;
|
||||
parts.push(te(key) ? t(key) : t('chat.shippingProcessing.assetStatusLabel', { status: assetStatus }));
|
||||
}
|
||||
if (gate?.gateCode) {
|
||||
parts.push(t('chat.shippingProcessing.gateCode', { code: gate.gateCode }));
|
||||
}
|
||||
return parts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Intake 可见动作(仅展示 retry_parse)。
|
||||
*/
|
||||
function visibleIntakeActions(item: ShippingProcessingProjection): string[] {
|
||||
const actions = Array.isArray(item.availableActions) ? item.availableActions : [];
|
||||
return actions.filter((code) => code === 'retry_parse');
|
||||
}
|
||||
|
||||
/**
|
||||
* Intake 动作文案。
|
||||
*/
|
||||
function intakeActionLabel(action: string): string {
|
||||
if (action === 'retry_parse') return t('chat.shippingProcessing.retryFromFailure');
|
||||
return action;
|
||||
}
|
||||
|
||||
/**
|
||||
* 触发 Intake 级动作。
|
||||
*/
|
||||
function onIntakeAction(item: ShippingProcessingProjection, action: string) {
|
||||
const code = String(action || '').trim();
|
||||
if (!code) return;
|
||||
emit('intakeAction', { item, action: code });
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-if="hasContent"
|
||||
class="space-y-3"
|
||||
data-testid="shipping-conversation-processing-card"
|
||||
>
|
||||
<section
|
||||
v-if="pendingIntakeItems.length"
|
||||
data-testid="shipping-processing-group-order-intake"
|
||||
>
|
||||
<div class="mb-1.5 text-[11px] font-semibold uppercase tracking-wide text-violet-700 dark:text-violet-300">
|
||||
{{ t('chat.shippingProcessing.pendingMaterials') }}
|
||||
· {{ pendingIntakeItems.length }}
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<article
|
||||
v-for="item in pendingIntakeItems"
|
||||
:key="item.workItemNo"
|
||||
class="rounded-lg border border-default bg-surface px-2.5 py-2"
|
||||
:data-testid="`shipping-processing-intake-${item.workItemNo}`"
|
||||
:data-source-type="item.sourceType"
|
||||
:data-status="item.status"
|
||||
>
|
||||
<div class="text-sm font-semibold text-primary">
|
||||
{{ intakeTitle(item) }}
|
||||
</div>
|
||||
<div class="mt-0.5 flex flex-wrap gap-x-2 gap-y-0.5 text-[11px] text-secondary">
|
||||
<span>{{ intakeSourceLabel(item) }}</span>
|
||||
<span>{{ intakeStatusLabel(item) }}</span>
|
||||
<span v-if="intakeStageLabel(item)">{{ intakeStageLabel(item) }}</span>
|
||||
</div>
|
||||
<div
|
||||
v-if="intakeRecoveryMeta(item).length"
|
||||
class="mt-1 flex flex-wrap gap-x-2 gap-y-0.5 text-[11px] text-rose-700 dark:text-rose-300"
|
||||
data-testid="shipping-processing-intake-recovery"
|
||||
>
|
||||
<span
|
||||
v-for="(meta, idx) in intakeRecoveryMeta(item)"
|
||||
:key="`${item.workItemNo}-meta-${idx}`"
|
||||
>{{ meta }}</span>
|
||||
</div>
|
||||
<div
|
||||
v-if="visibleIntakeActions(item).length"
|
||||
class="mt-1.5 flex flex-wrap gap-1.5"
|
||||
data-testid="shipping-processing-intake-actions"
|
||||
>
|
||||
<button
|
||||
v-for="action in visibleIntakeActions(item)"
|
||||
:key="`${item.workItemNo}-${action}`"
|
||||
type="button"
|
||||
class="rounded-md border border-default bg-surface px-2 py-0.5 text-[11px] text-secondary hover:text-primary"
|
||||
:data-testid="`shipping-processing-intake-action-${action}`"
|
||||
@click="onIntakeAction(item, action)"
|
||||
>
|
||||
{{ intakeActionLabel(action) }}
|
||||
</button>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section
|
||||
v-if="activeProjection?.needs_action.length"
|
||||
data-testid="shipping-processing-group-needs_action"
|
||||
>
|
||||
<div class="mb-1.5 text-[11px] font-semibold uppercase tracking-wide text-amber-700 dark:text-amber-300">
|
||||
{{ resolveShippingProcessingMessage('groupNeedsAction', te, t, { count: activeProjection.needs_action.length }) }}
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<article
|
||||
v-for="task in activeProjection.needs_action"
|
||||
:key="task.user_task_no"
|
||||
class="rounded-lg border px-2.5 py-2 transition"
|
||||
:class="[
|
||||
isNeedsActionHighlight(task)
|
||||
? 'border-amber-400 bg-amber-50/80 dark:border-amber-700 dark:bg-amber-950/30'
|
||||
: 'border-default bg-surface',
|
||||
focusedTaskNo === task.user_task_no ? 'ring-1 ring-brand-400' : '',
|
||||
]"
|
||||
:data-testid="`shipping-processing-task-${task.user_task_no}`"
|
||||
:data-focused="focusedTaskNo === task.user_task_no ? '1' : '0'"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="w-full text-left"
|
||||
@click="onSelectTask(task)"
|
||||
>
|
||||
<div class="text-sm font-semibold text-primary">
|
||||
{{ resolveShippingProcessingMessage('taskTitle', te, t, { label: taskLabel(task) }) }}
|
||||
</div>
|
||||
<div class="mt-0.5 flex flex-wrap gap-x-2 gap-y-0.5 text-[11px] text-secondary">
|
||||
<span v-if="fileCountLabel(task)">{{ fileCountLabel(task) }}</span>
|
||||
<span>{{ statusLabel(task) }}</span>
|
||||
<span v-if="activityLabel(task)">{{ activityLabel(task) }}</span>
|
||||
</div>
|
||||
<div
|
||||
v-if="documentNamesPreview(task)"
|
||||
class="mt-0.5 truncate text-[11px] text-muted"
|
||||
data-testid="shipping-processing-task-document-names"
|
||||
>
|
||||
{{ documentNamesPreview(task) }}
|
||||
</div>
|
||||
<div
|
||||
v-if="task.recent_append_count"
|
||||
class="mt-1 text-[11px] font-medium text-brand-700 dark:text-brand-300"
|
||||
>
|
||||
{{ resolveShippingProcessingMessage('justAppended', te, t, { count: task.recent_append_count }) }}
|
||||
</div>
|
||||
<div
|
||||
v-else-if="task.recently_created"
|
||||
class="mt-1 text-[11px] font-medium text-brand-700 dark:text-brand-300"
|
||||
>
|
||||
{{ resolveShippingProcessingMessage('justCreated', te, t) }}
|
||||
</div>
|
||||
</button>
|
||||
<div
|
||||
v-if="visibleTaskActions(task).length"
|
||||
class="mt-1.5 flex flex-wrap gap-1.5"
|
||||
data-testid="shipping-processing-task-actions"
|
||||
>
|
||||
<button
|
||||
v-for="action in visibleTaskActions(task)"
|
||||
:key="`${task.user_task_no}-${action}`"
|
||||
type="button"
|
||||
class="rounded-md border border-default bg-surface px-2 py-0.5 text-[11px] text-secondary hover:text-primary"
|
||||
:data-testid="`shipping-processing-action-${action}`"
|
||||
@click="onTaskAction(task, action)"
|
||||
>
|
||||
{{ actionLabel(task, action) }}
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="mt-1.5 flex items-center gap-1 text-[11px] text-secondary hover:text-primary"
|
||||
@click="onToggleDetails(task)"
|
||||
>
|
||||
<ChevronDown v-if="isDetailsExpanded(task)" class="h-3 w-3" />
|
||||
<ChevronRight v-else class="h-3 w-3" />
|
||||
{{ isDetailsExpanded(task)
|
||||
? t('chat.shippingProcessing.collapseFileDetails')
|
||||
: t('chat.shippingProcessing.expandFileDetails') }}
|
||||
</button>
|
||||
</article>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section
|
||||
v-if="activeProjection?.processing.length"
|
||||
data-testid="shipping-processing-group-processing"
|
||||
>
|
||||
<div class="mb-1.5 text-[11px] font-semibold uppercase tracking-wide text-sky-700 dark:text-sky-300">
|
||||
{{ resolveShippingProcessingMessage('groupProcessing', te, t, { count: activeProjection.processing.length }) }}
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<article
|
||||
v-for="task in activeProjection.processing"
|
||||
:key="task.user_task_no"
|
||||
class="rounded-lg border border-default bg-surface px-2.5 py-2"
|
||||
:class="focusedTaskNo === task.user_task_no
|
||||
? 'ring-1 ring-brand-400'
|
||||
: ''"
|
||||
:data-testid="`shipping-processing-task-${task.user_task_no}`"
|
||||
:data-focused="focusedTaskNo === task.user_task_no ? '1' : '0'"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="w-full text-left"
|
||||
@click="onSelectTask(task)"
|
||||
>
|
||||
<div class="text-sm font-semibold text-primary">
|
||||
{{ resolveShippingProcessingMessage('taskTitle', te, t, { label: taskLabel(task) }) }}
|
||||
</div>
|
||||
<div class="mt-0.5 flex flex-wrap gap-x-2 gap-y-0.5 text-[11px] text-secondary">
|
||||
<span v-if="fileCountLabel(task)">{{ fileCountLabel(task) }}</span>
|
||||
<span>{{ statusLabel(task) }}</span>
|
||||
<span v-if="activityLabel(task)">{{ activityLabel(task) }}</span>
|
||||
</div>
|
||||
<div
|
||||
v-if="documentNamesPreview(task)"
|
||||
class="mt-0.5 truncate text-[11px] text-muted"
|
||||
data-testid="shipping-processing-task-document-names"
|
||||
>
|
||||
{{ documentNamesPreview(task) }}
|
||||
</div>
|
||||
<div
|
||||
v-if="task.recent_append_count"
|
||||
class="mt-1 text-[11px] font-medium text-brand-700 dark:text-brand-300"
|
||||
>
|
||||
{{ resolveShippingProcessingMessage('justAppended', te, t, { count: task.recent_append_count }) }}
|
||||
</div>
|
||||
<div
|
||||
v-else-if="task.recently_created"
|
||||
class="mt-1 text-[11px] font-medium text-brand-700 dark:text-brand-300"
|
||||
>
|
||||
{{ resolveShippingProcessingMessage('justCreated', te, t) }}
|
||||
</div>
|
||||
</button>
|
||||
<div
|
||||
v-if="visibleTaskActions(task).length"
|
||||
class="mt-1.5 flex flex-wrap gap-1.5"
|
||||
data-testid="shipping-processing-task-actions"
|
||||
>
|
||||
<button
|
||||
v-for="action in visibleTaskActions(task)"
|
||||
:key="`${task.user_task_no}-${action}`"
|
||||
type="button"
|
||||
class="rounded-md border border-default bg-surface px-2 py-0.5 text-[11px] text-secondary hover:text-primary"
|
||||
:data-testid="`shipping-processing-action-${action}`"
|
||||
@click="onTaskAction(task, action)"
|
||||
>
|
||||
{{ actionLabel(task, action) }}
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="mt-1.5 flex items-center gap-1 text-[11px] text-secondary hover:text-primary"
|
||||
@click="onToggleDetails(task)"
|
||||
>
|
||||
<ChevronDown v-if="isDetailsExpanded(task)" class="h-3 w-3" />
|
||||
<ChevronRight v-else class="h-3 w-3" />
|
||||
{{ isDetailsExpanded(task)
|
||||
? t('chat.shippingProcessing.collapseFileDetails')
|
||||
: t('chat.shippingProcessing.expandFileDetails') }}
|
||||
</button>
|
||||
</article>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section
|
||||
v-if="completedTasks.length"
|
||||
data-testid="shipping-processing-group-completed"
|
||||
>
|
||||
<div class="mb-1.5 text-[11px] font-semibold uppercase tracking-wide text-emerald-700 dark:text-emerald-300">
|
||||
{{ resolveShippingProcessingMessage('groupCompleted', te, t, { count: completedTasks.length }) }}
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<article
|
||||
v-for="task in completedTasks"
|
||||
:key="task.user_task_no"
|
||||
class="rounded-lg border border-default bg-surface px-2.5 py-2"
|
||||
:class="focusedTaskNo === task.user_task_no
|
||||
? 'ring-1 ring-brand-400'
|
||||
: ''"
|
||||
:data-testid="`shipping-processing-task-${task.user_task_no}`"
|
||||
:data-focused="focusedTaskNo === task.user_task_no ? '1' : '0'"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="w-full text-left"
|
||||
@click="onSelectTask(task)"
|
||||
>
|
||||
<div class="text-sm font-semibold text-primary">
|
||||
{{ resolveShippingProcessingMessage('taskTitle', te, t, { label: taskLabel(task) }) }}
|
||||
</div>
|
||||
<div class="mt-0.5 flex flex-wrap gap-x-2 gap-y-0.5 text-[11px] text-secondary">
|
||||
<span v-if="fileCountLabel(task)">{{ fileCountLabel(task) }}</span>
|
||||
<span>{{ statusLabel(task) }}</span>
|
||||
<span v-if="activityLabel(task)">{{ activityLabel(task) }}</span>
|
||||
</div>
|
||||
<div
|
||||
v-if="documentNamesPreview(task)"
|
||||
class="mt-0.5 truncate text-[11px] text-muted"
|
||||
data-testid="shipping-processing-task-document-names"
|
||||
>
|
||||
{{ documentNamesPreview(task) }}
|
||||
</div>
|
||||
</button>
|
||||
<div
|
||||
v-if="visibleTaskActions(task).length"
|
||||
class="mt-1.5 flex flex-wrap gap-1.5"
|
||||
data-testid="shipping-processing-task-actions"
|
||||
>
|
||||
<button
|
||||
v-for="action in visibleTaskActions(task)"
|
||||
:key="`${task.user_task_no}-${action}`"
|
||||
type="button"
|
||||
class="rounded-md border border-default bg-surface px-2 py-0.5 text-[11px] text-secondary hover:text-primary"
|
||||
:data-testid="`shipping-processing-action-${action}`"
|
||||
@click="onTaskAction(task, action)"
|
||||
>
|
||||
{{ actionLabel(task, action) }}
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="mt-1.5 flex items-center gap-1 text-[11px] text-secondary hover:text-primary"
|
||||
@click="onToggleDetails(task)"
|
||||
>
|
||||
<ChevronDown v-if="isDetailsExpanded(task)" class="h-3 w-3" />
|
||||
<ChevronRight v-else class="h-3 w-3" />
|
||||
{{ isDetailsExpanded(task)
|
||||
? t('chat.shippingProcessing.collapseFileDetails')
|
||||
: t('chat.shippingProcessing.expandFileDetails') }}
|
||||
</button>
|
||||
</article>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
@@ -2,12 +2,10 @@
|
||||
* features/chat/components/shipping/ShippingOrderExtractionCard.vue
|
||||
* 用途:聊天主区批次进度卡——摘要计数、Run 级处理事项、当前文件阶段、健康提醒与动作。
|
||||
* 依赖:订单抽取 Run 状态卡 DTO、shipping.api 文档/进度接口、ShippingOrderExtractionDetailsDrawer、
|
||||
* orderExtractionProgressDisplay、Workflow 计数投影、vue-router、vue-i18n。
|
||||
* 逻辑:有 Workflow 投影时优先展示统一 counts;否则回退 handling_items / primary_notice;
|
||||
* Run 失败优先展示 errorExplainability.message(含 request_id 提示),禁止只展示技术错误码;
|
||||
* 「查看处理详情」挂载详情抽屉;抽屉内证据/复核入口携带 focus+document_id 打开复核页;
|
||||
* 文档与时间线加载失败支持独立就地重试;右侧 ShippingWorkflowTimeline 承接逐 PDF 明细;
|
||||
* Gate confirm_customer 经 ChatPage 打开客户选择弹窗。
|
||||
* orderExtractionProgressDisplay、vue-router、vue-i18n、ProcessGateRecoveryCard。
|
||||
* 逻辑:回退 handling_items / primary_notice / Run summary;
|
||||
* Run 失败优先展示 errorExplainability.message;详情抽屉证据入口携带 focus+document_id;
|
||||
* Gate confirm_customer 经 ChatPage 打开客户选择弹窗;不再读取 Workflow 空壳 counts。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed, inject, ref } from 'vue';
|
||||
@@ -23,7 +21,6 @@ import type {
|
||||
ShippingOrderExtractionDocumentResult,
|
||||
ShippingOrderExtractionProgressEvent,
|
||||
ShippingProcessGateUserSummary,
|
||||
ShippingWorkflowItemCounts,
|
||||
} from '../../types/shipping.api.types';
|
||||
import ProcessGateRecoveryCard from '@/features/shipping-process-gates/components/ProcessGateRecoveryCard.vue';
|
||||
import {
|
||||
@@ -39,7 +36,6 @@ import {
|
||||
type ShippingHandlingAffectedRef,
|
||||
type ShippingHandlingRefTarget,
|
||||
} from '../../shipping/orderExtractionHandlingRefs';
|
||||
import { SHIPPING_WORKFLOW_KEY } from '../../shipping/useShippingNoticeWorkflow';
|
||||
import ShippingOrderExtractionDetailsDrawer from './ShippingOrderExtractionDetailsDrawer.vue';
|
||||
|
||||
const props = defineProps<{
|
||||
@@ -48,8 +44,9 @@ const props = defineProps<{
|
||||
retrying?: boolean;
|
||||
refreshing?: boolean;
|
||||
cancelling?: boolean;
|
||||
/** 可选:父级传入的 Workflow 计数;优先于 Run summary。 */
|
||||
workflowSummary?: ShippingWorkflowItemCounts | null;
|
||||
/** 新版 Run 已替代旧版时,历史卡仅允许查看详情。 */
|
||||
readonly?: boolean;
|
||||
readonlyReason?: string | null;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -64,7 +61,6 @@ const router = useRouter();
|
||||
const chatPage = inject(CHAT_PAGE_KEY, null);
|
||||
const confirmCancelOpen = ref(false);
|
||||
const cancelReason = ref('');
|
||||
const injectedWorkflow = inject(SHIPPING_WORKFLOW_KEY, null);
|
||||
|
||||
/**
|
||||
* Gate 恢复卡「确认客户」:打开对话叠层客户选择弹窗。
|
||||
@@ -74,15 +70,9 @@ async function onGateConfirmCustomer(taskNo: string) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 Workflow Items 中取首个阻断 Gate 摘要,供 Run 级卡片展示。
|
||||
* Run 级阻断 Gate:co8 后不再从 Workflow items 读取;由复核/Gate 主路径承接。
|
||||
*/
|
||||
const runLevelProcessGate = computed((): ShippingProcessGateUserSummary | null => {
|
||||
const items = injectedWorkflow?.items.value || [];
|
||||
for (const item of items) {
|
||||
if (item.process_gate?.current_blocking_gate) return item.process_gate;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
const runLevelProcessGate = computed((): ShippingProcessGateUserSummary | null => null);
|
||||
|
||||
const gateNavigationContext = computed(() => ({
|
||||
agentId: String(route.params.agentId || ''),
|
||||
@@ -97,47 +87,10 @@ const progressLoading = ref(false);
|
||||
const progressLoadFailed = ref(false);
|
||||
const progressEvents = ref<ShippingOrderExtractionProgressEvent[]>([]);
|
||||
|
||||
/**
|
||||
* 统一计数:优先 props.workflowSummary,其次 inject 的 Workflow.counts,最后回退 Run summary。
|
||||
*/
|
||||
const unifiedCounts = computed(() => {
|
||||
const fromProp = props.workflowSummary;
|
||||
if (fromProp && Number(fromProp.total || 0) > 0) return fromProp;
|
||||
const fromInject = injectedWorkflow?.workflow.value?.counts;
|
||||
if (fromInject && Number(fromInject.total || 0) > 0) return fromInject;
|
||||
return null;
|
||||
});
|
||||
const displaySummary = computed(() => props.state.summary);
|
||||
|
||||
const displaySummary = computed(() => {
|
||||
const counts = unifiedCounts.value;
|
||||
if (!counts) return props.state.summary;
|
||||
return {
|
||||
totalDocuments: counts.total,
|
||||
processingDocuments: counts.processing,
|
||||
pendingDocuments: 0,
|
||||
completedDocuments: counts.completed,
|
||||
reviewRequiredDocuments: counts.pending_review,
|
||||
failedDocuments: counts.failed,
|
||||
cancelledDocuments: 0,
|
||||
candidateCount: props.state.summary.candidateCount,
|
||||
openedExistingCount: props.state.summary.openedExistingCount,
|
||||
};
|
||||
});
|
||||
|
||||
const workflowStageLabel = computed(() => {
|
||||
const stage = String(injectedWorkflow?.workflow.value?.current_stage || '').trim();
|
||||
if (!stage) return '';
|
||||
const key = `chat.shippingWorkflow.itemStatus.${stage}`;
|
||||
return te(key) ? t(key) : stage;
|
||||
});
|
||||
|
||||
const workflowLastActivityLabel = computed(() => {
|
||||
const raw = injectedWorkflow?.workflow.value?.last_activity_at;
|
||||
if (!raw) return '';
|
||||
const date = new Date(String(raw));
|
||||
if (Number.isNaN(date.getTime())) return '';
|
||||
return date.toLocaleString();
|
||||
});
|
||||
const workflowStageLabel = computed(() => '');
|
||||
const workflowLastActivityLabel = computed(() => '');
|
||||
|
||||
const handlingItems = computed(() => props.state.handlingItems || []);
|
||||
|
||||
@@ -261,11 +214,15 @@ const activityKey = computed(() => {
|
||||
});
|
||||
|
||||
const showRetry = computed(() => (
|
||||
!props.readonly && (
|
||||
props.state.availableActions.includes('retry_failed_attachments')
|
||||
|| displaySummary.value.failedDocuments > 0
|
||||
)
|
||||
));
|
||||
const showRefresh = computed(() => props.state.availableActions.includes('refresh_status'));
|
||||
const showRefresh = computed(() => !props.readonly && props.state.availableActions.includes('refresh_status'));
|
||||
const showCancel = computed(() => (
|
||||
!props.readonly
|
||||
&&
|
||||
props.state.availableActions.includes('cancel_run')
|
||||
&& !(props.state.cancellation?.requested && !props.state.cancellation?.completedAt)
|
||||
));
|
||||
@@ -404,6 +361,7 @@ function closeDetailsDrawer() {
|
||||
* 从详情抽屉进入复核/证据页。
|
||||
*/
|
||||
async function enterReviewFromDetails(payload?: { focus?: 'evidence' | 'draft'; documentId?: number }) {
|
||||
if (props.readonly) return;
|
||||
await openOrderReview({
|
||||
documentId: payload?.documentId,
|
||||
focus: payload?.focus === 'evidence' ? 'evidence' : 'draft',
|
||||
@@ -458,6 +416,7 @@ function affectedRows(item: ShippingOrderExtractionHandlingItemState) {
|
||||
* @param item - 处理事项
|
||||
*/
|
||||
async function handleHandlingAction(item: ShippingOrderExtractionHandlingItemState) {
|
||||
if (props.readonly) return;
|
||||
const action = String(item.primaryAction || '').trim();
|
||||
if (action === 'retry_failed_attachments') {
|
||||
emit('retry');
|
||||
@@ -489,6 +448,7 @@ function confirmCancel() {
|
||||
|
||||
/** 打开取消确认并清空上次填写的原因。 */
|
||||
function openCancelConfirm() {
|
||||
if (props.readonly) return;
|
||||
cancelReason.value = '';
|
||||
confirmCancelOpen.value = true;
|
||||
}
|
||||
@@ -516,6 +476,13 @@ function openCancelConfirm() {
|
||||
<CircleX v-else class="mt-0.5 h-4 w-4 shrink-0" />
|
||||
|
||||
<div class="min-w-0 flex-1">
|
||||
<div
|
||||
v-if="readonly"
|
||||
class="mb-1 text-xs font-medium opacity-80"
|
||||
data-testid="shipping-order-extraction-readonly"
|
||||
>
|
||||
{{ t('chat.shippingOrderExtractionHistory.superseded') }}
|
||||
</div>
|
||||
<div class="text-sm font-medium">{{ compactLine }}</div>
|
||||
<p
|
||||
v-if="state.errorExplainability?.request_id"
|
||||
@@ -564,7 +531,7 @@ function openCancelConfirm() {
|
||||
v-if="runLevelProcessGate?.current_blocking_gate"
|
||||
class="mt-2"
|
||||
:summary="runLevelProcessGate"
|
||||
:can-handle="true"
|
||||
:can-handle="!readonly"
|
||||
:navigation-context="gateNavigationContext"
|
||||
@refreshed="emit('refresh')"
|
||||
@refresh-needed="emit('refresh')"
|
||||
@@ -591,13 +558,15 @@ function openCancelConfirm() {
|
||||
<span class="ml-1 opacity-80">{{ t('chat.shippingOrderExtractionHandling.count', { count: item.count }) }}</span>
|
||||
</div>
|
||||
<button
|
||||
v-if="item.primaryAction"
|
||||
v-if="item.primaryAction && !readonly && (item.primaryAction !== 'review_candidate' || !handlingItems.some((other) => other.primaryAction === 'enter_manual_review'))"
|
||||
type="button"
|
||||
class="shrink-0 rounded-md border border-current/20 px-2 py-0.5 text-[11px] font-medium hover:bg-black/5 dark:hover:bg-white/5"
|
||||
@click="handleHandlingAction(item)"
|
||||
>
|
||||
{{ te(`chat.shippingOrderExtractionAction.${item.primaryAction}`)
|
||||
? t(`chat.shippingOrderExtractionAction.${item.primaryAction}`)
|
||||
{{ (item.primaryAction === 'review_candidate' || item.primaryAction === 'enter_manual_review')
|
||||
? t('chat.shippingOrderExtractionAction.enter_manual_review')
|
||||
: te(`chat.shippingOrderExtractionAction.${item.primaryAction}`)
|
||||
? t(`chat.shippingOrderExtractionAction.${item.primaryAction}`)
|
||||
: t('chat.shippingOrderExtractionAction.view_details') }}
|
||||
</button>
|
||||
</div>
|
||||
@@ -616,6 +585,7 @@ function openCancelConfirm() {
|
||||
:key="row.key"
|
||||
type="button"
|
||||
class="rounded border border-current/20 px-1.5 py-0.5 text-[11px] font-medium underline-offset-2 hover:underline"
|
||||
:disabled="readonly"
|
||||
@click="openAffectedRef(row.target)"
|
||||
>
|
||||
{{ row.label }}
|
||||
|
||||
+23
-23
@@ -65,21 +65,21 @@ const canReparse = computed(() => {
|
||||
|
||||
const reparseActionLabel = computed(() => {
|
||||
if (props.item?.reparse_kind === 'failed_run_retry') {
|
||||
return t('chat.shippingWorkflow.actions.retryFailedRun');
|
||||
return t('chat.shippingProcessing.actions.retryFailedRun');
|
||||
}
|
||||
return t('chat.shippingWorkflow.actions.reparse');
|
||||
return t('chat.shippingProcessing.actions.reparse');
|
||||
});
|
||||
|
||||
const filename = computed(() => {
|
||||
const name = String(props.item?.current_document_filename || '').trim();
|
||||
if (name) return name;
|
||||
if (!props.item) return '';
|
||||
return t('chat.shippingWorkflow.filenameFallback', {
|
||||
return t('chat.shippingProcessing.filenameFallback', {
|
||||
docId: props.item.current_document_id,
|
||||
});
|
||||
});
|
||||
|
||||
const title = computed(() => t('chat.shippingWorkflow.detail.title'));
|
||||
const title = computed(() => t('chat.shippingProcessing.detail.title'));
|
||||
|
||||
/**
|
||||
* 解析生命周期 / 阶段文案。
|
||||
@@ -87,8 +87,8 @@ const title = computed(() => t('chat.shippingWorkflow.detail.title'));
|
||||
function statusLabel(status?: string | null): string {
|
||||
const normalized = String(status || '').trim();
|
||||
if (!normalized) return '';
|
||||
const key = `chat.shippingWorkflow.itemStatus.${normalized}`;
|
||||
return te(key) ? t(key) : t('chat.shippingWorkflow.itemStatus.unknown');
|
||||
const key = `chat.shippingProcessing.itemStatus.${normalized}`;
|
||||
return te(key) ? t(key) : t('chat.shippingProcessing.itemStatus.unknown');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,8 +97,8 @@ function statusLabel(status?: string | null): string {
|
||||
function eventLabel(event: ShippingWorkflowEvent): string {
|
||||
const code = String(event.message_code || event.event_code || '').trim();
|
||||
if (!code) return '—';
|
||||
const key = `chat.shippingWorkflow.event.${code}`;
|
||||
return te(key) ? t(key) : t('chat.shippingWorkflow.event.unknown');
|
||||
const key = `chat.shippingProcessing.event.${code}`;
|
||||
return te(key) ? t(key) : t('chat.shippingProcessing.event.unknown');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -226,7 +226,7 @@ onBeforeUnmount(() => {
|
||||
ref="closeButtonRef"
|
||||
type="button"
|
||||
class="rounded-md p-1 text-muted hover:bg-surface-muted"
|
||||
:aria-label="t('chat.shippingWorkflow.detail.close')"
|
||||
:aria-label="t('chat.shippingProcessing.detail.close')"
|
||||
data-testid="shipping-workflow-item-drawer-close"
|
||||
@click="handleClose"
|
||||
>
|
||||
@@ -236,41 +236,41 @@ onBeforeUnmount(() => {
|
||||
|
||||
<div class="min-h-0 flex-1 overflow-auto p-4">
|
||||
<div v-if="loading" class="text-xs text-muted">
|
||||
{{ t('chat.shippingWorkflow.loading') }}
|
||||
{{ t('chat.shippingProcessing.loading') }}
|
||||
</div>
|
||||
<template v-else-if="item">
|
||||
<dl class="space-y-2 text-xs">
|
||||
<div class="flex justify-between gap-2">
|
||||
<dt class="text-secondary">{{ t('chat.shippingWorkflow.detail.filename') }}</dt>
|
||||
<dt class="text-secondary">{{ t('chat.shippingProcessing.detail.filename') }}</dt>
|
||||
<dd class="max-w-[60%] truncate font-medium text-primary" :title="filename">{{ filename }}</dd>
|
||||
</div>
|
||||
<div class="flex justify-between gap-2">
|
||||
<dt class="text-secondary">{{ t('chat.shippingWorkflow.detail.status') }}</dt>
|
||||
<dt class="text-secondary">{{ t('chat.shippingProcessing.detail.status') }}</dt>
|
||||
<dd class="font-medium text-primary">{{
|
||||
statusLabel(item.display_lifecycle_status || item.lifecycle_status)
|
||||
}}</dd>
|
||||
</div>
|
||||
<div class="flex justify-between gap-2">
|
||||
<dt class="text-secondary">{{ t('chat.shippingWorkflow.detail.stage') }}</dt>
|
||||
<dt class="text-secondary">{{ t('chat.shippingProcessing.detail.stage') }}</dt>
|
||||
<dd class="font-medium text-primary">{{ statusLabel(item.current_stage) || item.current_stage }}</dd>
|
||||
</div>
|
||||
<div v-if="item.current_run_no" class="flex justify-between gap-2">
|
||||
<dt class="text-secondary">{{ t('chat.shippingWorkflow.detail.runNo') }}</dt>
|
||||
<dt class="text-secondary">{{ t('chat.shippingProcessing.detail.runNo') }}</dt>
|
||||
<dd class="font-medium text-primary">{{ item.current_run_no }}</dd>
|
||||
</div>
|
||||
<div v-if="item.current_case_no" class="flex justify-between gap-2">
|
||||
<dt class="text-secondary">{{ t('chat.shippingWorkflow.detail.caseNo') }}</dt>
|
||||
<dt class="text-secondary">{{ t('chat.shippingProcessing.detail.caseNo') }}</dt>
|
||||
<dd class="font-medium text-primary">{{ item.current_case_no }}</dd>
|
||||
</div>
|
||||
<div v-if="item.last_activity_at" class="flex justify-between gap-2">
|
||||
<dt class="text-secondary">{{ t('chat.shippingWorkflow.detail.lastActivity') }}</dt>
|
||||
<dt class="text-secondary">{{ t('chat.shippingProcessing.detail.lastActivity') }}</dt>
|
||||
<dd class="font-medium text-primary">{{ formatTime(item.last_activity_at) }}</dd>
|
||||
</div>
|
||||
<div v-if="item.closed_reason" class="flex justify-between gap-2">
|
||||
<dt class="text-secondary">{{ t('chat.shippingWorkflow.detail.closedReason') }}</dt>
|
||||
<dt class="text-secondary">{{ t('chat.shippingProcessing.detail.closedReason') }}</dt>
|
||||
<dd class="font-medium text-primary">
|
||||
{{ te(`chat.shippingWorkflow.closedReason.${item.closed_reason}`)
|
||||
? t(`chat.shippingWorkflow.closedReason.${item.closed_reason}`)
|
||||
{{ te(`chat.shippingProcessing.closedReason.${item.closed_reason}`)
|
||||
? t(`chat.shippingProcessing.closedReason.${item.closed_reason}`)
|
||||
: item.closed_reason }}
|
||||
</dd>
|
||||
</div>
|
||||
@@ -289,7 +289,7 @@ onBeforeUnmount(() => {
|
||||
|
||||
<section class="mt-4">
|
||||
<h3 class="text-xs font-semibold text-secondary">
|
||||
{{ t('chat.shippingWorkflow.detail.eventsTitle') }}
|
||||
{{ t('chat.shippingProcessing.detail.eventsTitle') }}
|
||||
</h3>
|
||||
<ul v-if="events.length" class="mt-2 space-y-2" data-testid="shipping-workflow-item-events">
|
||||
<li
|
||||
@@ -306,11 +306,11 @@ onBeforeUnmount(() => {
|
||||
</li>
|
||||
</ul>
|
||||
<p v-else class="mt-2 text-xs text-muted">
|
||||
{{ t('chat.shippingWorkflow.detail.eventsEmpty') }}
|
||||
{{ t('chat.shippingProcessing.detail.eventsEmpty') }}
|
||||
</p>
|
||||
</section>
|
||||
</template>
|
||||
<p v-else class="text-xs text-muted">{{ t('chat.shippingWorkflow.detail.empty') }}</p>
|
||||
<p v-else class="text-xs text-muted">{{ t('chat.shippingProcessing.detail.empty') }}</p>
|
||||
</div>
|
||||
|
||||
<footer v-if="item && (canCancel || canReparse)" class="space-y-2 border-t border-default p-3">
|
||||
@@ -332,7 +332,7 @@ onBeforeUnmount(() => {
|
||||
data-testid="shipping-workflow-item-drawer-cancel"
|
||||
@click="emit('cancel', item)"
|
||||
>
|
||||
{{ t('chat.shippingWorkflow.actions.cancelFile') }}
|
||||
{{ t('chat.shippingProcessing.actions.cancelFile') }}
|
||||
</button>
|
||||
</footer>
|
||||
</aside>
|
||||
|
||||
@@ -32,18 +32,18 @@ const reasonInputRef = ref<HTMLTextAreaElement | null>(null);
|
||||
|
||||
const title = computed(() => (
|
||||
props.action === 'reparse'
|
||||
? t('chat.shippingWorkflow.reasonDialog.reparseTitle')
|
||||
: t('chat.shippingWorkflow.reasonDialog.cancelTitle')
|
||||
? t('chat.shippingProcessing.reasonDialog.reparseTitle')
|
||||
: t('chat.shippingProcessing.reasonDialog.cancelTitle')
|
||||
));
|
||||
|
||||
const confirmLabel = computed(() => (
|
||||
props.action === 'reparse'
|
||||
? t('chat.shippingWorkflow.reasonDialog.reparseConfirm')
|
||||
: t('chat.shippingWorkflow.reasonDialog.cancelConfirm')
|
||||
? t('chat.shippingProcessing.reasonDialog.reparseConfirm')
|
||||
: t('chat.shippingProcessing.reasonDialog.cancelConfirm')
|
||||
));
|
||||
|
||||
const reasonLabel = computed(() => t('chat.shippingWorkflow.reasonDialog.reasonLabel'));
|
||||
const reasonRequiredHint = computed(() => t('chat.shippingWorkflow.reasonRequired'));
|
||||
const reasonLabel = computed(() => t('chat.shippingProcessing.reasonDialog.reasonLabel'));
|
||||
const reasonRequiredHint = computed(() => t('chat.shippingProcessing.reasonRequired'));
|
||||
|
||||
/**
|
||||
* 关闭弹窗并重置本地表单。
|
||||
@@ -128,7 +128,7 @@ onBeforeUnmount(() => {
|
||||
>
|
||||
<h3 class="text-sm font-semibold text-primary">{{ title }}</h3>
|
||||
<p class="mt-1 text-xs text-secondary">
|
||||
{{ t('chat.shippingWorkflow.reasonDialog.impact') }}
|
||||
{{ t('chat.shippingProcessing.reasonDialog.impact') }}
|
||||
</p>
|
||||
|
||||
<label class="mt-3 block text-xs text-secondary">
|
||||
@@ -141,7 +141,7 @@ onBeforeUnmount(() => {
|
||||
class="input-field mt-1 w-full py-1.5 text-xs"
|
||||
:aria-invalid="reasonMissing"
|
||||
data-testid="shipping-workflow-reason-input"
|
||||
:placeholder="t('chat.shippingWorkflow.reasonDialog.reasonPlaceholder')"
|
||||
:placeholder="t('chat.shippingProcessing.reasonDialog.reasonPlaceholder')"
|
||||
/>
|
||||
</label>
|
||||
<p v-if="reasonMissing" class="mt-1 text-[11px] text-rose-600" data-testid="shipping-workflow-reason-missing">
|
||||
@@ -152,7 +152,7 @@ onBeforeUnmount(() => {
|
||||
v-if="action === 'reparse'"
|
||||
class="mt-2 block text-xs text-secondary"
|
||||
>
|
||||
{{ t('chat.shippingWorkflow.reasonDialog.commentOptional') }}
|
||||
{{ t('chat.shippingProcessing.reasonDialog.commentOptional') }}
|
||||
<textarea
|
||||
v-model="comment"
|
||||
rows="2"
|
||||
@@ -169,7 +169,7 @@ onBeforeUnmount(() => {
|
||||
data-testid="shipping-workflow-reason-cancel"
|
||||
@click="handleCancel"
|
||||
>
|
||||
{{ t('chat.shippingWorkflow.reasonDialog.dismiss') }}
|
||||
{{ t('chat.shippingProcessing.reasonDialog.dismiss') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
@@ -179,7 +179,7 @@ onBeforeUnmount(() => {
|
||||
@click="handleConfirm"
|
||||
>
|
||||
{{ confirmLoading
|
||||
? t('chat.shippingWorkflow.reasonDialog.submitting')
|
||||
? t('chat.shippingProcessing.reasonDialog.submitting')
|
||||
: confirmLabel }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -1,330 +1,464 @@
|
||||
/**
|
||||
* features/chat/components/shipping/ShippingWorkflowTimeline.spec.ts
|
||||
* 用途:验证右侧 Workflow 时间线分组、文件名、批次切换、过滤与取消/重识别弹窗。
|
||||
* 依赖:Vitest、Vue Test Utils、vue-i18n、shipping.api mock。
|
||||
* 逻辑:先展开侧栏并打开详情抽屉;断言 layout_parsing 可见;文件名优先;过滤与 cancel。
|
||||
*/
|
||||
import { mount, flushPromises } from '@vue/test-utils';
|
||||
import { describe, expect, it, vi, beforeEach } from 'vitest';
|
||||
import { createI18n } from 'vue-i18n';
|
||||
import { ref } from 'vue';
|
||||
import chatZhCn from '@/locales/zh-CN/chat.json';
|
||||
import ShippingWorkflowTimeline from './ShippingWorkflowTimeline.vue';
|
||||
import type { ShippingWorkflow, ShippingWorkflowItem } from '../../types/shipping.api.types';
|
||||
import type { UseShippingNoticeWorkflowReturn } from '../../shipping/useShippingNoticeWorkflow';
|
||||
|
||||
const routerPush = vi.fn(async () => undefined);
|
||||
vi.mock('vue-router', () => ({
|
||||
useRoute: () => ({ params: { agentId: 'agent-1' }, query: {} }),
|
||||
useRouter: () => ({ push: routerPush }),
|
||||
}));
|
||||
|
||||
vi.mock('@/features/chat/api/shipping.api', () => ({
|
||||
getWorkspaceShippingWorkflowItem: vi.fn(async (itemNo: string) => ({
|
||||
item_no: itemNo,
|
||||
workflow_no: 'SNWF-1',
|
||||
conversation_id: 'conv-1',
|
||||
root_document_id: 1,
|
||||
current_document_id: 1,
|
||||
current_document_filename: 'detail.pdf',
|
||||
current_version_no: 1,
|
||||
lifecycle_status: 'layout_parsing',
|
||||
current_stage: 'layout_parsing',
|
||||
lock_version: 1,
|
||||
events: [],
|
||||
})),
|
||||
listWorkspaceShippingWorkflows: vi.fn(),
|
||||
cancelWorkspaceShippingWorkflowItem: vi.fn(),
|
||||
reparseWorkspaceShippingWorkflowItem: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('@/shared/composables/useMessage', () => ({
|
||||
useMessage: () => ({
|
||||
success: vi.fn(),
|
||||
error: vi.fn(),
|
||||
warning: vi.fn(),
|
||||
info: vi.fn(),
|
||||
}),
|
||||
}));
|
||||
|
||||
const i18n = createI18n({
|
||||
legacy: false,
|
||||
locale: 'zh-CN',
|
||||
messages: { 'zh-CN': { chat: chatZhCn, errors: { generic: '错误' } } },
|
||||
});
|
||||
|
||||
function buildItem(patch: Partial<ShippingWorkflowItem> = {}): ShippingWorkflowItem {
|
||||
return {
|
||||
item_no: 'SWI-1',
|
||||
workflow_no: 'SNWF-1',
|
||||
conversation_id: 'conv-1',
|
||||
root_document_id: 10,
|
||||
current_document_id: 10,
|
||||
current_document_filename: 'shipping-notice.pdf',
|
||||
current_version_no: 1,
|
||||
lifecycle_status: 'layout_parsing',
|
||||
current_stage: 'layout_parsing',
|
||||
lock_version: 1,
|
||||
...patch,
|
||||
};
|
||||
}
|
||||
|
||||
function buildController(
|
||||
items: ShippingWorkflowItem[],
|
||||
extras?: { workflows?: ShippingWorkflow[] },
|
||||
): UseShippingNoticeWorkflowReturn {
|
||||
const workflowList = extras?.workflows ?? [{
|
||||
workflow_no: 'SNWF-1',
|
||||
conversation_id: 'conv-1',
|
||||
status: 'open',
|
||||
current_stage: 'layout_parsing',
|
||||
lock_version: 1,
|
||||
counts: {
|
||||
total: items.length,
|
||||
processing: items.filter((i) => i.lifecycle_status === 'layout_parsing' || i.lifecycle_status === 'extracting').length,
|
||||
pending_review: items.filter((i) => i.lifecycle_status === 'pending_review').length,
|
||||
failed: items.filter((i) => i.lifecycle_status === 'failed' || i.lifecycle_status === 'reparse_failed').length,
|
||||
completed: items.filter((i) => i.lifecycle_status === 'closed').length,
|
||||
},
|
||||
items,
|
||||
}];
|
||||
const selectedWorkflowNo = ref(workflowList[0]?.workflow_no || null);
|
||||
const workflows = ref(workflowList);
|
||||
const workflow = ref(workflowList[0] || null);
|
||||
const itemRef = ref(items);
|
||||
return {
|
||||
workflows,
|
||||
selectedWorkflowNo,
|
||||
selectWorkflow: vi.fn((no: string) => {
|
||||
selectedWorkflowNo.value = no;
|
||||
workflow.value = workflows.value.find((row) => row.workflow_no === no) || null;
|
||||
itemRef.value = workflow.value?.items || [];
|
||||
}),
|
||||
workflow,
|
||||
items: itemRef,
|
||||
loading: ref(false),
|
||||
error: ref(null),
|
||||
refresh: vi.fn(async () => undefined),
|
||||
cancelItem: vi.fn(async () => null),
|
||||
reparseItem: vi.fn(async () => null),
|
||||
stop: vi.fn(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 展开窄侧栏并打开详情抽屉(完整列表仅在抽屉内)。
|
||||
*/
|
||||
async function openDetailsDrawer(wrapper: ReturnType<typeof mount>) {
|
||||
const toggleCollapse = wrapper.find('[data-testid="shipping-workflow-timeline"] button');
|
||||
if (toggleCollapse.exists()) {
|
||||
await toggleCollapse.trigger('click');
|
||||
await flushPromises();
|
||||
}
|
||||
const openDetails = wrapper.find('[data-testid="shipping-workflow-toggle-details"]');
|
||||
expect(openDetails.exists()).toBe(true);
|
||||
await openDetails.trigger('click');
|
||||
await flushPromises();
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-details-drawer"]').exists()).toBe(true);
|
||||
}
|
||||
|
||||
const mountOptions = {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
stubs: {
|
||||
// 抽屉/原因框经 Teleport;单测就地渲染便于查询。
|
||||
teleport: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
describe('ShippingWorkflowTimeline', () => {
|
||||
beforeEach(() => {
|
||||
document.body.innerHTML = '';
|
||||
routerPush.mockClear();
|
||||
});
|
||||
|
||||
it('shows layout_parsing items with filename before review case exists', async () => {
|
||||
const controller = buildController([
|
||||
buildItem({
|
||||
item_no: 'SWI-LAYOUT',
|
||||
lifecycle_status: 'layout_parsing',
|
||||
current_case_no: null,
|
||||
current_document_filename: 'layout.pdf',
|
||||
}),
|
||||
buildItem({ item_no: 'SWI-REVIEW', lifecycle_status: 'pending_review', current_case_no: 'SNRC-1' }),
|
||||
]);
|
||||
const wrapper = mount(ShippingWorkflowTimeline, {
|
||||
props: { conversationId: 'conv-1', controller },
|
||||
...mountOptions,
|
||||
});
|
||||
await flushPromises();
|
||||
await openDetailsDrawer(wrapper);
|
||||
await wrapper.find('[data-testid="shipping-workflow-pending-only-filter"]').setValue(false);
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-item-SWI-LAYOUT"]').exists()).toBe(true);
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-item-SWI-LAYOUT"]').text()).toContain('layout.pdf');
|
||||
expect(wrapper.text()).toContain('尚无复核单');
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-group-processing"]').exists()).toBe(true);
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-group-pending_review"]').exists()).toBe(true);
|
||||
});
|
||||
|
||||
it('filters to actionable items when pending-only is checked', async () => {
|
||||
const controller = buildController([
|
||||
buildItem({ item_no: 'SWI-A', lifecycle_status: 'extracting' }),
|
||||
buildItem({ item_no: 'SWI-B', lifecycle_status: 'pending_review' }),
|
||||
]);
|
||||
const wrapper = mount(ShippingWorkflowTimeline, {
|
||||
props: { conversationId: 'conv-1', controller },
|
||||
...mountOptions,
|
||||
});
|
||||
await flushPromises();
|
||||
await openDetailsDrawer(wrapper);
|
||||
await wrapper.find('[data-testid="shipping-workflow-pending-only-filter"]').setValue(true);
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-item-SWI-B"]').exists()).toBe(true);
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-item-SWI-A"]').exists()).toBe(false);
|
||||
});
|
||||
|
||||
it('opens the review workspace directly for pending review items', async () => {
|
||||
const controller = buildController([
|
||||
buildItem({
|
||||
item_no: 'SWI-REVIEW-OPEN',
|
||||
lifecycle_status: 'pending_review',
|
||||
current_run_no: 'RUN-REVIEW-1',
|
||||
current_case_no: 'CASE-REVIEW-1',
|
||||
current_document_id: 42,
|
||||
}),
|
||||
]);
|
||||
const wrapper = mount(ShippingWorkflowTimeline, {
|
||||
props: { conversationId: 'conv-1', controller },
|
||||
...mountOptions,
|
||||
});
|
||||
await flushPromises();
|
||||
await openDetailsDrawer(wrapper);
|
||||
await wrapper.find('[data-testid="shipping-workflow-action-open-review"]').trigger('click');
|
||||
expect(routerPush).toHaveBeenCalledWith(expect.objectContaining({
|
||||
name: 'Chat',
|
||||
params: { agentId: 'agent-1' },
|
||||
query: expect.objectContaining({
|
||||
mode: 'order-review',
|
||||
run_no: 'RUN-REVIEW-1',
|
||||
case_no: 'CASE-REVIEW-1',
|
||||
document_id: '42',
|
||||
focus: 'draft',
|
||||
}),
|
||||
}));
|
||||
});
|
||||
|
||||
it('cancels an item via in-app reason dialog', async () => {
|
||||
const controller = buildController([
|
||||
buildItem({ item_no: 'SWI-CANCEL', lifecycle_status: 'extracting', lock_version: 3 }),
|
||||
]);
|
||||
const wrapper = mount(ShippingWorkflowTimeline, {
|
||||
props: { conversationId: 'conv-1', controller },
|
||||
...mountOptions,
|
||||
});
|
||||
await flushPromises();
|
||||
await openDetailsDrawer(wrapper);
|
||||
await wrapper.find('[data-testid="shipping-workflow-pending-only-filter"]').setValue(false);
|
||||
await wrapper.find('[data-testid="shipping-workflow-action-cancel"]').trigger('click');
|
||||
await flushPromises();
|
||||
const reasonInput = wrapper.find('[data-testid="shipping-workflow-reason-input"]');
|
||||
expect(reasonInput.exists()).toBe(true);
|
||||
await reasonInput.setValue('cancel reason');
|
||||
await wrapper.find('[data-testid="shipping-workflow-reason-confirm"]').trigger('click');
|
||||
await flushPromises();
|
||||
expect(controller.cancelItem).toHaveBeenCalledWith('SWI-CANCEL', {
|
||||
reason: 'cancel reason',
|
||||
expected_lock_version: 3,
|
||||
});
|
||||
});
|
||||
|
||||
it('shows batch switcher for multiple workflows', async () => {
|
||||
const itemsA = [buildItem({ item_no: 'SWI-A', workflow_no: 'SNWF-A' })];
|
||||
const itemsB = [buildItem({ item_no: 'SWI-B', workflow_no: 'SNWF-B', lifecycle_status: 'failed' })];
|
||||
const workflows = [
|
||||
{
|
||||
workflow_no: 'SNWF-A',
|
||||
conversation_id: 'conv-1',
|
||||
status: 'open',
|
||||
current_stage: 'layout_parsing',
|
||||
lock_version: 1,
|
||||
counts: { total: 1, processing: 1, pending_review: 0, failed: 0, completed: 0 },
|
||||
items: itemsA,
|
||||
},
|
||||
{
|
||||
workflow_no: 'SNWF-B',
|
||||
conversation_id: 'conv-1',
|
||||
status: 'open',
|
||||
current_stage: 'failed',
|
||||
lock_version: 1,
|
||||
counts: { total: 1, processing: 0, pending_review: 0, failed: 1, completed: 0 },
|
||||
items: itemsB,
|
||||
},
|
||||
];
|
||||
const controller = buildController(itemsA, { workflows });
|
||||
const wrapper = mount(ShippingWorkflowTimeline, {
|
||||
props: { conversationId: 'conv-1', controller },
|
||||
...mountOptions,
|
||||
});
|
||||
await flushPromises();
|
||||
await openDetailsDrawer(wrapper);
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-batch-switcher"]').exists()).toBe(true);
|
||||
await wrapper.find('[data-testid="shipping-workflow-batch-SNWF-B"]').trigger('click');
|
||||
expect(controller.selectWorkflow).toHaveBeenCalledWith('SNWF-B');
|
||||
});
|
||||
|
||||
it('shows reparse action for failed items', async () => {
|
||||
const controller = buildController([
|
||||
buildItem({
|
||||
item_no: 'SWI-FAIL',
|
||||
lifecycle_status: 'failed',
|
||||
current_document_filename: 'bad.pdf',
|
||||
available_actions: ['cancel', 'reparse'],
|
||||
reparse_kind: 'failed_run_retry',
|
||||
}),
|
||||
]);
|
||||
const wrapper = mount(ShippingWorkflowTimeline, {
|
||||
props: { conversationId: 'conv-1', controller },
|
||||
...mountOptions,
|
||||
});
|
||||
await flushPromises();
|
||||
await openDetailsDrawer(wrapper);
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-action-reparse"]').exists()).toBe(true);
|
||||
expect(wrapper.text()).toContain('重试失败识别');
|
||||
});
|
||||
|
||||
it('hides reparse for pending_review without available_actions.reparse', async () => {
|
||||
const controller = buildController([
|
||||
buildItem({
|
||||
item_no: 'SWI-PR',
|
||||
lifecycle_status: 'pending_review',
|
||||
current_case_no: null,
|
||||
available_actions: ['cancel'],
|
||||
reparse_kind: null,
|
||||
}),
|
||||
]);
|
||||
const wrapper = mount(ShippingWorkflowTimeline, {
|
||||
props: { conversationId: 'conv-1', controller },
|
||||
...mountOptions,
|
||||
});
|
||||
await flushPromises();
|
||||
await openDetailsDrawer(wrapper);
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-action-reparse"]').exists()).toBe(false);
|
||||
});
|
||||
|
||||
it('keeps sidebar width when opening details dialog overlay', async () => {
|
||||
const controller = buildController([buildItem()]);
|
||||
const wrapper = mount(ShippingWorkflowTimeline, {
|
||||
props: { conversationId: 'conv-1', controller },
|
||||
...mountOptions,
|
||||
});
|
||||
await flushPromises();
|
||||
await openDetailsDrawer(wrapper);
|
||||
const aside = wrapper.find('[data-testid="shipping-workflow-timeline"]');
|
||||
// 关键断言:弹层打开后侧栏仍固定窄宽,对话区不被列表撑开。
|
||||
expect(aside.classes().join(' ')).toContain('md:w-60');
|
||||
const overlay = wrapper.find('[data-testid="shipping-workflow-details-drawer"]');
|
||||
expect(overlay.exists()).toBe(true);
|
||||
expect(overlay.classes().join(' ')).toContain('fixed');
|
||||
expect(overlay.find('[role="dialog"]').exists()).toBe(true);
|
||||
});
|
||||
});
|
||||
/**␍
|
||||
* features/chat/components/shipping/ShippingWorkflowTimeline.spec.ts␍
|
||||
* 用途:验证右侧「本次处理中」OT 任务卡、展开后文件明细、过滤与取消/重识别弹窗。␍
|
||||
* 依赖:Vitest、Vue Test Utils、vue-i18n、shipping.api mock。␍
|
||||
* 逻辑:文件明细由 expandedTask.objects 经 mapUserTaskObjectsToFileRows 合成;␍
|
||||
* 须先展开 processing 任务才出现文件抽屉;WF 批次切换器恒隐藏。␍
|
||||
*/␍
|
||||
import { mount, flushPromises } from '@vue/test-utils';␍
|
||||
import { describe, expect, it, vi, beforeEach } from 'vitest';␍
|
||||
import { createI18n } from 'vue-i18n';␍
|
||||
import { ref } from 'vue';␍
|
||||
import chatZhCn from '@/locales/zh-CN/chat.json';␍
|
||||
import ShippingWorkflowTimeline from './ShippingWorkflowTimeline.vue';␍
|
||||
import type {␍
|
||||
ConversationProcessingObject,␍
|
||||
ConversationProcessingProjection,␍
|
||||
ConversationProcessingUserTask,␍
|
||||
ShippingWorkflowItem,␍
|
||||
} from '../../types/shipping.api.types';␍
|
||||
import type { UseShippingNoticeWorkflowReturn } from '../../shipping/useShippingNoticeWorkflow';␍
|
||||
␍
|
||||
const routerPush = vi.fn(async () => undefined);␍
|
||||
vi.mock('vue-router', () => ({␍
|
||||
useRoute: () => ({ params: { agentId: 'agent-1' }, query: {} }),␍
|
||||
useRouter: () => ({ push: routerPush }),␍
|
||||
}));␍
|
||||
␍
|
||||
const api = vi.hoisted(() => ({␍
|
||||
cancelRun: vi.fn(async () => ({})),␍
|
||||
reparseRun: vi.fn(async () => ({})),␍
|
||||
retryRun: vi.fn(async () => ({})),␍
|
||||
retryIntake: vi.fn(async () => ({})),␍
|
||||
}));␍
|
||||
␍
|
||||
vi.mock('@/features/chat/api/shipping.api', () => ({␍
|
||||
cancelWorkspaceShippingOrderExtractionRun: api.cancelRun,␍
|
||||
reparseWorkspaceShippingOrderExtractionRun: api.reparseRun,␍
|
||||
retryWorkspaceShippingOrderExtractionRun: api.retryRun,␍
|
||||
retryShippingNoticeIntake: api.retryIntake,␍
|
||||
}));␍
|
||||
␍
|
||||
vi.mock('@/shared/composables/useMessage', () => ({␍
|
||||
useMessage: () => ({␍
|
||||
success: vi.fn(),␍
|
||||
error: vi.fn(),␍
|
||||
warning: vi.fn(),␍
|
||||
info: vi.fn(),␍
|
||||
}),␍
|
||||
}));␍
|
||||
␍
|
||||
const i18n = createI18n({␍
|
||||
legacy: false,␍
|
||||
locale: 'zh-CN',␍
|
||||
messages: { 'zh-CN': { chat: chatZhCn, errors: { generic: '错误' } } },␍
|
||||
});␍
|
||||
␍
|
||||
const DEFAULT_TASK_NO = 'OT-TEST';␍
|
||||
␍
|
||||
function buildItem(patch: Partial<ShippingWorkflowItem> = {}): ShippingWorkflowItem {␍
|
||||
return {␍
|
||||
item_no: 'SWI-1',␍
|
||||
workflow_no: 'SNWF-1',␍
|
||||
conversation_id: 'conv-1',␍
|
||||
root_document_id: 10,␍
|
||||
current_document_id: 10,␍
|
||||
current_document_filename: 'shipping-notice.pdf',␍
|
||||
current_version_no: 1,␍
|
||||
lifecycle_status: 'layout_parsing',␍
|
||||
current_stage: 'layout_parsing',␍
|
||||
lock_version: 1,␍
|
||||
current_run_no: 'RUN-1',␍
|
||||
...patch,␍
|
||||
};␍
|
||||
}␍
|
||||
␍
|
||||
type DocumentObject = ConversationProcessingObject & {␍
|
||||
available_actions?: string[];␍
|
||||
reparse_kind?: string | null;␍
|
||||
lock_version?: number;␍
|
||||
};␍
|
||||
␍
|
||||
/**␍
|
||||
* 将 buildItem 文档行映射为 OT document object(供 processingFromDocuments 使用)。␍
|
||||
*/␍
|
||||
function documentObjectFromItem(doc: ShippingWorkflowItem): DocumentObject {␍
|
||||
return {␍
|
||||
kind: 'document',␍
|
||||
object_key: doc.item_no,␍
|
||||
workflow_item_no: doc.item_no,␍
|
||||
label: String(doc.current_document_filename || doc.item_no),␍
|
||||
filename: doc.current_document_filename ?? null,␍
|
||||
status_label: doc.lifecycle_status,␍
|
||||
document_id: doc.current_document_id,␍
|
||||
root_document_id: doc.root_document_id,␍
|
||||
content_hash: doc.content_hash ?? null,␍
|
||||
current_run_no: doc.current_run_no ?? null,␍
|
||||
case_no: doc.current_case_no ?? null,␍
|
||||
available_actions: doc.available_actions,␍
|
||||
reparse_kind: doc.reparse_kind ?? null,␍
|
||||
lock_version: doc.lock_version,␍
|
||||
};␍
|
||||
}␍
|
||||
␍
|
||||
/**␍
|
||||
* 构造含单个 processing 任务与 document objects 的会话投影。␍
|
||||
* 核心逻辑:objects 默认由 docs 映射;taskOverrides 可覆盖任务卡字段或整组 objects。␍
|
||||
*/␍
|
||||
function processingFromDocuments(␍
|
||||
docs: ShippingWorkflowItem[],␍
|
||||
taskOverrides?: Partial<ConversationProcessingUserTask>,␍
|
||||
): ConversationProcessingProjection {␍
|
||||
const userTaskNo = taskOverrides?.user_task_no ?? DEFAULT_TASK_NO;␍
|
||||
const objects = taskOverrides?.objects ?? docs.map(documentObjectFromItem);␍
|
||||
const filenames = docs␍
|
||||
.map((doc) => String(doc.current_document_filename || '').trim())␍
|
||||
.filter(Boolean);␍
|
||||
const task: ConversationProcessingUserTask = {␍
|
||||
user_task_no: userTaskNo,␍
|
||||
group: 'processing',␍
|
||||
status_label: docs[0]?.lifecycle_status ?? 'extracting',␍
|
||||
title: docs.length === 1 ? (docs[0]?.current_document_filename ?? null) : null,␍
|
||||
display_kind: docs.length > 1 ? 'multi_document_task' : 'single_document_task',␍
|
||||
document_names: filenames.length ? filenames : null,␍
|
||||
file_count: docs.length,␍
|
||||
run_no: docs[0]?.current_run_no ?? null,␍
|
||||
can_append: false,␍
|
||||
objects,␍
|
||||
...taskOverrides,␍
|
||||
};␍
|
||||
␍
|
||||
return {␍
|
||||
summary: {␍
|
||||
total_tasks: 1,␍
|
||||
total_files: docs.length,␍
|
||||
processing: 1,␍
|
||||
needs_action: 0,␍
|
||||
completed: 0,␍
|
||||
history: 0,␍
|
||||
},␍
|
||||
focused_task_no: null,␍
|
||||
recent_task_no: null,␍
|
||||
needs_action: [],␍
|
||||
processing: [task],␍
|
||||
completed: [],␍
|
||||
history: [],␍
|
||||
};␍
|
||||
}␍
|
||||
␍
|
||||
function buildController(␍
|
||||
extras?: {␍
|
||||
processing?: UseShippingNoticeWorkflowReturn['processing']['value'];␍
|
||||
},␍
|
||||
): UseShippingNoticeWorkflowReturn {␍
|
||||
return {␍
|
||||
processing: ref(extras?.processing ?? null),␍
|
||||
processingWorkItems: ref([]),␍
|
||||
loading: ref(false),␍
|
||||
error: ref(null),␍
|
||||
refresh: vi.fn(async () => undefined),␍
|
||||
focusConversationTask: vi.fn(async () => undefined),␍
|
||||
markConversationTaskViewed: vi.fn(async () => undefined),␍
|
||||
stop: vi.fn(),␍
|
||||
};␍
|
||||
}␍
|
||||
␍
|
||||
/**␍
|
||||
* 展开 processing 任务卡,使文件明细抽屉可见。␍
|
||||
*/␍
|
||||
async function expandProcessingTask(␍
|
||||
wrapper: ReturnType<typeof mount>,␍
|
||||
taskNo = DEFAULT_TASK_NO,␍
|
||||
) {␍
|
||||
if (wrapper.find('[data-testid="shipping-workflow-details-drawer"]').exists()) {␍
|
||||
return;␍
|
||||
}␍
|
||||
const task = wrapper.find(`[data-testid="shipping-processing-task-${taskNo}"]`);␍
|
||||
expect(task.exists()).toBe(true);␍
|
||||
await task.findAll('button').at(-1)!.trigger('click');␍
|
||||
await flushPromises();␍
|
||||
}␍
|
||||
␍
|
||||
async function openDetailsDrawer(␍
|
||||
wrapper: ReturnType<typeof mount>,␍
|
||||
taskNo = DEFAULT_TASK_NO,␍
|
||||
) {␍
|
||||
await flushPromises();␍
|
||||
await expandProcessingTask(wrapper, taskNo);␍
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-details-drawer"]').exists()).toBe(true);␍
|
||||
}␍
|
||||
␍
|
||||
const mountOptions = {␍
|
||||
global: {␍
|
||||
plugins: [i18n],␍
|
||||
stubs: {␍
|
||||
teleport: true,␍
|
||||
},␍
|
||||
},␍
|
||||
};␍
|
||||
␍
|
||||
describe('ShippingWorkflowTimeline', () => {␍
|
||||
beforeEach(() => {␍
|
||||
document.body.innerHTML = '';␍
|
||||
routerPush.mockClear();␍
|
||||
});␍
|
||||
␍
|
||||
it('shows layout_parsing items with filename before review case exists', async () => {␍
|
||||
const processing = processingFromDocuments([␍
|
||||
buildItem({␍
|
||||
item_no: 'SWI-LAYOUT',␍
|
||||
lifecycle_status: 'layout_parsing',␍
|
||||
current_case_no: null,␍
|
||||
current_document_filename: 'layout.pdf',␍
|
||||
}),␍
|
||||
buildItem({ item_no: 'SWI-REVIEW', lifecycle_status: 'pending_review', current_case_no: 'SNRC-1' }),␍
|
||||
]);␍
|
||||
const wrapper = mount(ShippingWorkflowTimeline, {␍
|
||||
props: { conversationId: 'conv-1', controller: buildController({ processing }) },␍
|
||||
...mountOptions,␍
|
||||
});␍
|
||||
await openDetailsDrawer(wrapper);␍
|
||||
// 断言:layout 文件行展示文件名␍
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-item-SWI-LAYOUT"]').exists()).toBe(true);␍
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-item-SWI-LAYOUT"]').text()).toContain('layout.pdf');␍
|
||||
// 断言:无复核单时展示占位文案␍
|
||||
expect(wrapper.text()).toContain('尚无复核单');␍
|
||||
// 断言:有 OT 任务投影时隐藏独立「当前阶段」卡(UI-F04)␍
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-current-stage"]').exists()).toBe(false);␍
|
||||
// 断言:processing / pending_review 分组均可见␍
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-group-processing"]').exists()).toBe(true);␍
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-group-pending_review"]').exists()).toBe(true);␍
|
||||
});␍
|
||||
␍
|
||||
it('shows processing and pending-review files together by default', async () => {␍
|
||||
const processing = processingFromDocuments([␍
|
||||
buildItem({ item_no: 'SWI-A', lifecycle_status: 'extracting' }),␍
|
||||
buildItem({ item_no: 'SWI-B', lifecycle_status: 'pending_review' }),␍
|
||||
]);␍
|
||||
const wrapper = mount(ShippingWorkflowTimeline, {␍
|
||||
props: { conversationId: 'conv-1', controller: buildController({ processing }) },␍
|
||||
...mountOptions,␍
|
||||
});␍
|
||||
await openDetailsDrawer(wrapper);␍
|
||||
// 断言:默认同时展示处理中与待复核文件␍
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-item-SWI-B"]').exists()).toBe(true);␍
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-item-SWI-A"]').exists()).toBe(true);␍
|
||||
});␍
|
||||
␍
|
||||
it('opens the review workspace directly for pending review items', async () => {␍
|
||||
const processing = processingFromDocuments([␍
|
||||
buildItem({␍
|
||||
item_no: 'SWI-REVIEW-OPEN',␍
|
||||
lifecycle_status: 'pending_review',␍
|
||||
current_run_no: 'RUN-REVIEW-1',␍
|
||||
current_case_no: 'CASE-REVIEW-1',␍
|
||||
current_document_id: 42,␍
|
||||
}),␍
|
||||
]);␍
|
||||
const wrapper = mount(ShippingWorkflowTimeline, {␍
|
||||
props: { conversationId: 'conv-1', controller: buildController({ processing }) },␍
|
||||
...mountOptions,␍
|
||||
});␍
|
||||
await openDetailsDrawer(wrapper);␍
|
||||
await wrapper.find('[data-testid="shipping-workflow-action-open-review"]').trigger('click');␍
|
||||
// 断言:跳转 order-review 并携带 run / case / document 上下文␍
|
||||
expect(routerPush).toHaveBeenCalledWith(expect.objectContaining({␍
|
||||
name: 'Chat',␍
|
||||
params: { agentId: 'agent-1' },␍
|
||||
query: expect.objectContaining({␍
|
||||
mode: 'order-review',␍
|
||||
run_no: 'RUN-REVIEW-1',␍
|
||||
case_no: 'CASE-REVIEW-1',␍
|
||||
document_id: '42',␍
|
||||
focus: 'draft',␍
|
||||
}),␍
|
||||
}));␍
|
||||
});␍
|
||||
␍
|
||||
it('cancels an item via Run API from in-app reason dialog', async () => {␍
|
||||
api.cancelRun.mockClear();␍
|
||||
const processing = processingFromDocuments([␍
|
||||
buildItem({␍
|
||||
item_no: 'SWI-CANCEL',␍
|
||||
lifecycle_status: 'extracting',␍
|
||||
lock_version: 3,␍
|
||||
current_run_no: 'RUN-CANCEL',␍
|
||||
available_actions: ['cancel'],␍
|
||||
}),␍
|
||||
]);␍
|
||||
const wrapper = mount(ShippingWorkflowTimeline, {␍
|
||||
props: { conversationId: 'conv-1', controller: buildController({ processing }) },␍
|
||||
...mountOptions,␍
|
||||
});␍
|
||||
await openDetailsDrawer(wrapper);␍
|
||||
await wrapper.find('[data-testid="shipping-workflow-action-cancel"]').trigger('click');␍
|
||||
await flushPromises();␍
|
||||
const reasonInput = wrapper.find('[data-testid="shipping-workflow-reason-input"]');␍
|
||||
// 断言:应用内原因弹窗出现␍
|
||||
expect(reasonInput.exists()).toBe(true);␍
|
||||
await reasonInput.setValue('cancel reason');␍
|
||||
await wrapper.find('[data-testid="shipping-workflow-reason-confirm"]').trigger('click');␍
|
||||
await flushPromises();␍
|
||||
// 断言:调用 Run 取消 API␍
|
||||
expect(api.cancelRun).toHaveBeenCalledWith('RUN-CANCEL', { reason: 'cancel reason' });␍
|
||||
});␍
|
||||
␍
|
||||
it('hides WF batch switcher as primary path', async () => {␍
|
||||
const processing = processingFromDocuments([buildItem({ item_no: 'SWI-A' })]);␍
|
||||
const wrapper = mount(ShippingWorkflowTimeline, {␍
|
||||
props: {␍
|
||||
conversationId: 'conv-1',␍
|
||||
controller: buildController({ processing }),␍
|
||||
},␍
|
||||
...mountOptions,␍
|
||||
});␍
|
||||
await openDetailsDrawer(wrapper);␍
|
||||
// 断言:批次切换器不再作为主路径展示␍
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-batch-switcher"]').exists()).toBe(false);␍
|
||||
});␍
|
||||
␍
|
||||
it('shows reparse action for failed items', async () => {␍
|
||||
const processing = processingFromDocuments([␍
|
||||
buildItem({␍
|
||||
item_no: 'SWI-FAIL',␍
|
||||
lifecycle_status: 'failed',␍
|
||||
current_document_filename: 'bad.pdf',␍
|
||||
current_run_no: 'RUN-FAIL',␍
|
||||
available_actions: ['cancel', 'reparse'],␍
|
||||
reparse_kind: 'failed_run_retry',␍
|
||||
}),␍
|
||||
]);␍
|
||||
const wrapper = mount(ShippingWorkflowTimeline, {␍
|
||||
props: { conversationId: 'conv-1', controller: buildController({ processing }) },␍
|
||||
...mountOptions,␍
|
||||
});␍
|
||||
await openDetailsDrawer(wrapper);␍
|
||||
// 断言:失败项展示重识别按钮与文案␍
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-action-reparse"]').exists()).toBe(true);␍
|
||||
expect(wrapper.text()).toContain('重试失败识别');␍
|
||||
});␍
|
||||
␍
|
||||
it('hides reparse for pending_review without available_actions.reparse', async () => {␍
|
||||
const processing = processingFromDocuments([␍
|
||||
buildItem({␍
|
||||
item_no: 'SWI-PR',␍
|
||||
lifecycle_status: 'pending_review',␍
|
||||
current_case_no: null,␍
|
||||
available_actions: ['cancel'],␍
|
||||
reparse_kind: null,␍
|
||||
}),␍
|
||||
]);␍
|
||||
const wrapper = mount(ShippingWorkflowTimeline, {␍
|
||||
props: { conversationId: 'conv-1', controller: buildController({ processing }) },␍
|
||||
...mountOptions,␍
|
||||
});␍
|
||||
await openDetailsDrawer(wrapper);␍
|
||||
// 断言:无 reparse 契约时不展示重识别␍
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-action-reparse"]').exists()).toBe(false);␍
|
||||
});␍
|
||||
␍
|
||||
it('keeps sidebar width while showing inline workflow details', async () => {␍
|
||||
const processing = processingFromDocuments([buildItem()]);␍
|
||||
const wrapper = mount(ShippingWorkflowTimeline, {␍
|
||||
props: {␍
|
||||
conversationId: 'conv-1',␍
|
||||
controller: buildController({ processing }),␍
|
||||
},␍
|
||||
...mountOptions,␍
|
||||
});␍
|
||||
await openDetailsDrawer(wrapper);␍
|
||||
const aside = wrapper.find('[data-testid="shipping-workflow-timeline"]');␍
|
||||
// 断言:侧栏宽度不变␍
|
||||
expect(aside.classes().join(' ')).toContain('md:w-[clamp(20rem,28vw,30rem)]');␍
|
||||
const overlay = wrapper.find('[data-testid="shipping-workflow-details-drawer"]');␍
|
||||
// 断言:文件明细内联展示,非 modal␍
|
||||
expect(overlay.exists()).toBe(true);␍
|
||||
expect(overlay.classes().join(' ')).toContain('rounded-xl');␍
|
||||
expect(overlay.find('[role="dialog"]').exists()).toBe(false);␍
|
||||
});␍
|
||||
␍
|
||||
it('keeps panel expanded while processing tasks exist', async () => {␍
|
||||
const processing = processingFromDocuments([buildItem()], {␍
|
||||
user_task_no: 'OT-PIN',␍
|
||||
status_label: 'extracting',␍
|
||||
title: 'order.pdf',␍
|
||||
file_count: 1,␍
|
||||
run_no: 'RUN-PIN',␍
|
||||
});␍
|
||||
const wrapper = mount(ShippingWorkflowTimeline, {␍
|
||||
props: { conversationId: 'conv-1', controller: buildController({ processing }) },␍
|
||||
...mountOptions,␍
|
||||
});␍
|
||||
await flushPromises();␍
|
||||
const aside = wrapper.find('[data-testid="shipping-workflow-timeline"]');␍
|
||||
const toggle = wrapper.find('[data-testid="shipping-workflow-panel-toggle"]');␍
|
||||
// 断言:有 processing 任务时侧栏默认展开␍
|
||||
expect(aside.classes().join(' ')).not.toContain('!w-14');␍
|
||||
expect(wrapper.find('[data-testid="shipping-processing-task-OT-PIN"]').exists()).toBe(true);␍
|
||||
await toggle.trigger('click');␍
|
||||
await flushPromises();␍
|
||||
// 断言:点击收起仍保持展开(pinned)␍
|
||||
expect(aside.classes().join(' ')).not.toContain('!w-14');␍
|
||||
expect(wrapper.find('[data-testid="shipping-processing-task-OT-PIN"]').exists()).toBe(true);␍
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-panel-pinned"]').exists()).toBe(true);␍
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-panel-summary"]').exists()).toBe(true);␍
|
||||
expect(wrapper.find('[data-testid="shipping-processing-summary"]').exists()).toBe(false);␍
|
||||
});␍
|
||||
␍
|
||||
it('expands all effective PDFs for one task even when they belong to different runs', async () => {␍
|
||||
const docs = [␍
|
||||
buildItem({␍
|
||||
item_no: 'SWI-PDF-91',␍
|
||||
current_run_no: 'RUN-NEW',␍
|
||||
root_document_id: 91,␍
|
||||
current_document_id: 191,␍
|
||||
content_hash: 'hash-a',␍
|
||||
current_document_filename: '4518838152.pdf',␍
|
||||
}),␍
|
||||
buildItem({␍
|
||||
item_no: 'SWI-PDF-92',␍
|
||||
current_run_no: 'RUN-OLD',␍
|
||||
root_document_id: 92,␍
|
||||
current_document_id: 92,␍
|
||||
content_hash: 'hash-b',␍
|
||||
current_document_filename: '4518838154.pdf',␍
|
||||
}),␍
|
||||
];␍
|
||||
const processing = processingFromDocuments(docs, {␍
|
||||
user_task_no: 'OT-MULTI-RUN',␍
|
||||
status_label: 'extracting',␍
|
||||
title: null,␍
|
||||
display_kind: 'multi_document_task',␍
|
||||
document_names: ['4518838152.pdf', '4518838154.pdf'],␍
|
||||
file_count: 2,␍
|
||||
run_no: 'RUN-NEW',␍
|
||||
objects: [␍
|
||||
{␍
|
||||
kind: 'document', object_key: 'DOC-191', workflow_item_no: 'SWI-PDF-91', label: '4518838152.pdf',␍
|
||||
status_label: 'extracting', document_id: 191, root_document_id: 91,␍
|
||||
content_hash: 'hash-a', current_run_no: 'RUN-NEW',␍
|
||||
},␍
|
||||
{␍
|
||||
kind: 'document', object_key: 'DOC-92', workflow_item_no: 'SWI-PDF-92', label: '4518838154.pdf',␍
|
||||
status_label: 'pending_review', document_id: 92, root_document_id: 92,␍
|
||||
content_hash: 'hash-b', current_run_no: 'RUN-OLD',␍
|
||||
},␍
|
||||
],␍
|
||||
});␍
|
||||
const wrapper = mount(ShippingWorkflowTimeline, {␍
|
||||
props: { conversationId: 'conv-1', controller: buildController({ processing }) },␍
|
||||
...mountOptions,␍
|
||||
});␍
|
||||
await flushPromises();␍
|
||||
␍
|
||||
const task = wrapper.find('[data-testid="shipping-processing-task-OT-MULTI-RUN"]');␍
|
||||
expect(task.exists()).toBe(true);␍
|
||||
await task.findAll('button').at(-1)!.trigger('click');␍
|
||||
await flushPromises();␍
|
||||
␍
|
||||
// 断言:任务内两 PDF 均展示,无关 PDF 被过滤␍
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-item-SWI-PDF-91"]').exists()).toBe(true);␍
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-item-SWI-PDF-92"]').exists()).toBe(true);␍
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-item-SWI-OTHER"]').exists()).toBe(false);␍
|
||||
});␍
|
||||
});␍
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user