feat:删除刷新保存功能,大幅提升性能
This commit is contained in:
		@@ -187,7 +187,6 @@ import { useAlertStore } from "@/components/Alert";
 | 
			
		||||
// 导入 diagram 管理器
 | 
			
		||||
import {
 | 
			
		||||
  loadDiagramData,
 | 
			
		||||
  saveDiagramData,
 | 
			
		||||
  updatePartPosition,
 | 
			
		||||
  updatePartAttribute,
 | 
			
		||||
  parseConnectionPin,
 | 
			
		||||
@@ -606,14 +605,13 @@ function onComponentDrag(e: MouseEvent) {
 | 
			
		||||
 | 
			
		||||
// 停止拖拽组件
 | 
			
		||||
function stopComponentDrag() {
 | 
			
		||||
  // 如果有组件被拖拽,保存当前状态
 | 
			
		||||
  // 如果有组件被拖拽,仅清除拖拽状态(不保存)
 | 
			
		||||
  if (draggingComponentId.value) {
 | 
			
		||||
    draggingComponentId.value = null;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  isComponentDragEventActive.value = false;
 | 
			
		||||
  
 | 
			
		||||
  saveDiagramData(diagramData.value);
 | 
			
		||||
  // 移除自动保存功能 - 不再自动保存到localStorage
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 更新组件属性
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,6 @@
 | 
			
		||||
import { ref, shallowRef, computed, reactive } from "vue";
 | 
			
		||||
import { createInjectionState } from "@vueuse/core";
 | 
			
		||||
import {
 | 
			
		||||
  saveDiagramData,
 | 
			
		||||
  type DiagramData,
 | 
			
		||||
  type DiagramPart,
 | 
			
		||||
} from "./diagramManager";
 | 
			
		||||
@@ -302,7 +301,7 @@ const [useProvideComponentManager, useComponentManager] = createInjectionState(
 | 
			
		||||
 | 
			
		||||
        // 使用 updateDiagramDataDirectly 避免触发加载状态
 | 
			
		||||
        canvasInstance.updateDiagramDataDirectly(currentData);
 | 
			
		||||
        saveDiagramData(currentData);
 | 
			
		||||
        // 移除自动保存功能
 | 
			
		||||
 | 
			
		||||
        console.log("组件添加完成:", newComponent);
 | 
			
		||||
 | 
			
		||||
@@ -431,7 +430,7 @@ const [useProvideComponentManager, useComponentManager] = createInjectionState(
 | 
			
		||||
          "=== 更新图表数据完成,新组件数量:",
 | 
			
		||||
          currentData.parts.length,
 | 
			
		||||
        );
 | 
			
		||||
        saveDiagramData(currentData);
 | 
			
		||||
        // 移除自动保存功能
 | 
			
		||||
 | 
			
		||||
        return { success: true, message: `已添加 ${templateData.name} 模板` };
 | 
			
		||||
      } else {
 | 
			
		||||
@@ -504,7 +503,7 @@ const [useProvideComponentManager, useComponentManager] = createInjectionState(
 | 
			
		||||
 | 
			
		||||
      canvasInstance.updateDiagramDataDirectly(currentData);
 | 
			
		||||
 | 
			
		||||
      saveDiagramData(currentData);
 | 
			
		||||
      // 移除自动保存功能
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -121,19 +121,9 @@ export async function loadDiagramData(examId?: string): Promise<DiagramData> {
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    // 如果没有examId或API加载失败,尝试从本地存储加载
 | 
			
		||||
    const savedData = localStorage.getItem('diagramData');
 | 
			
		||||
    if (savedData) {
 | 
			
		||||
      const data = JSON.parse(savedData);
 | 
			
		||||
      const validation = validateDiagramData(data);
 | 
			
		||||
      if (validation.isValid) {
 | 
			
		||||
        return data;
 | 
			
		||||
      } else {
 | 
			
		||||
        console.warn('本地存储的diagram数据格式无效:', validation.errors);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    // 如果没有examId或API加载失败,尝试从静态文件加载(不再使用本地存储)
 | 
			
		||||
    
 | 
			
		||||
    // 如果本地存储也没有,从静态文件加载(作为最后的备选)
 | 
			
		||||
    // 从静态文件加载(作为备选方案)
 | 
			
		||||
    const response = await fetch('/src/components/diagram.json');
 | 
			
		||||
    if (!response.ok) {
 | 
			
		||||
      throw new Error(`Failed to load diagram.json: ${response.statusText}`);
 | 
			
		||||
@@ -166,13 +156,10 @@ export function createEmptyDiagram(): DiagramData {
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 保存图表数据到本地存储
 | 
			
		||||
// 保存图表数据(已禁用本地存储)
 | 
			
		||||
export function saveDiagramData(data: DiagramData): void {
 | 
			
		||||
  try {
 | 
			
		||||
    localStorage.setItem('diagramData', JSON.stringify(data));
 | 
			
		||||
  } catch (error) {
 | 
			
		||||
    console.error('Error saving diagram data:', error);
 | 
			
		||||
  }
 | 
			
		||||
  // 本地存储功能已禁用 - 不再保存到localStorage
 | 
			
		||||
  console.debug('saveDiagramData called but localStorage saving is disabled');
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 更新组件位置
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user