2025-08-21 16:57:42 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div
|
|
|
|
|
|
class="icon-container"
|
2025-08-25 16:42:07 +08:00
|
|
|
|
:style="`grid-column: ${iconInfo.x}/${iconInfo.x + 1};grid-row: ${iconInfo.y}/${iconInfo.y + 1};`"
|
2025-08-21 16:57:42 +08:00
|
|
|
|
draggable="true"
|
|
|
|
|
|
@dragstart="onDragStart"
|
|
|
|
|
|
@dragend="onDragEnd"
|
|
|
|
|
|
>
|
2025-08-25 16:42:07 +08:00
|
|
|
|
{{ iconInfo.name }}
|
2025-08-21 16:57:42 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
|
import type { IDesktopAppIcon } from '@/core/desktop/types/IDesktopAppIcon.ts'
|
|
|
|
|
|
import type { IGridTemplateParams } from '@/core/desktop/types/IGridTemplateParams.ts'
|
2025-08-29 14:22:20 +08:00
|
|
|
|
import { eventManager } from '@/core/events/EventManager.ts'
|
2025-08-21 16:57:42 +08:00
|
|
|
|
|
2025-08-25 16:42:07 +08:00
|
|
|
|
const { iconInfo, gridTemplate } = defineProps<{ iconInfo: IDesktopAppIcon, gridTemplate: IGridTemplateParams }>()
|
2025-08-21 16:57:42 +08:00
|
|
|
|
|
|
|
|
|
|
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
|
2025-08-29 14:22:20 +08:00
|
|
|
|
if (!pointTarget.classList.contains('desktop-icons-container')) return
|
2025-08-22 15:49:10 +08:00
|
|
|
|
|
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-25 16:42:07 +08:00
|
|
|
|
iconInfo.x = gridX
|
|
|
|
|
|
iconInfo.y = gridY
|
|
|
|
|
|
|
2025-08-29 14:22:20 +08:00
|
|
|
|
eventManager.notifyEvent('onDesktopAppIconPos', iconInfo)
|
2025-08-21 16:57:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
|
.icon-container {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: 100%;
|
2025-08-25 16:42:07 +08:00
|
|
|
|
@apply flex flex-col items-center justify-center bg-gray-200;
|
2025-08-21 16:57:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
</style>
|