保存一下
This commit is contained in:
@@ -1,26 +1,31 @@
|
||||
import XSystem from '@/core/XSystem.ts'
|
||||
import type { IconType } from '@/core/desktop/types/IconType.ts'
|
||||
import { nextTick, onUnmounted, reactive, toRefs } from 'vue'
|
||||
import { nextTick, onMounted, onUnmounted, reactive, toRefs, useTemplateRef } from 'vue'
|
||||
import { DesktopEventEnum } from '@/core/events/EventTypes.ts'
|
||||
import { useDraggable } from '@vueuse/core'
|
||||
|
||||
export function useDesktopInit(container: HTMLElement) {
|
||||
export function useDesktopInit(containerStr: string) {
|
||||
let container:HTMLElement
|
||||
const gridTemplate = reactive({
|
||||
cellWidth: 90,
|
||||
cellHeight: 110,
|
||||
gap: 10,
|
||||
col: 1,
|
||||
row: 1
|
||||
colCount: 1,
|
||||
rowCount: 1
|
||||
})
|
||||
|
||||
const ro = new ResizeObserver(entries => {
|
||||
const entry= entries[0]
|
||||
const containerRect = entry.contentRect
|
||||
gridTemplate.col = Math.floor(containerRect.width / gridTemplate.cellWidth);
|
||||
gridTemplate.row = Math.floor(containerRect.height / (gridTemplate.cellHeight));
|
||||
console.log(1111)
|
||||
gridTemplate.colCount = Math.floor(containerRect.width / gridTemplate.cellWidth);
|
||||
gridTemplate.rowCount = Math.floor(containerRect.height / (gridTemplate.cellHeight));
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
container = document.querySelector(containerStr)!
|
||||
console.log( container)
|
||||
ro.observe(container)
|
||||
})
|
||||
ro.observe(container)
|
||||
onUnmounted(() => {
|
||||
ro.unobserve(container)
|
||||
})
|
||||
@@ -28,17 +33,20 @@ export function useDesktopInit(container: HTMLElement) {
|
||||
// 有桌面图标的app
|
||||
const apps = XSystem.instance.processManages.processInfos.filter(processInfo => !processInfo.isJustProcess)
|
||||
console.log(apps)
|
||||
const icons: IconType[] = apps.map(processInfo => {
|
||||
const icons: IconType[] = apps.map((processInfo, index) => {
|
||||
// 左上角坐标原点,从上到下从左到右
|
||||
const x = Math.floor(index / gridTemplate.rowCount)
|
||||
const y = index % gridTemplate.rowCount
|
||||
return {
|
||||
name: processInfo.name,
|
||||
icon: processInfo.icon,
|
||||
path: processInfo.startName,
|
||||
col: 0,
|
||||
row: 0
|
||||
col: x,
|
||||
row: y
|
||||
}
|
||||
})
|
||||
|
||||
return {
|
||||
...toRefs(gridTemplate),
|
||||
...toRefs(gridTemplate)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user