1.0.9-alpha.0.1 • Published 1 year ago

v3-dragblock v1.0.9-alpha.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

🌸 Get Started

使用 v3-dragblock 开发的示例。
使用文档地址:Document
Versel 演示地址: Demo - Vercel
Github 代码地址: Demo -Github

🎉 Introduce

V3-dragblock 是一个基于 Vue3 的拖拽组件,支持拖拽移动、缩放、吸附功能。目前初始版本暂时只支持 Vue3 版本,而且具有很多优化空间。

🏄‍♂️ Feature

  • 可配置 draggable 、 resizable 、 adsorbable
  • 可传入 draggable 和 resizable 的 start 和 end 事件
  • 可配置吸附线 adsorbline 的样式, 及吸附误差范围

👊 Todo

  • 简化组织代码
  • 按需打包 VueUse 的依赖
  • 适配 Vue2
  • 适配 React

🍄 Usage Steps

npm i v3-dragblock

如果已经经过 npm i v3-dragblock,那么下面就开始使用。 仅仅只需要,在需要的组件中 import V3Dragblock from 'v3-dragblock' 后,定义子项组件传入 V3Dragblock 后就可以使用。 当然需要通过 CSS 设置拖拽画布的大小。如果有不太理解的可以参考上面的 Demo Github

<script setup lang="ts">
import V3Dragblock from 'v3-dragblock'
import GridCellOne from '../components/GridCellOne.vue'
import GridCellTwo from '../components/GridCellTwo.vue'
import GridCellThree from '../components/GridCellThree.vue'
import GridCellFour from '../components/GridCellFour.vue'

const gridCells = ref([
  { id: '0', index: 0, x: 80, y: 310, width: 180, height: 230, component: markRaw(GridCellOne) },
  { id: '1', index: 0, x: 550, y: 95, width: 240, height: 240, component: markRaw(GridCellTwo) },
  { id: '2', index: 0, x: 377, y: 457, width: 305, height: 70, component: markRaw(GridCellThree) },
  { id: '3', index: 0, x: 180, y: 30, width: 130, height: 145, component: markRaw(GridCellFour) },
])
</script>

<template>
  <V3Dragblock
    class="V3Dragblock"
    :grid-cells="gridCells"
  />
</template>

<style scoped>
.V3Dragblock{
  background: #f7f4f0;
  width: 75vw;
  height: 75vh;
  border-radius: 10px;
  border-width: 1px;
  position: relative;
  margin-left: auto;
  margin-right: auto;
  overflow: hidden;
}
</style>

⚡ Configurations

这里展示一些组件的配置,包括设置 拖拽、缩放、吸附功能是否开启,以及一些事件方法。

<template>
  <V3Dragblock
    class="V3Dragblock"
    :grid-cells="gridCells"
    :draggable="true"
    :resizable="true"
    :adsorbable="true"
    :adsorb-line-style="adsorbLineStyle"
    @dragging="print('dragging', $event)"
    @drag-start="print('drag-start', $event)"
    @drag-end="save('drag-end', $event)"
    @resizing="print('resizing', $event)"
    @resize-start="print('resize-start', $event)"
    @resize-end="save('resize-end', $event)"
  />
</template>

🍔 class="V3Dragblock"

盒子的类名,用于比如设置拖拽盒子的尺寸或是一些其他 style 样式。子元素位置是在这个盒子内部的,不能超过这个尺寸。

🍔 :activated="true"

是否激活功能,这里其实就是监听 activated 添加或删除鼠标监听事件。

🍕 :grid-cells="gridCells"

需要用 ref 包着,具有响应性。

传入要拖拽的组件数组,要具有以下格式:

import V3Dragblock from 'v3-dragblock'
import GridCellOne from '../components/GridCellOne.vue'
import GridCellTwo from '../components/GridCellTwo.vue'
import GridCellThree from '../components/GridCellThree.vue'
import GridCellFour from '../components/GridCellFour.vue'

const gridCells = ref([
  { id: '0', index: 0, x: 80, y: 310, width: 180, height: 230, component: markRaw(GridCellOne) },
  { id: '1', index: 0, x: 550, y: 95, width: 240, height: 240, component: markRaw(GridCellTwo) },
  { id: '2', index: 0, x: 377, y: 457, width: 305, height: 70, component: markRaw(GridCellThree) },
  { id: '3', index: 0, x: 180, y: 30, width: 130, height: 145, component: markRaw(GridCellFour) },
])
字段作用
id唯一标识
index层级,两个元素重叠的层级
x离盒子的左边距离
y离盒子的上边距离
width元素的宽度
height元素的高度
component自定义的组件

🍟 :draggable="true" | :resizable="true" | :adsorbable="true"

Props作用默认
draggable拖拽true ( 启用 )
resizable缩放true ( 启用 )
adsorbable吸附true ( 启用 )

🍿 :adsorb-line-style="adsorbLineStyle"

开启吸附功能的时候,吸附线的样式

const adsorbLineStyle = {
  stroke: 'black',
  fill: 'black',
  strokeWidth: 2,
}

🍳 @dragging | @resizing | @drag-start | @resize-start| @drag-end|@resize-end

handles作用返回值
@dragging正在拖拽当前对象
@resizing正在缩放当前对象
@drag-start拖拽开始当前对象
@resize-start缩放开始当前对象
@drag-end拖拽结束所有对象的信息
@resize-end缩放结束所有对象的信息
1.0.9-alpha.0.1

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago