From 5dc334062e3b7e6aeaca6e95b922e2ec1dd3cbf8 Mon Sep 17 00:00:00 2001 From: chiyi Date: Mon, 12 Oct 2026 14:22:29 +0800 Subject: [PATCH] =?UTF-8?q?feat(canvas):=20=E9=BB=98=E8=AE=A4=E7=BC=A9?= =?UTF-8?q?=E6=94=BE=E6=94=B9=E4=B8=BA=2060%,=E6=96=B0=E5=A2=9E=20zoomTo?= =?UTF-8?q?=20=E7=BC=A9=E6=94=BE=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/utils/canvas.js | 3 ++- frontend/src/views/CanvasView.vue | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/frontend/src/utils/canvas.js b/frontend/src/utils/canvas.js index 33d564f..7dc0b8c 100644 --- a/frontend/src/utils/canvas.js +++ b/frontend/src/utils/canvas.js @@ -17,6 +17,7 @@ export function screenToWorld(sx, sy, vp) { export const MIN_SCALE = 0.05 export const MAX_SCALE = 4 +export const DEFAULT_SCALE = 0.6 // 新画布/重置视图的默认缩放 /** 以屏幕点 m 为锚缩放到 newScale,返回新 viewport(平移量按锚点保持不动) */ export function zoomAt(vp, mx, my, newScale) { @@ -78,7 +79,7 @@ export function newId(prefix) { */ export function normalizeDoc(raw) { const doc = { - viewport: { x: 0, y: 0, scale: 1 }, + viewport: { x: 0, y: 0, scale: DEFAULT_SCALE }, nodes: [], edges: [], } diff --git a/frontend/src/views/CanvasView.vue b/frontend/src/views/CanvasView.vue index a4f6719..a5c4d8d 100644 --- a/frontend/src/views/CanvasView.vue +++ b/frontend/src/views/CanvasView.vue @@ -5,7 +5,7 @@ import { computed, nextTick, onBeforeUnmount, onMounted, reactive, ref, watch } import { onBeforeRouteLeave } from 'vue-router' import { api, generatedUrl, jsonBody, thumbUrl } from '../api' import { auth } from '../auth' -import { normalizeDoc, newId, ratioToSize, serializeDoc, screenToWorld } from '../utils/canvas' +import { normalizeDoc, newId, ratioToSize, serializeDoc, screenToWorld, DEFAULT_SCALE } from '../utils/canvas' import CanvasStage from '../components/canvas/CanvasStage.vue' import SelectMenu from '../components/SelectMenu.vue' @@ -15,7 +15,7 @@ const stage = ref(null) const canvases = ref([]) const currentId = ref('') const title = ref('未命名画布') -const doc = reactive({ viewport: { x: 0, y: 0, scale: 1 }, nodes: [], edges: [] }) +const doc = reactive({ viewport: { x: 0, y: 0, scale: DEFAULT_SCALE }, nodes: [], edges: [] }) const loading = ref(true) const loadError = ref('') const saveState = ref('saved') // saved | dirty | saving | error @@ -752,7 +752,7 @@ function onKeydown(e) { } else if (e.key === '-') { stage.value?.zoomStep(-1) } else if (e.key === '0') { - stage.value?.setViewport({ x: 0, y: 0, scale: 1 }) + stage.value?.setViewport({ x: 0, y: 0, scale: DEFAULT_SCALE }) } else if (e.key === '1') { stage.value?.fitToContent?.() } @@ -836,7 +836,7 @@ const saveLabel = computed(() => ({ @update:model-value="(p) => stage?.zoomTo(p / 100)" /> - +