2025-08-19 14:56:38 +08:00
|
|
|
import XSystem from '@/core/XSystem.ts'
|
2025-08-20 09:59:19 +08:00
|
|
|
import type { IDesktopAppIcon } from '@/core/desktop/types/IDesktopAppIcon.ts'
|
|
|
|
|
import {
|
|
|
|
|
nextTick,
|
|
|
|
|
onMounted,
|
|
|
|
|
onUnmounted,
|
|
|
|
|
reactive,
|
|
|
|
|
toRefs,
|
|
|
|
|
useTemplateRef,
|
|
|
|
|
watch,
|
|
|
|
|
watchEffect,
|
|
|
|
|
} from 'vue'
|
2025-08-19 14:56:38 +08:00
|
|
|
import { DesktopEventEnum } from '@/core/events/EventTypes.ts'
|
|
|
|
|
import { useDraggable } from '@vueuse/core'
|
|
|
|
|
|
2025-08-19 16:59:58 +08:00
|
|
|
export function useDesktopInit(containerStr: string) {
|
|
|
|
|
let container:HTMLElement
|
2025-08-19 14:56:38 +08:00
|
|
|
const gridTemplate = reactive({
|
|
|
|
|
cellWidth: 90,
|
|
|
|
|
cellHeight: 110,
|
|
|
|
|
gap: 10,
|
2025-08-19 16:59:58 +08:00
|
|
|
colCount: 1,
|
|
|
|
|
rowCount: 1
|
2025-08-19 14:56:38 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const ro = new ResizeObserver(entries => {
|
|
|
|
|
const entry= entries[0]
|
|
|
|
|
const containerRect = entry.contentRect
|
2025-08-19 16:59:58 +08:00
|
|
|
gridTemplate.colCount = Math.floor(containerRect.width / gridTemplate.cellWidth);
|
|
|
|
|
gridTemplate.rowCount = Math.floor(containerRect.height / (gridTemplate.cellHeight));
|
2025-08-20 09:59:19 +08:00
|
|
|
console.log('resize', gridTemplate)
|
2025-08-19 16:59:58 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
container = document.querySelector(containerStr)!
|
|
|
|
|
ro.observe(container)
|
2025-08-19 14:56:38 +08:00
|
|
|
})
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
|
ro.unobserve(container)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 有桌面图标的app
|
2025-08-20 09:59:19 +08:00
|
|
|
const appInfos = XSystem.instance.processManages.processInfos.filter(processInfo => !processInfo.isJustProcess)
|
|
|
|
|
const appIcons: IDesktopAppIcon[] = appInfos.map((processInfo, index) => {
|
|
|
|
|
// 左上角坐标原点,从上到下从左到右 索引从1开始
|
|
|
|
|
const x = Math.floor(index / gridTemplate.rowCount) + 1
|
|
|
|
|
const y = index % gridTemplate.rowCount + 1
|
2025-08-19 14:56:38 +08:00
|
|
|
return {
|
|
|
|
|
name: processInfo.name,
|
|
|
|
|
icon: processInfo.icon,
|
|
|
|
|
path: processInfo.startName,
|
2025-08-19 16:59:58 +08:00
|
|
|
col: x,
|
|
|
|
|
row: y
|
2025-08-19 14:56:38 +08:00
|
|
|
}
|
|
|
|
|
})
|
2025-08-20 09:59:19 +08:00
|
|
|
const appIconsRef = reactive(appIcons)
|
|
|
|
|
|
|
|
|
|
watch(() => [gridTemplate.rowCount, gridTemplate.colCount], () => {
|
|
|
|
|
appIconsRef.forEach((appIcon, index) => {
|
|
|
|
|
const x = Math.floor(index / gridTemplate.rowCount) + 1
|
|
|
|
|
const y = index % gridTemplate.rowCount + 1
|
|
|
|
|
appIcon.col = x
|
|
|
|
|
appIcon.row = y
|
|
|
|
|
})
|
|
|
|
|
console.log(appIconsRef)
|
|
|
|
|
})
|
2025-08-19 14:56:38 +08:00
|
|
|
|
|
|
|
|
return {
|
2025-08-20 09:59:19 +08:00
|
|
|
...toRefs(gridTemplate),
|
|
|
|
|
appIconsRef
|
2025-08-19 14:56:38 +08:00
|
|
|
}
|
|
|
|
|
}
|