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)" /> - +