Procházet zdrojové kódy

feat(模板编辑): 添加"重新生成"按钮

在模板编辑器工具栏添加"重新生成"按钮,用于重新生成文档块结构
支持对已解析但没有 blocks 的历史文档重新生成并显示内容
何文松 před 4 týdny
rodič
revize
e0ee46ab70

+ 5 - 0
frontend/vue-demo/src/api/index.js

@@ -346,6 +346,11 @@ export const documentApi = {
   // 获取结构化文档(用于编辑器)
   getStructured(documentId) {
     return api.get(`/documents/${documentId}/structured`)
+  },
+
+  // 重新生成并保存文档块结构
+  regenerateBlocks(documentId) {
+    return api.post(`/ner/documents/${documentId}/regenerate-blocks`)
   }
 }
 

+ 38 - 1
frontend/vue-demo/src/views/Editor.vue

@@ -10,6 +10,14 @@
       />
       <span class="save-status" v-if="saved">✓ 已保存</span>
       <div class="toolbar-right">
+        <el-button 
+          :icon="Refresh" 
+          :loading="regenerating"
+          @click="handleRegenerateBlocks"
+          title="重新生成文档结构"
+        >
+          重新生成
+        </el-button>
         <el-button :icon="Clock">版本</el-button>
         <el-button :icon="Share">分享</el-button>
         <el-divider direction="vertical" />
@@ -302,7 +310,7 @@
 import { ref, reactive, computed, onMounted, onUnmounted } from 'vue'
 import { useRouter, useRoute } from 'vue-router'
 import {
-  ArrowLeft, Clock, Share, Check, Plus, Delete, Connection
+  ArrowLeft, Clock, Share, Check, Plus, Delete, Connection, Refresh
 } from '@element-plus/icons-vue'
 import { ElMessage } from 'element-plus'
 import { useTemplateStore } from '@/stores/template'
@@ -318,6 +326,7 @@ const viewMode = ref('edit')
 const saved = ref(true)
 const editorRef = ref(null)
 const loading = ref(false)
+const regenerating = ref(false)
 
 // 来源文件(从 API 获取)
 const sourceFiles = ref([])
@@ -439,6 +448,34 @@ function handleSave() {
   ElMessage.success('保存成功')
 }
 
+// 重新生成文档块结构
+async function handleRegenerateBlocks() {
+  const baseDocumentId = templateStore.currentTemplate?.baseDocumentId
+  if (!baseDocumentId) {
+    ElMessage.warning('没有关联的示例文档')
+    return
+  }
+
+  regenerating.value = true
+  try {
+    const result = await documentApi.regenerateBlocks(baseDocumentId)
+    ElMessage.success(`重新生成成功: ${result.blockCount} 个文档块, ${result.entityCount} 个实体`)
+    
+    // 重新加载文档内容
+    const structuredDoc = await documentApi.getStructured(baseDocumentId)
+    if (structuredDoc && structuredDoc.blocks && structuredDoc.blocks.length > 0) {
+      documentContent.value = structuredDoc.blocks
+        .map(block => block.markedHtml || block.html || block.plainText || '')
+        .join('')
+    }
+  } catch (error) {
+    console.error('重新生成失败:', error)
+    ElMessage.error('重新生成失败: ' + (error.message || '未知错误'))
+  } finally {
+    regenerating.value = false
+  }
+}
+
 function getFileIcon(file) {
   return '📄'
 }