diff --git a/README.md b/README.md index 1f1361a7..0b0bac8e 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ npm run dev - 元素动画(入场、退场、强调) - 选择面板(隐藏元素、层级排序、元素命名) - 查找/替换 +- 批注 ### 幻灯片元素编辑 - 元素添加、删除 - 元素复制粘贴 diff --git a/src/components/MoveablePanel.vue b/src/components/MoveablePanel.vue index f705ff4a..02aa473e 100644 --- a/src/components/MoveablePanel.vue +++ b/src/components/MoveablePanel.vue @@ -3,8 +3,8 @@ class="moveable-panel" ref="moveablePanelRef" :style="{ - width: width + 'px', - height: height ? height + 'px' : 'auto', + width: w + 'px', + height: h ? h + 'px' : 'auto', left: x + 'px', top: y + 'px', }" @@ -23,6 +23,8 @@
+ +
@@ -32,15 +34,25 @@ import { computed, onMounted, ref } from 'vue' const props = withDefaults(defineProps<{ width: number height: number + minWidth?: number + minHeight?: number + maxWidth?: number + maxHeight?: number left?: number top?: number title?: string moveable?: boolean + resizeable?: boolean }>(), { + minWidth: 20, + minHeight: 20, + maxWidth: 500, + maxHeight: 500, left: 10, top: 10, title: '', moveable: true, + resizeable: false, }) const emit = defineEmits<{ @@ -49,12 +61,14 @@ const emit = defineEmits<{ const x = ref(0) const y = ref(0) +const w = ref(0) +const h = ref(0) const moveablePanelRef = ref() const realHeight = computed(() => { - if (!props.height) { + if (!h.value) { return moveablePanelRef.value?.clientHeight || 0 } - return props.height + return h.value }) onMounted(() => { @@ -63,6 +77,9 @@ onMounted(() => { if (props.top >= 0) y.value = props.top else y.value = document.body.clientHeight + props.top - realHeight.value + + w.value = props.width + h.value = props.height }) const startMove = (e: MouseEvent) => { @@ -90,7 +107,7 @@ const startMove = (e: MouseEvent) => { if (left < 0) left = 0 if (top < 0) top = 0 - if (left + props.width > windowWidth) left = windowWidth - props.width + if (left + w.value > windowWidth) left = windowWidth - w.value if (top + realHeight.value > clientHeight) top = clientHeight - realHeight.value x.value = left @@ -103,6 +120,42 @@ const startMove = (e: MouseEvent) => { document.onmouseup = null } } + +const startResize = (e: MouseEvent) => { + if (!props.resizeable) return + + let isMouseDown = true + + const startPageX = e.pageX + const startPageY = e.pageY + + const originWidth = w.value + const originHeight = h.value + + document.onmousemove = e => { + if (!isMouseDown) return + + const moveX = e.pageX - startPageX + const moveY = e.pageY - startPageY + + let width = originWidth + moveX + let height = originHeight + moveY + + if (width < props.minWidth) width = props.minWidth + if (height < props.minHeight) height = props.minHeight + if (width > props.maxWidth) width = props.maxWidth + if (height > props.maxHeight) height = props.maxHeight + + w.value = width + h.value = height + } + document.onmouseup = () => { + isMouseDown = false + + document.onmousemove = null + document.onmouseup = null + } +} \ No newline at end of file diff --git a/src/views/Editor/index.vue b/src/views/Editor/index.vue index 446b8833..07849b9a 100644 --- a/src/views/Editor/index.vue +++ b/src/views/Editor/index.vue @@ -18,6 +18,7 @@ + mainStore.setDialogForExport('') const remarkHeight = ref(40)