mirror of
https://gitee.com/dromara/go-view.git
synced 2025-04-06 03:58:04 +08:00
perf: 优化画布缩放体验
This commit is contained in:
parent
de9e304dd4
commit
f2c49b171e
@ -14,7 +14,8 @@ export enum ChartLayoutStoreEnum {
|
|||||||
DETAILS = 'details',
|
DETAILS = 'details',
|
||||||
Chart_TYPE = 'chartType',
|
Chart_TYPE = 'chartType',
|
||||||
LAYER_TYPE = 'layerType',
|
LAYER_TYPE = 'layerType',
|
||||||
PERCENTAGE = 'percentage'
|
PERCENTAGE = 'percentage',
|
||||||
|
RE_POSITION_CANVAS = 'rePositionCanvas'
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ChartLayoutType {
|
export interface ChartLayoutType {
|
||||||
@ -30,4 +31,6 @@ export interface ChartLayoutType {
|
|||||||
[ChartLayoutStoreEnum.LAYER_TYPE]: LayerModeEnum
|
[ChartLayoutStoreEnum.LAYER_TYPE]: LayerModeEnum
|
||||||
// 当前正在加载的数量
|
// 当前正在加载的数量
|
||||||
[ChartLayoutStoreEnum.PERCENTAGE]: number
|
[ChartLayoutStoreEnum.PERCENTAGE]: number
|
||||||
|
// 是否重置当前画布位置
|
||||||
|
[ChartLayoutStoreEnum.RE_POSITION_CANVAS]: boolean
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,8 @@ export const useChartLayoutStore = defineStore({
|
|||||||
layerType: LayerModeEnum.THUMBNAIL,
|
layerType: LayerModeEnum.THUMBNAIL,
|
||||||
// 当前加载数量
|
// 当前加载数量
|
||||||
percentage: 0,
|
percentage: 0,
|
||||||
|
// 是否重置当前画布位置
|
||||||
|
rePositionCanvas: false,
|
||||||
// 防止值不存在
|
// 防止值不存在
|
||||||
...storageChartLayout
|
...storageChartLayout
|
||||||
}),
|
}),
|
||||||
@ -47,6 +49,9 @@ export const useChartLayoutStore = defineStore({
|
|||||||
},
|
},
|
||||||
getPercentage(): number {
|
getPercentage(): number {
|
||||||
return this.percentage
|
return this.percentage
|
||||||
|
},
|
||||||
|
getRePositionCanvas(): boolean {
|
||||||
|
return this.rePositionCanvas
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
@ -54,7 +59,10 @@ export const useChartLayoutStore = defineStore({
|
|||||||
this.$patch(state => {
|
this.$patch(state => {
|
||||||
state[key] = value
|
state[key] = value
|
||||||
})
|
})
|
||||||
|
// 存储本地
|
||||||
setLocalStorage(GO_CHART_LAYOUT_STORE, this.$state)
|
setLocalStorage(GO_CHART_LAYOUT_STORE, this.$state)
|
||||||
|
// 这里需要标记重置画布位置
|
||||||
|
this.rePositionCanvas = true;
|
||||||
// 重新计算拖拽区域缩放比例
|
// 重新计算拖拽区域缩放比例
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
chartEditStore.computedScale()
|
chartEditStore.computedScale()
|
||||||
|
@ -35,8 +35,11 @@ import { ref, reactive, onMounted, toRefs, watch, onUnmounted, computed } from '
|
|||||||
import { listen } from 'dom-helpers'
|
import { listen } from 'dom-helpers'
|
||||||
import { useDesignStore } from '@/store/modules/designStore/designStore'
|
import { useDesignStore } from '@/store/modules/designStore/designStore'
|
||||||
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
||||||
|
import { useChartLayoutStore } from '@/store/modules/chartLayoutStore/chartLayoutStore'
|
||||||
|
import { ChartLayoutStoreEnum } from '@/store/modules/chartLayoutStore/chartLayoutStore.d'
|
||||||
|
|
||||||
const chartEditStore = useChartEditStore()
|
const chartEditStore = useChartEditStore()
|
||||||
|
const chartLayoutStore = useChartLayoutStore()
|
||||||
const designStore = useDesignStore()
|
const designStore = useDesignStore()
|
||||||
|
|
||||||
const thick = 20
|
const thick = 20
|
||||||
@ -84,6 +87,7 @@ const themeColor = computed(() => {
|
|||||||
return designStore.getAppTheme
|
return designStore.getAppTheme
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 处理鼠标拖动
|
||||||
const handleWheel = (e: any) => {
|
const handleWheel = (e: any) => {
|
||||||
if (e.ctrlKey || e.metaKey) {
|
if (e.ctrlKey || e.metaKey) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@ -102,6 +106,7 @@ const handleWheel = (e: any) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 滚动条处理
|
||||||
const handleScroll = () => {
|
const handleScroll = () => {
|
||||||
if (!$app.value) return
|
if (!$app.value) return
|
||||||
const screensRect = $app.value.getBoundingClientRect()
|
const screensRect = $app.value.getBoundingClientRect()
|
||||||
@ -111,6 +116,7 @@ const handleScroll = () => {
|
|||||||
startY.value = (screensRect.top + thick - canvasRect.top) / scale.value
|
startY.value = (screensRect.top + thick - canvasRect.top) / scale.value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 拖拽处理
|
||||||
const dragCanvas = (e: any) => {
|
const dragCanvas = (e: any) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
@ -148,6 +154,7 @@ const dragCanvas = (e: any) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 计算画布大小
|
||||||
const canvasBox = () => {
|
const canvasBox = () => {
|
||||||
const layoutDom = document.getElementById('go-chart-edit-layout')
|
const layoutDom = document.getElementById('go-chart-edit-layout')
|
||||||
if (layoutDom) {
|
if (layoutDom) {
|
||||||
@ -162,7 +169,7 @@ const canvasBox = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 在位置不动的情况下重绘标尺
|
// 重绘标尺
|
||||||
const reDraw = () => {
|
const reDraw = () => {
|
||||||
sketchRuleReDraw.value = false
|
sketchRuleReDraw.value = false
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@ -170,12 +177,6 @@ const reDraw = () => {
|
|||||||
}, 10)
|
}, 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
|
||||||
() => designStore.getDarkTheme,
|
|
||||||
() => {
|
|
||||||
reDraw()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// 滚动居中
|
// 滚动居中
|
||||||
const canvasPosCenter = () => {
|
const canvasPosCenter = () => {
|
||||||
@ -186,13 +187,21 @@ const canvasPosCenter = () => {
|
|||||||
$app.value.scrollTop = containerHeight / 2 - height / 2
|
$app.value.scrollTop = containerHeight / 2 - height / 2
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理标尺重制大小
|
// 处理主题变化
|
||||||
|
watch(
|
||||||
|
() => designStore.getDarkTheme,
|
||||||
|
() => {
|
||||||
|
reDraw()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// // 处理标尺重制大小
|
||||||
watch(
|
watch(
|
||||||
() => scale.value,
|
() => scale.value,
|
||||||
(newValue, oldValue) => {
|
(newValue, oldValue) => {
|
||||||
if (oldValue !== newValue) {
|
if (oldValue !== newValue && chartLayoutStore.getRePositionCanvas) {
|
||||||
|
chartLayoutStore.setItemUnHandle(ChartLayoutStoreEnum.RE_POSITION_CANVAS, false)
|
||||||
handleScroll()
|
handleScroll()
|
||||||
chartEditStore.setScale(newValue)
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
canvasPosCenter()
|
canvasPosCenter()
|
||||||
}, 500)
|
}, 500)
|
||||||
@ -200,6 +209,7 @@ watch(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 处理鼠标样式
|
||||||
watch(
|
watch(
|
||||||
() => isPressSpace.value,
|
() => isPressSpace.value,
|
||||||
newValue => {
|
newValue => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user