@@ -251,6 +254,7 @@ import { ElMessage } from 'element-plus' import ConfigPanel from '@/components/ConfigPanel.vue' import MarkdownRenderer from '@/components/MarkdownRenderer.vue' import MindMapRenderer from '@/components/MindMapRenderer.vue' +import { hubCall, onOpenArtifact } from '@/api/hub' import { documentApi } from '@/api/document' import { DOCUMENT_CONFIG_STORAGE_KEY, useDocumentProcessor } from '@/composables/useDocumentProcessor' import { markdownToAstString } from '@/utils/markdownAst' @@ -457,14 +461,8 @@ const startSmartOrganize = async () => { try { await documentApi.createMindmapTask(taskId, markdown, 'hybrid', config.mindmapPrompt, { - base_url: config.mindmapLlmBaseUrl || undefined, - api_key: config.mindmapLlmApiKey || undefined, - model: config.mindmapLlmModel || undefined, - timeout: config.mindmapLlmTimeout, - temperature: config.mindmapLlmTemperature, - max_context_tokens: config.mindmapLlmMaxContextTokens, - max_output_tokens: config.mindmapLlmMaxOutputTokens, - safety_tokens: config.mindmapLlmSafetyTokens + model_id: config.mindmapModelId, + temperature: config.mindmapLlmTemperature }) startSmartOrganizePolling(taskId) } catch (err) { @@ -545,6 +543,8 @@ const applyConfig = (nextConfig: typeof config) => { } const handleProcessDocument = async () => { + openedArtifact.value = null + originalRecognized.value = '' resetSmartOrganizeState() await processDocument() if (error.value) { @@ -623,6 +623,8 @@ const triggerUpload = () => { const handleFileInputChange = async (event: Event) => { const input = event.target as HTMLInputElement if (input.files) { + openedArtifact.value = null + originalRecognized.value = '' await handleFileUpload(input.files) input.value = '' if (uploadedFiles.value.length > 0) { @@ -643,6 +645,8 @@ const handleDrop = async (event: DragEvent) => { isDragging.value = false if (event.dataTransfer?.files) { + openedArtifact.value = null + originalRecognized.value = '' await handleFileUpload(event.dataTransfer.files) if (uploadedFiles.value.length > 0) { resetSmartOrganizeState() @@ -671,12 +675,38 @@ const clearAllFiles = () => { isUploadAreaCollapsed.value = false } +const openedArtifact = ref(null) +const originalRecognized = ref('') +const stopArtifactListener = onOpenArtifact((artifact) => { + resetSmartOrganizeState() + openedArtifact.value = artifact + originalRecognized.value = artifact.original || '' + results.value = { markdown: artifact.markdown, source: artifact.markdown, mindmap: buildMindmapMarkdown(artifact.markdown) } +}) +watch(() => results.value?.markdown, (value) => { + if (!openedArtifact.value && value) originalRecognized.value = value +}) +async function saveArtifact() { + try { + const current = openedArtifact.value + const saved = await hubCall('artifacts', 'post', { + name: current?.name || uploadedDisplayFiles.value[0]?.name || '思维导图', + revision: current?.revision, markdown: activeSourceMarkdownContent.value, + original: originalRecognized.value || manualMarkdownContent.value, + layout: current?.layout || 'tree' + }, current?.id) + openedArtifact.value = saved + ElMessage.success('已保存') + } catch (e: any) { ElMessage.error(e.message || '保存失败') } +} + onMounted(() => { updateViewportState() window.addEventListener('resize', updateViewportState) }) onUnmounted(() => { + stopArtifactListener() stopSmartOrganizePolling() window.removeEventListener('resize', updateViewportState) })