878 lines
39 KiB
Vue
878 lines
39 KiB
Vue
/**
|
||
* features/chat/components/ChatInputBar.vue
|
||
* 用途:承载聊天文本输入、附件预览、语音、知识库选择与发送操作。
|
||
* 依赖:lucide 图标、附件完整性判断工具。
|
||
* 逻辑:附件卡片位于文本框上方;订单审核结果随对应聊天消息展示,输入区只保留附件处理状态。
|
||
* 同时支持采购合同双文件输入控件:底部左区放附件/合同等工具,右区语音与发送并排;采购合同审查用专用上传按钮,不展示通用回形针附件入口。
|
||
*/
|
||
<script setup lang="ts">
|
||
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||
import { useI18n } from 'vue-i18n';
|
||
import type { Ref } from 'vue';
|
||
import {
|
||
Check,
|
||
CircleAlert,
|
||
CircleCheck,
|
||
FileAudio,
|
||
FileImage,
|
||
FileText,
|
||
FileVideo,
|
||
Link2,
|
||
Loader2,
|
||
Mic,
|
||
Paperclip,
|
||
RefreshCw,
|
||
Send,
|
||
Square,
|
||
Upload,
|
||
X,
|
||
} from 'lucide-vue-next';
|
||
import type { ContractReviewMode } from '../composables/useProcurementContractChat';
|
||
import type { PendingAttachment, ShippingNoticePendingAttachment } from '../types/shipping.types';
|
||
import {
|
||
isBlockingWarning,
|
||
isShippingNoticeAttachmentParseIncomplete,
|
||
} from '../shipping/shippingNoticeAttachmentIntegrity';
|
||
import {
|
||
getAttachmentCardStatus,
|
||
getAttachmentExtension,
|
||
getAttachmentName,
|
||
getAttachmentSize,
|
||
isAttachmentRemoveDisabled,
|
||
} from '../utils/attachmentCard.utils';
|
||
|
||
export interface ChatInputAttachmentPolicy {
|
||
anyEnabled: boolean;
|
||
canLocal: boolean;
|
||
canRemote: boolean;
|
||
accept: string;
|
||
}
|
||
|
||
const inputValue = defineModel<string>({ required: true });
|
||
const procurementReviewMode = defineModel<ContractReviewMode>('procurementReviewMode', { default: 'compare' });
|
||
|
||
const props = defineProps<{
|
||
attachments: PendingAttachment[];
|
||
attachmentPolicy: ChatInputAttachmentPolicy;
|
||
isThinking: boolean;
|
||
isVoiceRecording: boolean;
|
||
isVoiceTranscribing: boolean;
|
||
isUploadingAttachments: boolean;
|
||
canSendMessage: boolean;
|
||
isShippingNoticeAgent: boolean;
|
||
isProcurementContractAgent?: boolean;
|
||
procurementOriginalContractName?: string | null;
|
||
isMaintenanceAgent?: boolean;
|
||
canManageMaintenance?: boolean;
|
||
canForceCreateShippingDuplicate?: boolean;
|
||
shippingSuggestedPrompt: string;
|
||
shippingFocusTaskNo?: string;
|
||
shippingFocusReason?: string;
|
||
/** 用对象包裹 Ref,避免 template 自动解包 */
|
||
shippingPickerRefHolder: { pickerRef: Ref<HTMLInputElement | null> };
|
||
shippingNoticePickerRefHolder: { pickerRef: Ref<HTMLInputElement | null> };
|
||
}>();
|
||
|
||
const emit = defineEmits<{
|
||
send: [];
|
||
stop: [];
|
||
'voice-click': [];
|
||
'remove-attachment': [id: string];
|
||
'retry-attachment': [id: string];
|
||
'retry-shipping-notice-attachment': [id: string];
|
||
'resolve-shipping-notice-duplicate': [id: string];
|
||
'select-shipping-candidate': [candidateNo: string, selected: boolean];
|
||
'resolve-shipping-candidate-duplicate': [candidateNo: string, action: import('../types/shipping.types').ShippingDuplicateAction, targetTaskNo: string | undefined, reason: string | undefined, done: (success: boolean) => void];
|
||
'local-files-selected': [event: Event];
|
||
'add-remote-url': [url: string];
|
||
'shipping-inventory-selected': [event: Event];
|
||
'use-shipping-suggested-prompt': [];
|
||
'maintenance-ledger-config': [];
|
||
'maintenance-create-record': [];
|
||
'clear-shipping-focus': [];
|
||
'procurement-original-contract-selected': [event: Event];
|
||
'clear-procurement-original-contract': [];
|
||
}>();
|
||
|
||
const filePickerRef = ref<HTMLInputElement | null>(null);
|
||
const originalContractPickerRef = ref<HTMLInputElement | null>(null);
|
||
const { t } = useI18n();
|
||
const textareaRef = ref<HTMLTextAreaElement | null>(null);
|
||
const attachmentMenuRef = ref<HTMLElement | null>(null);
|
||
const attachmentUrlInputRef = ref<HTMLInputElement | null>(null);
|
||
const showAttachmentMenu = ref(false);
|
||
const showAttachmentUrlPanel = ref(false);
|
||
const attachmentUrlInput = ref('');
|
||
const attachmentScrollerRef = ref<HTMLElement | null>(null);
|
||
const attachmentCanScrollLeft = ref(false);
|
||
const attachmentCanScrollRight = ref(false);
|
||
let attachmentDragStartX = 0;
|
||
let attachmentDragScrollLeft = 0;
|
||
let attachmentDragging = false;
|
||
|
||
/** 同步附件横向带的左右可滚动状态,供箭头按钮和无障碍状态使用。 */
|
||
function updateAttachmentScrollState() {
|
||
const element = attachmentScrollerRef.value;
|
||
if (!element) return;
|
||
attachmentCanScrollLeft.value = element.scrollLeft > 1;
|
||
attachmentCanScrollRight.value = element.scrollLeft + element.clientWidth < element.scrollWidth - 1;
|
||
}
|
||
|
||
/** 按固定步长移动附件横向带,避免大量附件撑高输入区。 */
|
||
function scrollAttachments(direction: 'left' | 'right') {
|
||
attachmentScrollerRef.value?.scrollBy({ left: direction === 'left' ? -320 : 320, behavior: 'smooth' });
|
||
}
|
||
|
||
/** 开始桌面端指针拖拽;触摸端交给原生横向滚动,避免手势冲突。 */
|
||
function startAttachmentDrag(event: PointerEvent) {
|
||
const element = attachmentScrollerRef.value;
|
||
if (!element || event.pointerType === 'touch') return;
|
||
attachmentDragging = true;
|
||
attachmentDragStartX = event.clientX;
|
||
attachmentDragScrollLeft = element.scrollLeft;
|
||
element.setPointerCapture?.(event.pointerId);
|
||
}
|
||
|
||
/** 根据指针位移更新附件横向滚动位置。 */
|
||
function moveAttachmentDrag(event: PointerEvent) {
|
||
if (!attachmentDragging || !attachmentScrollerRef.value) return;
|
||
attachmentScrollerRef.value.scrollLeft = attachmentDragScrollLeft - (event.clientX - attachmentDragStartX);
|
||
}
|
||
|
||
/** 结束附件横向拖拽并恢复普通指针状态。 */
|
||
function stopAttachmentDrag() {
|
||
attachmentDragging = false;
|
||
}
|
||
|
||
/** 当前发货通知是否仍在上传或预解析,决定输入框下方的操作提示。 */
|
||
const hasShippingNoticeInProgress = computed(() => props.attachments.some(
|
||
(attachment) => attachment.kind === 'shipping_notice'
|
||
&& (
|
||
attachment.uploadStatus === 'waiting'
|
||
|| attachment.uploadStatus === 'uploading'
|
||
|| ['waiting', 'queued', 'parsing'].includes(attachment.parseStatus)
|
||
),
|
||
));
|
||
|
||
const hasProcurementContractAttachment = computed(() =>
|
||
Boolean(props.isProcurementContractAgent)
|
||
&& props.attachments.some((item) => item.kind === 'local'),
|
||
);
|
||
|
||
/** 显示我方原合同卡片的文件扩展名;没有扩展名时使用通用文档标识。 */
|
||
function getProcurementOriginalContractExtension(name: string): string {
|
||
const extension = name.split('.').pop()?.trim();
|
||
return extension ? extension.toUpperCase().slice(0, 4) : 'DOC';
|
||
}
|
||
|
||
const procurementQuickActions = computed(() => {
|
||
const actions = [
|
||
{
|
||
label: 'chat.procurementContract.quickReview',
|
||
prompt: 'chat.procurementContract.promptReview',
|
||
},
|
||
{
|
||
label: 'chat.procurementContract.quickRisk',
|
||
prompt: 'chat.procurementContract.promptRisk',
|
||
},
|
||
];
|
||
if (procurementReviewMode.value === 'compare') {
|
||
actions.push({
|
||
label: 'chat.procurementContract.quickDiff',
|
||
prompt: 'chat.procurementContract.promptDiff',
|
||
});
|
||
}
|
||
actions.push({
|
||
label: 'chat.procurementContract.quickSuggestion',
|
||
prompt: 'chat.procurementContract.promptSuggestion',
|
||
});
|
||
return actions;
|
||
});
|
||
|
||
/**
|
||
* 汇总 EML 附件解析进度,供输入栏徽标展示。
|
||
* 核心逻辑:阶段 1 仅展示快览结果;优先说明发现了多少附件,技术失败/目录不完整再退化为问题提示。
|
||
*/
|
||
function shippingNoticeAttachmentHint(attachment: ShippingNoticePendingAttachment): string {
|
||
const summary = attachment.parseSummary;
|
||
const rows = summary?.attachments || [];
|
||
// 兼容旧摘要:早期快览未标记签名图,按内嵌标记、目录原因和图片 MIME 一并排除。
|
||
const businessRows = rows.filter((item) => {
|
||
const mimeType = String(item.mime_type || '').toLowerCase();
|
||
const catalogReason = String(item.catalog_reason || '').toLowerCase();
|
||
return !item.is_inline_resource
|
||
&& !mimeType.startsWith('image/')
|
||
&& catalogReason !== 'signature_or_logo'
|
||
&& catalogReason !== 'inline_resource';
|
||
});
|
||
const inlineCount = rows.length - businessRows.length;
|
||
const total = Math.max(0, Number(summary?.attachment_count || 0) - inlineCount);
|
||
const warnings = summary?.warnings || [];
|
||
const hasBlockingWarning = warnings.some((w) => isBlockingWarning(String(w || '')));
|
||
if (!total && !hasBlockingWarning && !businessRows.length) return '';
|
||
|
||
const effectiveTotal = total || businessRows.length;
|
||
const ok = Number(summary?.ready_attachment_count || businessRows.filter((item) => item.ready_for_extraction).length);
|
||
const problematic = businessRows.filter((item) =>
|
||
['failed', 'empty', 'skipped'].includes(String(item.parse_status || '')),
|
||
).length;
|
||
const duplicates = Number(
|
||
summary?.duplicate_attachment_count
|
||
|| businessRows.filter((item) => item.parse_status === 'duplicate').length,
|
||
);
|
||
const overflow = Math.max(0, effectiveTotal - businessRows.length);
|
||
const previewStatus = String(summary?.preview_status || '').trim().toLowerCase();
|
||
const issues = problematic
|
||
+ overflow
|
||
+ (hasBlockingWarning && problematic === 0 && overflow === 0 ? 1 : 0)
|
||
+ (
|
||
(summary?.technical_failure || previewStatus === 'technical_failed' || previewStatus === 'directory_incomplete')
|
||
&& problematic === 0
|
||
&& overflow === 0
|
||
? 1
|
||
: 0
|
||
);
|
||
|
||
if (issues > 0) {
|
||
return t('chat.shippingNoticeAttachmentHintPartial', {
|
||
ok,
|
||
total: effectiveTotal || Math.max(ok + issues, 1),
|
||
failed: issues,
|
||
});
|
||
}
|
||
if (duplicates > 0) {
|
||
return t('chat.shippingNoticeAttachmentHintDiscoveredWithDup', { total: effectiveTotal, duplicates });
|
||
}
|
||
if (!effectiveTotal) return '';
|
||
return t('chat.shippingNoticeAttachmentHintDiscovered', { total: effectiveTotal });
|
||
}
|
||
|
||
/**
|
||
* 是否展示「重试解析」:顶层失败,或已 parsed 但附件不完整。
|
||
*/
|
||
function canRetryShippingNoticeParse(attachment: ShippingNoticePendingAttachment): boolean {
|
||
if (attachment.kind !== 'shipping_notice') return false;
|
||
if (attachment.parseStatus === 'failed') return true;
|
||
return (
|
||
attachment.parseStatus === 'parsed'
|
||
&& isShippingNoticeAttachmentParseIncomplete(attachment.parseSummary)
|
||
);
|
||
}
|
||
|
||
/**
|
||
* 生成附件明细 title(文件名 + 状态 + 关键警告),便于悬停查看完整性。
|
||
*/
|
||
function shippingNoticeAttachmentTitle(attachment: ShippingNoticePendingAttachment): string {
|
||
const rows = attachment.parseSummary?.attachments || [];
|
||
const warnings = attachment.parseSummary?.warnings || [];
|
||
const lines: string[] = [];
|
||
for (const item of rows) {
|
||
const name = item.filename || item.attachment_key || 'attachment';
|
||
const status = item.parse_status || 'unknown';
|
||
lines.push(`${name}: ${status}`);
|
||
}
|
||
for (const warning of warnings) {
|
||
const text = String(warning || '').trim();
|
||
if (text) lines.push(`warning: ${text}`);
|
||
}
|
||
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;
|
||
attachmentUrlInput.value = '';
|
||
};
|
||
|
||
const toggleAttachmentMenu = () => {
|
||
if (props.isThinking || props.isUploadingAttachments) return;
|
||
showAttachmentMenu.value = !showAttachmentMenu.value;
|
||
if (!showAttachmentMenu.value) {
|
||
showAttachmentUrlPanel.value = false;
|
||
attachmentUrlInput.value = '';
|
||
}
|
||
};
|
||
|
||
const selectAttachmentLocal = () => {
|
||
if (!props.attachmentPolicy.canLocal) return;
|
||
closeAttachmentMenu();
|
||
filePickerRef.value?.click();
|
||
};
|
||
|
||
/**
|
||
* 采购合同 Agent 的主上传入口:比对模式选择卖方回传合同,单份模式选择待审合同。
|
||
*/
|
||
const selectProcurementContractLocal = () => {
|
||
if (!props.attachmentPolicy.canLocal || props.isThinking || props.isUploadingAttachments) return;
|
||
closeAttachmentMenu();
|
||
filePickerRef.value?.click();
|
||
};
|
||
|
||
const selectAttachmentUrl = async () => {
|
||
if (!props.attachmentPolicy.canRemote) return;
|
||
showAttachmentMenu.value = true;
|
||
showAttachmentUrlPanel.value = true;
|
||
await nextTick();
|
||
attachmentUrlInputRef.value?.focus();
|
||
};
|
||
|
||
const submitRemoteUrl = () => {
|
||
const raw = attachmentUrlInput.value.trim();
|
||
if (!raw) return;
|
||
emit('add-remote-url', raw);
|
||
closeAttachmentMenu();
|
||
};
|
||
|
||
/**
|
||
* 上传合同后的快捷审查动作:写入审查方案并立即发送。
|
||
*/
|
||
const runProcurementQuickAction = async (promptKey: string) => {
|
||
if (!hasProcurementContractAttachment.value || props.isThinking || props.isUploadingAttachments) return;
|
||
inputValue.value = t(promptKey);
|
||
await nextTick();
|
||
emit('send');
|
||
};
|
||
|
||
const bindShippingPickerRef = (el: unknown) => {
|
||
props.shippingPickerRefHolder.pickerRef.value = (el as HTMLInputElement | null) ?? null;
|
||
};
|
||
|
||
const bindShippingNoticePickerRef = (el: unknown) => {
|
||
props.shippingNoticePickerRefHolder.pickerRef.value = (el as HTMLInputElement | null) ?? null;
|
||
};
|
||
|
||
const bindAttachmentPickerRef = (el: unknown) => {
|
||
filePickerRef.value = (el as HTMLInputElement | null) ?? null;
|
||
bindShippingNoticePickerRef(el);
|
||
};
|
||
|
||
/**
|
||
* 点击输入栏外部时收起附件菜单。
|
||
*/
|
||
const handleDocumentPointerDown = (event: MouseEvent | TouchEvent) => {
|
||
const target = event.target as Node | null;
|
||
if (!target) return;
|
||
if (showAttachmentMenu.value && attachmentMenuRef.value && !attachmentMenuRef.value.contains(target)) {
|
||
closeAttachmentMenu();
|
||
}
|
||
};
|
||
|
||
onMounted(() => {
|
||
nextTick(updateAttachmentScrollState);
|
||
window.addEventListener('resize', updateAttachmentScrollState);
|
||
document.addEventListener('mousedown', handleDocumentPointerDown);
|
||
document.addEventListener('touchstart', handleDocumentPointerDown, { passive: true });
|
||
});
|
||
|
||
onBeforeUnmount(() => {
|
||
window.removeEventListener('resize', updateAttachmentScrollState);
|
||
document.removeEventListener('mousedown', handleDocumentPointerDown);
|
||
document.removeEventListener('touchstart', handleDocumentPointerDown);
|
||
});
|
||
|
||
watch(
|
||
() => props.isThinking,
|
||
async (thinking, prevThinking) => {
|
||
if (thinking || !prevThinking || props.isVoiceTranscribing) return;
|
||
await nextTick();
|
||
textareaRef.value?.focus();
|
||
},
|
||
);
|
||
|
||
watch(
|
||
() => inputValue.value,
|
||
async (value) => {
|
||
if (value) return;
|
||
await nextTick();
|
||
if (textareaRef.value && textareaRef.value.value !== '') {
|
||
textareaRef.value.value = '';
|
||
}
|
||
},
|
||
);
|
||
</script>
|
||
|
||
<template>
|
||
<footer class="safe-bottom z-20 shrink-0 bg-transparent p-2 md:p-3">
|
||
<div class="relative mx-auto max-w-4xl">
|
||
<div
|
||
v-if="isProcurementContractAgent"
|
||
class="mb-2 flex flex-wrap items-center gap-2"
|
||
>
|
||
<div
|
||
class="inline-flex items-center gap-1 rounded-full border border-[#d8e0ec] bg-[#eef2f7] p-[3px]"
|
||
role="tablist"
|
||
:aria-label="$t('chat.procurementContract.mode')"
|
||
>
|
||
<button
|
||
type="button"
|
||
role="tab"
|
||
class="rounded-full px-3 py-1.5 text-xs font-bold transition-all"
|
||
:class="procurementReviewMode === 'compare'
|
||
? 'bg-surface text-[#2f80d1] shadow-[0_1px_4px_rgba(23,32,51,0.08)]'
|
||
: 'bg-transparent text-[#667792] hover:text-[#172033]'"
|
||
:aria-selected="procurementReviewMode === 'compare'"
|
||
@click="procurementReviewMode = 'compare'"
|
||
>
|
||
{{ $t('chat.procurementContract.modeCompare') }}
|
||
</button>
|
||
<button
|
||
type="button"
|
||
role="tab"
|
||
class="rounded-full px-3 py-1.5 text-xs font-bold transition-all"
|
||
:class="procurementReviewMode === 'solo'
|
||
? 'bg-surface text-[#2f80d1] shadow-[0_1px_4px_rgba(23,32,51,0.08)]'
|
||
: 'bg-transparent text-[#667792] hover:text-[#172033]'"
|
||
:aria-selected="procurementReviewMode === 'solo'"
|
||
@click="procurementReviewMode = 'solo'"
|
||
>
|
||
{{ $t('chat.procurementContract.modeSolo') }}
|
||
</button>
|
||
</div>
|
||
<span class="text-xs text-[#667792]">
|
||
{{ $t(procurementReviewMode === 'compare'
|
||
? 'chat.procurementContract.compareHint'
|
||
: 'chat.procurementContract.soloHint') }}
|
||
</span>
|
||
</div>
|
||
|
||
<div class="flex flex-col rounded-2xl bg-surface p-1.5 shadow-[0_0_15px_rgba(0,0,0,0.05)] transition-all">
|
||
<div
|
||
v-if="isShippingNoticeAgent && shippingFocusTaskNo"
|
||
class="mb-2 flex items-center gap-2 rounded-xl bg-brand-500 px-3 py-2 text-xs font-medium text-white"
|
||
>
|
||
<span class="shrink-0">{{ $t('chat.shippingNoticeUi.currentFocus') }}</span>
|
||
<span class="rounded-md bg-white/15 px-2 py-0.5 font-mono">{{ shippingFocusTaskNo }}</span>
|
||
<span class="min-w-0 flex-1 truncate text-white/85">{{ shippingFocusReason || $t('chat.shippingNoticeUi.currentFocusDefaultReason') }}</span>
|
||
<button
|
||
type="button"
|
||
class="rounded-full p-1 text-white/80 transition hover:bg-white/15 hover:text-white"
|
||
:title="$t('chat.shippingNoticeUi.clearFocus')"
|
||
@click="emit('clear-shipping-focus')"
|
||
>
|
||
<X class="h-3.5 w-3.5" />
|
||
</button>
|
||
</div>
|
||
|
||
<div
|
||
v-if="attachments.length > 0 || (isProcurementContractAgent && procurementReviewMode === 'compare' && procurementOriginalContractName)"
|
||
data-testid="chat-attachment-list"
|
||
class="relative flex items-center gap-1 px-2.5 pb-2 pt-1"
|
||
>
|
||
<button v-if="attachmentCanScrollLeft" type="button" class="z-10 shrink-0 rounded-full border border-default bg-surface p-1 text-muted shadow-sm" aria-label="向左查看附件" @click="scrollAttachments('left')">‹</button>
|
||
<div
|
||
ref="attachmentScrollerRef"
|
||
class="flex min-w-0 flex-1 flex-nowrap gap-2 overflow-x-auto pb-1 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden"
|
||
:class="attachmentDragging ? 'cursor-grabbing select-none' : 'cursor-grab'"
|
||
@scroll="updateAttachmentScrollState"
|
||
@pointerdown="startAttachmentDrag"
|
||
@pointermove="moveAttachmentDrag"
|
||
@pointerup="stopAttachmentDrag"
|
||
@pointercancel="stopAttachmentDrag"
|
||
@pointerleave="stopAttachmentDrag"
|
||
>
|
||
<article
|
||
v-if="isProcurementContractAgent && procurementReviewMode === 'compare' && procurementOriginalContractName"
|
||
data-testid="procurement-original-contract-card"
|
||
class="group relative flex h-[68px] w-[250px] shrink-0 items-center gap-3 rounded-xl border border-[#9cc7f2] bg-[#eef6ff] px-3 py-2.5 transition-colors"
|
||
:title="procurementOriginalContractName"
|
||
>
|
||
<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"
|
||
>
|
||
<FileText class="h-4.5 w-4.5" />
|
||
<span class="mt-0.5 max-w-9 truncate text-[9px] font-bold leading-none">{{ getProcurementOriginalContractExtension(procurementOriginalContractName) }}</span>
|
||
</div>
|
||
<div class="min-w-0 flex-1 pr-5">
|
||
<p class="truncate text-sm font-medium text-primary">
|
||
<span class="mr-1 text-[#2f80d1]">{{ $t('chat.procurementContract.originalContractChip', { name: '' }) }}</span>
|
||
{{ procurementOriginalContractName }}
|
||
</p>
|
||
<div class="mt-1 flex min-w-0 items-center gap-1.5 text-[11px] leading-none text-muted">
|
||
<span>{{ $t('chat.attachment.pending') }}</span>
|
||
</div>
|
||
</div>
|
||
<button
|
||
type="button"
|
||
data-testid="remove-procurement-original-contract"
|
||
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"
|
||
:title="t('chat.attachment.remove')"
|
||
:aria-label="t('chat.attachment.removeNamed', { name: procurementOriginalContractName })"
|
||
@pointerdown.stop
|
||
@click.stop="emit('clear-procurement-original-contract')"
|
||
>
|
||
<X class="h-3.5 w-3.5" />
|
||
</button>
|
||
</article>
|
||
<article
|
||
v-for="a in attachments"
|
||
:key="a.id"
|
||
data-testid="chat-attachment-card"
|
||
class="group relative flex h-[68px] w-[250px] shrink-0 items-center gap-3 rounded-xl px-3 py-2.5 transition-colors"
|
||
:class="isProcurementContractAgent && a.kind === 'local'
|
||
? 'border border-[#9cc7f2] bg-[#eef6ff]'
|
||
: 'border border-default bg-surface-soft'"
|
||
: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">
|
||
<span v-if="isProcurementContractAgent" class="mr-1 text-[#2f80d1]">
|
||
{{ $t(procurementReviewMode === 'compare'
|
||
? 'chat.procurementContract.sellerReturnedContractLabel'
|
||
: 'chat.procurementContract.contractToReviewLabel') }}:
|
||
</span>
|
||
{{ 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-muted">·</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 === 'local' && a.uploadStatus === 'failed'"
|
||
class="absolute bottom-1.5 right-2 flex items-center gap-1"
|
||
>
|
||
<button
|
||
type="button"
|
||
class="rounded p-1 text-red-500 hover:bg-red-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand-400 disabled:cursor-not-allowed disabled:opacity-30 dark:hover:bg-red-950/30"
|
||
:disabled="isUploadingAttachments"
|
||
:title="t('chat.attachment.retry')"
|
||
:aria-label="t('chat.attachment.retryNamed', { name: getAttachmentName(a) })"
|
||
@click="emit('retry-attachment', a.id)"
|
||
>
|
||
<RefreshCw class="h-3.5 w-3.5" />
|
||
</button>
|
||
</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) })"
|
||
@pointerdown.stop
|
||
@click.stop="emit('remove-attachment', a.id)"
|
||
>
|
||
<X class="h-3.5 w-3.5" />
|
||
</button>
|
||
</article>
|
||
</div>
|
||
<button v-if="attachmentCanScrollRight" type="button" class="z-10 shrink-0 rounded-full border border-default bg-surface p-1 text-muted shadow-sm" aria-label="向右查看附件" @click="scrollAttachments('right')">›</button>
|
||
</div>
|
||
|
||
<input
|
||
:ref="bindShippingPickerRef"
|
||
type="file"
|
||
class="hidden"
|
||
accept=".xls,.xlsx,.csv,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,text/csv"
|
||
@change="emit('shipping-inventory-selected', $event)"
|
||
/>
|
||
|
||
<input
|
||
:ref="bindAttachmentPickerRef"
|
||
type="file"
|
||
multiple
|
||
class="hidden"
|
||
:accept="attachmentPolicy.accept || undefined"
|
||
@change="emit('local-files-selected', $event)"
|
||
/>
|
||
|
||
<input
|
||
ref="originalContractPickerRef"
|
||
type="file"
|
||
class="hidden"
|
||
accept=".pdf,.doc,.docx,.txt,.md"
|
||
@change="emit('procurement-original-contract-selected', $event)"
|
||
/>
|
||
|
||
<div
|
||
v-if="hasProcurementContractAttachment"
|
||
class="flex flex-wrap items-center gap-2 px-3 pb-1"
|
||
>
|
||
<button
|
||
v-for="action in procurementQuickActions"
|
||
:key="action.label"
|
||
type="button"
|
||
class="rounded-full border border-[#d8e0ec] bg-surface px-3 py-1.5 text-xs font-semibold text-[#31445f] transition-colors hover:border-[#2f80d1] hover:bg-[#eef6ff] hover:text-[#1f5f99] disabled:cursor-not-allowed disabled:opacity-50"
|
||
:disabled="isThinking || isUploadingAttachments"
|
||
@click="runProcurementQuickAction(action.prompt)"
|
||
>
|
||
{{ $t(action.label) }}
|
||
</button>
|
||
</div>
|
||
|
||
<div
|
||
v-if="isShippingNoticeAgent && attachments.length > 0"
|
||
class="flex flex-wrap items-center gap-2 px-3 pb-1 text-xs text-muted"
|
||
>
|
||
<button
|
||
type="button"
|
||
class="rounded-full border border-default bg-surface-soft px-3 py-1 font-medium text-secondary transition-colors hover:bg-surface-soft/70"
|
||
@click="emit('use-shipping-suggested-prompt')"
|
||
>
|
||
{{ shippingSuggestedPrompt || $t('chat.recommendedQuestion') }}
|
||
</button>
|
||
<span>{{ hasShippingNoticeInProgress ? t('chat.shippingNoticeWaitingForParse') : t('chat.shippingNoticeConfirmBatchHint') }}</span>
|
||
</div>
|
||
|
||
<textarea
|
||
ref="textareaRef"
|
||
v-model="inputValue"
|
||
rows="1"
|
||
:placeholder="isVoiceTranscribing ? $t('chat.voiceTranscribing') : isVoiceRecording ? $t('chat.voiceListening') : shippingFocusTaskNo ? $t('chat.shippingNoticeUi.focusInputPlaceholder', { taskId: shippingFocusTaskNo }) : isMaintenanceAgent ? $t('maintenance.chat.inputPlaceholder') : $t('chat.askAnything')"
|
||
class="w-full resize-none border-none bg-transparent px-2.5 py-1.5 text-[15px] leading-relaxed text-primary placeholder-slate-400 focus:border-transparent focus:outline-none focus:ring-0"
|
||
style="min-height: 40px; max-height: 220px;"
|
||
:disabled="isVoiceTranscribing"
|
||
spellcheck="false"
|
||
autocorrect="off"
|
||
autocapitalize="off"
|
||
@keydown.enter.prevent="emit('send')"
|
||
/>
|
||
|
||
<div class="mt-1.5 flex items-center justify-between gap-2 px-1.5 pb-0.5">
|
||
<div class="flex min-w-0 flex-1 flex-wrap items-center gap-2">
|
||
<div
|
||
v-if="attachmentPolicy.anyEnabled && !isProcurementContractAgent"
|
||
ref="attachmentMenuRef"
|
||
class="relative"
|
||
>
|
||
<button
|
||
type="button"
|
||
:disabled="isThinking || isUploadingAttachments"
|
||
:title="$t('chat.attachmentsUi.title')"
|
||
class="flex h-9 w-9 items-center justify-center rounded-lg text-muted transition-colors hover:text-brand-600 disabled:cursor-not-allowed disabled:opacity-50"
|
||
@click="toggleAttachmentMenu"
|
||
>
|
||
<Paperclip class="h-5 w-5" />
|
||
</button>
|
||
<div
|
||
v-if="showAttachmentMenu"
|
||
class="absolute bottom-full left-0 mb-2 w-72 animate-fade-in overflow-hidden rounded-xl border border-subtle bg-surface py-1 shadow-xl"
|
||
>
|
||
<button
|
||
v-if="attachmentPolicy.canLocal"
|
||
type="button"
|
||
class="flex w-full items-center gap-2 px-3 py-2 text-xs text-secondary transition-colors hover:bg-surface-soft"
|
||
@click="selectAttachmentLocal"
|
||
>
|
||
<Paperclip class="h-4 w-4 text-brand-500" />
|
||
{{ $t('chat.attachmentsUi.uploadLocal') }}
|
||
</button>
|
||
<button
|
||
v-if="attachmentPolicy.canRemote"
|
||
type="button"
|
||
class="flex w-full items-center gap-2 px-3 py-2 text-xs text-secondary transition-colors hover:bg-surface-soft"
|
||
@click="selectAttachmentUrl"
|
||
>
|
||
<Link2 class="h-4 w-4 text-brand-500" />
|
||
{{ $t('chat.attachmentsUi.pasteUrl') }}
|
||
</button>
|
||
<div v-if="showAttachmentUrlPanel" class="px-3 py-2">
|
||
<div class="flex items-center gap-2">
|
||
<input
|
||
ref="attachmentUrlInputRef"
|
||
v-model="attachmentUrlInput"
|
||
:disabled="isThinking || isUploadingAttachments"
|
||
:placeholder="$t('chat.attachmentsUi.urlPlaceholder')"
|
||
class="flex-1 rounded-lg border border-default bg-surface-soft px-3 py-2 text-xs text-secondary placeholder-slate-400 focus:outline-none focus:ring-0"
|
||
@keydown.enter.prevent="submitRemoteUrl"
|
||
/>
|
||
<button
|
||
type="button"
|
||
:disabled="isThinking || isUploadingAttachments"
|
||
class="flex h-9 w-9 items-center justify-center rounded-lg border border-default text-muted transition-colors hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-50"
|
||
:title="$t('chat.attachmentsUi.add')"
|
||
@click="submitRemoteUrl"
|
||
>
|
||
<Check class="h-4 w-4" />
|
||
</button>
|
||
<button
|
||
type="button"
|
||
:disabled="isThinking || isUploadingAttachments"
|
||
class="flex h-9 w-9 items-center justify-center rounded-lg border border-default text-muted transition-colors hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-50"
|
||
:title="$t('chat.attachmentsUi.cancel')"
|
||
@click="closeAttachmentMenu"
|
||
>
|
||
<X class="h-4 w-4" />
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div v-if="isProcurementContractAgent && procurementReviewMode === 'compare'" class="flex flex-wrap items-center gap-1.5">
|
||
<button
|
||
type="button"
|
||
class="flex items-center gap-1 rounded-full border border-[#8db8e6] bg-[#f8fbff] px-3 py-1.5 text-xs font-semibold text-[#1f5f99] transition-colors hover:border-[#2f80d1] hover:bg-[#eef6ff] disabled:cursor-not-allowed disabled:opacity-50"
|
||
:disabled="isThinking || isUploadingAttachments"
|
||
@click="originalContractPickerRef?.click()"
|
||
>
|
||
<Upload class="h-3.5 w-3.5" />
|
||
{{ $t('chat.procurementContract.uploadOriginalContract') }}
|
||
</button>
|
||
<button
|
||
type="button"
|
||
class="flex items-center gap-1 rounded-full bg-[#2f80d1] px-3 py-1.5 text-xs font-semibold text-white shadow-sm transition-colors hover:bg-[#2369ad] disabled:cursor-not-allowed disabled:opacity-50"
|
||
:disabled="isThinking || isUploadingAttachments || !attachmentPolicy.canLocal"
|
||
:title="$t('chat.procurementContract.uploadSellerReturnedContract')"
|
||
@click="selectProcurementContractLocal"
|
||
>
|
||
<Upload class="h-3.5 w-3.5" />
|
||
{{ $t('chat.procurementContract.uploadSellerReturnedContract') }}
|
||
</button>
|
||
</div>
|
||
<div
|
||
v-else-if="isProcurementContractAgent"
|
||
class="flex flex-wrap items-center gap-1.5"
|
||
>
|
||
<button
|
||
type="button"
|
||
class="flex items-center gap-1 rounded-full bg-[#2f80d1] px-3 py-1.5 text-xs font-semibold text-white shadow-sm transition-colors hover:bg-[#2369ad] disabled:cursor-not-allowed disabled:opacity-50"
|
||
:disabled="isThinking || isUploadingAttachments || !attachmentPolicy.canLocal"
|
||
:title="$t('chat.procurementContract.uploadContractToReview')"
|
||
@click="selectProcurementContractLocal"
|
||
>
|
||
<Upload class="h-3.5 w-3.5" />
|
||
{{ $t('chat.procurementContract.uploadContractToReview') }}
|
||
</button>
|
||
<span class="rounded-full border border-dashed border-[#d8e0ec] px-3 py-1.5 text-xs font-semibold text-[#667792]">
|
||
{{ $t('chat.procurementContract.soloHint') }}
|
||
</span>
|
||
</div>
|
||
|
||
<div
|
||
v-if="isMaintenanceAgent && canManageMaintenance"
|
||
class="flex flex-wrap items-center gap-2"
|
||
:title="$t('maintenance.panel.adminOnly')"
|
||
>
|
||
<button
|
||
type="button"
|
||
class="rounded-lg border border-brand-300 bg-brand-50 px-3 py-1.5 text-xs font-semibold text-brand-700 transition-colors hover:bg-brand-100"
|
||
@click="emit('maintenance-ledger-config')"
|
||
>
|
||
{{ $t('maintenance.chat.manageLedger') }}
|
||
</button>
|
||
<button
|
||
type="button"
|
||
class="rounded-lg border border-brand-300 bg-brand-50 px-3 py-1.5 text-xs font-semibold text-brand-700 transition-colors hover:bg-brand-100"
|
||
@click="emit('maintenance-create-record')"
|
||
>
|
||
{{ $t('maintenance.chat.logRepair') }}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="flex shrink-0 items-center gap-1.5">
|
||
<button
|
||
type="button"
|
||
:disabled="isThinking || isVoiceTranscribing"
|
||
:title="isVoiceRecording ? $t('chat.voiceStop') : isVoiceTranscribing ? $t('chat.voiceTranscribing') : $t('chat.voiceFeature')"
|
||
class="flex h-10 w-10 items-center justify-center rounded-full transition-colors disabled:cursor-not-allowed disabled:opacity-50"
|
||
:class="isVoiceRecording
|
||
? 'animate-pulse bg-rose-50 text-red-500'
|
||
: isVoiceTranscribing
|
||
? 'bg-brand-50 text-brand-500'
|
||
: 'text-muted hover:bg-surface-soft hover:text-brand-600'"
|
||
@click="emit('voice-click')"
|
||
>
|
||
<Loader2 v-if="isVoiceTranscribing" class="h-5 w-5 animate-spin" />
|
||
<Mic v-else class="h-5 w-5" />
|
||
</button>
|
||
|
||
<button
|
||
v-if="isThinking && !isUploadingAttachments"
|
||
type="button"
|
||
class="flex h-10 w-10 items-center justify-center rounded-full border border-rose-300 bg-rose-50 text-rose-600 shadow-sm transition-all duration-200 hover:scale-105 hover:bg-rose-100 active:scale-95"
|
||
:title="$t('chat.stopGenerating')"
|
||
:aria-label="$t('chat.stopGenerating')"
|
||
@click="emit('stop')"
|
||
>
|
||
<Square class="h-4 w-4 fill-current" />
|
||
</button>
|
||
<button
|
||
v-else
|
||
type="button"
|
||
:disabled="!canSendMessage"
|
||
class="flex h-10 w-10 shrink-0 items-center justify-center rounded-full border shadow-sm transition-all duration-200 disabled:cursor-not-allowed disabled:opacity-50"
|
||
:class="!canSendMessage
|
||
? 'border-default bg-surface-strong text-muted'
|
||
: 'border-brand-500 bg-brand-500 text-white shadow-[0_0_0_4px_rgba(59,130,246,0.18)] hover:scale-105 hover:bg-brand-600 hover:shadow-[0_0_0_6px_rgba(59,130,246,0.24)] active:scale-95'"
|
||
@click="emit('send')"
|
||
>
|
||
<Loader2 v-if="isUploadingAttachments" class="h-4 w-4 animate-spin" />
|
||
<Send v-else class="h-4 w-4" />
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="mt-3 text-center text-[11px] text-muted">
|
||
<span v-if="isThinking">{{ $t('chat.thinking') }}</span>
|
||
<span v-else>{{ $t('chat.disclaimer') }}</span>
|
||
</div>
|
||
</div>
|
||
</footer>
|
||
</template>
|