feat(shipping-notice): 增强订单抽取与审计功能,支持取消与保留策略
- 在环境配置中新增进度细化、订单提取取消与审计导出相关的开关 - 实现订单抽取运行的取消功能,允许管理员在运行中进行操作 - 引入审计事件的保留策略,支持三年保留期的自动清理 - 更新相关模型与服务,确保新功能的完整性与可追溯性 - 增强文档与代码注释,反映新的业务逻辑与审计要求
This commit is contained in:
1 parent
c85997884b
commit
95cdfe66b0
158 files changed
+19005
-1201
No files matched your search
@@ -6,7 +6,8 @@
|
||||
|
||||
* 依赖:ChatSidebar、ChatMessageList、ChatInputBar、ShippingSessionSummaryPanel、chat.context。
|
||||
|
||||
* 逻辑:本文件只做页面结构编排;货代 Chat 仅上传/进度通知,履约写操作不在本页;右侧摘要只读展示后端 ui_state/summary。
|
||||
* 逻辑:本文件只做页面结构编排;货代 Chat 仅上传/进度通知,履约写操作不在本页;
|
||||
* 右侧「本次处理」由 conversationId 驱动 session-work-items,extractionRunNo 仅作进度装饰。
|
||||
|
||||
*/
|
||||
|
||||
@@ -139,19 +140,13 @@ const activeExtractionRunNo = computed(() => {
|
||||
|
||||
|
||||
const showShippingSessionSummary = computed(() => (
|
||||
|
||||
page.isShippingNoticeAgent
|
||||
|
||||
&& Boolean(
|
||||
|
||||
page.shippingBatchSummary
|
||||
|
||||
page.conversationId
|
||||
|| page.shippingBatchSummary
|
||||
|| page.shippingConversationWorkspace?.batches?.length
|
||||
|
||||
|| activeExtractionRunNo.value
|
||||
|
||||
)
|
||||
|
||||
));
|
||||
|
||||
const embeddedIframeSrc = computed(() => {
|
||||
@@ -664,6 +659,8 @@ watch(() => page.currentAgentId, () => {
|
||||
|
||||
v-if="showShippingSessionSummary"
|
||||
|
||||
:conversation-id="page.conversationId"
|
||||
|
||||
:conversation-workspace="page.shippingConversationWorkspace"
|
||||
|
||||
:active-batch-no="page.activeShippingBatchNo"
|
||||
@@ -676,6 +673,8 @@ watch(() => page.currentAgentId, () => {
|
||||
|
||||
:extraction-run-no="activeExtractionRunNo"
|
||||
|
||||
:refresh-trigger="page.sessionWorkItemsRefreshTrigger"
|
||||
|
||||
/>
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
/**
|
||||
* features/chat/components/ShippingSessionSummaryPanel.spec.ts
|
||||
* 用途:验证右侧「本次处理」以 session-work-items 为列表事实源。
|
||||
* 依赖:Vitest、Vue Test Utils、vue-i18n、vue-router、shipping.api mock。
|
||||
* 逻辑:断言两次重识别后仍展示 2 条 open 项;已关闭分组默认折叠。
|
||||
*/
|
||||
import { mount, flushPromises } from '@vue/test-utils';
|
||||
import { describe, expect, it, vi, beforeEach } from 'vitest';
|
||||
import { createI18n } from 'vue-i18n';
|
||||
import { createRouter, createMemoryHistory } from 'vue-router';
|
||||
import chatZhCn from '@/locales/zh-CN/chat.json';
|
||||
import ShippingSessionSummaryPanel from './ShippingSessionSummaryPanel.vue';
|
||||
import type { ShippingSessionWorkItemSummary } from '../types/shipping.api.types';
|
||||
|
||||
vi.mock('@/features/chat/api/shipping.api', () => ({
|
||||
listWorkspaceShippingSessionWorkItems: vi.fn(),
|
||||
listWorkspaceShippingSessionWorkItemVersions: vi.fn(),
|
||||
getWorkspaceShippingOrderExtractionRun: vi.fn(),
|
||||
closeWorkspaceShippingSessionWorkItem: vi.fn(),
|
||||
markWorkspaceShippingOrderReviewNonOrder: vi.fn(),
|
||||
reparseWorkspaceShippingOrderReviewDocument: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('@/shared/composables/useMessage', () => ({
|
||||
useMessage: () => ({
|
||||
success: vi.fn(),
|
||||
error: vi.fn(),
|
||||
warning: vi.fn(),
|
||||
info: vi.fn(),
|
||||
}),
|
||||
}));
|
||||
|
||||
import {
|
||||
getWorkspaceShippingOrderExtractionRun,
|
||||
listWorkspaceShippingSessionWorkItems,
|
||||
} from '@/features/chat/api/shipping.api';
|
||||
|
||||
const i18n = createI18n({
|
||||
legacy: false,
|
||||
locale: 'zh-CN',
|
||||
messages: { 'zh-CN': { chat: chatZhCn } },
|
||||
});
|
||||
|
||||
const router = createRouter({
|
||||
history: createMemoryHistory(),
|
||||
routes: [{ path: '/chat/:agentId', name: 'Chat', component: { template: '<div />' } }],
|
||||
});
|
||||
|
||||
const buildWorkbench = (patch: Partial<ShippingSessionWorkItemSummary> = {}): ShippingSessionWorkItemSummary => ({
|
||||
conversation_id: 'conv-1',
|
||||
open_count: 2,
|
||||
closed_count: 1,
|
||||
pending_review_count: 2,
|
||||
extracting_count: 0,
|
||||
open_items: [
|
||||
{
|
||||
item_no: 'SWI-001',
|
||||
conversation_id: 'conv-1',
|
||||
owner_user_id: 1,
|
||||
root_document_id: 10,
|
||||
current_document_id: 10,
|
||||
current_document_filename: 'PO-A.pdf',
|
||||
current_run_no: 'SNER-1',
|
||||
current_case_no: 'SNRC-1',
|
||||
current_version_no: 1,
|
||||
lifecycle_status: 'pending_review',
|
||||
lock_version: 1,
|
||||
available_actions: [
|
||||
'enter_manual_review',
|
||||
'view_version_history',
|
||||
'request_reparse',
|
||||
'mark_non_order',
|
||||
'cancel',
|
||||
'replace_file',
|
||||
],
|
||||
},
|
||||
{
|
||||
item_no: 'SWI-002',
|
||||
conversation_id: 'conv-1',
|
||||
owner_user_id: 1,
|
||||
root_document_id: 11,
|
||||
current_document_id: 11,
|
||||
current_document_filename: 'PO-B.pdf',
|
||||
current_run_no: 'SNER-2',
|
||||
current_case_no: 'SNRC-2',
|
||||
current_version_no: 2,
|
||||
lifecycle_status: 'pending_review',
|
||||
lock_version: 2,
|
||||
version_replaced: true,
|
||||
available_actions: [
|
||||
'enter_manual_review',
|
||||
'view_version_history',
|
||||
'request_reparse',
|
||||
'mark_non_order',
|
||||
'cancel',
|
||||
'replace_file',
|
||||
],
|
||||
},
|
||||
],
|
||||
closed_items: [
|
||||
{
|
||||
item_no: 'SWI-003',
|
||||
conversation_id: 'conv-1',
|
||||
owner_user_id: 1,
|
||||
root_document_id: 12,
|
||||
current_document_id: 12,
|
||||
current_document_filename: 'PO-C.pdf',
|
||||
current_version_no: 1,
|
||||
lifecycle_status: 'closed',
|
||||
closed_reason: 'confirmed',
|
||||
lock_version: 1,
|
||||
available_actions: ['view_version_history'],
|
||||
},
|
||||
],
|
||||
closed_collapsed: true,
|
||||
max_open_items: 50,
|
||||
truncated: false,
|
||||
...patch,
|
||||
});
|
||||
|
||||
describe('ShippingSessionSummaryPanel', () => {
|
||||
beforeEach(() => {
|
||||
vi.mocked(listWorkspaceShippingSessionWorkItems).mockReset();
|
||||
vi.mocked(getWorkspaceShippingOrderExtractionRun).mockReset();
|
||||
vi.mocked(getWorkspaceShippingOrderExtractionRun).mockResolvedValue(null as never);
|
||||
});
|
||||
|
||||
it('shows two open work items after two reparses mock', async () => {
|
||||
vi.mocked(listWorkspaceShippingSessionWorkItems).mockResolvedValue(buildWorkbench());
|
||||
const wrapper = mount(ShippingSessionSummaryPanel, {
|
||||
props: {
|
||||
conversationId: 'conv-1',
|
||||
conversationWorkspace: null,
|
||||
activeBatchNo: '',
|
||||
batchSummary: null,
|
||||
batchTasks: [],
|
||||
activeTaskDetail: null,
|
||||
},
|
||||
global: { plugins: [i18n, router] },
|
||||
});
|
||||
await flushPromises();
|
||||
const rows = wrapper.findAll('[data-testid^="shipping-session-work-item-"]');
|
||||
expect(rows.length).toBe(2);
|
||||
expect(wrapper.text()).toContain('PO-A.pdf');
|
||||
expect(wrapper.text()).toContain('PO-B.pdf');
|
||||
expect(wrapper.text()).toContain('V2');
|
||||
expect(wrapper.text()).toContain('已生成新版本');
|
||||
expect(wrapper.findAll('[data-testid="shipping-session-action-cancel"]').length).toBe(2);
|
||||
expect(wrapper.findAll('[data-testid="shipping-session-action-non-order"]').length).toBe(2);
|
||||
expect(wrapper.findAll('[data-testid="shipping-session-action-reparse"]').length).toBe(2);
|
||||
expect(wrapper.findAll('[data-testid="shipping-session-action-replace"]').length).toBe(2);
|
||||
});
|
||||
|
||||
it('keeps closed section collapsed by default', async () => {
|
||||
vi.mocked(listWorkspaceShippingSessionWorkItems).mockResolvedValue(buildWorkbench());
|
||||
const wrapper = mount(ShippingSessionSummaryPanel, {
|
||||
props: {
|
||||
conversationId: 'conv-1',
|
||||
conversationWorkspace: null,
|
||||
activeBatchNo: '',
|
||||
batchSummary: null,
|
||||
batchTasks: [],
|
||||
activeTaskDetail: null,
|
||||
},
|
||||
global: { plugins: [i18n, router] },
|
||||
});
|
||||
await flushPromises();
|
||||
expect(wrapper.find('[data-testid="shipping-session-closed-section"]').exists()).toBe(true);
|
||||
expect(wrapper.text()).toContain('已完成 1 项');
|
||||
expect(wrapper.text()).not.toContain('PO-C.pdf');
|
||||
await wrapper.find('[data-testid="shipping-session-closed-section"] button').trigger('click');
|
||||
expect(wrapper.text()).toContain('PO-C.pdf');
|
||||
});
|
||||
});
|
||||
@@ -1,329 +1,284 @@
|
||||
/**
|
||||
* features/chat/components/ShippingSessionSummaryPanel.vue
|
||||
* 用途:聊天页右侧「本次处理」唯一状态面——每 PDF 实时状态、异常原因与复核/已有任务深链。
|
||||
* 依赖:vue-i18n、vue-router、lucide、shipping.api(含 extraction documents)。
|
||||
* 逻辑:合并批次 Task 行与抽取 Run 文档行;open_existing 分流为「重复处理中 + 查看已有任务」。
|
||||
* 用途:聊天页右侧「本次处理」面板——以会话级 PDF 工作项 API 为唯一列表事实源。
|
||||
* 依赖:vue-i18n、vue-router、shipping.api session-work-items / 复核处置、useMessage。
|
||||
* 逻辑:conversationId 驱动 listWorkspaceShippingSessionWorkItems 轮询;extractionRunNo 仅作 Run 级处理事项装饰;
|
||||
* 按 available_actions 渲染人工复核/版本历史/取消/非订单/重识别/替换文件入口。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, ref, watch } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ChevronDown, ChevronRight, ExternalLink } from 'lucide-vue-next';
|
||||
import { BusinessError } from '@/shared/api/client';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import {
|
||||
getWorkspaceShippingOrderReviewRun,
|
||||
listWorkspaceShippingOrderExtractionDocuments,
|
||||
closeWorkspaceShippingSessionWorkItem,
|
||||
getWorkspaceShippingOrderExtractionRun,
|
||||
listWorkspaceShippingSessionWorkItemVersions,
|
||||
listWorkspaceShippingSessionWorkItems,
|
||||
markWorkspaceShippingOrderReviewNonOrder,
|
||||
reparseWorkspaceShippingOrderReviewDocument,
|
||||
type ShippingBatchSummary,
|
||||
type ShippingConversationWorkspace,
|
||||
type ShippingTaskDetail,
|
||||
type ShippingTaskSummary,
|
||||
type ShippingTaskUiState,
|
||||
} from '@/features/chat/api/shipping.api';
|
||||
import type { ShippingOrderExtractionDocumentResult } from '@/features/chat/types/shipping.api.types';
|
||||
import type {
|
||||
ShippingOrderExtractionRun,
|
||||
ShippingSessionWorkItem,
|
||||
ShippingSessionWorkItemSummary,
|
||||
ShippingSessionWorkItemVersion,
|
||||
} from '@/features/chat/types/shipping.api.types';
|
||||
import {
|
||||
listDisplayableHandlingAffectedRefs,
|
||||
type ShippingHandlingAffectedRef,
|
||||
type ShippingHandlingRefTarget,
|
||||
} from '@/features/chat/shipping/orderExtractionHandlingRefs';
|
||||
|
||||
const props = defineProps<{
|
||||
/** 当前聊天会话 ID;工作项列表的唯一驱动键。 */
|
||||
conversationId?: string | null;
|
||||
conversationWorkspace: ShippingConversationWorkspace | null;
|
||||
activeBatchNo: string;
|
||||
batchSummary: ShippingBatchSummary | null;
|
||||
batchTasks: ShippingTaskSummary[];
|
||||
activeTaskDetail: ShippingTaskDetail | null;
|
||||
/** 当前会话活跃抽取 Run;有值时右侧轮询每 PDF 状态 */
|
||||
/** 可选:当前活跃抽取 Run,仅用于 Run 级 handling_items 装饰,不驱动 PDF 列表。 */
|
||||
extractionRunNo?: string | null;
|
||||
/** 父级递增以触发立即刷新(终态/重识别/会话恢复后)。 */
|
||||
refreshTrigger?: number;
|
||||
}>();
|
||||
|
||||
const { t, te } = useI18n();
|
||||
const { t, te, locale } = useI18n();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const msg = useMessage();
|
||||
const collapsed = ref(false);
|
||||
const extractionDocs = ref<ShippingOrderExtractionDocumentResult[]>([]);
|
||||
const docsLoading = ref(false);
|
||||
let docsTimer: ReturnType<typeof setInterval> | null = null;
|
||||
const openOnlyFilter = ref(false);
|
||||
const closedExpanded = ref(false);
|
||||
const workbench = ref<ShippingSessionWorkItemSummary | null>(null);
|
||||
const workItemsLoading = ref(false);
|
||||
const actionBusyItemNo = ref<string | null>(null);
|
||||
const extractionRun = ref<ShippingOrderExtractionRun | null>(null);
|
||||
const versionHistoryItemNo = ref<string | null>(null);
|
||||
const versionHistoryItems = ref<ShippingSessionWorkItemVersion[]>([]);
|
||||
const versionHistoryLoading = ref(false);
|
||||
let workItemsTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
let workItemsPollGeneration = 0;
|
||||
let workItemsRequestController: AbortController | null = null;
|
||||
|
||||
const workspaceBatches = computed(() => props.conversationWorkspace?.batches || []);
|
||||
const activeBatchNo = computed(() =>
|
||||
String(props.activeBatchNo || props.batchSummary?.batch_no || workspaceBatches.value[0]?.batch_no || '').trim(),
|
||||
);
|
||||
const FOREGROUND_POLL_MS = 2000;
|
||||
const BACKGROUND_POLL_MS = 8000;
|
||||
|
||||
/**
|
||||
* 判断文档是否为「打开已有任务」分流。
|
||||
* 按页面可见性选择工作项轮询间隔。
|
||||
*/
|
||||
function isOpenExistingDoc(doc: ShippingOrderExtractionDocumentResult): boolean {
|
||||
const taskNo = String(doc.existing_task_no || '').trim();
|
||||
return Boolean(
|
||||
taskNo
|
||||
&& (
|
||||
doc.duplicate_resolution === 'open_existing'
|
||||
|| doc.available_actions.includes('open_existing')
|
||||
),
|
||||
);
|
||||
function resolveWorkItemsPollMs(): number {
|
||||
if (typeof document !== 'undefined' && document.visibilityState === 'hidden') {
|
||||
return BACKGROUND_POLL_MS;
|
||||
}
|
||||
return FOREGROUND_POLL_MS;
|
||||
}
|
||||
|
||||
const processSummary = computed(() => {
|
||||
const summary = props.batchSummary?.process_summary || props.conversationWorkspace?.summary || null;
|
||||
const fromDocs = extractionDocs.value;
|
||||
const total = Number(
|
||||
(summary as { total?: number } | null)?.total
|
||||
|| props.batchSummary?.file_count
|
||||
|| props.batchTasks.length
|
||||
|| fromDocs.length
|
||||
|| 0,
|
||||
const normalizedConversationId = computed(() => String(props.conversationId || '').trim());
|
||||
|
||||
const handlingItems = computed(() => (
|
||||
Array.isArray(extractionRun.value?.handling_items)
|
||||
? extractionRun.value!.handling_items!.filter((item) => String(item.category || '').trim())
|
||||
: []
|
||||
));
|
||||
|
||||
const openItems = computed((): ShippingSessionWorkItem[] => workbench.value?.open_items || []);
|
||||
const closedItems = computed((): ShippingSessionWorkItem[] => workbench.value?.closed_items || []);
|
||||
|
||||
const displayOpenItems = computed(() => {
|
||||
if (!openOnlyFilter.value) return openItems.value;
|
||||
return openItems.value.filter((item) =>
|
||||
item.lifecycle_status === 'pending_review' || item.lifecycle_status === 'reparse_failed',
|
||||
);
|
||||
const reviewFromDocs = fromDocs.filter((d) =>
|
||||
!isOpenExistingDoc(d)
|
||||
&& (
|
||||
d.status === 'review_required'
|
||||
|| d.available_actions.some((a) => a === 'review_candidate' || a === 'manual_review')
|
||||
),
|
||||
).length;
|
||||
const openExistingFromDocs = fromDocs.filter((d) => isOpenExistingDoc(d)).length;
|
||||
return {
|
||||
total,
|
||||
completed: Number((summary as { completed?: number } | null)?.completed || 0),
|
||||
running: Number((summary as { running?: number } | null)?.running || 0),
|
||||
failed: Number((summary as { failed?: number } | null)?.failed
|
||||
|| fromDocs.filter((d) => d.status === 'failed').length
|
||||
|| 0),
|
||||
needsHuman: Number(
|
||||
(summary as { needs_human?: number } | null)?.needs_human
|
||||
|| props.conversationWorkspace?.summary?.needs_human
|
||||
|| reviewFromDocs
|
||||
|| 0,
|
||||
),
|
||||
openExisting: openExistingFromDocs,
|
||||
pending: Number((summary as { pending?: number } | null)?.pending || 0),
|
||||
};
|
||||
});
|
||||
|
||||
type SummaryRow = {
|
||||
key: string;
|
||||
fileName: string;
|
||||
taskNo: string;
|
||||
runNo: string;
|
||||
caseNo: string;
|
||||
index: number;
|
||||
total: number;
|
||||
stage: string;
|
||||
message: string;
|
||||
entrySurface: string;
|
||||
/** exception=需人工异常;duplicate=已识别重复关联;none=无标签 */
|
||||
badge: 'exception' | 'duplicate' | 'none';
|
||||
kind: 'task' | 'document';
|
||||
};
|
||||
const processSummary = computed(() => ({
|
||||
total: Number(workbench.value?.open_count || 0) + Number(workbench.value?.closed_count || 0),
|
||||
completed: Number(workbench.value?.closed_count || 0),
|
||||
running: Number(workbench.value?.extracting_count || 0),
|
||||
needsHuman: Number(workbench.value?.pending_review_count || 0),
|
||||
failed: openItems.value.filter((item) => item.lifecycle_status === 'reparse_failed').length,
|
||||
pending: 0,
|
||||
openExisting: 0,
|
||||
pendingConfirmation: 0,
|
||||
cancelled: 0,
|
||||
}));
|
||||
|
||||
/**
|
||||
* 将 Task ui_state 映射为右侧行。
|
||||
* 解析 Run 级处理事项标题。
|
||||
*/
|
||||
function mapTaskRow(task: ShippingTaskSummary, index: number, total: number): SummaryRow {
|
||||
const uiState: ShippingTaskUiState | null | undefined =
|
||||
(props.activeTaskDetail?.task_no === task.task_no ? props.activeTaskDetail.ui_state : null)
|
||||
|| task.ui_state;
|
||||
const summary = uiState?.summary;
|
||||
const kind = String(uiState?.checkpoint_kind || summary?.checkpoint_kind || '');
|
||||
const stage = String(summary?.stage || summary?.title || task.process_status || '').trim();
|
||||
let normalizedStage = stage;
|
||||
if (kind === 'wait_manual_upload') normalizedStage = t('chat.shippingSessionSummary.waitingUpload');
|
||||
else if (kind === 'auto_continue') normalizedStage = t('chat.shippingSessionSummary.autoProcessing');
|
||||
else if (kind === 'must_human') normalizedStage = stage || t('chat.shippingSessionSummary.needsReview');
|
||||
return {
|
||||
key: `task:${task.task_no || index}`,
|
||||
fileName: String(task.source_file_name || '').trim(),
|
||||
taskNo: String(task.task_no || '').trim(),
|
||||
runNo: '',
|
||||
caseNo: '',
|
||||
index: Number(task.batch_index || index + 1),
|
||||
total: Number(task.batch_total || total || 1),
|
||||
stage: normalizedStage,
|
||||
message: String(summary?.message || summary?.current_todo || summary?.pause_reason || '').trim(),
|
||||
entrySurface: String(summary?.entry_surface || 'none').trim(),
|
||||
badge: (
|
||||
summary?.pause_reason
|
||||
|| task.pending_human_reason
|
||||
|| task.error_message
|
||||
|| kind === 'must_human'
|
||||
|| ['rejected', 'upload_failed'].includes(String(task.process_status || ''))
|
||||
) ? 'exception' : 'none',
|
||||
kind: 'task',
|
||||
};
|
||||
function handlingTitle(category: string): string {
|
||||
const key = `chat.shippingOrderExtractionHandling.category.${category}`;
|
||||
return te(key) ? t(key) : category;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 reason_code / review_details 拼成用户可读原因。
|
||||
* 解析原因码文案。
|
||||
*/
|
||||
function formatDocumentReason(doc: ShippingOrderExtractionDocumentResult): string {
|
||||
const reasonKey = `chat.shippingOrderExtractionReason.${doc.reason_code || ''}`;
|
||||
const reasonText = doc.reason_code && te(reasonKey)
|
||||
? t(reasonKey)
|
||||
: String(doc.reason_code || doc.activity_event_code || '').trim();
|
||||
const detailParts: string[] = [];
|
||||
for (const detail of (doc.review_details || []).slice(0, 2)) {
|
||||
const fieldCode = String(detail.field_code || '').trim();
|
||||
const fieldKey = `chat.shippingOrderExtractionReviewField.${fieldCode || 'unknown'}`;
|
||||
const fieldLabel = te(fieldKey) ? t(fieldKey) : (fieldCode || t('chat.shippingOrderExtractionReviewField.unknown'));
|
||||
const detailReasonKey = `chat.shippingOrderExtractionReason.${detail.reason_code || ''}`;
|
||||
const detailReason = detail.reason_code && te(detailReasonKey)
|
||||
? t(detailReasonKey)
|
||||
: String(detail.reason_code || '').trim();
|
||||
detailParts.push(
|
||||
t('chat.shippingOrderExtractionReviewDetail', {
|
||||
line: detail.line_number,
|
||||
field: fieldLabel,
|
||||
}) + (detailReason ? `(${detailReason})` : ''),
|
||||
);
|
||||
}
|
||||
if (reasonText && detailParts.length) return `${reasonText};${detailParts.join(';')}`;
|
||||
if (detailParts.length) return detailParts.join(';');
|
||||
return reasonText;
|
||||
function handlingReasonLabel(code: string): string {
|
||||
const key = `chat.shippingOrderExtractionReason.${code}`;
|
||||
if (te(key)) return t(key);
|
||||
const freezeKey = `chat.shippingOrderExtractionHandling.reason.${code}`;
|
||||
return te(freezeKey) ? t(freezeKey) : code;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将抽取文档映射为建单前右侧行;open_existing 走任务深链。
|
||||
* 解析工作项生命周期状态文案。
|
||||
*/
|
||||
function mapDocumentRow(
|
||||
doc: ShippingOrderExtractionDocumentResult,
|
||||
index: number,
|
||||
total: number,
|
||||
runNo: string,
|
||||
caseNo = '',
|
||||
): SummaryRow {
|
||||
const existingTaskNo = String(doc.existing_task_no || '').trim();
|
||||
const openExisting = isOpenExistingDoc(doc);
|
||||
const needsReview = !openExisting && (
|
||||
doc.status === 'review_required'
|
||||
|| doc.available_actions.some((a) => a === 'review_candidate' || a === 'manual_review')
|
||||
|| Boolean(caseNo)
|
||||
);
|
||||
const failed = doc.status === 'failed';
|
||||
const reasonText = formatDocumentReason(doc);
|
||||
let stage = t('chat.shippingSessionSummary.autoProcessing');
|
||||
let entrySurface = 'none';
|
||||
let message = reasonText;
|
||||
let taskNo = '';
|
||||
if (openExisting && existingTaskNo) {
|
||||
stage = t('chat.shippingSessionSummary.duplicateProcessing');
|
||||
entrySurface = 'task_workbench';
|
||||
taskNo = existingTaskNo;
|
||||
message = reasonText
|
||||
? `${t('chat.shippingSessionSummary.existingTaskNo', { taskNo: existingTaskNo })} · ${reasonText}`
|
||||
: t('chat.shippingSessionSummary.existingTaskNo', { taskNo: existingTaskNo });
|
||||
} else if (needsReview) {
|
||||
stage = t('chat.shippingSessionSummary.needsReview');
|
||||
entrySurface = 'review_workbench';
|
||||
} else if (failed) {
|
||||
stage = t('chat.shippingOrderExtractionDocumentStatus.failed');
|
||||
}
|
||||
return {
|
||||
key: `doc:${doc.unit_id || doc.document_id || index}`,
|
||||
fileName: String(doc.file_name || '').trim(),
|
||||
taskNo,
|
||||
runNo,
|
||||
caseNo,
|
||||
index: index + 1,
|
||||
total,
|
||||
stage,
|
||||
message,
|
||||
entrySurface,
|
||||
badge: openExisting ? 'duplicate' : (needsReview || failed ? 'exception' : 'none'),
|
||||
kind: 'document',
|
||||
};
|
||||
function lifecycleStatusLabel(status: string): string {
|
||||
const key = `chat.shippingSessionWorkItem.status.${status}`;
|
||||
return te(key) ? t(key) : status;
|
||||
}
|
||||
|
||||
const caseNoByDocumentId = ref<Record<number, string>>({});
|
||||
|
||||
const taskRows = computed((): SummaryRow[] => {
|
||||
const runNo = String(props.extractionRunNo || '').trim();
|
||||
// [STEP 1] 建单前:有抽取 Run 时优先展示每 PDF 文档行(含复核/已有任务深链)。
|
||||
if (runNo && extractionDocs.value.length) {
|
||||
return extractionDocs.value.map((doc, index) =>
|
||||
mapDocumentRow(
|
||||
doc,
|
||||
index,
|
||||
extractionDocs.value.length,
|
||||
runNo,
|
||||
caseNoByDocumentId.value[Number(doc.document_id)] || '',
|
||||
));
|
||||
}
|
||||
// [STEP 2] 建单后:展示 Task 行。
|
||||
const tasks = props.batchTasks.length
|
||||
? props.batchTasks
|
||||
: (workspaceBatches.value.find((b) => b.batch_no === activeBatchNo.value)?.tasks || []);
|
||||
if (tasks.length) {
|
||||
return tasks.map((task, index) => mapTaskRow(task, index, processSummary.value.total || tasks.length));
|
||||
}
|
||||
return [];
|
||||
});
|
||||
/**
|
||||
* 解析工作项关闭原因文案。
|
||||
*/
|
||||
function closedReasonLabel(reason?: string | null): string {
|
||||
const normalized = String(reason || '').trim();
|
||||
if (!normalized) return '';
|
||||
const key = `chat.shippingSessionWorkItem.closedReason.${normalized}`;
|
||||
return te(key) ? t(key) : normalized;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拉取当前 Run 文档与复核 Case,保证右侧可深链 case_no/run_no/existing_task_no。
|
||||
* 格式化 updated_at 为「更新于 HH:mm」。
|
||||
*/
|
||||
async function refreshExtractionDocs() {
|
||||
const runNo = String(props.extractionRunNo || '').trim();
|
||||
if (!runNo || docsLoading.value) return;
|
||||
docsLoading.value = true;
|
||||
function formatUpdatedLabel(value?: string | null): string {
|
||||
const date = new Date(String(value || ''));
|
||||
if (Number.isNaN(date.getTime())) return '';
|
||||
const time = new Intl.DateTimeFormat(String(locale.value || 'zh-CN'), {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hour12: false,
|
||||
}).format(date);
|
||||
return t('chat.shippingOrderExtractionDocumentTiming.updated', { time });
|
||||
}
|
||||
|
||||
/**
|
||||
* 拉取会话工作台与可选 Run 装饰数据。
|
||||
*/
|
||||
async function refreshWorkItems() {
|
||||
const conversationId = normalizedConversationId.value;
|
||||
if (!conversationId || workItemsLoading.value) return;
|
||||
workItemsLoading.value = true;
|
||||
workItemsRequestController?.abort();
|
||||
const controller = new AbortController();
|
||||
workItemsRequestController = controller;
|
||||
try {
|
||||
const [docsResponse, reviewResponse] = await Promise.all([
|
||||
listWorkspaceShippingOrderExtractionDocuments(runNo),
|
||||
getWorkspaceShippingOrderReviewRun(runNo).catch(() => null),
|
||||
const [summaryResponse, runResponse] = await Promise.all([
|
||||
listWorkspaceShippingSessionWorkItems(conversationId, {
|
||||
open_only: openOnlyFilter.value,
|
||||
signal: controller.signal,
|
||||
}),
|
||||
(() => {
|
||||
const runNo = String(props.extractionRunNo || '').trim();
|
||||
return runNo ? getWorkspaceShippingOrderExtractionRun(runNo).catch(() => null) : Promise.resolve(null);
|
||||
})(),
|
||||
]);
|
||||
extractionDocs.value = docsResponse.items || [];
|
||||
const mapping: Record<number, string> = {};
|
||||
for (const item of reviewResponse?.items || []) {
|
||||
const docId = Number(item.document_id);
|
||||
const caseNo = String(item.case_no || '').trim();
|
||||
if (docId && caseNo) mapping[docId] = caseNo;
|
||||
if (controller.signal.aborted) return;
|
||||
workbench.value = summaryResponse;
|
||||
extractionRun.value = runResponse;
|
||||
if (!closedExpanded.value) {
|
||||
closedExpanded.value = false;
|
||||
}
|
||||
caseNoByDocumentId.value = mapping;
|
||||
} catch {
|
||||
/* 右侧失败不打断聊天 */
|
||||
} finally {
|
||||
docsLoading.value = false;
|
||||
if (workItemsRequestController === controller) {
|
||||
workItemsRequestController = null;
|
||||
}
|
||||
workItemsLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function stopDocsPolling() {
|
||||
if (docsTimer) clearInterval(docsTimer);
|
||||
docsTimer = null;
|
||||
function stopWorkItemsPolling() {
|
||||
if (workItemsTimer) clearTimeout(workItemsTimer);
|
||||
workItemsTimer = null;
|
||||
workItemsRequestController?.abort();
|
||||
workItemsRequestController = null;
|
||||
workItemsPollGeneration += 1;
|
||||
}
|
||||
|
||||
function restartDocsPolling() {
|
||||
stopDocsPolling();
|
||||
const runNo = String(props.extractionRunNo || '').trim();
|
||||
if (!runNo) {
|
||||
extractionDocs.value = [];
|
||||
return;
|
||||
}
|
||||
void refreshExtractionDocs();
|
||||
docsTimer = setInterval(() => void refreshExtractionDocs(), 2000);
|
||||
}
|
||||
|
||||
watch(() => props.extractionRunNo, () => restartDocsPolling(), { immediate: true });
|
||||
onBeforeUnmount(stopDocsPolling);
|
||||
|
||||
/**
|
||||
* 打开任务处理工作台。
|
||||
* 可见性感知的工作项轮询;前台 2s,后台 8s。
|
||||
*/
|
||||
async function openTaskWorkbench(taskNo: string) {
|
||||
const normalized = String(taskNo || '').trim();
|
||||
if (!normalized) return;
|
||||
await router.push({
|
||||
path: '/workspace/shipping-notice/my-tasks',
|
||||
query: { task_no: normalized },
|
||||
function scheduleWorkItemsPoll(generation: number, delayMs: number) {
|
||||
if (workItemsTimer) clearTimeout(workItemsTimer);
|
||||
workItemsTimer = setTimeout(async () => {
|
||||
if (generation !== workItemsPollGeneration) return;
|
||||
await refreshWorkItems();
|
||||
if (generation !== workItemsPollGeneration) return;
|
||||
if (!normalizedConversationId.value) return;
|
||||
scheduleWorkItemsPoll(generation, resolveWorkItemsPollMs());
|
||||
}, delayMs);
|
||||
}
|
||||
|
||||
function restartWorkItemsPolling() {
|
||||
stopWorkItemsPolling();
|
||||
const conversationId = normalizedConversationId.value;
|
||||
if (!conversationId) {
|
||||
workbench.value = null;
|
||||
extractionRun.value = null;
|
||||
return;
|
||||
}
|
||||
const generation = workItemsPollGeneration;
|
||||
void refreshWorkItems().then(() => {
|
||||
if (generation !== workItemsPollGeneration) return;
|
||||
scheduleWorkItemsPoll(generation, resolveWorkItemsPollMs());
|
||||
});
|
||||
}
|
||||
|
||||
function onVisibilityChange() {
|
||||
if (typeof document === 'undefined' || document.visibilityState !== 'visible') return;
|
||||
if (!normalizedConversationId.value) return;
|
||||
scheduleWorkItemsPoll(workItemsPollGeneration, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开人工复核(Chat order-review 模式);携带 case_no 精确定位 PDF。
|
||||
* 打开版本历史面板并拉取时间线。
|
||||
*/
|
||||
async function openReview(runNo: string, caseNo = '') {
|
||||
const normalized = String(runNo || '').trim();
|
||||
if (!normalized) return;
|
||||
async function openVersionHistory(item: ShippingSessionWorkItem) {
|
||||
const itemNo = String(item.item_no || '').trim();
|
||||
if (!itemNo) return;
|
||||
if (versionHistoryItemNo.value === itemNo) {
|
||||
versionHistoryItemNo.value = null;
|
||||
versionHistoryItems.value = [];
|
||||
return;
|
||||
}
|
||||
versionHistoryItemNo.value = itemNo;
|
||||
versionHistoryLoading.value = true;
|
||||
try {
|
||||
const response = await listWorkspaceShippingSessionWorkItemVersions(itemNo);
|
||||
versionHistoryItems.value = response.versions || [];
|
||||
} catch {
|
||||
versionHistoryItems.value = [];
|
||||
} finally {
|
||||
versionHistoryLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开人工复核(Chat order-review 模式);使用行内 case_no / run_no。
|
||||
*/
|
||||
async function openManualReview(item: ShippingSessionWorkItem) {
|
||||
const runNo = String(item.current_run_no || '').trim();
|
||||
if (!runNo) return;
|
||||
const caseNo = String(item.current_case_no || '').trim();
|
||||
const query: Record<string, string> = {
|
||||
...Object.fromEntries(
|
||||
Object.entries(route.query).filter(([, v]) => typeof v === 'string') as Array<[string, string]>,
|
||||
),
|
||||
mode: 'order-review',
|
||||
run_no: normalized,
|
||||
run_no: runNo,
|
||||
};
|
||||
const caseNormalized = String(caseNo || '').trim();
|
||||
if (caseNormalized) query.case_no = caseNormalized;
|
||||
if (caseNo) query.case = caseNo;
|
||||
await router.push({
|
||||
name: 'Chat',
|
||||
params: { agentId: String(route.params.agentId || '') },
|
||||
@@ -332,19 +287,171 @@ async function openReview(runNo: string, caseNo = '') {
|
||||
}
|
||||
|
||||
/**
|
||||
* 按 entry_surface 分发深链;复核必须有 run_no,禁止空 task 跳转。
|
||||
* 按 Run 级处理事项受影响对象跳转。
|
||||
*/
|
||||
async function openEntrySurface(row: SummaryRow) {
|
||||
if (row.entrySurface === 'review_workbench') {
|
||||
const runNo = row.runNo || String(props.extractionRunNo || '');
|
||||
if (!runNo) return;
|
||||
await openReview(runNo, row.caseNo);
|
||||
async function openAffectedRef(target: ShippingHandlingRefTarget, runNo?: string) {
|
||||
if (target.kind === 'task') {
|
||||
await router.push({
|
||||
name: 'workspace-shipping-tasks',
|
||||
params: { taskNo: target.taskNo },
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (row.entrySurface === 'task_workbench' && row.taskNo) {
|
||||
await openTaskWorkbench(row.taskNo);
|
||||
if (target.kind === 'review') {
|
||||
const normalizedRun = String(runNo || props.extractionRunNo || '').trim();
|
||||
if (!normalizedRun) return;
|
||||
await openManualReview({
|
||||
item_no: '',
|
||||
conversation_id: normalizedConversationId.value,
|
||||
owner_user_id: 0,
|
||||
root_document_id: 0,
|
||||
current_document_id: 0,
|
||||
current_run_no: normalizedRun,
|
||||
current_case_no: target.documentId ? '' : '',
|
||||
current_version_no: 1,
|
||||
lifecycle_status: 'pending_review',
|
||||
lock_version: 1,
|
||||
available_actions: [],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 按处理事项主动作打开复核入口。
|
||||
*/
|
||||
async function openHandlingAction(
|
||||
action?: string | null,
|
||||
refs?: Array<Record<string, unknown>> | null,
|
||||
) {
|
||||
const runNo = String(props.extractionRunNo || '').trim();
|
||||
if (!runNo) return;
|
||||
const rows = listDisplayableHandlingAffectedRefs(refs as ShippingHandlingAffectedRef[] | undefined);
|
||||
const first = rows[0];
|
||||
if (first) {
|
||||
await openAffectedRef(first.target, runNo);
|
||||
return;
|
||||
}
|
||||
const normalized = String(action || '').trim();
|
||||
if (
|
||||
normalized === 'enter_manual_review'
|
||||
|| normalized === 'review_candidate'
|
||||
|| normalized === 'view_details'
|
||||
|| !normalized
|
||||
) {
|
||||
await router.push({
|
||||
name: 'Chat',
|
||||
params: { agentId: String(route.params.agentId || '') },
|
||||
query: {
|
||||
...Object.fromEntries(
|
||||
Object.entries(route.query).filter(([, v]) => typeof v === 'string') as Array<[string, string]>,
|
||||
),
|
||||
mode: 'order-review',
|
||||
run_no: runNo,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提示并收集操作原因;取消输入时返回 null。
|
||||
*/
|
||||
function promptActionReason(messageKey: string): string | null {
|
||||
const reason = window.prompt(t(messageKey));
|
||||
if (reason == null) return null;
|
||||
const trimmed = reason.trim();
|
||||
if (!trimmed) {
|
||||
msg.warning(t('chat.shippingSessionWorkItem.reasonRequired'));
|
||||
return null;
|
||||
}
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行工作项写操作后刷新列表;失败用业务错误提示。
|
||||
*/
|
||||
async function runWorkItemAction(item: ShippingSessionWorkItem, action: () => Promise<unknown>) {
|
||||
const itemNo = String(item.item_no || '').trim();
|
||||
if (!itemNo || actionBusyItemNo.value) return;
|
||||
actionBusyItemNo.value = itemNo;
|
||||
try {
|
||||
await action();
|
||||
await refreshWorkItems();
|
||||
} catch (error) {
|
||||
const message = error instanceof BusinessError ? error.message : t('errors.generic');
|
||||
msg.error(message);
|
||||
} finally {
|
||||
actionBusyItemNo.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消本次处理(关闭工作项)。
|
||||
*/
|
||||
async function cancelWorkItem(item: ShippingSessionWorkItem) {
|
||||
const reason = promptActionReason('chat.shippingSessionWorkItem.cancelReasonPrompt');
|
||||
if (!reason) return;
|
||||
await runWorkItemAction(item, () => closeWorkspaceShippingSessionWorkItem(String(item.item_no), {
|
||||
reason,
|
||||
expected_lock_version: item.lock_version,
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* 标记非订单并关闭当前 Case/工作项。
|
||||
*/
|
||||
async function markNonOrderFromPanel(item: ShippingSessionWorkItem) {
|
||||
const caseNo = String(item.current_case_no || '').trim();
|
||||
if (!caseNo) {
|
||||
msg.warning(t('chat.shippingSessionWorkItem.caseRequired'));
|
||||
return;
|
||||
}
|
||||
const reason = promptActionReason('chat.shippingSessionWorkItem.nonOrderReasonPrompt');
|
||||
if (!reason) return;
|
||||
await runWorkItemAction(item, () => markWorkspaceShippingOrderReviewNonOrder(caseNo, 'non_order', reason));
|
||||
}
|
||||
|
||||
/**
|
||||
* 单文件重新识别。
|
||||
*/
|
||||
async function reparseFromPanel(item: ShippingSessionWorkItem) {
|
||||
const caseNo = String(item.current_case_no || '').trim();
|
||||
if (!caseNo) {
|
||||
msg.warning(t('chat.shippingSessionWorkItem.caseRequired'));
|
||||
return;
|
||||
}
|
||||
const reason = promptActionReason('chat.shippingSessionWorkItem.reparseReasonPrompt');
|
||||
if (!reason) return;
|
||||
await runWorkItemAction(item, () => reparseWorkspaceShippingOrderReviewDocument(caseNo, 'other', reason));
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换文件:进入人工复核页完成上传替代流程。
|
||||
*/
|
||||
async function replaceFileFromPanel(item: ShippingSessionWorkItem) {
|
||||
await openManualReview(item);
|
||||
}
|
||||
|
||||
function itemHasAction(item: ShippingSessionWorkItem, action: string): boolean {
|
||||
return Array.isArray(item.available_actions) && item.available_actions.includes(action);
|
||||
}
|
||||
|
||||
watch(normalizedConversationId, () => restartWorkItemsPolling(), { immediate: true });
|
||||
watch(openOnlyFilter, () => { void refreshWorkItems(); });
|
||||
watch(() => props.refreshTrigger, () => {
|
||||
if (!normalizedConversationId.value) return;
|
||||
scheduleWorkItemsPoll(workItemsPollGeneration, 0);
|
||||
});
|
||||
watch(() => props.extractionRunNo, () => { void refreshWorkItems(); });
|
||||
|
||||
if (typeof document !== 'undefined') {
|
||||
document.addEventListener('visibilitychange', onVisibilityChange);
|
||||
}
|
||||
onBeforeUnmount(() => {
|
||||
if (typeof document !== 'undefined') {
|
||||
document.removeEventListener('visibilitychange', onVisibilityChange);
|
||||
}
|
||||
stopWorkItemsPolling();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -362,7 +469,7 @@ async function openEntrySurface(row: SummaryRow) {
|
||||
{{ t('chat.shippingSessionSummary.title') }}
|
||||
</div>
|
||||
<div class="mt-0.5 text-xs text-secondary">
|
||||
{{ t('chat.shippingSessionSummary.pdfCount', { count: processSummary.total || taskRows.length }) }}
|
||||
{{ t('chat.shippingSessionSummary.pdfCount', { count: processSummary.total || displayOpenItems.length }) }}
|
||||
</div>
|
||||
</div>
|
||||
<ChevronDown v-if="!collapsed" class="h-4 w-4 shrink-0 text-muted" />
|
||||
@@ -370,6 +477,56 @@ async function openEntrySurface(row: SummaryRow) {
|
||||
</button>
|
||||
|
||||
<div v-if="!collapsed" class="min-h-0 flex-1 overflow-auto p-3">
|
||||
<label class="mb-3 flex cursor-pointer items-center gap-2 text-[11px] text-secondary">
|
||||
<input
|
||||
v-model="openOnlyFilter"
|
||||
type="checkbox"
|
||||
class="rounded border-default"
|
||||
data-testid="shipping-session-open-only-filter"
|
||||
/>
|
||||
{{ t('chat.shippingSessionWorkItem.openOnlyFilter') }}
|
||||
</label>
|
||||
|
||||
<div
|
||||
v-if="handlingItems.length"
|
||||
class="mb-3 space-y-1.5"
|
||||
data-testid="shipping-session-handling-items"
|
||||
>
|
||||
<div class="text-[11px] font-medium text-secondary">
|
||||
{{ t('chat.shippingOrderExtractionHandling.title') }}
|
||||
</div>
|
||||
<div
|
||||
v-for="item in handlingItems"
|
||||
:key="item.category"
|
||||
class="rounded-md border border-default bg-surface-muted/60 px-2 py-1.5 text-xs"
|
||||
>
|
||||
<div class="flex flex-wrap items-center justify-between gap-2">
|
||||
<div class="min-w-0 font-medium text-primary">
|
||||
{{ handlingTitle(item.category) }}
|
||||
<span class="ml-1 text-secondary">
|
||||
{{ t('chat.shippingOrderExtractionHandling.count', { count: item.count }) }}
|
||||
</span>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="shrink-0 rounded-md border border-default px-2 py-0.5 text-[11px] font-medium text-primary hover:bg-surface"
|
||||
@click="openHandlingAction(item.primary_action, item.affected_refs)"
|
||||
>
|
||||
{{ te(`chat.shippingOrderExtractionAction.${item.primary_action || 'view_details'}`)
|
||||
? t(`chat.shippingOrderExtractionAction.${item.primary_action || 'view_details'}`)
|
||||
: t('chat.shippingOrderExtractionAction.view_details') }}
|
||||
</button>
|
||||
</div>
|
||||
<div
|
||||
v-if="(item.reason_codes || []).length"
|
||||
class="mt-1 text-[11px] text-secondary"
|
||||
>
|
||||
{{ t('chat.shippingOrderExtractionHandling.reasonPrefix') }}
|
||||
{{ (item.reason_codes || []).slice(0, 4).map(handlingReasonLabel).join(';') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3 flex flex-wrap gap-1.5 text-[11px]">
|
||||
<span class="rounded-md bg-emerald-50 px-2 py-0.5 text-emerald-700 dark:bg-emerald-950/40 dark:text-emerald-200">
|
||||
{{ t('chat.shippingSessionSummary.completed', { count: processSummary.completed }) }}
|
||||
@@ -383,12 +540,6 @@ async function openEntrySurface(row: SummaryRow) {
|
||||
>
|
||||
{{ t('chat.shippingSessionSummary.needsHuman', { count: processSummary.needsHuman }) }}
|
||||
</span>
|
||||
<span
|
||||
v-if="processSummary.openExisting > 0"
|
||||
class="rounded-md bg-violet-50 px-2 py-0.5 text-violet-700 dark:bg-violet-950/40 dark:text-violet-200"
|
||||
>
|
||||
{{ t('chat.shippingSessionSummary.openExistingCount', { count: processSummary.openExisting }) }}
|
||||
</span>
|
||||
<span
|
||||
v-if="processSummary.failed > 0"
|
||||
class="rounded-md bg-rose-50 px-2 py-0.5 text-rose-700 dark:bg-rose-950/40 dark:text-rose-200"
|
||||
@@ -397,76 +548,173 @@ async function openEntrySurface(row: SummaryRow) {
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div v-if="!taskRows.length" class="text-xs text-muted">
|
||||
{{ docsLoading ? t('chat.shippingOrderExtractionDocumentsLoading') : t('chat.shippingSessionSummary.empty') }}
|
||||
<div v-if="!displayOpenItems.length && !closedItems.length" class="text-xs text-muted">
|
||||
{{ workItemsLoading
|
||||
? t('chat.shippingSessionWorkItem.loading')
|
||||
: t('chat.shippingSessionSummary.empty') }}
|
||||
</div>
|
||||
|
||||
<ul v-else class="space-y-2">
|
||||
<ul v-if="displayOpenItems.length" class="space-y-2" data-testid="shipping-session-open-items">
|
||||
<li
|
||||
v-for="row in taskRows"
|
||||
:key="row.key"
|
||||
v-for="item in displayOpenItems"
|
||||
:key="item.item_no"
|
||||
class="rounded-lg border border-default bg-surface-soft/80 px-2.5 py-2"
|
||||
:data-testid="`shipping-session-work-item-${item.item_no}`"
|
||||
>
|
||||
<div class="flex items-start justify-between gap-2">
|
||||
<div class="min-w-0">
|
||||
<div class="truncate text-xs font-semibold text-primary">
|
||||
{{ row.fileName || row.taskNo || t('chat.shippingSessionSummary.unnamedPdf') }}
|
||||
{{ item.current_document_filename || t('chat.shippingSessionSummary.unnamedPdf') }}
|
||||
</div>
|
||||
<div class="mt-0.5 text-[11px] text-muted">
|
||||
{{ t('chat.shippingSessionSummary.progressIndex', {
|
||||
current: row.index,
|
||||
total: row.total || processSummary.total || 1,
|
||||
}) }}
|
||||
<!-- 重复态任务号已在原因行「已有任务 SN-xxx」展示,序号行不再重复 -->
|
||||
<span
|
||||
v-if="row.taskNo && row.badge !== 'duplicate'"
|
||||
class="ml-1 font-mono"
|
||||
>{{ row.taskNo }}</span>
|
||||
{{ t('chat.shippingSessionWorkItem.versionLabel', { version: item.current_version_no }) }}
|
||||
</div>
|
||||
</div>
|
||||
<span
|
||||
v-if="row.badge === 'duplicate'"
|
||||
class="shrink-0 rounded-full bg-violet-100 px-1.5 py-0.5 text-[10px] font-medium text-violet-800 dark:bg-violet-900/50 dark:text-violet-100"
|
||||
class="shrink-0 rounded-full px-1.5 py-0.5 text-[10px] font-medium"
|
||||
:class="{
|
||||
'bg-amber-100 text-amber-800 dark:bg-amber-900/50 dark:text-amber-100':
|
||||
item.lifecycle_status === 'pending_review' || item.lifecycle_status === 'reparse_failed',
|
||||
'bg-sky-100 text-sky-800 dark:bg-sky-900/50 dark:text-sky-100':
|
||||
item.lifecycle_status === 'extracting',
|
||||
}"
|
||||
>
|
||||
{{ t('chat.shippingSessionSummary.duplicateBadge') }}
|
||||
</span>
|
||||
<span
|
||||
v-else-if="row.badge === 'exception'"
|
||||
class="shrink-0 rounded-full bg-amber-100 px-1.5 py-0.5 text-[10px] font-medium text-amber-800 dark:bg-amber-900/50 dark:text-amber-100"
|
||||
>
|
||||
{{ t('chat.shippingSessionSummary.exception') }}
|
||||
{{ lifecycleStatusLabel(String(item.lifecycle_status || '')) }}
|
||||
</span>
|
||||
</div>
|
||||
<div v-if="row.stage" class="mt-1 text-[11px] text-secondary">
|
||||
{{ row.stage }}
|
||||
<div v-if="item.version_replaced" class="mt-1 text-[11px] text-secondary">
|
||||
{{ t('chat.shippingSessionWorkItem.versionReplaced') }}
|
||||
</div>
|
||||
<div v-if="row.message" class="mt-0.5 line-clamp-3 text-[11px] text-muted">
|
||||
{{ row.message }}
|
||||
<div v-if="item.updated_at" class="mt-0.5 text-[11px] text-muted">
|
||||
{{ formatUpdatedLabel(item.updated_at) }}
|
||||
</div>
|
||||
<div class="mt-2 flex flex-wrap gap-2">
|
||||
<button
|
||||
v-if="row.entrySurface === 'review_workbench'"
|
||||
v-if="itemHasAction(item, 'enter_manual_review') && item.current_run_no"
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 text-[11px] font-medium text-brand-700 hover:underline"
|
||||
@click="openEntrySurface(row)"
|
||||
:disabled="actionBusyItemNo === item.item_no"
|
||||
data-testid="shipping-session-action-review"
|
||||
@click="openManualReview(item)"
|
||||
>
|
||||
<ExternalLink class="h-3 w-3" />
|
||||
{{ t('chat.shippingSessionSummary.openReview') }}
|
||||
{{ t('chat.shippingSessionWorkItem.enterManualReview') }}
|
||||
</button>
|
||||
<button
|
||||
v-else-if="row.entrySurface === 'task_workbench' && row.taskNo"
|
||||
v-if="itemHasAction(item, 'request_reparse') && item.current_case_no"
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 text-[11px] font-medium text-brand-700 hover:underline disabled:opacity-50"
|
||||
:disabled="actionBusyItemNo === item.item_no"
|
||||
data-testid="shipping-session-action-reparse"
|
||||
@click="reparseFromPanel(item)"
|
||||
>
|
||||
{{ t('chat.shippingSessionWorkItem.requestReparse') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="itemHasAction(item, 'mark_non_order') && item.current_case_no"
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 text-[11px] font-medium text-brand-700 hover:underline disabled:opacity-50"
|
||||
:disabled="actionBusyItemNo === item.item_no"
|
||||
data-testid="shipping-session-action-non-order"
|
||||
@click="markNonOrderFromPanel(item)"
|
||||
>
|
||||
{{ t('chat.shippingSessionWorkItem.markNonOrder') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="itemHasAction(item, 'replace_file') && item.current_run_no"
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 text-[11px] font-medium text-brand-700 hover:underline disabled:opacity-50"
|
||||
:disabled="actionBusyItemNo === item.item_no"
|
||||
data-testid="shipping-session-action-replace"
|
||||
@click="replaceFileFromPanel(item)"
|
||||
>
|
||||
{{ t('chat.shippingSessionWorkItem.replaceFile') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="itemHasAction(item, 'cancel')"
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 text-[11px] font-medium text-rose-700 hover:underline disabled:opacity-50"
|
||||
:disabled="actionBusyItemNo === item.item_no"
|
||||
data-testid="shipping-session-action-cancel"
|
||||
@click="cancelWorkItem(item)"
|
||||
>
|
||||
{{ t('chat.shippingSessionWorkItem.cancelProcessing') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="itemHasAction(item, 'view_version_history')"
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 text-[11px] font-medium text-brand-700 hover:underline"
|
||||
@click="openTaskWorkbench(row.taskNo)"
|
||||
data-testid="shipping-session-action-versions"
|
||||
@click="openVersionHistory(item)"
|
||||
>
|
||||
<ExternalLink class="h-3 w-3" />
|
||||
{{ row.kind === 'document'
|
||||
? t('chat.shippingSessionSummary.openExistingTask')
|
||||
: t('chat.shippingSessionSummary.openTask') }}
|
||||
{{ t('chat.shippingSessionWorkItem.viewVersionHistory') }}
|
||||
</button>
|
||||
</div>
|
||||
<div
|
||||
v-if="versionHistoryItemNo === item.item_no"
|
||||
class="mt-2 rounded-md border border-default bg-surface-muted/40 p-2"
|
||||
data-testid="shipping-session-version-history"
|
||||
>
|
||||
<div class="text-[11px] font-medium text-secondary">
|
||||
{{ t('chat.shippingSessionWorkItem.versionHistoryTitle') }}
|
||||
</div>
|
||||
<div v-if="versionHistoryLoading" class="mt-1 text-[11px] text-muted">
|
||||
{{ t('chat.shippingSessionWorkItem.loading') }}
|
||||
</div>
|
||||
<ul v-else-if="versionHistoryItems.length" class="mt-1 space-y-1">
|
||||
<li
|
||||
v-for="version in versionHistoryItems"
|
||||
:key="version.case_no"
|
||||
class="text-[11px] text-primary"
|
||||
>
|
||||
{{ version.version_label || version.case_no }}
|
||||
<span v-if="version.is_current" class="ml-1 text-brand-700">
|
||||
({{ t('chat.shippingSessionWorkItem.currentVersion') }})
|
||||
</span>
|
||||
<span v-else-if="version.is_readonly" class="ml-1 text-muted">
|
||||
({{ t('chat.shippingSessionWorkItem.readonlyVersion') }})
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
<div v-else class="mt-1 text-[11px] text-muted">
|
||||
{{ t('chat.shippingSessionWorkItem.noVersions') }}
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div
|
||||
v-if="closedItems.length"
|
||||
class="mt-3"
|
||||
data-testid="shipping-session-closed-section"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="flex w-full items-center justify-between gap-2 rounded-md border border-default bg-surface-muted/50 px-2 py-1.5 text-left text-[11px] font-medium text-secondary hover:bg-surface"
|
||||
@click="closedExpanded = !closedExpanded"
|
||||
>
|
||||
<span>{{ t('chat.shippingSessionWorkItem.completedCollapsed', { count: closedItems.length }) }}</span>
|
||||
<ChevronDown v-if="closedExpanded" class="h-3.5 w-3.5 shrink-0" />
|
||||
<ChevronRight v-else class="h-3.5 w-3.5 shrink-0" />
|
||||
</button>
|
||||
<ul v-if="closedExpanded" class="mt-2 space-y-2">
|
||||
<li
|
||||
v-for="item in closedItems"
|
||||
:key="`closed:${item.item_no}`"
|
||||
class="rounded-lg border border-default bg-surface-soft/60 px-2.5 py-2 opacity-80"
|
||||
>
|
||||
<div class="truncate text-xs font-semibold text-primary">
|
||||
{{ item.current_document_filename || t('chat.shippingSessionSummary.unnamedPdf') }}
|
||||
</div>
|
||||
<div class="mt-0.5 text-[11px] text-muted">
|
||||
{{ t('chat.shippingSessionWorkItem.versionLabel', { version: item.current_version_no }) }}
|
||||
<span v-if="item.closed_reason" class="ml-1">
|
||||
· {{ closedReasonLabel(item.closed_reason) }}
|
||||
</span>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
</template>
|
||||
@@ -126,6 +126,8 @@ const showActions = computed(() => (
|
||||
));
|
||||
const shippingOrderExtractionState = computed(() => message.shipping_order_extraction_state);
|
||||
const retryingOrderExtraction = ref(false);
|
||||
const refreshingOrderExtraction = ref(false);
|
||||
const cancellingOrderExtraction = ref(false);
|
||||
const shippingOrderExtractionRunNo = computed(() => {
|
||||
const payload = message.payload && typeof message.payload === 'object'
|
||||
? message.payload as Record<string, unknown>
|
||||
@@ -142,6 +144,26 @@ const retryShippingOrderExtraction = async () => {
|
||||
retryingOrderExtraction.value = false;
|
||||
}
|
||||
};
|
||||
/** 只读刷新 Run 投影,不改变后台业务状态。 */
|
||||
const refreshShippingOrderExtraction = async () => {
|
||||
if (!shippingOrderExtractionRunNo.value || refreshingOrderExtraction.value) return;
|
||||
refreshingOrderExtraction.value = true;
|
||||
try {
|
||||
await shippingHandlers.refreshOrderExtractionRun(shippingOrderExtractionRunNo.value);
|
||||
} finally {
|
||||
refreshingOrderExtraction.value = false;
|
||||
}
|
||||
};
|
||||
/** 请求取消整批;确认后走请求语义,不伪造即时终态。 */
|
||||
const cancelShippingOrderExtraction = async (reason?: string) => {
|
||||
if (!shippingOrderExtractionRunNo.value || cancellingOrderExtraction.value) return;
|
||||
cancellingOrderExtraction.value = true;
|
||||
try {
|
||||
await shippingHandlers.cancelOrderExtractionRun(shippingOrderExtractionRunNo.value, reason || null);
|
||||
} finally {
|
||||
cancellingOrderExtraction.value = false;
|
||||
}
|
||||
};
|
||||
const isLastMessage = computed(() => index === messageCount - 1 || (message.role === 'assistant' && isLatestAssistantMessage));
|
||||
const isCopied = computed(() => copiedIndex === index);
|
||||
const renderedMarkdown = computed(() => (
|
||||
@@ -668,7 +690,12 @@ function handleInlineDownload(file: InlineDownloadFile): void {
|
||||
v-if="shippingOrderExtractionState"
|
||||
:state="shippingOrderExtractionState"
|
||||
:run-no="shippingOrderExtractionRunNo"
|
||||
:retrying="retryingOrderExtraction"
|
||||
:refreshing="refreshingOrderExtraction"
|
||||
:cancelling="cancellingOrderExtraction"
|
||||
@retry="retryShippingOrderExtraction"
|
||||
@refresh="refreshShippingOrderExtraction"
|
||||
@cancel="cancelShippingOrderExtraction"
|
||||
/>
|
||||
<LeaveMessageBlock
|
||||
v-if="isLeaveMessage"
|
||||
|
||||
@@ -16,6 +16,9 @@ export interface ShippingMessageHandlers {
|
||||
addLine: (msg: ChatMessage, line: Partial<ShippingNoticeLine>) => Promise<boolean>;
|
||||
removeLine: (msg: ChatMessage, lineIndex: number) => Promise<boolean>;
|
||||
retryOrderExtractionRun: (runNo: string) => Promise<boolean>;
|
||||
refreshOrderExtractionRun: (runNo: string) => Promise<boolean>;
|
||||
cancelOrderExtractionRun: (runNo: string, reason?: string | null) => Promise<boolean>;
|
||||
cancelOrderExtractionUnit: (runNo: string, documentId: number, reason?: string | null) => Promise<boolean>;
|
||||
reparseOrderExtractionRun: (runNo: string, reason: 'rule_updated' | 'field_mapping_error' | 'document_quality' | 'other') => Promise<boolean>;
|
||||
resolveCandidateDuplicate: (candidateNo: string, action: import('../../types/shipping.types').ShippingDuplicateAction, targetTaskNo: string | undefined, reason: string | undefined, done: (success: boolean) => void) => Promise<void>;
|
||||
promoteCandidate: (candidateNo: string, done: (success: boolean) => void) => Promise<void>;
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
<!--
|
||||
features/chat/components/shipping-review/ReviewActionConfirmDialog.vue
|
||||
用途:复核页破坏性/不可逆操作的二次确认弹窗(确认建单、重识别、非订单、质量异常、替代 PDF)。
|
||||
依赖:vue-i18n、dialog-overlay / dialog-panel 设计系统样式。
|
||||
逻辑:ShippingOrderReviewView 以 v-model 控制显隐;质量异常须选原因码,other 时备注必填;
|
||||
非订单/重识别将说明写入 comment,并附带稳定 reasonCode。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
export type ReviewConfirmAction = 'confirm' | 'reparse' | 'non_order' | 'replace' | 'quality_issue';
|
||||
|
||||
/** 确认弹窗提交载荷:稳定原因码 + 自由说明,供后端审计复盘。 */
|
||||
export type ReviewConfirmPayload = {
|
||||
reasonCode: string;
|
||||
comment: string;
|
||||
};
|
||||
|
||||
const QUALITY_REASON_CODES = [
|
||||
'blurred',
|
||||
'incomplete_pages',
|
||||
'password_protected',
|
||||
'corrupted',
|
||||
'wrong_orientation',
|
||||
'unsupported_layout',
|
||||
'missing_order_table',
|
||||
'other',
|
||||
] as const;
|
||||
|
||||
interface Props {
|
||||
modelValue: boolean;
|
||||
action: ReviewConfirmAction;
|
||||
confirmLoading?: boolean;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
confirmLoading: false,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:modelValue', value: boolean): void;
|
||||
(e: 'confirm', payload: ReviewConfirmPayload): void;
|
||||
(e: 'cancel'): void;
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
const reasonCode = ref('other');
|
||||
const comment = ref('');
|
||||
const reasonMissing = ref(false);
|
||||
const commentMissing = ref(false);
|
||||
|
||||
/** 非订单 / 重识别 / 质量异常需要说明或原因选择。 */
|
||||
const needsDispositionInput = computed(
|
||||
() => props.action === 'non_order' || props.action === 'reparse' || props.action === 'quality_issue',
|
||||
);
|
||||
|
||||
const title = computed(() => t(`chat.shippingOrderReview.confirmDialog.${props.action}.title`));
|
||||
const impact = computed(() => t(`chat.shippingOrderReview.confirmDialog.${props.action}.impact`));
|
||||
const confirmText = computed(() => t(`chat.shippingOrderReview.confirmDialog.${props.action}.confirm`));
|
||||
const confirmTone = computed(() => (props.action === 'confirm' ? 'primary' : 'danger'));
|
||||
const confirmButtonClass = computed(() =>
|
||||
confirmTone.value === 'primary' ? 'btn-primary btn-sm' : 'btn-danger btn-sm',
|
||||
);
|
||||
|
||||
/**
|
||||
* 质量异常原因码的展示文案。
|
||||
* @param code - 后端允许的 quality reason 码
|
||||
*/
|
||||
const qualityReasonLabel = (code: string) =>
|
||||
t(`chat.shippingOrderReview.confirmDialog.qualityReasons.${code}`);
|
||||
|
||||
/** 关闭弹窗并同步 v-model。 */
|
||||
const closeDialog = () => {
|
||||
emit('update:modelValue', false);
|
||||
};
|
||||
|
||||
const handleCancel = () => {
|
||||
emit('cancel');
|
||||
closeDialog();
|
||||
};
|
||||
|
||||
/**
|
||||
* 按 action 组装原因码与备注后触发确认。
|
||||
* 核心逻辑:质量异常 `other` 强制备注;非订单/重识别使用稳定 reasonCode + 自由 comment。
|
||||
*/
|
||||
const handleConfirm = () => {
|
||||
reasonMissing.value = false;
|
||||
commentMissing.value = false;
|
||||
const trimmedComment = comment.value.trim();
|
||||
|
||||
if (props.action === 'quality_issue') {
|
||||
if (!reasonCode.value) {
|
||||
reasonMissing.value = true;
|
||||
return;
|
||||
}
|
||||
if (reasonCode.value === 'other' && !trimmedComment) {
|
||||
commentMissing.value = true;
|
||||
return;
|
||||
}
|
||||
emit('confirm', { reasonCode: reasonCode.value, comment: trimmedComment });
|
||||
closeDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
if (props.action === 'non_order' || props.action === 'reparse') {
|
||||
if (!trimmedComment) {
|
||||
commentMissing.value = true;
|
||||
return;
|
||||
}
|
||||
const code = props.action === 'non_order' ? 'non_order' : 'document_quality';
|
||||
emit('confirm', { reasonCode: code, comment: trimmedComment });
|
||||
closeDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
emit('confirm', { reasonCode: '', comment: '' });
|
||||
closeDialog();
|
||||
};
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(open) => {
|
||||
if (!open) {
|
||||
reasonCode.value = 'other';
|
||||
comment.value = '';
|
||||
reasonMissing.value = false;
|
||||
commentMissing.value = false;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
const onKeydown = (event: KeyboardEvent) => {
|
||||
if (event.key === 'Escape' && props.modelValue) handleCancel();
|
||||
};
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(open) => {
|
||||
if (typeof document === 'undefined') return;
|
||||
if (open) document.addEventListener('keydown', onKeydown);
|
||||
else document.removeEventListener('keydown', onKeydown);
|
||||
},
|
||||
);
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (typeof document !== 'undefined') document.removeEventListener('keydown', onKeydown);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Teleport to="body">
|
||||
<div
|
||||
v-if="modelValue"
|
||||
class="dialog-overlay z-50 flex items-center justify-center p-4"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
:aria-label="title"
|
||||
data-testid="review-action-confirm-dialog"
|
||||
@click.self="handleCancel"
|
||||
>
|
||||
<div class="dialog-panel w-full max-w-md space-y-4 p-5">
|
||||
<header>
|
||||
<h2 class="text-base font-semibold text-primary">{{ title }}</h2>
|
||||
<p class="mt-2 text-sm text-secondary">{{ impact }}</p>
|
||||
</header>
|
||||
|
||||
<template v-if="needsDispositionInput">
|
||||
<label v-if="action === 'quality_issue'" class="block space-y-1 text-sm">
|
||||
<span class="text-secondary">{{ t('chat.shippingOrderReview.confirmDialog.reasonCodeLabel') }}</span>
|
||||
<select
|
||||
v-model="reasonCode"
|
||||
class="select-field w-full text-sm"
|
||||
data-testid="review-action-reason-code"
|
||||
@change="reasonMissing = false"
|
||||
>
|
||||
<option v-for="code in QUALITY_REASON_CODES" :key="code" :value="code">
|
||||
{{ qualityReasonLabel(code) }}
|
||||
</option>
|
||||
</select>
|
||||
<p v-if="reasonMissing" class="text-xs text-rose-600 dark:text-rose-400">
|
||||
{{ t('chat.shippingOrderReview.confirmDialog.reasonCodeRequired') }}
|
||||
</p>
|
||||
</label>
|
||||
|
||||
<label class="block space-y-1 text-sm">
|
||||
<span class="text-secondary">{{ t('chat.shippingOrderReview.confirmDialog.reasonLabel') }}</span>
|
||||
<textarea
|
||||
v-model="comment"
|
||||
rows="3"
|
||||
class="input-field w-full resize-y text-sm"
|
||||
:placeholder="t('chat.shippingOrderReview.confirmDialog.reasonPlaceholder')"
|
||||
data-testid="review-action-reason"
|
||||
@input="commentMissing = false"
|
||||
/>
|
||||
<p v-if="commentMissing" class="text-xs text-rose-600 dark:text-rose-400">
|
||||
{{ t('chat.shippingOrderReview.confirmDialog.reasonRequired') }}
|
||||
</p>
|
||||
</label>
|
||||
</template>
|
||||
|
||||
<footer class="flex justify-end gap-2 pt-1">
|
||||
<button type="button" class="btn-secondary btn-sm" :disabled="confirmLoading" @click="handleCancel">
|
||||
{{ t('common.deleteDialog.cancel') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
:class="confirmButtonClass"
|
||||
:disabled="confirmLoading"
|
||||
data-testid="review-action-confirm-submit"
|
||||
@click="handleConfirm"
|
||||
>
|
||||
{{ confirmLoading ? t('chat.shippingOrderReview.saving') : confirmText }}
|
||||
</button>
|
||||
</footer>
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
</template>
|
||||
@@ -4,7 +4,7 @@
|
||||
逻辑:预览失败独立显示,不影响同页草稿编辑;缺少可靠 bbox 时只保留页码定位。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { nextTick, ref, watch } from 'vue';
|
||||
import { computed, nextTick, ref, watch } from 'vue';
|
||||
import * as pdfjs from 'pdfjs-dist';
|
||||
import workerUrl from 'pdfjs-dist/build/pdf.worker.min.mjs?url';
|
||||
import type { ShippingOrderReviewEvidence } from '../../types/shipping.api.types';
|
||||
@@ -21,6 +21,8 @@ const props = defineProps<{
|
||||
const canvas = ref<HTMLCanvasElement | null>(null);
|
||||
const loading = ref(false);
|
||||
const failed = ref(false);
|
||||
const scale = ref(1.5);
|
||||
const zoomLabel = computed(() => `${Math.round(scale.value * 100)}%`);
|
||||
|
||||
/** 将当前页渲染到 canvas;高亮以 PDF viewport 为基准,绝不猜测不可靠坐标。 */
|
||||
const render = async () => {
|
||||
@@ -31,7 +33,7 @@ const render = async () => {
|
||||
const document = await pdfjs.getDocument(props.src).promise;
|
||||
const pageNo = Math.min(Math.max(props.evidence?.page_no || 1, 1), document.numPages);
|
||||
const page = await document.getPage(pageNo);
|
||||
const viewport = page.getViewport({ scale: 1.4 });
|
||||
const viewport = page.getViewport({ scale: scale.value });
|
||||
await nextTick();
|
||||
if (!canvas.value) return;
|
||||
canvas.value.width = Math.ceil(viewport.width);
|
||||
@@ -60,14 +62,25 @@ const render = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
watch(() => [props.src, props.evidence?.evidence_id], () => { void render(); }, { immediate: true });
|
||||
const zoomIn = () => { scale.value = Math.min(scale.value + 0.25, 3); };
|
||||
const zoomOut = () => { scale.value = Math.max(scale.value - 0.25, 0.75); };
|
||||
const fitWidth = () => { scale.value = 1.75; };
|
||||
|
||||
watch(() => [props.src, props.evidence?.evidence_id, scale.value], () => { void render(); }, { immediate: true });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="relative flex min-h-[360px] items-center justify-center overflow-auto bg-slate-100 p-3 dark:bg-slate-950">
|
||||
<div class="relative flex min-h-[180px] flex-1 flex-col overflow-hidden bg-slate-100 xl:min-h-[360px] dark:bg-slate-950">
|
||||
<div class="flex shrink-0 items-center justify-end gap-1 border-b border-slate-200 bg-white/95 px-2 py-1.5 text-xs dark:border-slate-800 dark:bg-slate-900/95">
|
||||
<button type="button" class="rounded border px-2 py-1 hover:bg-slate-50 dark:border-slate-700 dark:hover:bg-slate-800" @click="zoomOut">−</button>
|
||||
<button type="button" class="min-w-12 rounded border px-2 py-1 hover:bg-slate-50 dark:border-slate-700 dark:hover:bg-slate-800" @click="fitWidth">{{ zoomLabel }}</button>
|
||||
<button type="button" class="rounded border px-2 py-1 hover:bg-slate-50 dark:border-slate-700 dark:hover:bg-slate-800" @click="zoomIn">+</button>
|
||||
</div>
|
||||
<div class="relative flex min-h-0 flex-1 items-start justify-center overflow-auto p-4">
|
||||
<!-- Keep the canvas mounted while PDF.js is loading; otherwise nextTick cannot obtain a render target. -->
|
||||
<canvas ref="canvas" :aria-label="title" class="max-w-full bg-white shadow" :class="{ invisible: loading || failed }" />
|
||||
<canvas ref="canvas" :aria-label="title" class="bg-white shadow" :class="{ invisible: loading || failed }" />
|
||||
<span v-if="loading" class="absolute text-sm text-slate-500">{{ loadingText }}</span>
|
||||
<span v-else-if="failed" class="absolute text-sm text-rose-600">{{ unavailableText }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,135 @@
|
||||
<!--
|
||||
features/chat/components/shipping-review/ReviewVersionHistoryPanel.vue
|
||||
用途:复核页工作项版本历史时间线;支持只读跳转至历史 Case。
|
||||
依赖:vue-i18n、ShippingSessionWorkItemVersion 类型。
|
||||
逻辑:ShippingOrderReviewView 传入 versions;emit select 供父级切换 case_no。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import type { ShippingSessionWorkItemVersion } from '@/features/chat/types/shipping.api.types';
|
||||
|
||||
const props = defineProps<{
|
||||
itemNo?: string | null;
|
||||
versions: ShippingSessionWorkItemVersion[];
|
||||
loading?: boolean;
|
||||
activeCaseNo?: string | null;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'select', caseNo: string, readonly: boolean): void;
|
||||
}>();
|
||||
|
||||
const { t, te } = useI18n();
|
||||
|
||||
/**
|
||||
* 解析 Case 状态为结果文案。
|
||||
*/
|
||||
function resultLabel(status?: string | null): string {
|
||||
const normalized = String(status || '').trim();
|
||||
if (!normalized) return '—';
|
||||
const key = `chat.shippingOrderReview.caseStatuses.${normalized}`;
|
||||
return te(key) ? t(key) : normalized;
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化时间戳为本地化短日期时间。
|
||||
*/
|
||||
function formatTime(value?: string | null): string {
|
||||
const date = new Date(String(value || ''));
|
||||
if (Number.isNaN(date.getTime())) return '—';
|
||||
return date.toLocaleString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转至指定版本;历史版本以只读模式打开。
|
||||
*/
|
||||
function selectVersion(version: ShippingSessionWorkItemVersion) {
|
||||
const caseNo = String(version.case_no || '').trim();
|
||||
if (!caseNo) return;
|
||||
emit('select', caseNo, Boolean(version.is_readonly));
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section
|
||||
class="rounded-xl border border-slate-200 bg-white p-4 shadow-sm dark:border-slate-800 dark:bg-slate-900"
|
||||
data-testid="review-version-history-panel"
|
||||
:aria-label="t('chat.shippingOrderReview.versionHistory.title')"
|
||||
>
|
||||
<header class="mb-3 flex items-center justify-between gap-2">
|
||||
<div>
|
||||
<h2 class="text-sm font-semibold">{{ t('chat.shippingOrderReview.versionHistory.title') }}</h2>
|
||||
<p v-if="itemNo" class="mt-0.5 text-xs text-slate-500 dark:text-slate-400">
|
||||
{{ t('chat.shippingOrderReview.versionHistory.itemNo', { itemNo }) }}
|
||||
</p>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div v-if="loading" class="py-4 text-sm text-slate-500">{{ t('chat.shippingSessionWorkItem.loading') }}</div>
|
||||
<p v-else-if="!versions.length" class="py-4 text-sm text-slate-500">
|
||||
{{ t('chat.shippingSessionWorkItem.noVersions') }}
|
||||
</p>
|
||||
|
||||
<ol v-else class="space-y-2">
|
||||
<li
|
||||
v-for="version in versions"
|
||||
:key="version.case_no"
|
||||
class="rounded-lg border p-3 text-sm"
|
||||
:class="activeCaseNo === version.case_no
|
||||
? 'border-sky-500 bg-sky-50 dark:border-sky-700 dark:bg-sky-950/30'
|
||||
: 'border-slate-200 dark:border-slate-700'"
|
||||
:data-testid="`review-version-row-${version.case_no}`"
|
||||
>
|
||||
<div class="flex flex-wrap items-start justify-between gap-2">
|
||||
<div class="min-w-0">
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<span class="font-medium">
|
||||
{{ version.version_label || t('chat.shippingSessionWorkItem.versionLabel', { version: '?' }) }}
|
||||
</span>
|
||||
<span
|
||||
v-if="version.is_current"
|
||||
class="rounded-full bg-emerald-100 px-2 py-0.5 text-[11px] text-emerald-800 dark:bg-emerald-950 dark:text-emerald-100"
|
||||
>
|
||||
{{ t('chat.shippingSessionWorkItem.currentVersion') }}
|
||||
</span>
|
||||
<span
|
||||
v-else-if="version.is_readonly"
|
||||
class="rounded-full bg-slate-100 px-2 py-0.5 text-[11px] text-slate-600 dark:bg-slate-800 dark:text-slate-300"
|
||||
>
|
||||
{{ t('chat.shippingSessionWorkItem.readonlyVersion') }}
|
||||
</span>
|
||||
</div>
|
||||
<p class="mt-1 truncate text-xs text-slate-500 dark:text-slate-400">
|
||||
{{ version.document_filename || version.case_no }}
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
v-if="activeCaseNo !== version.case_no"
|
||||
type="button"
|
||||
class="shrink-0 rounded border border-slate-200 px-2 py-1 text-xs hover:bg-slate-50 dark:border-slate-700 dark:hover:bg-slate-800"
|
||||
@click="selectVersion(version)"
|
||||
>
|
||||
{{ version.is_readonly
|
||||
? t('chat.shippingOrderReview.versionHistory.viewReadonly')
|
||||
: t('chat.shippingOrderReview.versionHistory.open') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<dl class="mt-2 grid gap-1 text-xs text-slate-600 dark:text-slate-400 sm:grid-cols-2">
|
||||
<div>
|
||||
<dt class="inline">{{ t('chat.shippingOrderReview.versionHistory.result') }}:</dt>
|
||||
<dd class="inline">{{ resultLabel(version.case_status) }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt class="inline">{{ t('chat.shippingOrderReview.versionHistory.createdAt') }}:</dt>
|
||||
<dd class="inline">{{ formatTime(version.created_at) }}</dd>
|
||||
</div>
|
||||
<div v-if="version.confirmed_at">
|
||||
<dt class="inline">{{ t('chat.shippingOrderReview.versionHistory.confirmedAt') }}:</dt>
|
||||
<dd class="inline">{{ formatTime(version.confirmed_at) }}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</li>
|
||||
</ol>
|
||||
</section>
|
||||
</template>
|
||||
@@ -3,7 +3,7 @@
|
||||
* features/chat/components/shipping/ShippingOrderDocumentResultItem.vue
|
||||
* 用途:渲染单个 PDF 的订单抽取结果摘要,供详情抽屉按文档逐项展示。
|
||||
* 依赖:订单抽取文档 DTO、vue-i18n。
|
||||
* 逻辑:只显示用户可理解的业务字段;人工复核由上层统一跳转独立工作台。
|
||||
* 逻辑:只显示用户可理解的业务字段;reason_code 优先 i18n,缺失时对 SHIPPING_NOTICE.* 回退通用提示;人工复核由上层统一跳转。
|
||||
*/
|
||||
import { computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
@@ -52,11 +52,16 @@ const activityTimeLabel = computed(() => {
|
||||
if (props.document.started_at) return t('chat.shippingOrderExtractionDocumentTiming.started', { time: formatTime(props.document.started_at) });
|
||||
return '';
|
||||
});
|
||||
const reasonLabel = computed(() => (
|
||||
props.document.reason_code
|
||||
? t(`chat.shippingOrderExtractionReason.${props.document.reason_code}`)
|
||||
: ''
|
||||
));
|
||||
const reasonLabel = computed(() => {
|
||||
const code = String(props.document.reason_code || '').trim();
|
||||
if (!code) return '';
|
||||
const key = `chat.shippingOrderExtractionReason.${code}`;
|
||||
if (te(key)) return t(key);
|
||||
if (code.startsWith('SHIPPING_NOTICE.')) {
|
||||
return t('chat.shippingOrderExtractionTechnicalFailureUserHint');
|
||||
}
|
||||
return code;
|
||||
});
|
||||
const emailSupplementLabel = computed(() => {
|
||||
const status = props.document.email_supplement?.status || 'none';
|
||||
const key = `chat.shippingOrderExtractionEmailSupplement.${status}`;
|
||||
|
||||
+139
-14
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* features/chat/components/shipping/ShippingOrderExtractionCard.spec.ts
|
||||
* 用途:覆盖聊天主区一句过程通知卡(无逐 PDF 列表、无复核按钮、无重复统计)。
|
||||
* 用途:覆盖批次进度卡摘要、阶段、健康提醒与刷新/取消/重试动作。
|
||||
* 依赖:Vitest、Vue Test Utils、vue-i18n、本域组件与 DTO 类型。
|
||||
* 逻辑:断言 processNotice 文案与技术失败重试;复核深链由右侧摘要面板承担。
|
||||
* 逻辑:断言过程通知、摘要计数、取消确认与重试;逐 PDF 深链仍由右侧面板承担。
|
||||
*/
|
||||
import { mount } from '@vue/test-utils';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
@@ -29,15 +29,19 @@ const buildState = (patch: Partial<ShippingOrderExtractionState> = {}): Shipping
|
||||
processingDocuments: 1,
|
||||
completedDocuments: 1,
|
||||
reviewRequiredDocuments: 1,
|
||||
failedDocuments: 1,
|
||||
failedDocuments: 0,
|
||||
cancelledDocuments: 0,
|
||||
candidateCount: 2,
|
||||
},
|
||||
currentActivity: {
|
||||
unitId: 12,
|
||||
fileName: 'PO-450003.pdf',
|
||||
eventCode: 'profile_matching',
|
||||
eventCode: 'extracting',
|
||||
userVisibleStage: 'extracting',
|
||||
elapsedSeconds: 75,
|
||||
},
|
||||
availableActions: [],
|
||||
availableActions: ['refresh_status', 'cancel_run'],
|
||||
healthTips: [{ code: 'processing_slow', thresholdSeconds: 60, idleOrElapsedSeconds: 90 }],
|
||||
terminal: false,
|
||||
refreshFailed: false,
|
||||
errorCode: null,
|
||||
@@ -47,15 +51,16 @@ const buildState = (patch: Partial<ShippingOrderExtractionState> = {}): Shipping
|
||||
});
|
||||
|
||||
describe('ShippingOrderExtractionCard', () => {
|
||||
it('renders one-line process notice without per-PDF list, review CTA, or count stats', () => {
|
||||
it('renders batch summary, current stage, health tip and action buttons', () => {
|
||||
const wrapper = mount(ShippingOrderExtractionCard, {
|
||||
props: { state: buildState(), runNo: 'SNER-1' },
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
expect(wrapper.text()).toContain('正在处理附件');
|
||||
expect(wrapper.text()).toContain('右侧');
|
||||
expect(wrapper.text()).not.toContain('自动推进');
|
||||
expect(wrapper.text()).not.toContain('进入人工复核');
|
||||
expect(wrapper.text()).toContain('PO-450003.pdf');
|
||||
expect(wrapper.text()).toContain('提取订单字段中');
|
||||
expect(wrapper.text()).toContain('处理时间偏长');
|
||||
expect(wrapper.text()).toContain('刷新状态');
|
||||
expect(wrapper.text()).toContain('取消本次识别');
|
||||
expect(wrapper.findAll('[data-testid="shipping-order-document-result"]').length).toBe(0);
|
||||
});
|
||||
|
||||
@@ -75,6 +80,8 @@ describe('ShippingOrderExtractionCard', () => {
|
||||
openedExistingCount: 2,
|
||||
},
|
||||
availableActions: ['view_details'],
|
||||
healthTips: [],
|
||||
currentActivity: null,
|
||||
}),
|
||||
runNo: 'SNER-DUP',
|
||||
},
|
||||
@@ -85,7 +92,123 @@ describe('ShippingOrderExtractionCard', () => {
|
||||
expect(wrapper.text()).not.toContain('需人工处理');
|
||||
});
|
||||
|
||||
it('emits retry for failed attachments only', async () => {
|
||||
it('does not label generated candidates as manual-review exceptions', () => {
|
||||
const wrapper = mount(ShippingOrderExtractionCard, {
|
||||
props: {
|
||||
state: buildState({
|
||||
status: 'review_required',
|
||||
summary: {
|
||||
totalDocuments: 2,
|
||||
pendingDocuments: 0,
|
||||
processingDocuments: 0,
|
||||
completedDocuments: 2,
|
||||
reviewRequiredDocuments: 0,
|
||||
failedDocuments: 0,
|
||||
candidateCount: 2,
|
||||
},
|
||||
availableActions: ['view_details', 'review_candidate'],
|
||||
primaryNotice: 'candidate_confirmation',
|
||||
handlingItems: [{
|
||||
category: 'candidate_confirmation',
|
||||
count: 2,
|
||||
reasonCodes: [],
|
||||
affectedRefs: [],
|
||||
primaryAction: 'review_candidate',
|
||||
}],
|
||||
healthTips: [],
|
||||
currentActivity: null,
|
||||
}),
|
||||
runNo: 'SNER-CANDIDATES',
|
||||
},
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
stubs: { 'router-link': true },
|
||||
},
|
||||
});
|
||||
// 关键断言:成功候选可待人工确认,但绝不能提示为识别异常。
|
||||
expect(wrapper.text()).toContain('订单候选已生成');
|
||||
expect(wrapper.text()).toContain('候选待人工确认');
|
||||
expect(wrapper.text()).not.toContain('部分附件需人工处理');
|
||||
});
|
||||
|
||||
it('renders mixed handling items with reasons instead of a vague needs-action notice', () => {
|
||||
const wrapper = mount(ShippingOrderExtractionCard, {
|
||||
props: {
|
||||
state: buildState({
|
||||
status: 'partially_completed',
|
||||
summary: {
|
||||
totalDocuments: 3,
|
||||
pendingDocuments: 0,
|
||||
processingDocuments: 0,
|
||||
completedDocuments: 1,
|
||||
reviewRequiredDocuments: 1,
|
||||
failedDocuments: 1,
|
||||
candidateCount: 1,
|
||||
},
|
||||
availableActions: ['enter_manual_review', 'retry_failed_attachments', 'view_details'],
|
||||
primaryNotice: 'technical_failure',
|
||||
handlingItems: [
|
||||
{
|
||||
category: 'technical_failure',
|
||||
count: 1,
|
||||
reasonCodes: ['document_unreadable'],
|
||||
affectedRefs: [],
|
||||
primaryAction: 'retry_failed_attachments',
|
||||
},
|
||||
{
|
||||
category: 'candidate_missing_info',
|
||||
count: 1,
|
||||
reasonCodes: ['required_field_missing'],
|
||||
affectedRefs: [],
|
||||
primaryAction: 'review_candidate',
|
||||
},
|
||||
{
|
||||
category: 'auto_freeze_blocked',
|
||||
count: 1,
|
||||
reasonCodes: ['profile_manual_confirmation_required'],
|
||||
affectedRefs: [{ type: 'task', task_no: 'ST-88', candidate_no: 'C-9' }],
|
||||
primaryAction: 'view_details',
|
||||
},
|
||||
],
|
||||
healthTips: [],
|
||||
currentActivity: null,
|
||||
terminal: true,
|
||||
}),
|
||||
runNo: 'SNER-MIXED',
|
||||
},
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
expect(wrapper.text()).toContain('部分附件处理失败');
|
||||
expect(wrapper.text()).toContain('订单待补信息');
|
||||
expect(wrapper.text()).toContain('自动冻结受阻');
|
||||
expect(wrapper.text()).toContain('文件损坏、加密或无法读取');
|
||||
expect(wrapper.text()).toContain('影响对象:');
|
||||
expect(wrapper.text()).toContain('ST-88');
|
||||
expect(wrapper.findAll('[data-testid="shipping-order-extraction-handling-item"]').length).toBe(3);
|
||||
});
|
||||
|
||||
it('emits cancel after confirmation', async () => {
|
||||
const wrapper = mount(ShippingOrderExtractionCard, {
|
||||
props: {
|
||||
state: buildState({
|
||||
availableActions: ['cancel_run', 'refresh_status'],
|
||||
}),
|
||||
runNo: 'SNER-1',
|
||||
},
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
const cancelBtn = wrapper.findAll('button').find((b) => b.text().includes('取消本次识别'));
|
||||
expect(cancelBtn).toBeTruthy();
|
||||
await cancelBtn!.trigger('click');
|
||||
expect(wrapper.text()).toContain('确认取消本次识别');
|
||||
const textarea = wrapper.find('textarea');
|
||||
await textarea.setValue('不再需要识别');
|
||||
const confirmBtn = wrapper.findAll('button').find((b) => b.text() === '取消本次识别');
|
||||
await confirmBtn!.trigger('click');
|
||||
expect(wrapper.emitted('cancel')?.[0]).toEqual(['不再需要识别']);
|
||||
});
|
||||
|
||||
it('emits retry for failed attachments', async () => {
|
||||
const wrapper = mount(ShippingOrderExtractionCard, {
|
||||
props: {
|
||||
state: buildState({
|
||||
@@ -99,12 +222,14 @@ describe('ShippingOrderExtractionCard', () => {
|
||||
failedDocuments: 1,
|
||||
candidateCount: 0,
|
||||
},
|
||||
healthTips: [],
|
||||
}),
|
||||
runNo: 'SNER-2',
|
||||
runNo: 'SNER-1',
|
||||
},
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
await wrapper.get('button').trigger('click');
|
||||
expect(wrapper.emitted('retry')).toBeTruthy();
|
||||
const retryBtn = wrapper.findAll('button').find((b) => b.text().includes('重试失败附件'));
|
||||
await retryBtn!.trigger('click');
|
||||
expect(wrapper.emitted('retry')?.length).toBe(1);
|
||||
});
|
||||
});
|
||||
@@ -1,30 +1,55 @@
|
||||
/**
|
||||
* features/chat/components/shipping/ShippingOrderExtractionCard.vue
|
||||
* 用途:聊天主区一句过程通知——不重复右侧统计,无逐 PDF 列表、无复核按钮。
|
||||
* 依赖:订单抽取 Run 状态卡 DTO、vue-i18n。
|
||||
* 逻辑:右侧 ShippingSessionSummaryPanel 为唯一状态与跳转面;纯 open_existing 时用重复关联文案。
|
||||
* 用途:聊天主区批次进度卡——摘要计数、Run 级处理事项、当前文件阶段、健康提醒与动作。
|
||||
* 依赖:订单抽取 Run 状态卡 DTO、orderExtractionProgressDisplay、vue-router、vue-i18n。
|
||||
* 逻辑:事实一律来自后端 handling_items / primary_notice;右侧 ShippingSessionSummaryPanel 承接逐 PDF 明细。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { computed, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { CircleCheck, CircleX, LoaderCircle, TriangleAlert } from 'lucide-vue-next';
|
||||
import type { ShippingOrderExtractionState } from '../../types/chat.types';
|
||||
import type {
|
||||
ShippingOrderExtractionHandlingItemState,
|
||||
ShippingOrderExtractionState,
|
||||
} from '../../types/chat.types';
|
||||
import {
|
||||
formatOrderExtractionElapsed,
|
||||
resolveOrderExtractionUserStageKey,
|
||||
} from '../../shipping/orderExtractionProgressDisplay';
|
||||
import {
|
||||
listDisplayableHandlingAffectedRefs,
|
||||
type ShippingHandlingAffectedRef,
|
||||
type ShippingHandlingRefTarget,
|
||||
} from '../../shipping/orderExtractionHandlingRefs';
|
||||
|
||||
const props = defineProps<{
|
||||
state: ShippingOrderExtractionState;
|
||||
runNo?: string;
|
||||
retrying?: boolean;
|
||||
refreshing?: boolean;
|
||||
cancelling?: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
retry: [];
|
||||
refresh: [];
|
||||
cancel: [reason?: string];
|
||||
}>();
|
||||
|
||||
const { t, te } = useI18n();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const confirmCancelOpen = ref(false);
|
||||
const cancelReason = ref('');
|
||||
|
||||
const handlingItems = computed(() => props.state.handlingItems || []);
|
||||
|
||||
/**
|
||||
* 是否为「仅重复关联已有任务、无需人工复核」终态通知。
|
||||
*/
|
||||
const isDuplicateOnlyNotice = computed(() => {
|
||||
if (handlingItems.value.length > 0) return false;
|
||||
const opened = Math.max(0, Number(props.state.summary.openedExistingCount || 0));
|
||||
if (opened <= 0) return false;
|
||||
const review = Math.max(0, Number(props.state.summary.reviewRequiredDocuments || 0));
|
||||
@@ -32,10 +57,25 @@ const isDuplicateOnlyNotice = computed(() => {
|
||||
return review === 0 && failed === 0;
|
||||
});
|
||||
|
||||
/**
|
||||
* 是否为纯候选确认场景;优先信任后端 primary_notice,避免用摘要计数掩盖混合原因。
|
||||
*/
|
||||
const isCandidateConfirmationNotice = computed(() => (
|
||||
props.state.primaryNotice === 'candidate_confirmation'
|
||||
|| (
|
||||
!props.state.primaryNotice
|
||||
&& handlingItems.value.length === 1
|
||||
&& handlingItems.value[0]?.category === 'candidate_confirmation'
|
||||
)
|
||||
));
|
||||
|
||||
const toneClass = computed(() => {
|
||||
if (isDuplicateOnlyNotice.value) {
|
||||
return 'border-violet-200 bg-violet-50/80 text-violet-950 dark:border-violet-800 dark:bg-violet-950/35 dark:text-violet-100';
|
||||
}
|
||||
if (isCandidateConfirmationNotice.value) {
|
||||
return 'border-teal-200 bg-teal-50/80 text-teal-950 dark:border-teal-800 dark:bg-teal-950/35 dark:text-teal-100';
|
||||
}
|
||||
switch (props.state.status) {
|
||||
case 'completed':
|
||||
return 'border-emerald-200 bg-emerald-50/80 text-emerald-950 dark:border-emerald-800 dark:bg-emerald-950/35 dark:text-emerald-100';
|
||||
@@ -50,13 +90,42 @@ const toneClass = computed(() => {
|
||||
}
|
||||
});
|
||||
|
||||
const stageLabel = computed(() => {
|
||||
const key = resolveOrderExtractionUserStageKey(
|
||||
props.state.currentActivity?.userVisibleStage || props.state.userVisibleStage,
|
||||
props.state.currentActivity?.eventCode || props.state.status,
|
||||
);
|
||||
return te(key) ? t(key) : '';
|
||||
});
|
||||
|
||||
const elapsedLabel = computed(() =>
|
||||
formatOrderExtractionElapsed(props.state.currentActivity?.elapsedSeconds),
|
||||
);
|
||||
|
||||
/**
|
||||
* 一句过程通知;纯重复关联不误报「需人工处理」。
|
||||
* 将处理事项类别映射为一句过程通知文案。
|
||||
* @param category - 后端 primary_notice / handling item category
|
||||
*/
|
||||
function noticeForCategory(category: string): string {
|
||||
const key = `chat.shippingOrderExtractionHandling.primaryNotice.${category}`;
|
||||
return te(key) ? t(key) : t('chat.shippingSessionSummary.processNoticeNeedsAction');
|
||||
}
|
||||
|
||||
/**
|
||||
* 一句过程通知;有 handling_items 时以后端类别为准,不再笼统写「需人工处理」。
|
||||
*/
|
||||
const compactLine = computed(() => {
|
||||
if (props.state.cancellation?.requested && !props.state.cancellation?.completedAt && !props.state.terminal) {
|
||||
return t('chat.shippingOrderExtractionUserStage.cancellation_requested');
|
||||
}
|
||||
if (isDuplicateOnlyNotice.value) {
|
||||
return t('chat.shippingSessionSummary.processNoticeDuplicateLinked');
|
||||
}
|
||||
const notice = String(props.state.primaryNotice || '').trim();
|
||||
if (notice) return noticeForCategory(notice);
|
||||
if (handlingItems.value[0]?.category) {
|
||||
return noticeForCategory(handlingItems.value[0].category);
|
||||
}
|
||||
switch (props.state.status) {
|
||||
case 'completed':
|
||||
return t('chat.shippingSessionSummary.processNoticeCompleted');
|
||||
@@ -66,8 +135,23 @@ const compactLine = computed(() => {
|
||||
case 'failed':
|
||||
case 'cancelled':
|
||||
return t('chat.shippingSessionSummary.processNoticeFailed');
|
||||
default:
|
||||
default: {
|
||||
if (props.state.status === 'queued' || props.state.status === 'processing') {
|
||||
const parts: string[] = [];
|
||||
const fileName = String(props.state.currentActivity?.fileName || '').trim();
|
||||
if (fileName) {
|
||||
parts.push(t('chat.shippingOrderExtractionCurrentFile', {
|
||||
fileName: fileName || t('chat.shippingOrderExtractionUnknownDocument'),
|
||||
}));
|
||||
}
|
||||
const stage = stageLabel.value;
|
||||
if (stage) parts.push(stage);
|
||||
const elapsed = elapsedLabel.value;
|
||||
if (elapsed) parts.push(t('chat.shippingOrderExtractionElapsed', { elapsed }));
|
||||
if (parts.length) return parts.join(' · ');
|
||||
}
|
||||
return t('chat.shippingSessionSummary.processNoticeProcessing');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -81,6 +165,133 @@ const showRetry = computed(() => (
|
||||
props.state.availableActions.includes('retry_failed_attachments')
|
||||
|| props.state.summary.failedDocuments > 0
|
||||
));
|
||||
const showRefresh = computed(() => props.state.availableActions.includes('refresh_status'));
|
||||
const showCancel = computed(() => (
|
||||
props.state.availableActions.includes('cancel_run')
|
||||
&& !(props.state.cancellation?.requested && !props.state.cancellation?.completedAt)
|
||||
));
|
||||
const healthTips = computed(() => props.state.healthTips || []);
|
||||
|
||||
/**
|
||||
* 解析处理事项标题。
|
||||
* @param item - 后端 handling item
|
||||
*/
|
||||
function handlingTitle(item: ShippingOrderExtractionHandlingItemState): string {
|
||||
const key = `chat.shippingOrderExtractionHandling.category.${item.category}`;
|
||||
return te(key) ? t(key) : item.category;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析原因码文案;未知码回退为原文。
|
||||
* @param code - 原因码
|
||||
*/
|
||||
function reasonLabel(code: string): string {
|
||||
const key = `chat.shippingOrderExtractionReason.${code}`;
|
||||
if (te(key)) return t(key);
|
||||
const freezeKey = `chat.shippingOrderExtractionHandling.reason.${code}`;
|
||||
return te(freezeKey) ? t(freezeKey) : code;
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开订单复核工作台(Chat order-review 模式)。
|
||||
* @param options.documentId - 可选,定位到具体 PDF(由右侧 case 映射承接时仍打开 Run 复核)
|
||||
* @param options.candidateNo - 可选,写入 query 供复核页筛选
|
||||
*/
|
||||
async function openOrderReview(options?: { documentId?: number; candidateNo?: string }) {
|
||||
const runNo = String(props.runNo || '').trim();
|
||||
if (!runNo) return;
|
||||
const query: Record<string, string> = {
|
||||
...Object.fromEntries(
|
||||
Object.entries(route.query).filter(([, v]) => typeof v === 'string') as Array<[string, string]>,
|
||||
),
|
||||
mode: 'order-review',
|
||||
run_no: runNo,
|
||||
};
|
||||
const candidateNo = String(options?.candidateNo || '').trim();
|
||||
if (candidateNo) query.candidate = candidateNo;
|
||||
const documentId = Number(options?.documentId || 0);
|
||||
if (documentId > 0) query.document_id = String(documentId);
|
||||
await router.push({
|
||||
name: 'Chat',
|
||||
params: { agentId: String(route.params.agentId || '') },
|
||||
query,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开任务工作台,定位自动冻结受阻等任务号。
|
||||
*/
|
||||
async function openTaskWorkbench(taskNo: string) {
|
||||
const normalized = String(taskNo || '').trim();
|
||||
if (!normalized) return;
|
||||
await router.push({
|
||||
name: 'workspace-shipping-tasks',
|
||||
params: { taskNo: normalized },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 按受影响对象引用跳转到任务或复核入口。
|
||||
*/
|
||||
async function openAffectedRef(target: ShippingHandlingRefTarget) {
|
||||
if (target.kind === 'task') {
|
||||
await openTaskWorkbench(target.taskNo);
|
||||
return;
|
||||
}
|
||||
if (target.kind === 'review') {
|
||||
await openOrderReview({
|
||||
documentId: target.documentId,
|
||||
candidateNo: target.candidateNo,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 列出事项下可展示的受影响对象。
|
||||
*/
|
||||
function affectedRows(item: ShippingOrderExtractionHandlingItemState) {
|
||||
return listDisplayableHandlingAffectedRefs(item.affectedRefs as ShippingHandlingAffectedRef[]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按处理事项主动作跳转或触发重试;优先跳到首个受影响对象。
|
||||
* @param item - 处理事项
|
||||
*/
|
||||
async function handleHandlingAction(item: ShippingOrderExtractionHandlingItemState) {
|
||||
const action = String(item.primaryAction || '').trim();
|
||||
if (action === 'retry_failed_attachments') {
|
||||
emit('retry');
|
||||
return;
|
||||
}
|
||||
const first = affectedRows(item)[0];
|
||||
if (first && first.target.kind !== 'none') {
|
||||
await openAffectedRef(first.target);
|
||||
return;
|
||||
}
|
||||
if (
|
||||
action === 'enter_manual_review'
|
||||
|| action === 'review_candidate'
|
||||
|| action === 'view_details'
|
||||
) {
|
||||
await openOrderReview();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认后发出取消事件;取消是请求语义,由后端检查点生效。
|
||||
*/
|
||||
function confirmCancel() {
|
||||
confirmCancelOpen.value = false;
|
||||
const reason = String(cancelReason.value || '').trim();
|
||||
cancelReason.value = '';
|
||||
emit('cancel', reason || undefined);
|
||||
}
|
||||
|
||||
/** 打开取消确认并清空上次填写的原因。 */
|
||||
function openCancelConfirm() {
|
||||
cancelReason.value = '';
|
||||
confirmCancelOpen.value = true;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -95,7 +306,7 @@ const showRetry = computed(() => (
|
||||
class="mt-0.5 h-4 w-4 shrink-0 animate-spin"
|
||||
/>
|
||||
<CircleCheck
|
||||
v-else-if="state.status === 'completed' || isDuplicateOnlyNotice"
|
||||
v-else-if="state.status === 'completed' || isDuplicateOnlyNotice || isCandidateConfirmationNotice"
|
||||
class="mt-0.5 h-4 w-4 shrink-0"
|
||||
/>
|
||||
<TriangleAlert
|
||||
@@ -106,23 +317,175 @@ const showRetry = computed(() => (
|
||||
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="text-sm font-medium">{{ compactLine }}</div>
|
||||
|
||||
<div
|
||||
v-if="state.summary.totalDocuments > 0"
|
||||
class="mt-1.5 flex flex-wrap gap-1.5 text-[11px] opacity-90"
|
||||
data-testid="shipping-order-extraction-summary"
|
||||
>
|
||||
<span>{{ t('chat.shippingOrderExtractionSummary.total', { count: state.summary.totalDocuments }) }}</span>
|
||||
<span v-if="state.summary.processingDocuments > 0">
|
||||
{{ t('chat.shippingOrderExtractionSummary.processing', { count: state.summary.processingDocuments }) }}
|
||||
</span>
|
||||
<span v-if="state.summary.pendingDocuments > 0">
|
||||
{{ t('chat.shippingOrderExtractionSummary.pending', { count: state.summary.pendingDocuments }) }}
|
||||
</span>
|
||||
<span v-if="state.summary.completedDocuments > 0">
|
||||
{{ t('chat.shippingOrderExtractionSummary.completed', { count: state.summary.completedDocuments }) }}
|
||||
</span>
|
||||
<span v-if="state.summary.reviewRequiredDocuments > 0">
|
||||
{{ t('chat.shippingOrderExtractionSummary.reviewRequired', { count: state.summary.reviewRequiredDocuments }) }}
|
||||
</span>
|
||||
<span v-if="state.summary.failedDocuments > 0">
|
||||
{{ t('chat.shippingOrderExtractionSummary.failed', { count: state.summary.failedDocuments }) }}
|
||||
</span>
|
||||
<span v-if="(state.summary.cancelledDocuments || 0) > 0">
|
||||
{{ t('chat.shippingOrderExtractionSummary.cancelled', { count: state.summary.cancelledDocuments }) }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="handlingItems.length"
|
||||
class="mt-2 space-y-1.5"
|
||||
data-testid="shipping-order-extraction-handling-items"
|
||||
>
|
||||
<div class="text-[11px] font-medium opacity-90">
|
||||
{{ t('chat.shippingOrderExtractionHandling.title') }}
|
||||
</div>
|
||||
<div
|
||||
v-for="item in handlingItems"
|
||||
:key="item.category"
|
||||
class="rounded-md border border-current/15 bg-black/5 px-2 py-1.5 text-xs dark:bg-white/5"
|
||||
data-testid="shipping-order-extraction-handling-item"
|
||||
>
|
||||
<div class="flex flex-wrap items-center justify-between gap-2">
|
||||
<div class="min-w-0 font-medium">
|
||||
{{ handlingTitle(item) }}
|
||||
<span class="ml-1 opacity-80">{{ t('chat.shippingOrderExtractionHandling.count', { count: item.count }) }}</span>
|
||||
</div>
|
||||
<button
|
||||
v-if="item.primaryAction"
|
||||
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}`)
|
||||
: t('chat.shippingOrderExtractionAction.view_details') }}
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="item.reasonCodes.length" class="mt-1 opacity-80">
|
||||
{{ t('chat.shippingOrderExtractionHandling.reasonPrefix') }}
|
||||
{{ item.reasonCodes.slice(0, 4).map(reasonLabel).join(';') }}
|
||||
</div>
|
||||
<div
|
||||
v-if="affectedRows(item).length"
|
||||
class="mt-1.5 flex flex-wrap gap-1"
|
||||
data-testid="shipping-order-extraction-affected-refs"
|
||||
>
|
||||
<span class="opacity-80">{{ t('chat.shippingOrderExtractionHandling.affectedPrefix') }}</span>
|
||||
<button
|
||||
v-for="row in affectedRows(item)"
|
||||
: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"
|
||||
@click="openAffectedRef(row.target)"
|
||||
>
|
||||
{{ row.label }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="state.currentActivity?.fileName" class="mt-1 text-xs opacity-80">
|
||||
{{ t('chat.shippingOrderExtractionCurrentFile', {
|
||||
fileName: state.currentActivity.fileName || t('chat.shippingOrderExtractionUnknownDocument'),
|
||||
}) }}
|
||||
<span v-if="activityKey"> · {{ t(activityKey) }}</span>
|
||||
<span v-if="stageLabel"> · {{ stageLabel }}</span>
|
||||
<span v-else-if="activityKey"> · {{ t(activityKey) }}</span>
|
||||
<span v-if="elapsedLabel"> · {{ t('chat.shippingOrderExtractionElapsed', { elapsed: elapsedLabel }) }}</span>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-for="tip in healthTips"
|
||||
:key="tip.code"
|
||||
class="mt-1 text-xs font-medium opacity-90"
|
||||
data-testid="shipping-order-extraction-health-tip"
|
||||
>
|
||||
{{ t(`chat.shippingOrderExtractionHealthTip.${tip.code}`) }}
|
||||
</div>
|
||||
|
||||
<div v-if="state.refreshFailed" class="mt-1 text-xs font-medium opacity-90">
|
||||
{{ t('chat.shippingOrderExtractionRefreshFailed') }}
|
||||
</div>
|
||||
<button
|
||||
v-if="showRetry"
|
||||
type="button"
|
||||
class="mt-2 inline-flex items-center rounded-md border border-current/20 px-2.5 py-1 text-xs font-medium hover:bg-black/5 dark:hover:bg-white/5"
|
||||
@click="emit('retry')"
|
||||
>
|
||||
{{ t('chat.shippingOrderExtractionAction.retry_failed_attachments') }}
|
||||
</button>
|
||||
|
||||
<div v-if="confirmCancelOpen" class="mt-2 rounded-md border border-current/20 bg-black/5 p-2 text-xs dark:bg-white/5">
|
||||
<div class="font-medium">{{ t('chat.shippingOrderExtractionCancel.confirmTitle') }}</div>
|
||||
<div class="mt-1 opacity-80">{{ t('chat.shippingOrderExtractionCancel.confirmImpact') }}</div>
|
||||
<label class="mt-2 block opacity-90">
|
||||
{{ t('chat.shippingOrderExtractionCancel.reasonOptional') }}
|
||||
<textarea
|
||||
v-model="cancelReason"
|
||||
rows="2"
|
||||
class="input-field mt-1 w-full py-1 text-xs"
|
||||
:placeholder="t('chat.shippingOrderExtractionCancel.reasonOptional')"
|
||||
/>
|
||||
</label>
|
||||
<div class="mt-2 flex flex-wrap gap-2">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center rounded-md border border-current/20 px-2.5 py-1 text-xs font-medium hover:bg-black/5 dark:hover:bg-white/5"
|
||||
:disabled="cancelling"
|
||||
@click="confirmCancel"
|
||||
>
|
||||
{{ cancelling
|
||||
? t('chat.shippingOrderExtractionCancel.submitting')
|
||||
: t('chat.shippingOrderExtractionAction.cancel_run') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center rounded-md px-2.5 py-1 text-xs font-medium opacity-80 hover:underline"
|
||||
:disabled="cancelling"
|
||||
@click="confirmCancelOpen = false; cancelReason = ''"
|
||||
>
|
||||
{{ t('chat.shippingOrderExtractionCancel.dismiss') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="mt-2 flex flex-wrap gap-2">
|
||||
<button
|
||||
v-if="showRefresh"
|
||||
type="button"
|
||||
class="inline-flex items-center rounded-md border border-current/20 px-2.5 py-1 text-xs font-medium hover:bg-black/5 dark:hover:bg-white/5"
|
||||
:disabled="refreshing"
|
||||
@click="emit('refresh')"
|
||||
>
|
||||
{{ refreshing
|
||||
? t('chat.shippingOrderExtractionRefreshing')
|
||||
: t('chat.shippingOrderExtractionAction.refresh_status') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="showCancel"
|
||||
type="button"
|
||||
class="inline-flex items-center rounded-md border border-current/20 px-2.5 py-1 text-xs font-medium hover:bg-black/5 dark:hover:bg-white/5"
|
||||
:disabled="cancelling"
|
||||
@click="openCancelConfirm"
|
||||
>
|
||||
{{ t('chat.shippingOrderExtractionAction.cancel_run') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="showRetry"
|
||||
type="button"
|
||||
class="inline-flex items-center rounded-md border border-current/20 px-2.5 py-1 text-xs font-medium hover:bg-black/5 dark:hover:bg-white/5"
|
||||
:disabled="retrying"
|
||||
@click="emit('retry')"
|
||||
>
|
||||
{{ retrying
|
||||
? t('chat.shippingOrderExtractionRetrying')
|
||||
: t('chat.shippingOrderExtractionAction.retry_failed_attachments') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user