feat:删除刷新保存功能,大幅提升性能

This commit is contained in:
alivender 2025-08-01 20:51:50 +08:00
parent 2e9e378457
commit e5f2be616c
3 changed files with 10 additions and 26 deletions

View File

@ -187,7 +187,6 @@ import { useAlertStore } from "@/components/Alert";
// diagram // diagram
import { import {
loadDiagramData, loadDiagramData,
saveDiagramData,
updatePartPosition, updatePartPosition,
updatePartAttribute, updatePartAttribute,
parseConnectionPin, parseConnectionPin,
@ -606,14 +605,13 @@ function onComponentDrag(e: MouseEvent) {
// //
function stopComponentDrag() { function stopComponentDrag() {
// //
if (draggingComponentId.value) { if (draggingComponentId.value) {
draggingComponentId.value = null; draggingComponentId.value = null;
} }
isComponentDragEventActive.value = false; isComponentDragEventActive.value = false;
// - localStorage
saveDiagramData(diagramData.value);
} }
// //

View File

@ -1,7 +1,6 @@
import { ref, shallowRef, computed, reactive } from "vue"; import { ref, shallowRef, computed, reactive } from "vue";
import { createInjectionState } from "@vueuse/core"; import { createInjectionState } from "@vueuse/core";
import { import {
saveDiagramData,
type DiagramData, type DiagramData,
type DiagramPart, type DiagramPart,
} from "./diagramManager"; } from "./diagramManager";
@ -302,7 +301,7 @@ const [useProvideComponentManager, useComponentManager] = createInjectionState(
// 使用 updateDiagramDataDirectly 避免触发加载状态 // 使用 updateDiagramDataDirectly 避免触发加载状态
canvasInstance.updateDiagramDataDirectly(currentData); canvasInstance.updateDiagramDataDirectly(currentData);
saveDiagramData(currentData); // 移除自动保存功能
console.log("组件添加完成:", newComponent); console.log("组件添加完成:", newComponent);
@ -431,7 +430,7 @@ const [useProvideComponentManager, useComponentManager] = createInjectionState(
"=== 更新图表数据完成,新组件数量:", "=== 更新图表数据完成,新组件数量:",
currentData.parts.length, currentData.parts.length,
); );
saveDiagramData(currentData); // 移除自动保存功能
return { success: true, message: `已添加 ${templateData.name} 模板` }; return { success: true, message: `已添加 ${templateData.name} 模板` };
} else { } else {
@ -504,7 +503,7 @@ const [useProvideComponentManager, useComponentManager] = createInjectionState(
canvasInstance.updateDiagramDataDirectly(currentData); canvasInstance.updateDiagramDataDirectly(currentData);
saveDiagramData(currentData); // 移除自动保存功能
} }
/** /**

View File

@ -121,19 +121,9 @@ export async function loadDiagramData(examId?: string): Promise<DiagramData> {
} }
} }
// 如果没有examId或API加载失败尝试从本地存储加载 // 如果没有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);
}
}
// 如果本地存储也没有,从静态文件加载(作为最后的备选) // 从静态文件加载(作为备选方案)
const response = await fetch('/src/components/diagram.json'); const response = await fetch('/src/components/diagram.json');
if (!response.ok) { if (!response.ok) {
throw new Error(`Failed to load diagram.json: ${response.statusText}`); throw new Error(`Failed to load diagram.json: ${response.statusText}`);
@ -166,13 +156,10 @@ export function createEmptyDiagram(): DiagramData {
}; };
} }
// 保存图表数据到本地存储 // 保存图表数据(已禁用本地存储)
export function saveDiagramData(data: DiagramData): void { export function saveDiagramData(data: DiagramData): void {
try { // 本地存储功能已禁用 - 不再保存到localStorage
localStorage.setItem('diagramData', JSON.stringify(data)); console.debug('saveDiagramData called but localStorage saving is disabled');
} catch (error) {
console.error('Error saving diagram data:', error);
}
} }
// 更新组件位置 // 更新组件位置