DragResizeRotate.vue 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <VueDragResizeRotate :x="drapJson.x" :y="drapJson.y" class-name-handle="my-handle-class-dd handle" class-name-active="my-active-class-dd" class-name="my-class-dd" :w="drapJson.w" :h="drapJson.h" :r="drapJson.r" :parent="true" @resizing="onResize" @resizestop="onResizeStop" @activated="onActivated" @deactivated="onDeactivated" @dragging="onDrag" @dragstop="onDragStop">
  3. <slot>
  4. <div class="w-100% h-100% d-flex a-c j-c p-rtv" style="background-color: rgba(116, 251, 229, .3)">
  5. <span></span>
  6. <div class="f-s-18 c-danger delete-icon_box" @click.stop="deleteItem">
  7. <el-icon>
  8. <CircleCloseFilled />
  9. </el-icon>
  10. </div>
  11. </div>
  12. </slot>
  13. </VueDragResizeRotate>
  14. </template>
  15. <script setup lang="ts" name="ptpl-edit-index">
  16. import { propTypes } from '@/utils/propTypes';
  17. import VueDragResizeRotate from '@gausszhou/vue3-drag-resize-rotate';
  18. import '@gausszhou/vue3-drag-resize-rotate/lib/bundle.esm.css';
  19. const prop = defineProps({
  20. modelValue: propTypes.any.def({
  21. id: ''
  22. })
  23. });
  24. const emit = defineEmits([
  25. 'update:modelValue',
  26. 'activated',
  27. 'deactivated',
  28. 'dragging',
  29. 'dragstop',
  30. 'resizing',
  31. 'resizestop',
  32. 'delete'
  33. ]);
  34. const drapJson = ref({
  35. x: 0, y: 0, w: 100, h: 100,
  36. r:0,
  37. ...prop.modelValue
  38. });
  39. const onActivated = () => {
  40. emit('activated');
  41. };
  42. const onDeactivated = () => {
  43. emit('deactivated');
  44. };
  45. const onDrag = (left: number, top: number) => {
  46. emit('dragging', left, top);
  47. };
  48. const onDragStop = (x: number, y: number) => {
  49. emit('update:modelValue', { ...drapJson.value, x, y });
  50. emit('dragstop', x, y);
  51. };
  52. const onResize = (x: number, y: number, width: number, height: number) => {
  53. emit('resizing', x, y, width, height);
  54. };
  55. const onResizeStop = (x: number, y: number, width: number, height: number) => {
  56. emit('update:modelValue', { ...drapJson.value, x, y, w: width, h: height });
  57. emit('resizestop', x, y, width, height);
  58. };
  59. const deleteItem = () => {
  60. emit('deactivated');
  61. emit('delete')
  62. };
  63. watch(() => prop.modelValue, (newVal) => {
  64. drapJson.value = { ...drapJson.value, ...newVal };
  65. });
  66. </script>
  67. <style lang="scss" scoped>
  68. .delete-icon_box {
  69. position: absolute;
  70. top: 0px;
  71. right: 0px;
  72. width: 24px;
  73. height: 24px;
  74. cursor: pointer;
  75. display: flex;
  76. align-items: center;
  77. justify-content: center;
  78. }
  79. .my-active-class-dd {
  80. border-color: #74FBE5;
  81. }
  82. .my-class-dd {
  83. touch-action: none;
  84. position: absolute;
  85. box-sizing: border-box;
  86. border: 2px dashed;
  87. border-color: #74FBE5;
  88. }
  89. .my-handle-class-dd {
  90. border: 2px solid #74FBE5;
  91. }
  92. </style>