C内核流量计算方法优化,前端文件名称读取优化
This commit is contained in:
1 parent
5d5a2e1843
commit
808c484f5b
94 files changed
+20163
-4418
No files matched your search
+64
-4
@@ -29,6 +29,7 @@ import {
|
||||
FileDown,
|
||||
FileUp,
|
||||
FlipHorizontal2,
|
||||
FlipVertical2,
|
||||
FolderOpen,
|
||||
Grip,
|
||||
ListChecks,
|
||||
@@ -5950,6 +5951,50 @@ function FlowWorkbench() {
|
||||
);
|
||||
}, [appendConsoleEntry, recordHistory, selectedNodeId, setEdges, setNodes]);
|
||||
|
||||
const mirrorSelectionVertically = useCallback(() => {
|
||||
const selectedIds = new Set(
|
||||
nodesRef.current
|
||||
.filter((node) => node.selected || node.id === selectedNodeId)
|
||||
.map((node) => node.id),
|
||||
);
|
||||
if (selectedIds.size === 0) {
|
||||
appendConsoleEntry("warning", "请先选择需要镜像的组件");
|
||||
return;
|
||||
}
|
||||
recordHistory();
|
||||
const previousNodes = nodesRef.current;
|
||||
const mirroredNodes = previousNodes.map((node) =>
|
||||
selectedIds.has(node.id)
|
||||
? {
|
||||
...node,
|
||||
data: {
|
||||
...node.data,
|
||||
// Reflect in canvas coordinates: Sy R(theta) Sx(m) = R(180-theta) Sx(!m).
|
||||
rotation: normalizeNodeRotation((540 - normalizeNodeRotation(node.data.rotation)) % 360),
|
||||
mirrored: !node.data.mirrored,
|
||||
},
|
||||
}
|
||||
: node,
|
||||
);
|
||||
const { remainingEdges, removedEdges } = disconnectInvalidatedContactEdges(
|
||||
previousNodes,
|
||||
mirroredNodes,
|
||||
edgesRef.current,
|
||||
selectedIds,
|
||||
);
|
||||
nodesRef.current = mirroredNodes;
|
||||
edgesRef.current = remainingEdges;
|
||||
setNodes(mirroredNodes);
|
||||
if (removedEdges.length > 0) {
|
||||
setEdges(remainingEdges);
|
||||
appendConsoleEntry(
|
||||
"info",
|
||||
`镜像使接口分离,已断开 ${removedEdges.length} 个接触连接`,
|
||||
);
|
||||
}
|
||||
appendConsoleEntry("info", `已竖直镜像 ${selectedIds.size} 个组件`);
|
||||
}, [appendConsoleEntry, recordHistory, selectedNodeId, setEdges, setNodes]);
|
||||
|
||||
const handleNodesChange = useCallback(
|
||||
(changes: NodeChange<SimulationNode>[]) => {
|
||||
const removesNodes = changes.some((change) => change.type === "remove");
|
||||
@@ -7391,7 +7436,7 @@ function FlowWorkbench() {
|
||||
const loadedEdges = edgeNormalization.edges;
|
||||
setNodes(loadedNodes);
|
||||
setEdges(loadedEdges);
|
||||
setProjectName(project.name || "untitled");
|
||||
setProjectName(project.name.trim() || "untitled");
|
||||
setSimulationConfig({ ...defaultSimulationConfig, ...project.simulation });
|
||||
setSelectedNodeId(null);
|
||||
setSelectedEdgeId(null);
|
||||
@@ -7472,7 +7517,8 @@ function FlowWorkbench() {
|
||||
return;
|
||||
}
|
||||
applyProject(
|
||||
project,
|
||||
// Older entries may still contain a name that differs from their storage key.
|
||||
{ ...project, name },
|
||||
`工程已加载:${project.nodes.length} 个组件,${project.edges.length} 条连接`,
|
||||
);
|
||||
} catch (error) {
|
||||
@@ -7505,7 +7551,11 @@ function FlowWorkbench() {
|
||||
if (!project) {
|
||||
throw new Error("文件不是有效的 ReactFlow 工程 JSON");
|
||||
}
|
||||
applyProject(project, `已导入工程:${file.name}`);
|
||||
const importedName = file.name.trim().replace(/\.json$/i, "").trim();
|
||||
applyProject(
|
||||
{ ...project, name: importedName || project.name.trim() || "untitled" },
|
||||
`已导入工程:${file.name}`,
|
||||
);
|
||||
} catch (error) {
|
||||
appendConsoleEntry("error", `导入失败:${formatError(error)}`);
|
||||
}
|
||||
@@ -8058,7 +8108,7 @@ function FlowWorkbench() {
|
||||
}
|
||||
if (
|
||||
pendingPasteRef.current &&
|
||||
((event.shiftKey && !commandKey && !event.altKey && key === "h") ||
|
||||
((event.shiftKey && !commandKey && !event.altKey && ["h", "v"].includes(key)) ||
|
||||
(commandKey && ["a", "c", "v", "y", "z"].includes(key)))
|
||||
) {
|
||||
event.preventDefault();
|
||||
@@ -8067,6 +8117,9 @@ function FlowWorkbench() {
|
||||
if (event.shiftKey && !commandKey && !event.altKey && key === "h") {
|
||||
event.preventDefault();
|
||||
mirrorSelection();
|
||||
} else if (event.shiftKey && !commandKey && !event.altKey && key === "v") {
|
||||
event.preventDefault();
|
||||
mirrorSelectionVertically();
|
||||
} else if (commandKey && key === "z") {
|
||||
event.preventDefault();
|
||||
event.shiftKey ? redo() : undo();
|
||||
@@ -8093,6 +8146,7 @@ function FlowWorkbench() {
|
||||
cancelPortConnection,
|
||||
copySelection,
|
||||
mirrorSelection,
|
||||
mirrorSelectionVertically,
|
||||
pasteSelection,
|
||||
redo,
|
||||
rotatePendingPaste,
|
||||
@@ -8753,6 +8807,12 @@ function FlowWorkbench() {
|
||||
onClick={mirrorSelection}
|
||||
pressed={allSelectedNodesMirrored}
|
||||
/>
|
||||
<ToolbarButton
|
||||
disabled={Boolean(pendingPaste) || selectedNodesForTools.length === 0}
|
||||
icon={FlipVertical2}
|
||||
label="竖直镜像 (Shift+V)"
|
||||
onClick={mirrorSelectionVertically}
|
||||
/>
|
||||
</div>
|
||||
<span aria-hidden="true" className="toolbar-separator" />
|
||||
<div aria-label="画布显示" className="toolbar-group" role="group">
|
||||
|
||||
Reference in new issue
Block a user