Files
syops/frontend/src/features/chat/components/ChatViewContent.vue
T

329 lines
15 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* features/chat/components/ChatViewContent.vue
* 用途:对话页主区域,组合侧栏、发货批次进度区、消息列表、输入栏与内置浏览器。
* 依赖:ChatSidebar、ChatMessageList、ChatInputBar、ShippingBatchProgressPanel、ShippingBatchWorkspaceDrawer、chat.context。
* 逻辑:本文件只做页面结构编排;发货批次进度样式与任务续办交互下沉到独立面板组件。
*/
<script setup lang="ts">
import { computed, ref, watch } from 'vue';
import { Maximize2, Minimize2, Loader2 } from 'lucide-vue-next';
import ChatShell from '@/shared/layouts/ChatShell.vue';
import ChatSidebar from '@/features/chat/components/ChatSidebar.vue';
import ChatInputBar from '@/features/chat/components/ChatInputBar.vue';
import ChatMessageList from '@/features/chat/components/ChatMessageList.vue';
import ChatMobileHeader from '@/features/chat/components/ChatMobileHeader.vue';
import ChatBrowserPanel from '@/features/chat/components/ChatBrowserPanel.vue';
import ShippingBatchProgressPanel from '@/features/chat/components/ShippingBatchProgressPanel.vue';
import ShippingBatchWorkspaceDrawer from '@/features/chat/components/ShippingBatchWorkspaceDrawer.vue';
import TrainingWorkspacePanel from '@/features/chat/components/TrainingWorkspacePanel.vue';
import LedgerConfigPanel from '@/features/maintenance/components/LedgerConfigPanel.vue';
import MaintenanceRecordManagerPanel from '@/features/maintenance/components/MaintenanceRecordManagerPanel.vue';
import { useChatPageContext } from '@/features/chat/composables/chat.context';
import { matchesTrainingAgent } from '@/features/chat/training/trainingWorkspace.utils';
const page = useChatPageContext();
const isTrainingAgentPage = computed(() => matchesTrainingAgent(page.currentAgent));
const isMaintenanceAgentPage = computed(() => {
const name = String(page.currentAgent?.name || '').trim();
return name === '设备维保助手' || (name.includes('设备维保') && name.includes('助手'));
});
const hideWelcomePanel = computed(() => isTrainingAgentPage.value);
const isTrainingWorkspaceExpanded = ref(false);
const maintenancePanel = ref<'ledger' | 'record' | null>(null);
const maintenancePanelWidth = ref(560);
const isMaintenancePanelFullscreen = ref(false);
const isMaintenancePanelResizing = ref(false);
const maintenancePanelStyle = computed(() => {
if (isMaintenancePanelFullscreen.value) {
return { width: '100%', minWidth: '100%', maxWidth: '100%' };
}
return {
width: `${maintenancePanelWidth.value}px`,
minWidth: '420px',
maxWidth: '82vw',
};
});
/**
* 开始拖拽设备维保右侧面板左边缘,允许管理员按表格内容临时调宽。
* @param event - 鼠标按下事件。
*/
const startMaintenancePanelResize = (event: MouseEvent): void => {
if (isMaintenancePanelFullscreen.value) return;
event.preventDefault();
isMaintenancePanelResizing.value = true;
const startX = event.clientX;
const startWidth = maintenancePanelWidth.value;
const handleMove = (moveEvent: MouseEvent) => {
const nextWidth = startWidth + (startX - moveEvent.clientX);
const maxWidth = Math.max(420, Math.floor(window.innerWidth * 0.82));
maintenancePanelWidth.value = Math.min(maxWidth, Math.max(420, nextWidth));
};
const stopResize = () => {
isMaintenancePanelResizing.value = false;
window.removeEventListener('mousemove', handleMove);
window.removeEventListener('mouseup', stopResize);
};
window.addEventListener('mousemove', handleMove);
window.addEventListener('mouseup', stopResize);
};
// 切换 Agent 时,重置工作区展开状态,确保每次进入都是收起状态(聊天优先)
watch(() => page.currentAgentId, () => {
isTrainingWorkspaceExpanded.value = false;
maintenancePanel.value = null;
isMaintenancePanelFullscreen.value = false;
});
</script>
<template>
<ChatShell>
<template #overlay>
<div
v-if="page.isSidebarOpen && !page.isMobile"
class="fixed inset-0 z-40 bg-overlay backdrop-blur-sm transition-opacity md:hidden"
@click="page.isSidebarOpen = false"
/>
</template>
<template #sidebar>
<ChatSidebar
v-if="!page.isMobile"
v-model:collapsed="page.sidebarCollapsed"
v-model:agent-panel-open="page.showAgentPanel"
:is-open="page.isSidebarOpen"
:current-agent="page.currentAgent"
:current-agent-id="page.currentAgentId"
:agent-description="page.agentDescription"
:has-agent-guides="page.agentGuides.length > 0"
:display-history="page.displayHistory"
:active-history-key="page.activeHistoryKey"
:user-agents="page.userAgents"
:current-user="page.currentUser"
:applied-theme="page.appliedTheme"
@new-chat="page.handleSidebarNewChat"
@open-guide="page.openGuideModal"
@history-select="page.handleHistorySelect"
@clear-all-history="page.clearAllHistory"
@delete-history-item="page.deleteHistoryItem"
@switch-agent="page.switchToAgent"
@toggle-theme="page.toggleLightDark"
@open-feedback="page.showGeneralFeedbackDialog = true"
@go-workspace="page.goToWorkspace()"
@go-admin="page.goToAdmin"
@logout="page.handleLogout"
/>
</template>
<ChatMobileHeader
v-if="page.isMobile && page.currentAgent"
:agent-name="page.currentAgent?.name || 'AI'"
:active-agent-id="page.currentAgentId"
:has-agent-guides="page.agentGuides.length > 0"
:user-agents="page.userAgents"
@open-guide="page.openGuideModal"
@go-history="page.goToWorkspace('history')"
@open-agent-popover="page.loadUserAgents"
@switch-agent="page.switchToAgent"
/>
<div v-if="!page.currentAgent" class="flex flex-1 flex-col items-center justify-center space-y-4">
<Loader2 class="h-10 w-10 animate-spin text-brand-500" />
<p class="text-sm animate-pulse text-muted">{{ $t('chat.loadingAgent') }}</p>
</div>
<div v-else-if="page.currentAgent.type === 'iframe'" class="relative h-full w-full flex-1">
<iframe
:src="page.currentAgent.extra_config?.iframe_url"
class="h-full w-full border-0 bg-surface"
allow="microphone; camera; clipboard-read; clipboard-write"
/>
</div>
<template v-else>
<div class="flex min-h-0 min-w-0 flex-1">
<div class="flex min-h-0 min-w-0 flex-1 flex-col">
<TrainingWorkspacePanel
:current-agent="page.currentAgent"
:current-user="page.currentUser"
:agent-guides="page.agentGuides"
:has-messages="page.messages.length > 0"
:new-session-tick="page.viewId"
:training="page.training"
@open-guide="page.openGuideModal"
@send-chat-prompt="page.handleSend($event)"
@push-local-assistant-message="page.pushLocalAssistantMessage($event)"
@update:expanded="isTrainingWorkspaceExpanded = $event"
/>
<ShippingBatchProgressPanel
v-if="page.isShippingNoticeAgent && (page.shippingBatchSummary || page.activeShippingTaskDetail)"
:conversation-workspace="page.shippingConversationWorkspace"
:active-batch-no="page.activeShippingBatchNo"
:batch-summary="page.shippingBatchSummary"
:batch-tasks="page.shippingBatchTasks"
:active-task-detail="page.activeShippingTaskDetail"
:workspace-open="page.shippingWorkspaceOpen"
@switch-batch="page.switchShippingBatch"
@toggle-workspace="page.shippingWorkspaceOpen = !page.shippingWorkspaceOpen"
/>
<ChatMessageList
v-show="!isTrainingWorkspaceExpanded"
:messages="page.messages"
:agent-name="page.currentAgent?.name || 'AI'"
:suggested-questions-style="page.suggestedQuestionsStyle"
:styled-sections="page.styledSuggestedQuestionSections"
:suggested-questions="page.agentSuggestedQuestions"
:show-thinking-bubble="page.shouldShowThinkingBubble"
:is-thinking="page.isThinking"
:show-chat-rating="page.showChatRating"
:copied-index="page.copiedIndex"
:is-shipping-notice-agent="page.isShippingNoticeAgent"
:handlers="page.messageBubbleHandlers"
:leave-handlers="page.leaveMessageHandlers"
:shipping-handlers="page.shippingMappingHandlers"
:training-handlers="page.trainingHandlers"
:should-render-message="page.shouldRenderMessage"
:should-show-tool-run-progress-after-message="page.shouldShowToolRunProgressAfterMessage"
:get-message-run-progress="page.getMessageRunProgress"
:get-message-run-progress-error="page.getMessageRunProgressError"
:is-message-run-progress-loading="page.isMessageRunProgressLoading"
:tool-run-progress="page.toolRunProgress"
:tool-run-progress-title="page.toolRunProgressTitle"
:show-scroll-to-bottom="page.showScrollToBottom"
:hide-welcome-panel="hideWelcomePanel"
:pin-messages-to-bottom="!isTrainingAgentPage"
:scroll-container-holder="page.scrollContainerHolder"
@copy="page.copyToClipboard($event.message, $event.index)"
@edit="page.input = $event"
@resend="page.handleSend($event)"
@regenerate="page.regenerate"
@open-feedback="page.handleOpenFeedback($event)"
@select-question="page.handleSend"
@scroll-to-bottom="page.scrollToBottom"
/>
<ChatInputBar
v-show="!isTrainingWorkspaceExpanded"
:key="`${page.currentAgentId}-${page.conversationId || 'draft'}-${page.messages.length}`"
v-model="page.input"
v-model:selected-kb="page.selectedKb"
:attachments="page.attachments"
:attachment-policy="page.attachmentPolicy"
:available-kb-options="page.availableKbOptions"
:kb-dropdown-disabled="page.kbDropdownDisabled"
:is-thinking="page.isThinking"
:is-voice-recording="page.isVoiceRecording"
:is-voice-transcribing="page.isVoiceTranscribing"
:is-uploading-attachments="page.isUploadingAttachments"
:can-send-message="page.canSendMessage"
:is-shipping-notice-agent="page.isShippingNoticeAgent"
:is-maintenance-agent="isMaintenanceAgentPage"
:shipping-suggested-prompt="page.shippingSuggestedPrompt"
:shipping-focus-task-no="page.focusedShippingTaskNo"
:shipping-focus-reason="page.shippingFocusReason"
:shipping-picker-ref-holder="page.shippingPickerRefHolder"
:shipping-notice-picker-ref-holder="page.shippingNoticePickerRefHolder"
:get-kb-label="page.getKbLabel"
@send="page.handleSend()"
@voice-click="page.handleVoiceFeatureClick"
@remove-attachment="page.removeAttachment"
@local-files-selected="page.handleLocalFilesSelected"
@add-remote-url="page.addRemoteUrlAttachment"
@shipping-inventory-selected="page.handleShippingInventorySelected"
@use-shipping-suggested-prompt="page.useShippingSuggestedPrompt"
@maintenance-ledger-config="maintenancePanel = 'ledger'"
@maintenance-create-record="maintenancePanel = 'record'"
@clear-shipping-focus="page.clearShippingFocus"
/>
</div>
<aside
v-if="isMaintenanceAgentPage && maintenancePanel"
class="relative flex flex-col border-l border-default bg-surface shadow-[-8px_0_24px_rgba(15,23,42,0.06)]"
:class="[
isMaintenancePanelFullscreen ? 'absolute inset-y-0 right-0 z-30' : '',
isMaintenancePanelResizing ? 'select-none' : '',
]"
:style="maintenancePanelStyle"
>
<button
v-if="!isMaintenancePanelFullscreen"
type="button"
class="absolute inset-y-0 left-[-4px] z-10 w-2 cursor-col-resize bg-transparent hover:bg-brand-200/60"
:title="$t('maintenance.panel.resizeTitle')"
@mousedown="startMaintenancePanelResize"
/>
<div class="flex items-start justify-between gap-3 border-b border-default px-4 py-3">
<div>
<h2 class="text-base font-semibold text-primary">
{{ maintenancePanel === 'ledger' ? $t('maintenance.panel.ledgerTitle') : $t('maintenance.panel.recordTitle') }}
</h2>
<p class="mt-1 text-xs text-secondary">
{{ maintenancePanel === 'ledger' ? $t('maintenance.panel.ledgerSubtitle') : $t('maintenance.panel.recordSubtitle') }}
</p>
</div>
<div class="flex items-center gap-2">
<button
type="button"
class="inline-flex h-8 w-8 items-center justify-center rounded-lg border border-default text-secondary hover:bg-surface-soft"
:title="isMaintenancePanelFullscreen ? $t('maintenance.panel.exitFullscreen') : $t('maintenance.panel.fullscreen')"
@click="isMaintenancePanelFullscreen = !isMaintenancePanelFullscreen"
>
<Minimize2 v-if="isMaintenancePanelFullscreen" class="h-4 w-4" />
<Maximize2 v-else class="h-4 w-4" />
</button>
<button
type="button"
class="inline-flex h-8 w-8 items-center justify-center rounded-lg border border-default text-sm text-secondary hover:bg-surface-soft"
:title="$t('maintenance.panel.close')"
@click="maintenancePanel = null"
>
×
</button>
</div>
</div>
<div class="min-h-0 flex-1 overflow-auto p-4">
<LedgerConfigPanel v-if="maintenancePanel === 'ledger'" />
<MaintenanceRecordManagerPanel v-else />
</div>
</aside>
<ChatBrowserPanel
v-model:open="page.browserPanelOpen"
v-model:draft-url="page.browserDraftUrl"
:current-url="page.browserCurrentUrl"
:frame-key="page.browserFrameKey"
:panel-style="page.browserPanelStyle"
:is-resizing="page.isBrowserResizing"
@load="page.browser.loadPage"
@refresh="page.browser.refreshPage"
@open-new-tab="page.browser.openInNewTab"
@url-enter="page.browser.onUrlEnter"
@start-resize="page.browser.startResize"
@close="page.browser.close"
/>
<ShippingBatchWorkspaceDrawer
v-if="page.isShippingNoticeAgent && (page.shippingConversationWorkspace || page.shippingBatchSummary)"
v-model:open="page.shippingWorkspaceOpen"
:conversation-workspace="page.shippingConversationWorkspace"
:active-batch-no="page.activeShippingBatchNo"
:focused-task-no="page.focusedShippingTaskNo"
:batch-summary="page.shippingBatchSummary"
:batch-tasks="page.shippingBatchTasks"
:active-task-detail="page.activeShippingTaskDetail"
:retrying-pending="page.retryingShippingPendingTasks"
@switch-batch="page.switchShippingBatch"
@focus-task="page.switchShippingFocusTask"
@resume-task="page.resumeShippingTask"
@retry-rpa="page.retryShippingInventoryRpa"
@query-shortage="page.queryShippingShortageDetails"
@retry-pending="page.retryCurrentShippingBatchPendingTasks"
/>
</div>
</template>
</ChatShell>
</template>