Skip to content

Commit

Permalink
optimize: 优化拖拽效果
Browse files Browse the repository at this point in the history
  • Loading branch information
STATICHIT committed Oct 23, 2024
1 parent f388a91 commit 9af9a40
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
6 changes: 5 additions & 1 deletion packages/common/component/PluginPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default {
},
emits: ['close'],
setup(props, { emit }) {
const { getPluginWidth, changePluginWidth, getPluginByLayout } = useLayout()
const { getPluginWidth, changePluginWidth, getPluginByLayout, changeMoveDragBarState } = useLayout()
const panelState = inject('panelState')
const closePanel = () => {
useLayout().closePlugin()
Expand Down Expand Up @@ -129,23 +129,27 @@ export default {
const throttledMouseMoveLeft = throttle(onMouseMoveLeft, 50)
const onMouseUpRight = () => {
changeMoveDragBarState(false)
document.removeEventListener('mousemove', throttledMouseMoveRight)
document.removeEventListener('mouseup', onMouseUpRight)
}
const onMouseUpLeft = () => {
changeMoveDragBarState(false)
document.removeEventListener('mousemove', throttledMouseMoveLeft)
document.removeEventListener('mouseup', onMouseUpLeft)
}
const onMouseDownRight = (event) => {
changeMoveDragBarState(true)
startX = event.clientX
startWidth = panel.value.offsetWidth
document.addEventListener('mousemove', throttledMouseMoveRight)
document.addEventListener('mouseup', onMouseUpRight)
}
const onMouseDownLeft = (event) => {
changeMoveDragBarState(true)
startX = event.clientX
startWidth = panel.value.offsetWidth
document.addEventListener('mousemove', throttledMouseMoveLeft)
Expand Down
11 changes: 10 additions & 1 deletion packages/controller/src/useLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const pluginState = reactive({
})

const layoutState = reactive({
isMoveDragBar: false,
deviceType: 'desktop',
iframeWidth: '1200px',
dimension: {
Expand Down Expand Up @@ -82,6 +83,12 @@ const layoutState = reactive({
},
pageStatus: ''
})
const getMoveDragBarState = () => {
return layoutState.isMoveDragBar
}
const changeMoveDragBarState = (state) => {
layoutState.isMoveDragBar = state
}
const leftMenuShownStorage = useStorage('leftMenuShown', layoutState.plugins.isShow)
const rightMenuShownStorage = useStorage('rightMenuShown', layoutState.settings.isShow)
const changeMenuShown = (menuName) => {
Expand Down Expand Up @@ -312,6 +319,8 @@ export default () => {
isSameSide,
getPluginShown,
changePluginShown,
changeMenuShown
changeMenuShown,
getMoveDragBarState,
changeMoveDragBarState
}
}
15 changes: 13 additions & 2 deletions packages/design-core/src/DesignCanvas.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<template>
<div id="canvas-wrap" ref="canvasRef">
<div ref="siteCanvas" class="site-canvas" :style="siteCanvasStyle">
<div
ref="siteCanvas"
class="site-canvas"
:style="siteCanvasStyle"
:class="{ 'not-selected': getMoveDragBarState() }"
>
<canvas-container
:controller="controller"
:materials-panel="materialsPanel"
Expand Down Expand Up @@ -52,6 +57,7 @@ export default {
const showMask = ref(true)
const canvasRef = ref(null)
let showModal = false // 弹窗标识
const { getMoveDragBarState } = useLayout()
const removeNode = (node) => {
const { pageState } = useCanvas()
Expand Down Expand Up @@ -193,7 +199,8 @@ export default {
ast
},
siteCanvasStyle,
canvasRef
canvasRef,
getMoveDragBarState
}
}
}
Expand All @@ -216,4 +223,8 @@ export default {
transform-origin: top;
}
}
.not-selected {
pointer-events: none;
user-select: none;
}
</style>
11 changes: 8 additions & 3 deletions packages/design-core/src/DesignPlugins.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
</div>
</div>

<div>
<div :class="{ 'not-selected': getMoveDragBarState() }">
<!-- 插件面板 -->
<div
v-show="renderPanel && components[renderPanel]"
Expand Down Expand Up @@ -185,7 +185,8 @@ export default {
dragPluginLayout,
isSameSide,
getPluginShown,
closePlugin
closePlugin,
getMoveDragBarState
} = useLayout()

const rightMenu = ref(null)
Expand Down Expand Up @@ -311,7 +312,8 @@ export default {
PLUGIN_POSITION,
getPluginShown,
switchAlign,
rightMenu
rightMenu,
getMoveDragBarState
}
}
}
Expand Down Expand Up @@ -454,4 +456,7 @@ export default {
:deep(.svg-icon.icon-plugin-icon-plugin-help) {
font-size: 22px;
}
.not-selected {
user-select: none;
}
</style>
6 changes: 4 additions & 2 deletions packages/design-core/src/DesignSettings.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- 右侧插件栏-->
<template>
<!-- 插件面板 -->
<div>
<div :class="{ 'not-selected': getMoveDragBarState() }">
<div
v-show="renderPanel && components[renderPanel]"
id="tiny-engine-right-panel"
Expand Down Expand Up @@ -83,6 +83,7 @@ export default {
dragPluginLayout,
isSameSide,
getPluginShown,
getMoveDragBarState,
layoutState: { settings: settingsState }
} = useLayout()

Expand Down Expand Up @@ -172,7 +173,8 @@ export default {
PLUGIN_POSITION,
getPluginShown,
switchAlign,
rightMenu
rightMenu,
getMoveDragBarState
}
}
}
Expand Down

0 comments on commit 9af9a40

Please sign in to comment.