- 移除不再使用的 SHIPPING_NOTICE_LAYOUT_PARSER_REVISION 配置 - 在环境配置中新增 SHIPPING_NOTICE_WORKER_CONCURRENCY 和 SHIPPING_NOTICE_JOB_RUNNING_TIMEOUT_SECONDS - 实现发货通知 worker 进程,支持并发处理订单抽取任务 - 引入紧急停止功能,允许管理员在运行中控制订单解析状态 - 更新相关 API,支持读取与设置紧急停止状态 - 增强文档与代码注释,反映新的业务逻辑与功能要求
267 lines
13 KiB
Vue
267 lines
13 KiB
Vue
<script setup lang="ts">
|
||
/**
|
||
* features/chat/components/shipping/ShippingOrderDocumentResultItem.vue
|
||
* 用途:渲染单个 PDF 的订单抽取结果摘要,供详情抽屉按文档逐项展示。
|
||
* 依赖:订单抽取文档 DTO、vue-i18n。
|
||
* 逻辑:默认只展示状态/PO/行数/阻断原因;审计与补充信息收入详情折叠;
|
||
* 「查看证据」与「人工复核」分别携带 focus+documentId;未知原因码回退通用文案并展开技术码。
|
||
*/
|
||
import { computed } from 'vue';
|
||
import { useI18n } from 'vue-i18n';
|
||
import { CircleCheck, CircleX, FileText, LoaderCircle, TriangleAlert } from 'lucide-vue-next';
|
||
import type { ShippingOrderExtractionDocumentResult } from '../../types/shipping.api.types';
|
||
|
||
const props = defineProps<{
|
||
document: ShippingOrderExtractionDocumentResult;
|
||
}>();
|
||
|
||
const emit = defineEmits<{
|
||
enterManualReview: [payload?: { focus?: 'evidence' | 'draft'; documentId?: number }];
|
||
}>();
|
||
|
||
/**
|
||
* 向父级发出进入复核事件,并带上当前文档与入口焦点。
|
||
* @param focus - evidence=查看证据;draft=人工复核草稿
|
||
*/
|
||
function emitEnterReview(focus: 'evidence' | 'draft') {
|
||
emit('enterManualReview', {
|
||
focus,
|
||
documentId: Number(props.document.document_id || 0) || undefined,
|
||
});
|
||
}
|
||
|
||
const { t, te, locale } = useI18n();
|
||
|
||
const statusTone = computed(() => {
|
||
switch (props.document.status) {
|
||
case 'candidate_ready':
|
||
return 'border-emerald-200 bg-emerald-50/70 text-emerald-900 dark:border-emerald-800 dark:bg-emerald-950/25 dark:text-emerald-100';
|
||
case 'review_required':
|
||
return 'border-amber-200 bg-amber-50/70 text-amber-950 dark:border-amber-800 dark:bg-amber-950/25 dark:text-amber-100';
|
||
case 'failed':
|
||
case 'cancelled':
|
||
return 'border-rose-200 bg-rose-50/70 text-rose-900 dark:border-rose-800 dark:bg-rose-950/25 dark:text-rose-100';
|
||
default:
|
||
return 'border-slate-200 bg-slate-50/70 text-slate-900 dark:border-slate-700 dark:bg-slate-900/40 dark:text-slate-100';
|
||
}
|
||
});
|
||
|
||
const statusLabel = computed(() => t(`chat.shippingOrderExtractionDocumentStatus.${props.document.status}`));
|
||
const statusActivityLabel = computed(() => {
|
||
const key = `chat.shippingOrderExtractionActivity.${props.document.activity_event_code || props.document.status}`;
|
||
return te(key) ? t(key) : statusLabel.value;
|
||
});
|
||
const formatTime = (value: string | null | undefined): string => {
|
||
const date = new Date(String(value || ''));
|
||
if (Number.isNaN(date.getTime())) return '';
|
||
return new Intl.DateTimeFormat(String(locale.value || 'zh-CN'), {
|
||
hour: '2-digit', minute: '2-digit', hour12: false,
|
||
}).format(date);
|
||
};
|
||
const activityTimeLabel = computed(() => {
|
||
if (props.document.finished_at) return t('chat.shippingOrderExtractionDocumentTiming.finished', { time: formatTime(props.document.finished_at) });
|
||
if (props.document.last_activity_at) return t('chat.shippingOrderExtractionDocumentTiming.updated', { time: formatTime(props.document.last_activity_at) });
|
||
if (props.document.started_at) return t('chat.shippingOrderExtractionDocumentTiming.started', { time: formatTime(props.document.started_at) });
|
||
return '';
|
||
});
|
||
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 t('chat.shippingOrderExtractionReasonUnknown');
|
||
});
|
||
const reasonTechnicalCode = computed(() => {
|
||
const code = String(props.document.reason_code || '').trim();
|
||
if (!code) return '';
|
||
const key = `chat.shippingOrderExtractionReason.${code}`;
|
||
if (te(key) || code.startsWith('SHIPPING_NOTICE.')) return '';
|
||
return code;
|
||
});
|
||
const emailSupplementLabel = computed(() => {
|
||
const status = props.document.email_supplement?.status || 'none';
|
||
const key = `chat.shippingOrderExtractionEmailSupplement.${status}`;
|
||
return te(key) ? t(key) : t('chat.shippingOrderExtractionEmailSupplement.none');
|
||
});
|
||
const emailSupplementRelations = computed(() => (
|
||
(props.document.email_supplement?.relation_codes || [])
|
||
.map((code) => {
|
||
const key = `chat.shippingOrderExtractionEmailSupplementRelation.${code}`;
|
||
return te(key) ? t(key) : code;
|
||
})
|
||
));
|
||
const reservationStatusLabel = computed(() => {
|
||
const key = `chat.shippingOrderExtractionEmailSupplementFieldStatus.${props.document.email_supplement?.reservation_id_status || 'none'}`;
|
||
return te(key) ? t(key) : t('chat.shippingOrderExtractionEmailSupplementFieldStatus.none');
|
||
});
|
||
const sourceTypeStatusLabel = computed(() => {
|
||
const key = `chat.shippingOrderExtractionEmailSupplementFieldStatus.${props.document.email_supplement?.source_type_status || 'none'}`;
|
||
return te(key) ? t(key) : t('chat.shippingOrderExtractionEmailSupplementFieldStatus.none');
|
||
});
|
||
const retryStatusLabel = computed(() => {
|
||
const status = String(props.document.retry_status || '').trim();
|
||
const key = `chat.shippingOrderExtractionRetryStatus.${status}`;
|
||
return status && te(key) ? t(key) : '';
|
||
});
|
||
const routeTypeLabel = computed(() => {
|
||
const code = String(props.document.route_type || '').trim();
|
||
if (!code) return '';
|
||
const key = `chat.shippingOrderExtractionRouteType.${code}`;
|
||
return te(key) ? t(key) : code;
|
||
});
|
||
const freezeSourceLabel = computed(() => {
|
||
const code = String(props.document.freeze_source || '').trim();
|
||
if (!code) return '';
|
||
const key = `chat.shippingOrderExtractionFreezeSource.${code}`;
|
||
return te(key) ? t(key) : code;
|
||
});
|
||
const budgetCostLabel = computed(() => {
|
||
if (!props.document.budget_cost) return '';
|
||
return t('chat.shippingOrderExtractionBudgetCost', {
|
||
attachments: props.document.budget_cost.initial_attachment_budget || 0,
|
||
concurrency: props.document.budget_cost.initial_concurrency_budget || 0,
|
||
selected: props.document.budget_cost.selected_in_batch || 0,
|
||
});
|
||
});
|
||
const reviewDetails = computed(() => props.document.review_details || []);
|
||
const reviewFieldLabel = (fieldCode: string | null | undefined): string => {
|
||
const key = `chat.shippingOrderExtractionReviewField.${fieldCode || ''}`;
|
||
return fieldCode && te(key) ? t(key) : (fieldCode || t('chat.shippingOrderExtractionReviewField.unknown'));
|
||
};
|
||
|
||
const canEnterManualReview = computed(() => (
|
||
props.document.available_actions.some((action) => action === 'review_candidate' || action === 'manual_review')
|
||
));
|
||
const canViewEvidence = computed(() => props.document.available_actions.includes('view_evidence'));
|
||
|
||
const hasAuditDetails = computed(() => Boolean(
|
||
props.document.selection_batch
|
||
|| props.document.group_key
|
||
|| props.document.profile
|
||
|| routeTypeLabel.value
|
||
|| freezeSourceLabel.value
|
||
|| (props.document.email_supplement?.status && props.document.email_supplement.status !== 'none')
|
||
|| emailSupplementRelations.value.length
|
||
|| (props.document.email_supplement?.conflict_count || 0) > 0
|
||
|| retryStatusLabel.value
|
||
|| budgetCostLabel.value
|
||
|| (
|
||
props.document.email_supplement?.reservation_id_status
|
||
&& props.document.email_supplement.reservation_id_status !== 'none'
|
||
)
|
||
|| (
|
||
props.document.email_supplement?.source_type_status
|
||
&& props.document.email_supplement.source_type_status !== 'none'
|
||
),
|
||
));
|
||
</script>
|
||
|
||
<template>
|
||
<section class="rounded-lg border p-3" :class="statusTone">
|
||
<div class="flex items-start gap-2">
|
||
<LoaderCircle
|
||
v-if="['pending', 'routing', 'matching_profile', 'extracting', 'merging_supplement'].includes(document.status)"
|
||
class="mt-0.5 h-4 w-4 shrink-0 animate-spin"
|
||
/>
|
||
<CircleCheck v-else-if="document.status === 'candidate_ready'" class="mt-0.5 h-4 w-4 shrink-0" />
|
||
<TriangleAlert v-else-if="document.status === 'review_required'" class="mt-0.5 h-4 w-4 shrink-0" />
|
||
<CircleX v-else class="mt-0.5 h-4 w-4 shrink-0" />
|
||
<div class="min-w-0 flex-1">
|
||
<div class="flex flex-wrap items-center gap-2">
|
||
<div class="truncate text-sm font-semibold">{{ document.file_name || t('chat.shippingOrderExtractionUnknownDocument') }}</div>
|
||
<span class="rounded-full bg-black/10 px-2 py-0.5 text-[11px] dark:bg-white/10">{{ statusLabel }}</span>
|
||
</div>
|
||
<div v-if="['pending', 'routing', 'matching_profile', 'extracting', 'merging_supplement'].includes(document.status) || document.activity_event_code" class="mt-1 text-xs font-medium opacity-85">
|
||
{{ statusActivityLabel }}
|
||
</div>
|
||
<!-- 核心业务结果:状态时间 + PO + 行数 -->
|
||
<div class="mt-2 flex flex-wrap gap-x-4 gap-y-1 text-xs opacity-85">
|
||
<span v-if="activityTimeLabel">{{ activityTimeLabel }}</span>
|
||
<span v-if="document.po_number">
|
||
{{ t('chat.shippingOrderExtractionPoNumber', { value: document.po_number }) }}
|
||
</span>
|
||
<span v-if="document.line_count > 0">
|
||
{{ t('chat.shippingOrderExtractionLineCount', { count: document.line_count }) }}
|
||
</span>
|
||
</div>
|
||
<!-- 异常信息 -->
|
||
<div v-if="reasonLabel" class="mt-2 text-xs font-medium opacity-90">
|
||
{{ reasonLabel }}
|
||
<details v-if="reasonTechnicalCode" class="mt-1 font-normal opacity-80">
|
||
<summary class="cursor-pointer">{{ t('chat.shippingOrderExtractionReasonTechDetails') }}</summary>
|
||
<code class="mt-1 block break-all text-[11px]">{{ reasonTechnicalCode }}</code>
|
||
</details>
|
||
</div>
|
||
<ul v-if="reviewDetails.length" class="mt-2 space-y-1 text-xs font-medium opacity-90">
|
||
<li v-for="detail in reviewDetails" :key="`${detail.line_number}-${detail.field_code || 'general'}`">
|
||
{{ t('chat.shippingOrderExtractionReviewDetail', {
|
||
line: detail.line_number,
|
||
field: reviewFieldLabel(detail.field_code),
|
||
}) }}
|
||
</li>
|
||
</ul>
|
||
<div v-if="document.status === 'failed'" class="mt-1 text-xs font-medium opacity-90">
|
||
{{ t('chat.shippingOrderExtractionTechnicalFailureUserHint') }}
|
||
</div>
|
||
<!-- 审计/补充详情:默认折叠,降低首屏密度 -->
|
||
<details v-if="hasAuditDetails" class="mt-2 text-xs opacity-85">
|
||
<summary class="cursor-pointer select-none font-medium">
|
||
{{ t('chat.shippingOrderExtractionMoreDetails') }}
|
||
</summary>
|
||
<div class="mt-2 flex flex-wrap gap-x-4 gap-y-1">
|
||
<span v-if="document.selection_batch">
|
||
{{ t('chat.shippingOrderExtractionSelectionBatch', { batch: document.selection_batch }) }}
|
||
</span>
|
||
<span v-if="document.group_key">
|
||
{{ t('chat.shippingOrderExtractionGroupKey', { key: document.group_key }) }}
|
||
</span>
|
||
<span v-if="document.profile">
|
||
{{ t('chat.shippingOrderExtractionProfileSummary', {
|
||
name: document.profile.name || document.profile.code,
|
||
version: document.profile.version,
|
||
}) }}
|
||
</span>
|
||
<span v-if="routeTypeLabel">{{ routeTypeLabel }}</span>
|
||
<span v-if="freezeSourceLabel">{{ freezeSourceLabel }}</span>
|
||
<span>{{ emailSupplementLabel }}</span>
|
||
<span>
|
||
{{ t('chat.shippingOrderExtractionEmailSupplementField.reservation') }}{{ reservationStatusLabel }}
|
||
</span>
|
||
<span>
|
||
{{ t('chat.shippingOrderExtractionEmailSupplementField.sourceType') }}{{ sourceTypeStatusLabel }}
|
||
</span>
|
||
<span v-for="relation in emailSupplementRelations" :key="relation">{{ relation }}</span>
|
||
<span v-if="document.email_supplement.conflict_count > 0">
|
||
{{ t('chat.shippingOrderExtractionEmailSupplementConflictCount', { count: document.email_supplement.conflict_count }) }}
|
||
</span>
|
||
<span v-if="retryStatusLabel">{{ retryStatusLabel }}</span>
|
||
<span v-if="budgetCostLabel">{{ budgetCostLabel }}</span>
|
||
</div>
|
||
</details>
|
||
<div class="mt-2 flex flex-wrap gap-2">
|
||
<button
|
||
v-if="canViewEvidence"
|
||
type="button"
|
||
class="inline-flex items-center gap-1 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="emitEnterReview('evidence')"
|
||
>
|
||
<FileText class="h-3.5 w-3.5" />
|
||
{{ t('chat.shippingOrderExtractionAction.view_evidence') }}
|
||
</button>
|
||
<button
|
||
v-if="canEnterManualReview"
|
||
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"
|
||
@click="emitEnterReview('draft')"
|
||
>
|
||
{{ t(`chat.shippingOrderExtractionAction.${document.available_actions.includes('review_candidate') ? 'review_candidate' : 'manual_review'}`) }}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
</template>
|