diff --git a/src/store/main.ts b/src/store/main.ts index 41dce63b..196cfd42 100644 --- a/src/store/main.ts +++ b/src/store/main.ts @@ -19,7 +19,7 @@ export interface MainState { thumbnailsFocus: boolean editorAreaFocus: boolean disableHotkeys: boolean - showGridLines: boolean + gridLineSize: number showRuler: boolean creatingElement: CreatingElement | null availableFonts: typeof SYS_FONTS @@ -47,7 +47,7 @@ export const useMainStore = defineStore('main', { thumbnailsFocus: false, // 左侧导航缩略图区域聚焦 editorAreaFocus: false, // 编辑区域聚焦 disableHotkeys: false, // 禁用快捷键 - showGridLines: false, // 显示网格线 + gridLineSize: 0, // 网格线尺寸(0表示不显示网格线) showRuler: false, // 显示标尺 creatingElement: null, // 正在插入的元素信息,需要通过绘制插入的元素(文字、形状、线条) availableFonts: SYS_FONTS, // 当前环境可用字体 @@ -117,8 +117,8 @@ export const useMainStore = defineStore('main', { this.disableHotkeys = disable }, - setGridLinesState(show: boolean) { - this.showGridLines = show + setGridLineSize(size: number) { + this.gridLineSize = size }, setRulerState(show: boolean) { diff --git a/src/views/Editor/Canvas/GridLines.vue b/src/views/Editor/Canvas/GridLines.vue index 13a0853d..df6cff65 100644 --- a/src/views/Editor/Canvas/GridLines.vue +++ b/src/views/Editor/Canvas/GridLines.vue @@ -21,7 +21,7 @@ import { useMainStore, useSlidesStore } from '@/store' import { VIEWPORT_SIZE } from '@/configs/canvas' import { SlideBackground } from '@/types/slides' -const { canvasScale } = storeToRefs(useMainStore()) +const { canvasScale, gridLineSize } = storeToRefs(useMainStore()) const { currentSlide, viewportRatio } = storeToRefs(useSlidesStore()) const background = computed(() => currentSlide.value?.background) @@ -33,24 +33,20 @@ const gridColor = computed(() => { return tinycolor.mostReadable(bgColor, colorList, { includeFallbackColors: true }).setAlpha(.5).toRgbString() }) -const gridSize = 50 - -// 计算网格路径 -const getPath = () => { +// 网格路径 +const path = computed(() => { const maxX = VIEWPORT_SIZE const maxY = VIEWPORT_SIZE * viewportRatio.value - let path = '' - for (let i = 0; i <= Math.floor(maxY / gridSize); i++) { - path += `M0 ${i * gridSize} L${maxX} ${i * gridSize} ` + let p = '' + for (let i = 0; i <= Math.floor(maxY / gridLineSize.value); i++) { + p += `M0 ${i * gridLineSize.value} L${maxX} ${i * gridLineSize.value} ` } - for (let i = 0; i <= Math.floor(maxX / gridSize); i++) { - path += `M${i * gridSize} 0 L${i * gridSize} ${maxY} ` + for (let i = 0; i <= Math.floor(maxX / gridLineSize.value); i++) { + p += `M${i * gridLineSize.value} 0 L${i * gridLineSize.value} ${maxY} ` } - return path -} - -const path = getPath() + return p +})