按住拖动滚动条

This commit is contained in:
caixiaofeng 2024-08-03 21:28:07 +08:00
parent c2a3033854
commit 0077389f62
4 changed files with 54 additions and 5 deletions

View 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,
};
}

View File

@ -13,6 +13,7 @@ import type {
} from './nodes/type'
import type { FilterRules } from '@/components/AdvancedFilter/type'
import type { Field } from '@/components/Render/type'
import { useDraggableScroll } from '@/hooks/useDraggableScroll'
const props = withDefaults(
defineProps<{
@ -54,6 +55,9 @@ const activeData = ref<FlowNode>({
})
const penalVisible = ref(false)
const nodesError = ref<Recordable<ErrorInfo[]>>({})
const designerContainerRef = ref<HTMLElement | null>(null)
useDraggableScroll(designerContainerRef);
provide('flowDesign', {
readOnly: readOnly,
fields: flatFields,
@ -315,7 +319,7 @@ defineExpose({
</script>
<template>
<div class="designer-container">
<div class="designer-container cursor-default active:cursor-grabbing" ref="designerContainerRef">
<div class="tool">
<slot></slot>
</div>
@ -344,8 +348,8 @@ defineExpose({
position: relative;
display: flex;
flex-direction: row;
min-height: 100%;
min-width: 100%;
height: 100%;
width: 100%;
overflow: auto;
background-color: var(--flow-bg-color);
@ -376,7 +380,6 @@ defineExpose({
display: flex;
align-items: center;
flex-direction: column;
padding-top: 50px;
}
}
</style>

View File

@ -36,6 +36,7 @@ const activeNode = () => {
<style scoped lang="scss">
.node-box {
position: relative;
padding-bottom: 50px;
.end-node-circle {
width: 10px;

View File

@ -35,6 +35,7 @@ watchEffect(() => {
<style scoped lang="scss">
.start-node {
padding-top: 50px;
:deep(.node-box) {
&:after {
display: none;