feat: 插入元素拖动范围不足时,按默认尺寸创建

This commit is contained in:
pipipi-pikachu 2021-03-03 22:52:31 +08:00
parent d61efe0c4b
commit a3158d96f3
2 changed files with 19 additions and 12 deletions

View File

@ -19,14 +19,9 @@ export default defineComponent({
setup() { setup() {
const store = useStore() const store = useStore()
const screening = computed(() => store.state.screening) const screening = computed(() => store.state.screening)
window.onbeforeunload = function(e: Event) {
e = e || window.event if (process.env.NODE_ENV === 'production') {
// IE8Firefox 4 window.onbeforeunload = () => false
if (e) {
e.returnValue = false
}
// Chrome, Safari, Firefox 4+, Opera 12+ , IE 9+
return false
} }
onMounted(() => { onMounted(() => {

View File

@ -38,8 +38,8 @@ export default defineComponent({
const ctrlOrShiftKeyActive = computed<boolean>(() => store.getters.ctrlOrShiftKeyActive) const ctrlOrShiftKeyActive = computed<boolean>(() => store.getters.ctrlOrShiftKeyActive)
const creatingElement = computed(() => store.state.creatingElement) const creatingElement = computed(() => store.state.creatingElement)
const start = ref<[number, number] | null>(null) const start = ref<[number, number]>()
const end = ref<[number, number] | null>(null) const end = ref<[number, number]>()
const selectionRef = ref<HTMLElement>() const selectionRef = ref<HTMLElement>()
const offset = reactive({ const offset = reactive({
@ -110,13 +110,25 @@ export default defineComponent({
const minSize = 30 const minSize = 30
if (Math.abs(endPageX - startPageX) >= minSize || Math.abs(endPageY - startPageY) >= minSize) { if (Math.abs(endPageX - startPageX) >= minSize && Math.abs(endPageY - startPageY) >= minSize) {
emit('created', { emit('created', {
start: start.value, start: start.value,
end: end.value, end: end.value,
}) })
} }
else store.commit(MutationTypes.SET_CREATING_ELEMENT, null) else {
const defaultSize = 100
const minX = Math.min(endPageX, startPageX)
const minY = Math.min(endPageY, startPageY)
const maxX = Math.max(endPageX, startPageX)
const maxY = Math.max(endPageY, startPageY)
const offsetX = maxX - minX >= minSize ? maxX - minX : defaultSize
const offsetY = maxY - minY >= minSize ? maxY - minY : defaultSize
emit('created', {
start: [minX, minY],
end: [minX + offsetX, minY + offsetY],
})
}
} }
} }