|
@@ -2,34 +2,24 @@
|
|
|
import { ref, computed, onUnmounted } from 'vue'
|
|
|
import { Delete, MoreFilled, Edit } from '@element-plus/icons-vue'
|
|
|
import Markdown from '/@/components/markdown/Markdown.vue'
|
|
|
-
|
|
|
-type MarkdownDashBoard = {
|
|
|
- x: number
|
|
|
- y: number
|
|
|
- w: number
|
|
|
- h: number
|
|
|
- z: number
|
|
|
- title: string
|
|
|
- data: string
|
|
|
-}
|
|
|
+import type { MarkdownDashBoard, Position, Size, Content, ResizeType } from './types'
|
|
|
|
|
|
const props = defineProps<{
|
|
|
card: MarkdownDashBoard
|
|
|
- index: number
|
|
|
}>()
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
- updatePosition: [index: number, position: { x: number; y: number }]
|
|
|
- updateSize: [index: number, size: { w: number; h: number }]
|
|
|
- updateContent: [index: number, content: { title: string; data: string }]
|
|
|
- remove: [index: number]
|
|
|
+ updatePosition: [id: string, position: Position]
|
|
|
+ updateSize: [id: string, size: Size]
|
|
|
+ updateContent: [id: string, content: Content]
|
|
|
+ remove: [id: string]
|
|
|
}>()
|
|
|
|
|
|
const cardRef = ref<HTMLElement>()
|
|
|
const isDragging = ref(false)
|
|
|
const isResizing = ref(false)
|
|
|
const dragOffset = ref({ x: 0, y: 0 })
|
|
|
-const resizeType = ref<'se' | 'e' | 's' | ''>('')
|
|
|
+const resizeType = ref<ResizeType>('')
|
|
|
const initialSize = ref({ w: 0, h: 0 })
|
|
|
const initialPosition = ref({ x: 0, y: 0 })
|
|
|
|
|
@@ -103,7 +93,7 @@ const handleDrag = (event: MouseEvent) => {
|
|
|
const constrainedX = Math.max(0, Math.min(100 - props.card.w, newX))
|
|
|
const constrainedY = Math.max(0, Math.min(100 - props.card.h, newY))
|
|
|
|
|
|
- emit('updatePosition', props.index, { x: constrainedX, y: constrainedY })
|
|
|
+ emit('updatePosition', props.card.id, { x: constrainedX, y: constrainedY })
|
|
|
}
|
|
|
|
|
|
// 处理拖拽调整大小
|
|
@@ -130,7 +120,7 @@ const handleResize = (event: MouseEvent) => {
|
|
|
newH = Math.max(10, Math.min(100 - props.card.y, initialSize.value.h + deltaYPercent))
|
|
|
}
|
|
|
|
|
|
- emit('updateSize', props.index, { w: newW, h: newH })
|
|
|
+ emit('updateSize', props.card.id, { w: newW, h: newH })
|
|
|
}
|
|
|
|
|
|
// 停止拖拽移动
|
|
@@ -158,7 +148,7 @@ const handleEdit = () => {
|
|
|
// 确认编辑
|
|
|
const confirmEdit = () => {
|
|
|
if (editTitle.value.trim() && editData.value.trim()) {
|
|
|
- emit('updateContent', props.index, {
|
|
|
+ emit('updateContent', props.card.id, {
|
|
|
title: editTitle.value.trim(),
|
|
|
data: editData.value.trim()
|
|
|
})
|
|
@@ -175,7 +165,7 @@ const cancelEdit = () => {
|
|
|
|
|
|
// 删除卡片
|
|
|
const handleRemove = () => {
|
|
|
- emit('remove', props.index)
|
|
|
+ emit('remove', props.card.id)
|
|
|
}
|
|
|
|
|
|
// 清理事件监听器
|