feat(shipping-notice): 新增货代客户管理功能,支持客户导入、识别证据管理与客户确认
This commit is contained in:
1 parent
b595e157e9
commit
4fbaed2b4c
176 files changed
+14011
-994
No files matched your search
@@ -1,7 +1,8 @@
|
||||
/**
|
||||
* features/chat/components/ChatInputBar.vue
|
||||
* 聊天输入栏:文本框、附件、语音、知识库选择与发送按钮。
|
||||
* 逻辑:设备维保助手的管理入口(设备台账、登记维修)与语音按钮同侧排列,发送按钮独占右侧。
|
||||
* 用途:承载聊天文本输入、附件预览、语音、知识库选择与发送操作。
|
||||
* 依赖:lucide 图标、ShippingNoticeCandidateReview、附件完整性判断工具。
|
||||
* 逻辑:附件卡片位于文本框上方;发货通知保留解析/重复处理能力,普通附件展示逐文件上传状态。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||||
@@ -10,7 +11,13 @@ import type { Ref } from 'vue';
|
||||
import {
|
||||
Check,
|
||||
ChevronDown,
|
||||
CircleAlert,
|
||||
CircleCheck,
|
||||
Database,
|
||||
FileAudio,
|
||||
FileImage,
|
||||
FileText,
|
||||
FileVideo,
|
||||
Link2,
|
||||
Loader2,
|
||||
Mic,
|
||||
@@ -26,6 +33,13 @@ import {
|
||||
isBlockingWarning,
|
||||
isShippingNoticeAttachmentParseIncomplete,
|
||||
} from '../shipping/shippingNoticeAttachmentIntegrity';
|
||||
import {
|
||||
getAttachmentCardStatus,
|
||||
getAttachmentExtension,
|
||||
getAttachmentName,
|
||||
getAttachmentSize,
|
||||
isAttachmentRemoveDisabled,
|
||||
} from '../utils/attachmentCard.utils';
|
||||
|
||||
export interface ChatInputAttachmentPolicy {
|
||||
anyEnabled: boolean;
|
||||
@@ -156,6 +170,15 @@ function shippingNoticeAttachmentTitle(attachment: ShippingNoticePendingAttachme
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
/** 根据附件业务类型选择文件图标,帮助用户快速区分媒体与文档。 */
|
||||
function attachmentIcon(attachment: PendingAttachment) {
|
||||
if (attachment.kind === 'remote') return Link2;
|
||||
if (attachment.type === 'image') return FileImage;
|
||||
if (attachment.type === 'audio') return FileAudio;
|
||||
if (attachment.type === 'video') return FileVideo;
|
||||
return FileText;
|
||||
}
|
||||
|
||||
const closeAttachmentMenu = () => {
|
||||
showAttachmentMenu.value = false;
|
||||
showAttachmentUrlPanel.value = false;
|
||||
@@ -293,6 +316,92 @@ watch(
|
||||
@resolve-duplicate="(candidateNo, action, targetTaskNo, reason, done) => emit('resolve-shipping-candidate-duplicate', candidateNo, action, targetTaskNo, reason, done)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="attachments.length > 0"
|
||||
data-testid="chat-attachment-list"
|
||||
class="flex flex-wrap gap-2 px-2.5 pb-2 pt-1"
|
||||
>
|
||||
<article
|
||||
v-for="a in attachments"
|
||||
:key="a.id"
|
||||
class="group relative flex min-w-0 basis-full items-center gap-3 rounded-xl border border-default bg-surface-soft px-3 py-2.5 transition-colors sm:basis-[calc(50%-0.25rem)] lg:max-w-[310px]"
|
||||
:title="a.kind === 'shipping_notice' ? shippingNoticeAttachmentTitle(a) : getAttachmentName(a)"
|
||||
>
|
||||
<div
|
||||
class="flex h-11 w-10 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"
|
||||
>
|
||||
<component :is="attachmentIcon(a)" class="h-4.5 w-4.5" />
|
||||
<span class="mt-0.5 max-w-9 truncate text-[9px] font-bold leading-none">{{ getAttachmentExtension(a) }}</span>
|
||||
</div>
|
||||
|
||||
<div class="min-w-0 flex-1 pr-5">
|
||||
<p class="truncate text-sm font-medium text-primary">{{ getAttachmentName(a) }}</p>
|
||||
<div class="mt-1 flex min-w-0 items-center gap-1.5 text-[11px] leading-none">
|
||||
<span v-if="getAttachmentSize(a)" class="shrink-0 text-muted">{{ getAttachmentSize(a) }}</span>
|
||||
<span v-if="getAttachmentSize(a)" class="text-slate-300">·</span>
|
||||
<span
|
||||
class="flex min-w-0 items-center gap-1 truncate"
|
||||
:class="{
|
||||
'text-muted': getAttachmentCardStatus(a).state === 'pending',
|
||||
'text-brand-600': ['uploading', 'processing'].includes(getAttachmentCardStatus(a).state),
|
||||
'text-amber-700': getAttachmentCardStatus(a).state === 'attention',
|
||||
'text-emerald-600': getAttachmentCardStatus(a).state === 'ready',
|
||||
'text-red-500': getAttachmentCardStatus(a).state === 'failed',
|
||||
}"
|
||||
>
|
||||
<Loader2
|
||||
v-if="['uploading', 'processing'].includes(getAttachmentCardStatus(a).state)"
|
||||
class="h-3 w-3 shrink-0 animate-spin"
|
||||
/>
|
||||
<CircleCheck v-else-if="getAttachmentCardStatus(a).state === 'ready'" class="h-3 w-3 shrink-0" />
|
||||
<CircleAlert v-else-if="['attention', 'failed'].includes(getAttachmentCardStatus(a).state)" class="h-3 w-3 shrink-0" />
|
||||
<span class="truncate">{{ t(getAttachmentCardStatus(a).labelKey) }}</span>
|
||||
<template v-if="a.kind === 'shipping_notice' && shippingNoticeAttachmentHint(a)">
|
||||
<span class="truncate">· {{ shippingNoticeAttachmentHint(a) }}</span>
|
||||
</template>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="a.kind === 'shipping_notice' && (canRetryShippingNoticeParse(a) || (!a.candidates?.length && a.duplicate?.blocking && !a.duplicateResolution?.action))"
|
||||
class="absolute bottom-1.5 right-2 flex items-center gap-1"
|
||||
>
|
||||
<button
|
||||
v-if="!a.candidates?.length && a.duplicate?.blocking && !a.duplicateResolution?.action"
|
||||
type="button"
|
||||
class="rounded px-1.5 py-1 text-[10px] font-medium text-amber-700 hover:bg-amber-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-400"
|
||||
:title="t('chat.shippingNoticeDuplicateHandle')"
|
||||
@click="emit('resolve-shipping-notice-duplicate', a.id)"
|
||||
>
|
||||
{{ t('chat.shippingNoticeDuplicateHandle') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="canRetryShippingNoticeParse(a)"
|
||||
type="button"
|
||||
class="rounded p-1 text-muted hover:bg-surface hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand-400"
|
||||
:title="t('chat.shippingNoticeRetryParse')"
|
||||
@click="emit('retry-shipping-notice-attachment', a.id)"
|
||||
>
|
||||
<RefreshCw class="h-3.5 w-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="absolute right-1.5 top-1.5 flex h-6 w-6 items-center justify-center rounded-full text-muted opacity-80 transition hover:bg-surface hover:text-red-500 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand-400 disabled:cursor-not-allowed disabled:opacity-30"
|
||||
:disabled="isAttachmentRemoveDisabled(a)"
|
||||
:title="t('chat.attachment.remove')"
|
||||
:aria-label="t('chat.attachment.removeNamed', { name: getAttachmentName(a) })"
|
||||
@click="emit('remove-attachment', a.id)"
|
||||
>
|
||||
<X class="h-3.5 w-3.5" />
|
||||
</button>
|
||||
</article>
|
||||
</div>
|
||||
|
||||
<textarea
|
||||
ref="textareaRef"
|
||||
v-model="inputValue"
|
||||
@@ -324,77 +433,6 @@ watch(
|
||||
@change="emit('local-files-selected', $event)"
|
||||
/>
|
||||
|
||||
<div v-if="attachments.length > 0" class="flex flex-wrap gap-2 px-3 pb-1">
|
||||
<div
|
||||
v-for="a in attachments"
|
||||
:key="a.id"
|
||||
class="flex items-center gap-2 rounded-lg border border-default bg-surface-soft px-2 py-1 text-xs text-secondary"
|
||||
>
|
||||
<span class="max-w-[220px] truncate">
|
||||
<template v-if="a.kind === 'shipping_notice'">
|
||||
{{ a.originalFilename }}
|
||||
<span v-if="a.uploadStatus === 'uploading'" class="text-muted"> · {{ t('chat.shippingNoticeUploading') }}</span>
|
||||
<span v-else-if="a.parseStatus === 'queued' || a.parseStatus === 'parsing'" class="text-muted"> · {{ t('chat.shippingNoticeParsing') }}</span>
|
||||
<span
|
||||
v-else-if="a.parseStatus === 'parsed' && !a.candidates?.length && a.duplicate?.status === 'possible_duplicate' && !a.duplicateResolution?.action"
|
||||
class="font-medium text-amber-700"
|
||||
> · {{ t('chat.shippingNoticeDuplicatePossibleBadge') }}</span>
|
||||
<span
|
||||
v-else-if="a.parseStatus === 'parsed' && !a.candidates?.length && a.duplicate?.blocking && !a.duplicateResolution?.action"
|
||||
class="font-medium text-amber-700"
|
||||
> · {{ t('chat.shippingNoticeDuplicateBlockingBadge') }}</span>
|
||||
<span
|
||||
v-else-if="a.parseStatus === 'parsed' && a.duplicateResolution?.action === 'create_revision'"
|
||||
class="text-brand-700"
|
||||
> · {{ t('chat.shippingNoticeDuplicateRevisionChosen') }}</span>
|
||||
<span
|
||||
v-else-if="a.parseStatus === 'parsed' && a.duplicateResolution?.action === 'force_create'"
|
||||
class="text-amber-700"
|
||||
> · {{ t('chat.shippingNoticeDuplicateForceChosen') }}</span>
|
||||
<span
|
||||
v-else-if="a.parseStatus === 'parsed' && a.duplicateResolution?.action === 'open_existing'"
|
||||
class="text-muted"
|
||||
> · {{ t('chat.shippingNoticeDuplicateOpenChosen') }}</span>
|
||||
<span
|
||||
v-else-if="a.parseStatus === 'parsed'"
|
||||
class="text-muted"
|
||||
:title="shippingNoticeAttachmentTitle(a)"
|
||||
>
|
||||
· {{ t('chat.shippingNoticeParsed') }}
|
||||
<template v-if="shippingNoticeAttachmentHint(a)">
|
||||
· {{ shippingNoticeAttachmentHint(a) }}
|
||||
</template>
|
||||
</span>
|
||||
<span v-else-if="a.parseStatus === 'failed'" class="text-muted"> · {{ t('chat.shippingNoticeParseFailed') }}</span>
|
||||
</template>
|
||||
<template v-else>
|
||||
{{ a.kind === 'local' ? a.file.name : a.url }}
|
||||
</template>
|
||||
</span>
|
||||
<button
|
||||
v-if="a.kind === 'shipping_notice' && !a.candidates?.length && a.duplicate?.blocking && !a.duplicateResolution?.action"
|
||||
type="button"
|
||||
class="text-amber-700 hover:text-amber-800"
|
||||
:title="t('chat.shippingNoticeDuplicateHandle')"
|
||||
@click="emit('resolve-shipping-notice-duplicate', a.id)"
|
||||
>
|
||||
{{ t('chat.shippingNoticeDuplicateHandle') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="a.kind === 'shipping_notice' && canRetryShippingNoticeParse(a)"
|
||||
type="button"
|
||||
class="text-muted hover:text-primary"
|
||||
:title="t('chat.shippingNoticeRetryParse')"
|
||||
@click="emit('retry-shipping-notice-attachment', a.id)"
|
||||
>
|
||||
<RefreshCw class="h-3.5 w-3.5" />
|
||||
</button>
|
||||
<button type="button" class="text-muted hover:text-red-500" @click="emit('remove-attachment', a.id)">
|
||||
<X class="h-3.5 w-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="isShippingNoticeAgent && attachments.length > 0"
|
||||
class="flex flex-wrap items-center gap-2 px-3 pb-1 text-xs text-muted"
|
||||
|
||||
@@ -11,6 +11,7 @@ import ChatLeaveAgentDialog from '@/features/chat/components/ChatLeaveAgentDialo
|
||||
import ChatOALoginDialog from '@/features/chat/components/ChatOALoginDialog.vue';
|
||||
import ChatGuideModal from '@/features/chat/components/ChatGuideModal.vue';
|
||||
import ShippingNoticeDuplicateDialog from '@/features/chat/components/ShippingNoticeDuplicateDialog.vue';
|
||||
import ShippingCustomerConfirmDialog from '@/features/chat/components/ShippingCustomerConfirmDialog.vue';
|
||||
import { Check, Loader2, X } from 'lucide-vue-next';
|
||||
import { nextTick } from 'vue';
|
||||
import { useChatPageContext } from '@/features/chat/composables/chat.context';
|
||||
@@ -155,4 +156,12 @@ async function handleQueryPreviewAssetImage(assetId: string, assetName: string)
|
||||
@remove="() => void page.removeShippingDuplicateDialogAttachment?.()"
|
||||
@cancel="page.closeShippingDuplicateDialog?.()"
|
||||
/>
|
||||
<ShippingCustomerConfirmDialog
|
||||
:open="!!page.showShippingCustomerDialog"
|
||||
:options="page.shippingCustomerOptions || []"
|
||||
:loading="!!page.shippingCustomerLoading"
|
||||
@close="page.closeShippingCustomerDialog?.()"
|
||||
@search="(query) => void page.searchShippingCustomers?.(query)"
|
||||
@confirm="(customerId) => void page.confirmShippingCustomer?.(customerId)"
|
||||
/>
|
||||
</template>
|
||||
@@ -563,7 +563,12 @@ const handleSwitchBatch = (batchNo: string) => {
|
||||
></div>
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div class="min-w-0">
|
||||
<div class="truncate font-mono text-sm font-bold text-primary">{{ task.task_no }}</div>
|
||||
<div class="truncate font-mono text-sm font-bold text-primary">
|
||||
{{ task.business_no || task.task_no }}
|
||||
</div>
|
||||
<div v-if="task.business_no" class="mt-0.5 truncate font-mono text-[10px] text-muted">
|
||||
{{ t('chat.shippingNoticeUi.technicalTaskNo', { taskNo: task.task_no }) }}
|
||||
</div>
|
||||
<div class="mt-0.5 truncate text-xs text-muted">
|
||||
{{ task.source_file_name || task.customer_name || t('chat.shippingNoticeUi.currentNotice') }}
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<!--
|
||||
features/chat/components/ShippingCustomerConfirmDialog.vue
|
||||
用途:在 customer_review 检查点搜索并确认启用标准客户。
|
||||
依赖:ShippingCustomerOption、vue-i18n。
|
||||
逻辑:父 composable 提供选项与提交动作;本组件不解析邮件客户名,也不创建客户资料。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import type { ShippingCustomerOption } from '@/features/chat/types/shipping.api.types';
|
||||
|
||||
const props = defineProps<{ open: boolean; options: ShippingCustomerOption[]; loading: boolean }>();
|
||||
const emit = defineEmits<{ close: []; search: [query: string]; confirm: [customerId: number] }>();
|
||||
const { t } = useI18n();
|
||||
const query = ref('');
|
||||
const selectedId = ref<number | null>(null);
|
||||
|
||||
/** 每次打开对话框时清空上次选择。 */
|
||||
watch(() => props.open, (open) => {
|
||||
if (open) {
|
||||
query.value = '';
|
||||
selectedId.value = null;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="open" class="admin-modal-overlay animate-fade-in items-center z-[170]">
|
||||
<div class="admin-modal-panel max-w-xl max-h-[90vh] scale-100">
|
||||
<div class="px-6 py-5 border-b border-subtle"><h3 class="section-title">{{ t('chat.shippingCustomer.title') }}</h3><p class="section-desc mt-1">{{ t('chat.shippingCustomer.subtitle') }}</p></div>
|
||||
<div class="px-6 py-5 space-y-4 overflow-y-auto">
|
||||
<div class="flex gap-2"><input v-model="query" class="input-field text-sm" :placeholder="t('chat.shippingCustomer.searchPlaceholder')" @keyup.enter="emit('search', query)" /><button type="button" class="btn-ghost" @click="emit('search', query)">{{ t('chat.shippingCustomer.search') }}</button></div>
|
||||
<div class="space-y-2 max-h-80 overflow-y-auto">
|
||||
<label v-for="customer in options" :key="customer.id" class="flex items-center gap-3 rounded-xl border border-default p-3 cursor-pointer hover:border-brand-300"><input v-model="selectedId" type="radio" :value="customer.id" /><span class="flex-1"><span class="font-medium text-primary">{{ customer.standard_name }}</span><span class="ml-2 font-mono text-xs text-muted">{{ customer.short_code }}</span></span></label>
|
||||
<div v-if="!loading && !options.length" class="text-sm text-muted py-8 text-center">{{ t('chat.shippingCustomer.empty') }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-modal-footer"><button type="button" class="btn-ghost" @click="emit('close')">{{ t('common.cancel') }}</button><button type="button" class="btn-primary" :disabled="!selectedId || loading" @click="selectedId && emit('confirm', selectedId)">{{ t('chat.shippingCustomer.confirm') }}</button></div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -14,7 +14,7 @@ interface EditableCandidateLine {
|
||||
sku: string;
|
||||
qty: string;
|
||||
reservation_id: string;
|
||||
hub_code: string;
|
||||
source_type: string;
|
||||
uom: string;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,12 @@ watch(() => props.attachment.candidates, () => {
|
||||
}
|
||||
});
|
||||
|
||||
/** 将 Candidate 摘要投影为业务用户可编辑的 PO、SKU、Qty、Reservation 与 Hub 字段。 */
|
||||
/**
|
||||
* 将 Candidate 摘要投影为可编辑的 PO 与订单行。
|
||||
* 核心逻辑:保留原始扩展字段,并显式映射 SKU、数量、Reservation ID、Source Type 与单位。
|
||||
* @param candidateNo - 待编辑的 Candidate 编号
|
||||
* @returns 无返回值;Candidate 不存在时保持当前编辑状态
|
||||
*/
|
||||
function startEdit(candidateNo: string): void {
|
||||
const candidate = candidates.value.find((item) => item.candidateNo === candidateNo);
|
||||
if (!candidate) return;
|
||||
@@ -58,30 +63,41 @@ function startEdit(candidateNo: string): void {
|
||||
sku: String(line.sku || ''),
|
||||
qty: String(line.qty ?? ''),
|
||||
reservation_id: String(line.reservation_id || ''),
|
||||
hub_code: String(line.hub_code || ''),
|
||||
source_type: String(line.source_type || ''),
|
||||
uom: String(line.uom || 'EA'),
|
||||
})));
|
||||
if (!editLines.length) addLine();
|
||||
editError.value = '';
|
||||
}
|
||||
|
||||
/** 新增一条待修订订单行。 */
|
||||
/**
|
||||
* 新增一条待修订订单行。
|
||||
* 核心逻辑:创建带可选 Source Type 路由线索的空白草稿。
|
||||
* @returns 无返回值
|
||||
*/
|
||||
function addLine(): void {
|
||||
editLines.push({ source: {}, sku: '', qty: '', reservation_id: '', hub_code: '', uom: 'EA' });
|
||||
editLines.push({ source: {}, sku: '', qty: '', reservation_id: '', source_type: '', uom: 'EA' });
|
||||
}
|
||||
|
||||
/** 校验所有订单行后提交,不允许空 SKU、非正数数量或空行静默通过。 */
|
||||
/**
|
||||
* 校验并提交 Candidate 修订。
|
||||
* 核心逻辑:保留原始扩展字段,并将 Source Type 作为唯一可选库存路由线索提交。
|
||||
* @returns 无返回值;校验失败时写入本地错误提示
|
||||
*/
|
||||
function saveEdit(): void {
|
||||
const candidate = candidates.value.find((item) => item.candidateNo === editingCandidateNo.value);
|
||||
if (!candidate || !editLines.length) return;
|
||||
const normalizedLines = editLines.map((line) => ({
|
||||
...line.source,
|
||||
sku: line.sku.trim(),
|
||||
qty: Number(line.qty),
|
||||
reservation_id: line.reservation_id.trim() || undefined,
|
||||
hub_code: line.hub_code.trim() || undefined,
|
||||
uom: line.uom.trim() || 'EA',
|
||||
}));
|
||||
const normalizedLines = editLines.map((line) => {
|
||||
const source = { ...line.source };
|
||||
return {
|
||||
...source,
|
||||
sku: line.sku.trim(),
|
||||
qty: Number(line.qty),
|
||||
reservation_id: line.reservation_id.trim() || undefined,
|
||||
source_type: line.source_type.trim() || undefined,
|
||||
uom: line.uom.trim() || 'EA',
|
||||
};
|
||||
});
|
||||
if (normalizedLines.some((line) => !line.sku || !Number.isFinite(line.qty) || line.qty <= 0)) {
|
||||
editError.value = t('chat.shippingCandidateInvalidLine');
|
||||
return;
|
||||
@@ -200,7 +216,7 @@ function submitForceCreate(candidateNo: string): void {
|
||||
<input v-model="line.sku" :placeholder="t('chat.shippingCandidateSku')" class="rounded border border-default px-2 py-1" />
|
||||
<input v-model="line.qty" type="number" min="0.0001" step="any" :placeholder="t('chat.shippingCandidateQty')" class="rounded border border-default px-2 py-1" />
|
||||
<input v-model="line.reservation_id" :placeholder="t('chat.shippingCandidateReservation')" class="rounded border border-default px-2 py-1" />
|
||||
<input v-model="line.hub_code" :placeholder="t('chat.shippingCandidateHubCode')" class="rounded border border-default px-2 py-1" />
|
||||
<input v-model="line.source_type" :placeholder="t('chat.shippingCandidateSourceType')" class="rounded border border-default px-2 py-1" />
|
||||
<div class="flex gap-1">
|
||||
<input v-model="line.uom" :placeholder="t('chat.shippingCandidateUom')" class="min-w-0 flex-1 rounded border border-default px-2 py-1" />
|
||||
<button v-if="editLines.length > 1" type="button" class="text-red-600" @click="editLines.splice(index, 1)">×</button>
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* features/chat/components/messages/ChatMessageAttachmentList.vue
|
||||
* 用途:在用户消息中展示已发送附件快照。
|
||||
* 依赖:lucide 文件图标、attachmentCard.utils 的大小格式化、chat.types 的消息附件契约。
|
||||
* 逻辑:ChatMessageBubble 将当前用户消息附件传入;本组件只读展示,不提供删除、重试或上传状态操作。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { FileAudio, FileImage, FileText, FileVideo, Link2 } from 'lucide-vue-next';
|
||||
import { formatAttachmentSize } from '../../utils/attachmentCard.utils';
|
||||
import type { ChatMessageAttachment } from '../../types/chat.types';
|
||||
|
||||
const { attachments } = defineProps<{
|
||||
attachments: ChatMessageAttachment[];
|
||||
}>();
|
||||
|
||||
/** 根据附件来源与业务类型选择只读消息卡片图标。 */
|
||||
function attachmentIcon(attachment: ChatMessageAttachment) {
|
||||
if (attachment.source === 'remote') return Link2;
|
||||
if (attachment.type === 'image') return FileImage;
|
||||
if (attachment.type === 'audio') return FileAudio;
|
||||
if (attachment.type === 'video') return FileVideo;
|
||||
return FileText;
|
||||
}
|
||||
|
||||
/** 生成附件类型徽标,优先使用快照扩展名。 */
|
||||
function attachmentBadge(attachment: ChatMessageAttachment): string {
|
||||
const extension = String(attachment.extension || '').trim().toUpperCase();
|
||||
if (extension) return extension.slice(0, 5);
|
||||
if (attachment.source === 'remote') return 'URL';
|
||||
return attachment.type.toUpperCase().slice(0, 5);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-if="attachments.length > 0"
|
||||
data-testid="chat-message-attachment-list"
|
||||
class="mb-2 flex w-full flex-wrap justify-end gap-2"
|
||||
>
|
||||
<article
|
||||
v-for="(attachment, attachmentIndex) in attachments"
|
||||
:key="attachment.id || `${attachment.name}-${attachment.size ?? 'unknown'}-${attachmentIndex}`"
|
||||
class="flex min-w-0 basis-full items-center gap-2.5 rounded-xl border border-default bg-surface px-3 py-2.5 shadow-sm dark:bg-slate-900 sm:basis-[calc(50%-0.25rem)] sm:min-w-[220px] sm:max-w-[290px]"
|
||||
:title="attachment.name"
|
||||
>
|
||||
<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"
|
||||
>
|
||||
<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>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,14 +1,29 @@
|
||||
/**
|
||||
* features/chat/components/messages/ChatMessageBubble.vue
|
||||
* 用途:渲染单条聊天消息,统一承接用户气泡、助手 Markdown、内嵌文件下载、请假/出货子组件与操作栏。
|
||||
* 依赖:Vue computed、lucide 图标、Leave/Shipping 子消息组件、chat.types 与页面级 handlers。
|
||||
* 逻辑:由 ChatMessageList 按消息逐条挂载;正文渲染与特殊交互委托 useChatPageMarkdown 等页面编排层提供的 handlers。
|
||||
* 依赖:Vue computed、lucide 图标、消息附件/Leave/Shipping 子组件、chat.types 与页面级 handlers。
|
||||
* 逻辑:由 ChatMessageList 按消息逐条挂载;用户附件显示在文字气泡上方,助手正文与特殊交互委托页面 handlers。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, ref, watch } from 'vue';
|
||||
import { Check, Copy, Download, Edit2, Eye, LayoutGrid, MessageSquareText, RotateCw, X } from 'lucide-vue-next';
|
||||
import {
|
||||
Check,
|
||||
CircleCheck,
|
||||
CircleX,
|
||||
Copy,
|
||||
Download,
|
||||
Edit2,
|
||||
Eye,
|
||||
LayoutGrid,
|
||||
LoaderCircle,
|
||||
MessageSquareText,
|
||||
RotateCw,
|
||||
TriangleAlert,
|
||||
X,
|
||||
} from 'lucide-vue-next';
|
||||
import { useAuthStore } from '@/features/auth/stores/auth.store';
|
||||
import LeaveMessageBlock, { type LeaveMessageHandlers } from './LeaveMessageBlock.vue';
|
||||
import ChatMessageAttachmentList from './ChatMessageAttachmentList.vue';
|
||||
import MaintenanceDeviceResultCard from './MaintenanceDeviceResultCard.vue';
|
||||
import ShippingInventoryMappingMessage, { type ShippingMappingHandlers } from './ShippingInventoryMappingMessage.vue';
|
||||
import ShippingMatchResultCard from './ShippingMatchResultCard.vue';
|
||||
@@ -109,12 +124,30 @@ const showSourceSection = computed(() => {
|
||||
|| sourceLinks.value.length > 0;
|
||||
});
|
||||
|
||||
const showActions = computed(() => message.type !== 'leave-form');
|
||||
const hasUserContent = computed(() => message.role === 'user' && String(message.content || '').trim().length > 0);
|
||||
const showActions = computed(() => (
|
||||
message.type !== 'leave-form'
|
||||
&& (message.role !== 'user' || hasUserContent.value)
|
||||
));
|
||||
const showShippingActionsPanel = computed(() =>
|
||||
isShippingNoticeAgent
|
||||
&& !!message.shipping_actions?.length
|
||||
&& message.type !== 'shipping-match-result',
|
||||
);
|
||||
const shippingOrderExtractionState = computed(() => message.shipping_order_extraction_state);
|
||||
const shippingOrderExtractionTitleKey = computed(() => {
|
||||
switch (shippingOrderExtractionState.value?.status) {
|
||||
case 'completed': return 'chat.shippingOrderExtractionCompleted';
|
||||
case 'partially_completed': return 'chat.shippingOrderExtractionPartiallyCompleted';
|
||||
case 'failed': return 'chat.shippingOrderExtractionFailed';
|
||||
default: return 'chat.shippingOrderExtractionProcessing';
|
||||
}
|
||||
});
|
||||
const showShippingOrderExtractionMessage = computed(() => {
|
||||
const stateMessage = String(shippingOrderExtractionState.value?.message || '').trim();
|
||||
const assistantContent = String(message.content || '').trim();
|
||||
return !!stateMessage && stateMessage !== assistantContent && !assistantContent.includes(stateMessage);
|
||||
});
|
||||
const isLastMessage = computed(() => index === messageCount - 1 || (message.role === 'assistant' && isLatestAssistantMessage));
|
||||
const isCopied = computed(() => copiedIndex === index);
|
||||
const renderedMarkdown = computed(() => (
|
||||
@@ -622,7 +655,12 @@ function handleInlineDownload(file: InlineDownloadFile): void {
|
||||
class="flex flex-col"
|
||||
:class="message.role === 'user' ? 'max-w-[88%] md:max-w-[74%] items-end' : 'w-full'"
|
||||
>
|
||||
<ChatMessageAttachmentList
|
||||
v-if="message.role === 'user' && message.attachments?.length"
|
||||
:attachments="message.attachments"
|
||||
/>
|
||||
<div
|
||||
v-if="message.role === 'assistant' || hasUserContent"
|
||||
class="text-[15px] leading-relaxed"
|
||||
:class="message.role === 'user'
|
||||
? 'rounded-2xl rounded-tr-sm bg-brand-600 px-5 py-2.5 text-white shadow-sm shadow-brand-500/15'
|
||||
@@ -630,6 +668,80 @@ function handleInlineDownload(file: InlineDownloadFile): void {
|
||||
>
|
||||
<div v-if="message.role === 'user'" class="whitespace-pre-wrap">{{ message.content }}</div>
|
||||
<div v-else>
|
||||
<div
|
||||
v-if="shippingOrderExtractionState"
|
||||
class="mb-3 flex min-h-[60px] items-start gap-3 rounded-lg border px-3.5 py-3"
|
||||
:class="{
|
||||
'border-sky-200 bg-sky-50/80 text-sky-900 dark:border-sky-800 dark:bg-sky-950/35 dark:text-sky-100': shippingOrderExtractionState.status === 'extracting',
|
||||
'border-emerald-200 bg-emerald-50/80 text-emerald-900 dark:border-emerald-800 dark:bg-emerald-950/35 dark:text-emerald-100': shippingOrderExtractionState.status === 'completed',
|
||||
'border-amber-200 bg-amber-50/80 text-amber-950 dark:border-amber-800 dark:bg-amber-950/35 dark:text-amber-100': shippingOrderExtractionState.status === 'partially_completed',
|
||||
'border-rose-200 bg-rose-50/80 text-rose-900 dark:border-rose-800 dark:bg-rose-950/35 dark:text-rose-100': shippingOrderExtractionState.status === 'failed',
|
||||
}"
|
||||
>
|
||||
<LoaderCircle
|
||||
v-if="shippingOrderExtractionState.status === 'extracting'"
|
||||
class="mt-0.5 h-5 w-5 shrink-0 animate-spin"
|
||||
/>
|
||||
<CircleCheck
|
||||
v-else-if="shippingOrderExtractionState.status === 'completed'"
|
||||
class="mt-0.5 h-5 w-5 shrink-0"
|
||||
/>
|
||||
<TriangleAlert
|
||||
v-else-if="shippingOrderExtractionState.status === 'partially_completed'"
|
||||
class="mt-0.5 h-5 w-5 shrink-0"
|
||||
/>
|
||||
<CircleX v-else class="mt-0.5 h-5 w-5 shrink-0" />
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="text-sm font-semibold">{{ $t(shippingOrderExtractionTitleKey) }}</div>
|
||||
<div
|
||||
data-testid="shipping-order-extraction-progress"
|
||||
class="mt-2 h-1.5 w-full overflow-hidden rounded-full bg-black/10 dark:bg-white/15"
|
||||
role="progressbar"
|
||||
:aria-label="$t(shippingOrderExtractionTitleKey)"
|
||||
aria-valuemin="0"
|
||||
aria-valuemax="100"
|
||||
:aria-valuenow="shippingOrderExtractionState.terminal ? 100 : undefined"
|
||||
:aria-busy="shippingOrderExtractionState.status === 'extracting'"
|
||||
>
|
||||
<div
|
||||
v-if="shippingOrderExtractionState.status === 'extracting'"
|
||||
class="shipping-order-extraction-indeterminate h-full w-2/5 rounded-full bg-sky-500"
|
||||
/>
|
||||
<div
|
||||
v-else
|
||||
class="h-full w-full rounded-full"
|
||||
:class="{
|
||||
'bg-emerald-500': shippingOrderExtractionState.status === 'completed',
|
||||
'bg-amber-500': shippingOrderExtractionState.status === 'partially_completed',
|
||||
'bg-rose-500': shippingOrderExtractionState.status === 'failed',
|
||||
}"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
v-if="shippingOrderExtractionState.terminal"
|
||||
class="mt-1 flex flex-wrap gap-x-3 gap-y-1 text-xs"
|
||||
>
|
||||
<span v-if="shippingOrderExtractionState.created_count > 0">
|
||||
{{ $t('chat.shippingOrderExtractionCreatedCount', { count: shippingOrderExtractionState.created_count }) }}
|
||||
</span>
|
||||
<span v-if="shippingOrderExtractionState.opened_existing_count > 0">
|
||||
{{ $t('chat.shippingOrderExtractionOpenedExistingCount', { count: shippingOrderExtractionState.opened_existing_count }) }}
|
||||
</span>
|
||||
<span v-if="shippingOrderExtractionState.pending_count > 0">
|
||||
{{ $t('chat.shippingOrderExtractionPendingCount', { count: shippingOrderExtractionState.pending_count }) }}
|
||||
</span>
|
||||
<span v-if="shippingOrderExtractionState.non_shipping_count > 0">
|
||||
{{ $t('chat.shippingOrderExtractionIgnoredCount', { count: shippingOrderExtractionState.non_shipping_count }) }}
|
||||
</span>
|
||||
<span v-if="shippingOrderExtractionState.created_with_missing_fields_count > 0">
|
||||
{{ $t('chat.shippingOrderExtractionMissingFieldsCount', { count: shippingOrderExtractionState.created_with_missing_fields_count }) }}
|
||||
</span>
|
||||
</div>
|
||||
<div v-if="showShippingOrderExtractionMessage" class="mt-1 break-words text-xs opacity-80">
|
||||
{{ shippingOrderExtractionState.message }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<LeaveMessageBlock
|
||||
v-if="isLeaveMessage"
|
||||
:message="message"
|
||||
@@ -1034,6 +1146,28 @@ function handleInlineDownload(file: InlineDownloadFile): void {
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.shipping-order-extraction-indeterminate {
|
||||
animation: shipping-order-extraction-progress 1.25s ease-in-out infinite;
|
||||
will-change: transform;
|
||||
}
|
||||
|
||||
@keyframes shipping-order-extraction-progress {
|
||||
from {
|
||||
transform: translateX(-100%);
|
||||
}
|
||||
|
||||
to {
|
||||
transform: translateX(250%);
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.shipping-order-extraction-indeterminate {
|
||||
animation: none;
|
||||
transform: translateX(75%);
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.chat-markdown) {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user