2025-08-21 16:57:42 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div
|
|
|
|
|
|
class="icon-container"
|
|
|
|
|
|
:style="`grid-column: ${icon.col}/${icon.col + 1};grid-row: ${icon.row}/${icon.row + 1};`"
|
|
|
|
|
|
draggable="true"
|
|
|
|
|
|
@dragstart="onDragStart"
|
|
|
|
|
|
@dragend="onDragEnd"
|
|
|
|
|
|
>
|
|
|
|
|
|
{{ icon.name }}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
|
import type { IDesktopAppIcon } from '@/core/desktop/types/IDesktopAppIcon.ts'
|
|
|
|
|
|
import type { IGridTemplateParams } from '@/core/desktop/types/IGridTemplateParams.ts'
|
|
|
|
|
|
|
|
|
|
|
|
const { icon, gridTemplate } = defineProps<{ icon: IDesktopAppIcon, gridTemplate: IGridTemplateParams }>()
|
|
|
|
|
|
|
|
|
|
|
|
const onDragStart = (e: DragEvent) => {}
|
|
|
|
|
|
|
|
|
|
|
|
const onDragEnd = (e: DragEvent) => {
|
|
|
|
|
|
const el = e.target as HTMLElement | null
|
|
|
|
|
|
if (!el) return
|
2025-08-22 15:49:10 +08:00
|
|
|
|
// 鼠标所在位置已存在图标元素
|
|
|
|
|
|
const pointTarget = document.elementFromPoint(e.clientX, e.clientY)
|
|
|
|
|
|
if (!pointTarget) return
|
|
|
|
|
|
if (pointTarget.classList.contains('icon-container')) return
|
|
|
|
|
|
if (!pointTarget.classList.contains('desktop-container')) return
|
|
|
|
|
|
|
2025-08-21 16:57:42 +08:00
|
|
|
|
// 获取容器边界
|
|
|
|
|
|
const rect = el.parentElement!.getBoundingClientRect()
|
|
|
|
|
|
|
|
|
|
|
|
// 鼠标相对容器左上角坐标
|
|
|
|
|
|
const mouseX = e.clientX - rect.left
|
|
|
|
|
|
const mouseY = e.clientY - rect.top
|
|
|
|
|
|
|
|
|
|
|
|
// 计算鼠标所在单元格坐标(向上取整,从1开始)
|
|
|
|
|
|
const gridX = Math.ceil(mouseX / gridTemplate.cellRealWidth)
|
|
|
|
|
|
const gridY = Math.ceil(mouseY / gridTemplate.cellRealHeight)
|
2025-08-22 15:49:10 +08:00
|
|
|
|
|
2025-08-21 16:57:42 +08:00
|
|
|
|
icon.col = gridX
|
|
|
|
|
|
icon.row = gridY
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
|
.icon-container {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
@apply flex flex-col items-center justify-center rounded bg-gray-200;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|