0.1.2 • Published 3 years ago

qn-drag v0.1.2

Weekly downloads
-
License
-
Repository
-
Last release
3 years ago

用于可调整大小和可拖动元素的组件、并支持组件之间的冲突检测和组件对齐。

使用流程

安装依赖

npm install --save qn-drag

注册组件(在main.js中添加下列代码)

import qnDrag from 'qn-drag'
import 'qn-drag/lib/qn-drag.css'
Vue.use(qnDrag);

在文件中使用该组件:

<template>
  <div class="hello">
    <div class="parent-box">


      <qn-drag :snapTolerance="10" :isConflictCheck="true"
               :snap="true" @refLineParams="getRefLineParams" style="background-color: red"  :parent="true"
               :is-conflict-check="true"
      >
        <p>Grid 20x20 starting from the top-left corner</p>
      </qn-drag>

      <qn-drag :snapTolerance="10" :isConflictCheck="true"
               :snap="true" @refLineParams="getRefLineParams" style="background-color: blueviolet" :grid=[20,20]
               :parent="true"
               :is-conflict-check="true">
        <p>Grid 20x20 starting from the top-left corner</p>
      </qn-drag>

      <span class="ref-line v-line"
            v-for="item in vLine"
            v-show="item.display"
            :style="{ left: item.position, top: item.origin, height: item.lineLength}"
      />
      <span class="ref-line h-line"
            v-for="item in hLine"
            v-show="item.display"
            :style="{ top: item.position, left: item.origin, width: item.lineLength}"
      />
    </div>
  </div>
</template>

<script>


export default {

  name: 'HelloWorld',
  props: {
    msg: String
  },
  data() {
    return {
      vLine: [],
      hLine: []
    }
  },
  /**
   * 页面调用函数
   * @type {Object}
   */
  methods: {
    /**
     * 设置辅助线
     * @param params
     */
    getRefLineParams(params) {
      console.log("params", params)
      const {vLine, hLine} = params
      this.vLine = vLine
      this.hLine = hLine
    },
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.parent-box {
  position: relative;
  width: 800px;
  height: 700px;
  background: linear-gradient(-90deg, rgba(0, 0, 0, 0.1) 1px, transparent 1px) 0% 0% / 20px 20px, linear-gradient(rgba(0, 0, 0, 0.1) 1px, transparent 1px) 0% 0% / 20px 20px;
}

.v-line {
  width: 1px;
  height: 1px;
}

.ref-line {
  position: absolute;
  background-color: rgb(255, 0, 204);
  z-index: 9999;
}
</style>
参数说明类型必填项默认值备注
isConflictCheck定义组件是否开启冲突检测Booleanfalsefalse
snap定义组件是否开启元素对齐Booleanfalsefalse
snapTolerance当调用snap时,定义组件与元素之间的对齐距离,以像素为单位Numberfalse5
active确定组件是否应处于活动状态。 prop对更改做出反应,也可以与syncmodifier 一起使用以保持状态与父级同步Booleanfalsefalse
draggable定义组件应该是否可拖动Booleanfalsetrue
resizable定义组件是否可以调整大小Booleanfalsetrue
w定义元素的初始宽度Numberfalse200
h定义元素的初始高度Numberfalse200
minw定义元素的最小宽度Numberfalse50
minh定义元素的最小高度Numberfalse50
x定义元素的初始x位置Numberfalse0
y定义元素的初始y位置Numberfalse0
z定义元素的zIndexNumberfalseauto
axis定义元素可拖动的轴。可用值为x, y 或者 bothStringfalseboth
grid定义捕捉元素的网格Arrayfalse1,1
parent将元素的移动和尺寸限制为父元素Arrayfalsefalse
Events单击组件时调用,以显示句柄-false-@Events
deactivated定义捕捉元素的网格-false-@activated
resizing每当组件调整大小时调用-false-@resizing
resizestop每当组件停止调整大小时调用-false-@resizestop
dragging每当拖动组件时调用-false-@dragging
dragstop每当组件停止拖动时调用-false-@dragstop
0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago