!115 画布优化

Merge pull request !115 from MajorMayer/dev
This commit is contained in:
奔跑的面条 2022-12-17 13:57:38 +00:00 committed by Gitee
commit 4ef77fcf25
3 changed files with 46 additions and 35 deletions

View File

@ -286,7 +286,7 @@ export const setKeyboardDressShow = (keyCode?: number) => {
return return
} }
if (keyCode && code.has(keyCode)) { if (keyCode && code.has(keyCode)) {
window.onKeySpacePressHold?.(true) if (keyCode == 32) window.onKeySpacePressHold?.(true)
dom.innerText = `按下了「${code.get(keyCode)}」键` dom.innerText = `按下了「${code.get(keyCode)}」键`
} }
} }

View File

@ -1,25 +1,12 @@
<template> <template>
<div class="go-sketch-rule"> <div class="go-sketch-rule">
<sketch-rule <sketch-rule v-if="sketchRuleReDraw" :thick="thick" :scale="scale" :width="canvasBox().width"
v-if="sketchRuleReDraw" :height="canvasBox().height" :startX="startX" :startY="startY" :lines="lines" :palette="paletteStyle">
:thick="thick"
:scale="scale"
:width="canvasBox().width"
:height="canvasBox().height"
:startX="startX"
:startY="startY"
:lines="lines"
:palette="paletteStyle"
>
</sketch-rule> </sketch-rule>
<div ref="$app" class="edit-screens" @scroll="handleScroll"> <div ref="$app" class="edit-screens" @scroll="handleScroll">
<div ref="$container" class="edit-screen-container" :style="{ width: width * 2 + 'px' }"> <div ref="$container" class="edit-screen-container" :style="{ width: width * 2 + 'px' }">
<div <div ref="refSketchRuleBox" class="canvas" @mousedown="dragCanvas"
ref="refSketchRuleBox" :style="{ marginLeft: '-' + (canvasBox().width / 2 - 25) + 'px' }">
class="canvas"
@mousedown="dragCanvas"
:style="{ marginLeft: '-' + (canvasBox().width / 2 - 25) + 'px' }"
>
<div :style="{ pointerEvents: isPressSpace ? 'none' : 'auto' }"> <div :style="{ pointerEvents: isPressSpace ? 'none' : 'auto' }">
<slot></slot> <slot></slot>
</div> </div>
@ -112,14 +99,14 @@ const handleScroll = () => {
} }
const dragCanvas = (e: any) => { const dragCanvas = (e: any) => {
if (!window.$KeyboardActive?.space) return
// @ts-ignore
document.activeElement?.blur()
e.preventDefault() e.preventDefault()
e.stopPropagation() e.stopPropagation()
if (e.which == 2) isPressSpace.value = true
else if (!window.$KeyboardActive?.space) return
// @ts-ignore
document.activeElement?.blur()
const startX = e.pageX const startX = e.pageX
const startY = e.pageY const startY = e.pageY
@ -144,6 +131,7 @@ const dragCanvas = (e: any) => {
listenMouseup() listenMouseup()
prevMoveXVallue = [0, 0] prevMoveXVallue = [0, 0]
prevMoveYVallue = [0, 0] prevMoveYVallue = [0, 0]
isPressSpace.value = false
}) })
} }
@ -151,7 +139,7 @@ const canvasBox = () => {
const layoutDom = document.getElementById('go-chart-edit-layout') const layoutDom = document.getElementById('go-chart-edit-layout')
if (layoutDom) { if (layoutDom) {
return { return {
height: layoutDom.clientHeight, height: layoutDom.clientHeight - 25,
width: layoutDom.clientWidth width: layoutDom.clientWidth
} }
} }
@ -176,6 +164,15 @@ watch(
} }
) )
//
const canvasPosCenter = () => {
const { width: containerWidth, height: containerHeight } = $container.value.getBoundingClientRect()
const { width, height } = canvasBox()
$app.value.scrollLeft = containerWidth / 2 - width / 2
$app.value.scrollTop = containerHeight / 2 - height / 2
}
// //
watch( watch(
() => scale.value, () => scale.value,
@ -183,6 +180,9 @@ watch(
if (oldValue !== newValue) { if (oldValue !== newValue) {
handleScroll() handleScroll()
chartEditStore.setScale(newValue) chartEditStore.setScale(newValue)
setTimeout(() => {
canvasPosCenter()
}, 500);
} }
} }
) )
@ -197,8 +197,7 @@ watch(
onMounted(() => { onMounted(() => {
if ($app.value) { if ($app.value) {
$app.value.addEventListener('wheel', handleWheel, { passive: false }) $app.value.addEventListener('wheel', handleWheel, { passive: false })
// canvasPosCenter()
$app.value.scrollLeft = $container.value.getBoundingClientRect().width / 2 - canvasBox().width / 2
} }
}) })
@ -220,28 +219,34 @@ window.onKeySpacePressHold = (isHold: boolean) => {
top: 0; top: 0;
left: 0; left: 0;
} }
/* 横线 */ /* 横线 */
#mb-ruler .v-container .lines .line { #mb-ruler .v-container .lines .line {
/* 最大缩放 200% */ /* 最大缩放 200% */
width: 200vw !important; width: 200vw !important;
border-top: 1px dashed v-bind('themeColor') !important; border-top: 1px dashed v-bind('themeColor') !important;
} }
#mb-ruler .v-container .indicator { #mb-ruler .v-container .indicator {
border-bottom: 1px dashed v-bind('themeColor') !important; border-bottom: 1px dashed v-bind('themeColor') !important;
} }
/* 竖线 */ /* 竖线 */
#mb-ruler .h-container .lines .line { #mb-ruler .h-container .lines .line {
/* 最大缩放 200% */ /* 最大缩放 200% */
height: 200vh !important; height: 200vh !important;
border-left: 1px dashed v-bind('themeColor') !important; border-left: 1px dashed v-bind('themeColor') !important;
} }
#mb-ruler .h-container .indicator { #mb-ruler .h-container .indicator {
border-left: 1px dashed v-bind('themeColor') !important; border-left: 1px dashed v-bind('themeColor') !important;
} }
/* 坐标数值背景颜色 */ /* 坐标数值背景颜色 */
#mb-ruler .indicator .value { #mb-ruler .indicator .value {
background-color: rgba(0, 0, 0, 0); background-color: rgba(0, 0, 0, 0);
} }
/* 删除按钮 */ /* 删除按钮 */
#mb-ruler .line .del { #mb-ruler .line .del {
padding: 0; padding: 0;
@ -302,13 +307,16 @@ window.onKeySpacePressHold = (isHold: boolean) => {
.edit-screen-container { .edit-screen-container {
position: absolute; position: absolute;
height: v-bind('containerWidth'); height: v-bind('containerWidth');
top: 0;
left: 0;
} }
.canvas { .canvas {
position: absolute; position: absolute;
top: 80px; top: 50%;
left: 50%; left: 50%;
transform-origin: 50% 0; transform-origin: 50% 0;
transform: translateY(-50%);
&:hover { &:hover {
cursor: v-bind('cursorStyle'); cursor: v-bind('cursorStyle');

View File

@ -62,6 +62,9 @@ export const mousedownHandleUnStop = (e: MouseEvent, item?: CreateComponentType
// * 框选 // * 框选
export const mousedownBoxSelect = (e: MouseEvent, item?: CreateComponentType | CreateComponentGroupType) => { export const mousedownBoxSelect = (e: MouseEvent, item?: CreateComponentType | CreateComponentGroupType) => {
if (e.which == 2) return
if (window.$KeyboardActive?.space) return
mousedownHandleUnStop(e) mousedownHandleUnStop(e)
// 记录点击初始位置 // 记录点击初始位置