fix(shipping-notice): 修复模板签名误杀 Qty.Req 并加固订单抽取链路

收紧动态 token 过滤避免列名被剔除;同步表区裁剪、物理表门禁、邮件补充合并与对话附件折叠展示。
This commit is contained in:
hugo committed 2026-09-08 14:06:27 +08:00
1 parent e40743871c
commit 5ce9221476
29 files changed
+1702 -108

No files matched your search

@@ -1,6 +1,9 @@
/**
* features/chat/components/ChatMessageList.vue
* 消息列表主区域:滚动容器、欢迎页、消息气泡与思考中占位。
* 用途:消息列表主区域(滚动容器、欢迎页、气泡与思考中占位)。
* 依赖:ChatMessageBubble、各类进度卡、chat.types。
* 逻辑:按 shouldRenderMessage 过滤;货代抽取卡按 run / upload_batch / client_submission 去重只留最后一张;
* 用户气泡在下方已有抽取进度卡时对附件启用 summaryOnly,避免与进度卡重复堆文件明细。
*/
<script setup lang="ts">
import type { Ref } from 'vue';
@@ -84,7 +87,7 @@ const getMessageKey = (msg: ChatMessage, index: number) => (
|| `${msg.role}:${msg.run_id || 'none'}:${String(msg.content || '').slice(0, 40)}:${index}`
);
/** 同一 Run 或同一次上传批次只展示最后一张状态卡,避免历史恢复/SSE 补帧造成重复窗口。 */
/** 同一 Run / 上传批次 / 提交幂等键只展示最后一张状态卡,避免历史恢复造成重复窗口。 */
const isDuplicateShippingExtractionMessage = (items: ChatMessage[], index: number): boolean => {
const current = items[index];
if (!current?.shipping_order_extraction_state) return false;
@@ -102,7 +105,12 @@ const isDuplicateShippingExtractionMessage = (items: ChatMessage[], index: numbe
|| current.shipping_order_extraction_state.uploadBatchId
|| '',
).trim();
if (!runIdentity && !batchIdentity) return false;
const submissionIdentity = String(
payload.shipping_order_extraction_client_submission_id
|| current.shipping_order_extraction_state.clientSubmissionId
|| '',
).trim();
if (!runIdentity && !batchIdentity && !submissionIdentity) return false;
return items.slice(index + 1).some((candidate) => {
if (!candidate?.shipping_order_extraction_state) return false;
const candidatePayload = candidate.payload && typeof candidate.payload === 'object'
@@ -119,8 +127,14 @@ const isDuplicateShippingExtractionMessage = (items: ChatMessage[], index: numbe
|| candidate.shipping_order_extraction_state.uploadBatchId
|| '',
).trim();
const candidateSubmissionIdentity = String(
candidatePayload.shipping_order_extraction_client_submission_id
|| candidate.shipping_order_extraction_state.clientSubmissionId
|| '',
).trim();
return Boolean(
(batchIdentity && candidateBatchIdentity === batchIdentity)
|| (submissionIdentity && candidateSubmissionIdentity === submissionIdentity)
|| (runIdentity && candidateRunIdentity === runIdentity),
);
});
@@ -139,6 +153,20 @@ const isLatestAssistantMessage = (items: ChatMessage[], index: number) => {
}
return true;
};
/**
* 用户消息与下一轮用户输入之间,是否已有货代订单抽取进度卡。
* 核心逻辑:有进度卡时附件区只留摘要,文件明细交给进度卡展示。
*/
const hasFollowingShippingProgressCard = (items: ChatMessage[], index: number): boolean => {
for (let i = index + 1; i < items.length; i += 1) {
const candidate = items[i];
if (!candidate) continue;
if (candidate.role === 'user') break;
if (candidate.shipping_order_extraction_state) return true;
}
return false;
};
</script>
<template>
@@ -180,6 +208,7 @@ const isLatestAssistantMessage = (items: ChatMessage[], index: number) => {
:shipping-handlers="shippingHandlers"
:training-handlers="trainingHandlers"
:compact-shipping-progress="compactShippingProgress"
:attachment-summary-only="hasFollowingShippingProgressCard(messages, index)"
@copy="emit('copy', { message: msg, index })"
@edit="emit('edit', $event)"
@resend="emit('resend', $event)"
@@ -1,22 +1,82 @@
/**
* features/chat/components/messages/ChatMessageAttachmentList.spec.ts
* 用途:校验已发送附件分层展示(chip / 摘要折叠 / 进度卡并存只留摘要)。
* 依赖:Vitest、Vue Test Utils、vue-i18n。
* 逻辑:覆盖 ≤3 chip、>3 摘要可展开、summaryOnly 不可展开。
*/
import { mount } from '@vue/test-utils';
import { describe, expect, it } from 'vitest';
import { createI18n } from 'vue-i18n';
import ChatMessageAttachmentList from './ChatMessageAttachmentList.vue';
import type { ChatMessageAttachment } from '../../types/chat.types';
const i18n = createI18n({
legacy: false,
locale: 'zh-CN',
messages: {
'zh-CN': {
chat: {
attachment: {
summaryCount: '{count} 个附件',
expandList: '展开附件列表',
collapseList: '收起附件列表',
},
},
},
},
});
const makeAttachments = (count: number): ChatMessageAttachment[] =>
Array.from({ length: count }, (_, index) => ({
name: `file-${index + 1}.eml`,
type: 'document' as const,
source: 'local' as const,
size: 1024 * (index + 1),
extension: 'eml',
}));
describe('ChatMessageAttachmentList', () => {
it('keeps many sent attachments in a single horizontally scrollable row', () => {
it('renders compact chips when there are at most three attachments', () => {
const wrapper = mount(ChatMessageAttachmentList, {
props: {
attachments: [
{ name: 'one.eml', type: 'document', source: 'local', size: 1024, extension: 'eml' },
{ name: 'two.eml', type: 'document', source: 'local', size: 2048, extension: 'eml' },
{ name: 'three.eml', type: 'document', source: 'local', size: 3072, extension: 'eml' },
],
},
props: { attachments: makeAttachments(3) },
global: { plugins: [i18n] },
});
const list = wrapper.get('[data-testid="chat-message-attachment-list"]');
expect(list.classes()).toContain('overflow-x-auto');
expect(list.classes()).toContain('flex-nowrap');
expect(wrapper.findAll('article')).toHaveLength(3);
expect(wrapper.find('[data-testid="chat-message-attachment-chips"]').exists()).toBe(true);
expect(wrapper.findAll('[data-testid="chat-message-attachment-chip"]')).toHaveLength(3);
expect(wrapper.find('[data-testid="chat-message-attachment-summary"]').exists()).toBe(false);
});
it('collapses many attachments into a summary that expands into a scrollable list', async () => {
const wrapper = mount(ChatMessageAttachmentList, {
props: { attachments: makeAttachments(5) },
global: { plugins: [i18n] },
});
const summary = wrapper.get('[data-testid="chat-message-attachment-summary"]');
expect(summary.text()).toContain('5 个附件');
expect(wrapper.find('[data-testid="chat-message-attachment-expanded"]').exists()).toBe(false);
await summary.trigger('click');
const expanded = wrapper.get('[data-testid="chat-message-attachment-expanded"]');
expect(expanded.classes()).toContain('max-h-40');
expect(expanded.findAll('article')).toHaveLength(5);
});
it('keeps only the summary when a shipping progress card follows the message', async () => {
const wrapper = mount(ChatMessageAttachmentList, {
props: {
attachments: makeAttachments(2),
summaryOnly: true,
},
global: { plugins: [i18n] },
});
expect(wrapper.find('[data-testid="chat-message-attachment-chips"]').exists()).toBe(false);
const summary = wrapper.get('[data-testid="chat-message-attachment-summary"]');
expect(summary.text()).toContain('2 个附件');
await summary.trigger('click');
expect(wrapper.find('[data-testid="chat-message-attachment-expanded"]').exists()).toBe(false);
});
});
@@ -1,18 +1,49 @@
/**
* features/chat/components/messages/ChatMessageAttachmentList.vue
* 用途:在用户消息中展示已发送附件快照。
* 依赖:lucide 文件图标、attachmentCard.utils 的大小格式化、chat.types 的消息附件契约。
* 逻辑:ChatMessageBubble 将当前用户消息附件传入;本组件只读展示,不提供删除、重试或上传状态操作。
* 用途:在用户消息中分层展示已发送附件快照(少文件 chip / 多文件摘要折叠)。
* 依赖:lucide 图标、vue-i18n、attachmentCard.utils、chat.types。
* 逻辑:ChatMessageBubble 传入附件与 summaryOnly;≤3 用紧凑 chip,>3 默认摘要条可展开纵向列表;
* 下方已有货代进度卡时 summaryOnly=true,只留摘要避免与进度卡重复。
*/
<script setup lang="ts">
import { FileAudio, FileImage, FileText, FileVideo, Link2 } from 'lucide-vue-next';
import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { ChevronDown, ChevronUp, FileAudio, FileImage, FileText, FileVideo, Link2, Paperclip } from 'lucide-vue-next';
import { formatAttachmentSize } from '../../utils/attachmentCard.utils';
import type { ChatMessageAttachment } from '../../types/chat.types';
const { attachments } = defineProps<{
/** 超过该数量后默认折叠为摘要条,避免气泡内横排大卡。 */
const CHIP_LIMIT = 3;
/** 展开列表内部最大高度(约 4~5 行)。 */
const EXPANDED_LIST_MAX_HEIGHT_CLASS = 'max-h-40';
const props = defineProps<{
attachments: ChatMessageAttachment[];
/** 下方已有货代进度卡时为 true:只显示摘要,不展开明细。 */
summaryOnly?: boolean;
}>();
const { t } = useI18n();
const expanded = ref(false);
const attachmentCount = computed(() => props.attachments.length);
const useChips = computed(() => !props.summaryOnly && attachmentCount.value > 0 && attachmentCount.value <= CHIP_LIMIT);
const useCollapsibleSummary = computed(() => !props.summaryOnly && attachmentCount.value > CHIP_LIMIT);
const showSummaryBar = computed(() => Boolean(props.summaryOnly) || useCollapsibleSummary.value);
const totalSizeLabel = computed(() => {
let total = 0;
let known = 0;
for (const item of props.attachments) {
if (typeof item.size === 'number' && Number.isFinite(item.size) && item.size >= 0) {
total += item.size;
known += 1;
}
}
if (!known) return '';
return formatAttachmentSize(total);
});
/** 根据附件来源与业务类型选择只读消息卡片图标。 */
function attachmentIcon(attachment: ChatMessageAttachment) {
if (attachment.source === 'remote') return Link2;
@@ -29,35 +60,104 @@ function attachmentBadge(attachment: ChatMessageAttachment): string {
if (attachment.source === 'remote') return 'URL';
return attachment.type.toUpperCase().slice(0, 5);
}
/** 切换多附件摘要的展开/收起;summaryOnly 时不可展开。 */
function toggleExpanded() {
if (props.summaryOnly) return;
expanded.value = !expanded.value;
}
</script>
<template>
<div
v-if="attachments.length > 0"
v-if="attachmentCount > 0"
data-testid="chat-message-attachment-list"
class="mb-2 flex w-full flex-nowrap justify-end gap-2 overflow-x-auto pb-1 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden"
class="mb-2 w-full"
>
<article
v-for="(attachment, attachmentIndex) in attachments"
:key="`${attachment.name}-${attachment.size ?? 'unknown'}-${attachmentIndex}`"
class="flex h-[68px] w-[250px] shrink-0 items-center gap-2.5 rounded-xl border border-default bg-surface px-3 py-2.5 shadow-sm dark:bg-slate-900"
:title="attachment.name"
<!-- ≤3:紧凑 chip,宽度自适应 -->
<div
v-if="useChips"
data-testid="chat-message-attachment-chips"
class="flex w-full flex-wrap justify-end gap-1.5"
>
<div
class="flex h-10 w-9 shrink-0 flex-col items-center justify-center rounded-lg bg-brand-50 text-brand-700 dark:bg-brand-900/30 dark:text-brand-300"
aria-hidden="true"
<article
v-for="(attachment, attachmentIndex) in props.attachments"
:key="`${attachment.name}-${attachment.size ?? 'unknown'}-${attachmentIndex}`"
class="flex h-10 max-w-[220px] items-center gap-2 rounded-lg border border-white/25 bg-white/95 px-2.5 text-slate-800 shadow-sm dark:border-white/10 dark:bg-slate-900/90 dark:text-slate-100"
:title="attachment.name"
data-testid="chat-message-attachment-chip"
>
<component :is="attachmentIcon(attachment)" class="h-4 w-4" />
<span class="mt-0.5 max-w-8 truncate text-[8px] font-bold leading-none">
{{ attachmentBadge(attachment) }}
</span>
</div>
<div class="min-w-0 flex-1">
<div class="truncate text-sm font-semibold text-primary">{{ attachment.name }}</div>
<div v-if="attachment.size !== undefined" class="mt-1 text-[11px] leading-none text-muted">
{{ formatAttachmentSize(attachment.size) }}
<div
class="flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-brand-50 text-brand-700 dark:bg-brand-900/40 dark:text-brand-300"
aria-hidden="true"
>
<component :is="attachmentIcon(attachment)" class="h-3.5 w-3.5" />
</div>
<div class="min-w-0 flex-1">
<div class="truncate text-xs font-semibold leading-tight">{{ attachment.name }}</div>
<div class="mt-0.5 flex items-center gap-1 text-[10px] leading-none text-slate-500 dark:text-slate-400">
<span>{{ attachmentBadge(attachment) }}</span>
<span v-if="attachment.size !== undefined">· {{ formatAttachmentSize(attachment.size) }}</span>
</div>
</div>
</article>
</div>
<!-- >3 或货代进度卡并存:摘要条 -->
<div v-else-if="showSummaryBar" class="flex w-full flex-col items-end gap-1.5">
<button
type="button"
data-testid="chat-message-attachment-summary"
class="inline-flex max-w-full items-center gap-2 rounded-lg border border-white/25 bg-white/15 px-3 py-2 text-left text-white transition hover:bg-white/20"
:class="props.summaryOnly ? 'cursor-default' : 'cursor-pointer'"
:aria-expanded="props.summaryOnly ? undefined : expanded"
:aria-controls="props.summaryOnly || !expanded ? undefined : 'chat-message-attachment-expanded'"
:aria-label="props.summaryOnly
? t('chat.attachment.summaryCount', { count: attachmentCount })
: (expanded ? t('chat.attachment.collapseList') : t('chat.attachment.expandList'))"
@click="toggleExpanded"
>
<Paperclip class="h-3.5 w-3.5 shrink-0 opacity-90" aria-hidden="true" />
<span class="truncate text-xs font-semibold">
{{ t('chat.attachment.summaryCount', { count: attachmentCount }) }}
</span>
<span v-if="totalSizeLabel" class="shrink-0 text-[11px] opacity-80">· {{ totalSizeLabel }}</span>
<component
:is="expanded ? ChevronUp : ChevronDown"
v-if="!props.summaryOnly"
class="h-3.5 w-3.5 shrink-0 opacity-80"
aria-hidden="true"
/>
</button>
<div
v-if="useCollapsibleSummary && expanded"
id="chat-message-attachment-expanded"
data-testid="chat-message-attachment-expanded"
class="w-full max-w-sm overflow-y-auto rounded-xl border border-white/20 bg-white/95 p-1.5 shadow-sm dark:bg-slate-900/95"
:class="EXPANDED_LIST_MAX_HEIGHT_CLASS"
>
<article
v-for="(attachment, attachmentIndex) in props.attachments"
:key="`expanded-${attachment.name}-${attachment.size ?? 'unknown'}-${attachmentIndex}`"
class="flex items-center gap-2 rounded-lg px-2 py-1.5 text-slate-800 dark:text-slate-100"
:title="attachment.name"
>
<div
class="flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-brand-50 text-brand-700 dark:bg-brand-900/40 dark:text-brand-300"
aria-hidden="true"
>
<component :is="attachmentIcon(attachment)" class="h-3.5 w-3.5" />
</div>
<div class="min-w-0 flex-1">
<div class="truncate text-xs font-semibold">{{ attachment.name }}</div>
<div class="mt-0.5 text-[10px] text-slate-500 dark:text-slate-400">
<span>{{ attachmentBadge(attachment) }}</span>
<span v-if="attachment.size !== undefined"> · {{ formatAttachmentSize(attachment.size) }}</span>
</div>
</div>
</article>
</div>
</article>
</div>
</div>
</template>
@@ -3,6 +3,7 @@
* 用途:渲染单条聊天消息,统一承接用户气泡、助手 Markdown、内嵌文件下载、请假/出货子组件与操作栏。
* 依赖:Vue computed、lucide 图标、消息附件/Leave/Shipping 子组件、chat.types 与页面级 handlers。
* 逻辑:由 ChatMessageList 按消息逐条挂载;货代履约写按钮不在气泡内渲染,仅展示只读卡与深链通知。
* 用户附件区支持 summaryOnly:下方已有抽取进度卡时只显示附件摘要。
* 兼容:同时承接采购合同审查、库存映射、订单提取和 Mermaid 展示。
*/
<script setup lang="ts">
@@ -60,6 +61,7 @@ const {
handlers,
leaveHandlers,
shippingHandlers,
attachmentSummaryOnly = false,
} = defineProps<{
message: ChatMessage;
index: number;
@@ -74,6 +76,8 @@ const {
shippingHandlers: ShippingMessageHandlers;
trainingHandlers: TrainingHandlers;
compactShippingProgress?: boolean;
/** 下方已有货代进度卡时,用户气泡附件只显示摘要。 */
attachmentSummaryOnly?: boolean;
}>();
const emit = defineEmits<{
@@ -729,6 +733,7 @@ function handleInlineDownload(file: InlineDownloadFile): void {
<ChatMessageAttachmentList
v-if="message.attachments?.length"
:attachments="message.attachments"
:summary-only="attachmentSummaryOnly"
/>
<div v-if="hasUserContent" class="whitespace-pre-wrap px-2.5 py-1">{{ message.content }}</div>
</template>