|
@@ -0,0 +1,85 @@
|
|
|
+<template>
|
|
|
+ <vue-drag-resize :isActive="isActive" :w="w" :h="h" :x="left" :y="top" :minh="minh" :isResizable="isResizable"
|
|
|
+ :sticks="sticks" v-on:resizing="resizing" v-on:dragging="dragging" v-on:clicked="clicked"
|
|
|
+ @deactivated="onDeactivated">
|
|
|
+ <component class="draggable" :is="getWidget(dargData.type)" :config="dargData"></component>
|
|
|
+ </vue-drag-resize>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script lang="ts" setup>
|
|
|
+import getName from '../../views/widgets/getWidget';
|
|
|
+import VueDragResize from 'vue-drag-resize/src'
|
|
|
+import { ref } from "vue";
|
|
|
+const w = ref(0)
|
|
|
+const h = ref(0)
|
|
|
+const top = ref(0)
|
|
|
+const left = ref(0)
|
|
|
+const minh = ref(50)
|
|
|
+const isResizable = ref(false)
|
|
|
+const sticks = ref([])
|
|
|
+const isActive = ref(false)
|
|
|
+
|
|
|
+const porps = defineProps({
|
|
|
+ dargData: {
|
|
|
+ type: Object,
|
|
|
+ required: true
|
|
|
+ },
|
|
|
+})
|
|
|
+w.value = porps.dargData.css.width
|
|
|
+h.value = porps.dargData.css.height
|
|
|
+minh.value = porps.dargData.css.height
|
|
|
+top.value = porps.dargData.css.top
|
|
|
+left.value = porps.dargData.css.left
|
|
|
+isResizable.value = porps.dargData.config.isResizable
|
|
|
+sticks.value = porps.dargData.config.sticks
|
|
|
+
|
|
|
+// 要实现双向数据响应要使用 defineEmits 接受父组件传递过来的 textVal 的 update函数
|
|
|
+// const emit = defineEmits(['dargData'])
|
|
|
+// 缩放时事件
|
|
|
+function resizing(newRect) {
|
|
|
+ w.value = newRect.width
|
|
|
+ h.value = newRect.height
|
|
|
+ top.value = newRect.top
|
|
|
+ left.value = newRect.left
|
|
|
+
|
|
|
+ porps.dargData.css.width = newRect.width
|
|
|
+ porps.dargData.css.height = newRect.height
|
|
|
+ porps.dargData.css.top = newRect.top
|
|
|
+ porps.dargData.css.left = newRect.left
|
|
|
+ // const arr = JSON.parse(JSON.stringify(porps.dargData))
|
|
|
+ // arr.css.width = newRect.width
|
|
|
+ // arr.css.height = newRect.height
|
|
|
+ // arr.css.top = newRect.top
|
|
|
+ // arr.css.left = newRect.left
|
|
|
+ // emit('dargData', arr, porps.indexes)
|
|
|
+}
|
|
|
+// 拖拽时事件
|
|
|
+function dragging(newRect) {
|
|
|
+ w.value = newRect.width
|
|
|
+ h.value = newRect.height
|
|
|
+ top.value = newRect.top
|
|
|
+ left.value = newRect.left
|
|
|
+
|
|
|
+ porps.dargData.css.width = newRect.width
|
|
|
+ porps.dargData.css.height = newRect.height
|
|
|
+ porps.dargData.css.top = newRect.top
|
|
|
+ porps.dargData.css.left = newRect.left
|
|
|
+ // const arr = JSON.parse(JSON.stringify(porps.dargData))
|
|
|
+ // arr.css.width = newRect.width
|
|
|
+ // arr.css.height = newRect.height
|
|
|
+ // arr.css.top = newRect.top
|
|
|
+ // arr.css.left = newRect.left
|
|
|
+ // emit('dargData', arr, porps.indexes)
|
|
|
+}
|
|
|
+// 组件点击事件
|
|
|
+function clicked(params) {
|
|
|
+ console.log(params, '组件点击事件');
|
|
|
+}
|
|
|
+function onDeactivated() {
|
|
|
+ console.log('点击组件外事件');
|
|
|
+}
|
|
|
+const getWidget = (name: string) => {
|
|
|
+ //写的时候,组件的起名一定要与dragList中的element名字一模一样,不然会映射不上
|
|
|
+ return getName[name]
|
|
|
+}
|
|
|
+</script>
|