mirror of
https://gitee.com/dromara/go-view.git
synced 2025-02-24 16:22:57 +08:00
fix: 画布变化后始终居中
This commit is contained in:
parent
117b9d0114
commit
355c95785a
@ -928,6 +928,8 @@ export const useChartEditStore = defineStore({
|
|||||||
const scaleHeight = parseFloat((width / baseProportion / editCanvasHeight).toFixed(5))
|
const scaleHeight = parseFloat((width / baseProportion / editCanvasHeight).toFixed(5))
|
||||||
this.setScale(scaleHeight > 1 ? 1 : scaleHeight)
|
this.setScale(scaleHeight > 1 ? 1 : scaleHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.onCanvsSizecomputed?.()
|
||||||
} else {
|
} else {
|
||||||
window['$message'].warning('请先创建画布,再进行缩放')
|
window['$message'].warning('请先创建画布,再进行缩放')
|
||||||
}
|
}
|
||||||
|
@ -281,7 +281,7 @@ export const setKeyboardDressShow = (keyCode?: number) => {
|
|||||||
const dom = document.getElementById('keyboard-dress-show')
|
const dom = document.getElementById('keyboard-dress-show')
|
||||||
if (!dom) return
|
if (!dom) return
|
||||||
if (!keyCode) {
|
if (!keyCode) {
|
||||||
if (keyCode == 32) window.onKeySpacePressHold?.(false)
|
window.onKeySpacePressHold?.(false)
|
||||||
dom.innerText = ''
|
dom.innerText = ''
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -63,13 +63,27 @@ 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
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
$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
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
window.onCanvsSizecomputed = () => {
|
||||||
|
setTimeout(() => {
|
||||||
|
canvasPosCenter()
|
||||||
|
}, 500)
|
||||||
|
}
|
||||||
|
|
||||||
const handleScroll = () => {
|
const handleScroll = () => {
|
||||||
const screensRect = $app.value.getBoundingClientRect()
|
const screensRect = $app.value.getBoundingClientRect()
|
||||||
const canvasRect = refcanvasBox.value.getBoundingClientRect()
|
const canvasRect = refcanvasBox.value.getBoundingClientRect()
|
||||||
@ -133,7 +147,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 - 40 - 44,
|
height: layoutDom.clientHeight - 25,
|
||||||
width: layoutDom.clientWidth
|
width: layoutDom.clientWidth
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,9 +192,10 @@ const canvasBox = () => {
|
|||||||
|
|
||||||
.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');
|
||||||
|
@ -161,7 +161,6 @@ onMounted(() => {
|
|||||||
|
|
||||||
@include goId('chart-edit-content') {
|
@include goId('chart-edit-content') {
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
margin: 25px;
|
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
@extend .go-transition;
|
@extend .go-transition;
|
||||||
@include fetch-theme('box-shadow');
|
@include fetch-theme('box-shadow');
|
||||||
|
3
types/global.d.ts
vendored
3
types/global.d.ts
vendored
@ -11,6 +11,9 @@ interface Window {
|
|||||||
|
|
||||||
// 编辑 JSON 的存储对象
|
// 编辑 JSON 的存储对象
|
||||||
opener: any
|
opener: any
|
||||||
|
|
||||||
|
//当画布大小重新计算后
|
||||||
|
onCanvsSizecomputed:Function
|
||||||
}
|
}
|
||||||
|
|
||||||
declare type Recordable<T = any> = Record<string, T>
|
declare type Recordable<T = any> = Record<string, T>
|
||||||
|
Loading…
Reference in New Issue
Block a user