feat:删除刷新保存功能,大幅提升性能
This commit is contained in:
parent
2e9e378457
commit
e5f2be616c
|
@ -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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新组件属性
|
// 更新组件属性
|
||||||
|
|
|
@ -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);
|
// 移除自动保存功能
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新组件位置
|
// 更新组件位置
|
||||||
|
|
Loading…
Reference in New Issue