From e3c199499635235e8790d9ced2bc9d532ee66a13 Mon Sep 17 00:00:00 2001 From: pipipi-pikachu Date: Sat, 16 Jul 2022 10:25:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=A4=9A=E7=A7=8D?= =?UTF-8?q?=E7=BD=91=E6=A0=BC=E7=BA=BF=E5=B0=BA=E5=AF=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/main.ts | 8 ++-- src/views/Editor/Canvas/GridLines.vue | 24 +++++------- .../Editor/Canvas/ViewportBackground.vue | 4 +- src/views/Editor/Canvas/index.vue | 38 +++++++++++++------ src/views/Editor/EditorHeader/index.vue | 6 +-- 5 files changed, 46 insertions(+), 34 deletions(-) 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 +})