Files
docuseal/app/javascript/flow_builder/page.vue
T

150 lines
3.5 KiB
Vue
Raw Normal View History

2023-05-21 17:59:36 +03:00
<template>
<div class="relative">
<img
ref="image"
:src="image.url"
:width="width"
2023-05-31 00:50:43 +03:00
class="shadow-md mb-4"
2023-05-21 17:59:36 +03:00
:height="height"
loading="lazy"
>
<div
class="top-0 bottom-0 left-0 right-0 absolute"
>
<FieldArea
v-for="(item, i) in areas"
:key="i"
:bounds="item.area"
:field="item.field"
@start-resize="showMask = true"
@stop-resize="showMask = false"
@start-drag="showMask = true"
@stop-drag="showMask = false"
/>
<FieldArea
v-if="newArea"
:bounds="newArea"
/>
</div>
<div
2023-05-23 00:03:26 +03:00
v-show="isDraw || isDrag || showMask"
2023-05-21 17:59:36 +03:00
id="mask"
ref="mask"
class="top-0 bottom-0 left-0 right-0 absolute"
@pointerdown="onPointerdown"
@pointermove="onPointermove"
2023-05-23 00:03:26 +03:00
@dragover.prevent
@drop="onDrop"
2023-05-21 17:59:36 +03:00
@pointerup="onPointerup"
/>
</div>
</template>
<script>
import FieldArea from './area'
export default {
name: 'FlowPage',
components: {
FieldArea
},
props: {
image: {
type: Object,
required: true
},
areas: {
type: Array,
required: false,
default: () => []
},
isDraw: {
type: Boolean,
required: false,
default: false
},
2023-05-23 00:03:26 +03:00
isDrag: {
type: Boolean,
required: false,
default: false
},
2023-05-21 17:59:36 +03:00
number: {
type: Number,
required: true
}
},
2023-05-23 00:03:26 +03:00
emits: ['draw', 'drop-field'],
2023-05-21 17:59:36 +03:00
data () {
return {
showMask: false,
newArea: null
}
},
computed: {
width () {
return this.image.metadata.width
},
height () {
return this.image.metadata.height
}
},
methods: {
2023-05-23 00:03:26 +03:00
onDrop (e) {
this.$emit('drop-field', {
2023-05-23 00:22:17 +03:00
x: e.layerX / this.$refs.mask.clientWidth,
2023-05-28 23:20:48 +03:00
y: e.layerY / this.$refs.mask.clientHeight - (this.$refs.mask.clientWidth / 30 / this.$refs.mask.clientWidth) / 2,
2023-05-23 00:22:17 +03:00
w: this.$refs.mask.clientWidth / 5 / this.$refs.mask.clientWidth,
h: this.$refs.mask.clientWidth / 30 / this.$refs.mask.clientWidth,
2023-05-23 00:03:26 +03:00
page: this.number
})
},
2023-05-21 17:59:36 +03:00
onPointerdown (e) {
if (this.isDraw) {
this.newArea = {
2023-05-23 00:22:17 +03:00
initialX: e.layerX / this.$refs.mask.clientWidth,
initialY: e.layerY / this.$refs.mask.clientHeight,
x: e.layerX / this.$refs.mask.clientWidth,
y: e.layerY / this.$refs.mask.clientHeight,
2023-05-21 17:59:36 +03:00
w: 0,
h: 0
}
}
},
onPointermove (e) {
if (this.newArea) {
2023-05-23 00:22:17 +03:00
const dx = e.layerX / this.$refs.mask.clientWidth - this.newArea.initialX
const dy = e.layerY / this.$refs.mask.clientHeight - this.newArea.initialY
2023-05-21 17:59:36 +03:00
if (dx > 0) {
this.newArea.x = this.newArea.initialX
} else {
2023-05-23 00:22:17 +03:00
this.newArea.x = e.layerX / this.$refs.mask.clientWidth
2023-05-21 17:59:36 +03:00
}
if (dy > 0) {
this.newArea.y = this.newArea.initialY
} else {
2023-05-23 00:22:17 +03:00
this.newArea.y = e.layerY / this.$refs.mask.clientHeight
2023-05-21 17:59:36 +03:00
}
this.newArea.w = Math.abs(dx)
this.newArea.h = Math.abs(dy)
}
},
onPointerup (e) {
if (this.isDraw && this.newArea) {
this.$emit('draw', {
x: this.newArea.x,
y: this.newArea.y,
2023-05-23 00:22:17 +03:00
w: Math.max(this.newArea.w, this.$refs.mask.clientWidth / 5 / this.$refs.mask.clientWidth),
h: Math.max(this.newArea.h, this.$refs.mask.clientWidth / 30 / this.$refs.mask.clientWidth),
2023-05-21 17:59:36 +03:00
page: this.number
})
}
this.newArea = null
}
}
}
</script>