Browse Source

fix(editor): 允许直接进入空白报告编辑页

- 移除"该报告还没有关联文档"的警告提示
- 没有关联文档的报告可以直接进入空白编辑页
- 添加 currentReportId 用于正确标记列表选中状态
- 空白报告使用特殊标识符触发编辑器视图
何文松 3 tuần trước cách đây
mục cha
commit
a6eaedcb39
1 tập tin đã thay đổi với 33 bổ sung6 xóa
  1. 33 6
      frontend/vue-demo/src/views/Editor.vue

+ 33 - 6
frontend/vue-demo/src/views/Editor.vue

@@ -94,7 +94,7 @@
               v-for="report in filteredReports"
               :key="report.id"
               class="report-item"
-              :class="{ active: currentDocumentId && currentDocumentId === report.baseDocumentId }"
+              :class="{ active: currentReportId === report.id }"
               @click="switchReport(report)"
             >
               <div class="report-icon">📄</div>
@@ -581,6 +581,9 @@ const templateStore = useTemplateStore()
 // 从 URL 查询参数获取文档ID
 const currentDocumentId = ref(route.query.doc || null)
 
+// 当前选中的报告ID(用于标记左侧列表的选中状态)
+const currentReportId = ref(null)
+
 // 是否有当前激活的文档
 const hasActiveDocument = computed(() => !!currentDocumentId.value)
 
@@ -689,13 +692,34 @@ async function loadMyReports() {
 // 切换报告
 async function switchReport(report) {
   // 如果点击的是当前已选中的报告,则取消选中
-  if (currentDocumentId.value === report.baseDocumentId) {
+  if (currentDocumentId.value && currentDocumentId.value === report.baseDocumentId) {
+    unselectReport()
+    return
+  }
+  
+  // 如果是当前选中的空白报告(无 baseDocumentId),也取消选中
+  if (!report.baseDocumentId && currentReportId.value === report.id) {
     unselectReport()
     return
   }
   
+  // 更新当前报告ID(用于标记选中状态)
+  currentReportId.value = report.id
+  
   if (!report.baseDocumentId) {
-    ElMessage.warning('该报告还没有关联文档')
+    // 没有关联文档,进入空白编辑页面
+    currentDocumentId.value = 'empty-' + report.id  // 使用特殊标识表示空白文档
+    reportTitle.value = report.name || '未命名报告'
+    
+    // 清空文档内容,显示空白提示
+    blocks.value = []
+    tocItems.value = []
+    documentContent.value = emptyPlaceholder
+    entities.value = []
+    sourceFiles.value = []
+    
+    // 切换到资源 Tab
+    leftPanelTab.value = 'files'
     return
   }
   
@@ -721,8 +745,9 @@ function unselectReport() {
   newUrl.searchParams.delete('doc')
   window.history.replaceState({}, '', newUrl.toString())
   
-  // 清除当前文档
+  // 清除当前文档和报告
   currentDocumentId.value = null
+  currentReportId.value = null
   reportTitle.value = '新建报告'
   
   // 清空文档内容
@@ -1152,14 +1177,16 @@ onMounted(async () => {
       // 只有 URL 明确指定了文档才加载
       currentDocumentId.value = docId
       await loadDocumentById(docId)
-      // 找到对应的报告设置标题
+      // 找到对应的报告设置标题和ID
       const report = myReports.value.find(r => r.baseDocumentId === docId)
       if (report) {
         reportTitle.value = report.name || '未命名报告'
+        currentReportId.value = report.id
       }
     } else {
-      // 没有指定文档,显示空白编辑器,不自动选中任何报告
+      // 没有指定文档,显示欢迎页,不自动选中任何报告
       reportTitle.value = '新建报告'
+      currentReportId.value = null
       documentContent.value = emptyPlaceholder
     }
   } catch (err) {