mirror of
https://gitee.com/cai_xiao_feng/lowflow-design.git
synced 2025-12-07 00:28:23 +08:00
按住拖动滚动条
This commit is contained in:
parent
c2a3033854
commit
0077389f62
44
src/hooks/useDraggableScroll.ts
Normal file
44
src/hooks/useDraggableScroll.ts
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import { ref, onMounted, onBeforeUnmount, type Ref } from 'vue'
|
||||||
|
|
||||||
|
export function useDraggableScroll(containerRef: Ref<HTMLElement | null>) {
|
||||||
|
const isDragging = ref(false);
|
||||||
|
let startX: number, startY: number;
|
||||||
|
let scrollLeft: number, scrollTop: number;
|
||||||
|
|
||||||
|
const onMouseDown = (e: MouseEvent) => {
|
||||||
|
if (!containerRef.value) return;
|
||||||
|
isDragging.value = true;
|
||||||
|
startX = e.pageX;
|
||||||
|
startY = e.pageY;
|
||||||
|
scrollLeft = containerRef.value.scrollLeft;
|
||||||
|
scrollTop = containerRef.value.scrollTop;
|
||||||
|
document.addEventListener('mousemove', onMouseMove);
|
||||||
|
document.addEventListener('mouseup', onMouseUp);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onMouseMove = (e: MouseEvent) => {
|
||||||
|
if (!isDragging.value || !containerRef.value) return;
|
||||||
|
const deltaX = e.pageX - startX;
|
||||||
|
const deltaY = e.pageY - startY;
|
||||||
|
containerRef.value.scrollLeft = scrollLeft - deltaX;
|
||||||
|
containerRef.value.scrollTop = scrollTop - deltaY;
|
||||||
|
};
|
||||||
|
|
||||||
|
const onMouseUp = () => {
|
||||||
|
isDragging.value = false;
|
||||||
|
document.removeEventListener('mousemove', onMouseMove);
|
||||||
|
document.removeEventListener('mouseup', onMouseUp);
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
containerRef.value?.addEventListener('mousedown', onMouseDown);
|
||||||
|
});
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
containerRef.value?.removeEventListener('mousedown', onMouseDown);
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
isDragging,
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -13,6 +13,7 @@ import type {
|
|||||||
} from './nodes/type'
|
} from './nodes/type'
|
||||||
import type { FilterRules } from '@/components/AdvancedFilter/type'
|
import type { FilterRules } from '@/components/AdvancedFilter/type'
|
||||||
import type { Field } from '@/components/Render/type'
|
import type { Field } from '@/components/Render/type'
|
||||||
|
import { useDraggableScroll } from '@/hooks/useDraggableScroll'
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
@ -54,6 +55,9 @@ const activeData = ref<FlowNode>({
|
|||||||
})
|
})
|
||||||
const penalVisible = ref(false)
|
const penalVisible = ref(false)
|
||||||
const nodesError = ref<Recordable<ErrorInfo[]>>({})
|
const nodesError = ref<Recordable<ErrorInfo[]>>({})
|
||||||
|
|
||||||
|
const designerContainerRef = ref<HTMLElement | null>(null)
|
||||||
|
useDraggableScroll(designerContainerRef);
|
||||||
provide('flowDesign', {
|
provide('flowDesign', {
|
||||||
readOnly: readOnly,
|
readOnly: readOnly,
|
||||||
fields: flatFields,
|
fields: flatFields,
|
||||||
@ -315,7 +319,7 @@ defineExpose({
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="designer-container">
|
<div class="designer-container cursor-default active:cursor-grabbing" ref="designerContainerRef">
|
||||||
<div class="tool">
|
<div class="tool">
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</div>
|
</div>
|
||||||
@ -330,7 +334,7 @@ defineExpose({
|
|||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
</div>
|
</div>
|
||||||
<!--流程树-->
|
<!--流程树-->
|
||||||
<div class="node-container">
|
<div class="node-container" >
|
||||||
<TreeNode :node="process" @addNode="addNode" @delNode="delNode" @activeNode="openPenal" />
|
<TreeNode :node="process" @addNode="addNode" @delNode="delNode" @activeNode="openPenal" />
|
||||||
</div>
|
</div>
|
||||||
<!--属性面板-->
|
<!--属性面板-->
|
||||||
@ -344,8 +348,8 @@ defineExpose({
|
|||||||
position: relative;
|
position: relative;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
min-height: 100%;
|
height: 100%;
|
||||||
min-width: 100%;
|
width: 100%;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
background-color: var(--flow-bg-color);
|
background-color: var(--flow-bg-color);
|
||||||
|
|
||||||
@ -376,7 +380,6 @@ defineExpose({
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
padding-top: 50px;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@ -36,6 +36,7 @@ const activeNode = () => {
|
|||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
.node-box {
|
.node-box {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
padding-bottom: 50px;
|
||||||
|
|
||||||
.end-node-circle {
|
.end-node-circle {
|
||||||
width: 10px;
|
width: 10px;
|
||||||
|
|||||||
@ -35,6 +35,7 @@ watchEffect(() => {
|
|||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
.start-node {
|
.start-node {
|
||||||
|
padding-top: 50px;
|
||||||
:deep(.node-box) {
|
:deep(.node-box) {
|
||||||
&:after {
|
&:after {
|
||||||
display: none;
|
display: none;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user