Files
vue-desktop/src/core/desktop/ui/DesktopComponent.vue

74 lines
2.2 KiB
Vue
Raw Normal View History

2025-08-19 14:56:38 +08:00
<template>
2025-08-19 16:59:58 +08:00
<n-config-provider
:config-provider-props="configProviderProps"
class="w-full h-full pos-relative"
>
2025-08-19 14:56:38 +08:00
<div ref="desktopRootDom" class="desktop-root">
2025-08-21 16:57:42 +08:00
<div class="desktop-container"
:style="gridStyle">
<AppIcon v-for="(appIcon, i) in appIconsRef" :key="i"
:icon="appIcon" :gridTemplate="gridTemplate" />
2025-08-19 14:56:38 +08:00
</div>
<div class="task-bar"></div>
</div>
</n-config-provider>
</template>
<script setup lang="ts">
import type { DesktopProcess } from '@/core/desktop/DesktopProcess.ts'
import XSystem from '@/core/XSystem.ts'
import { notificationApi } from '@/core/common/naive-ui/discrete-api.ts'
import { configProviderProps } from '@/core/common/naive-ui/theme.ts'
import { DesktopEventEnum } from '@/core/events/EventTypes.ts'
import { useIconDrag } from '@/core/desktop/utils/useIconDrag.ts'
2025-08-20 09:59:19 +08:00
import type { IDesktopAppIcon } from '@/core/desktop/types/IDesktopAppIcon.ts'
2025-08-19 14:56:38 +08:00
import { useDesktopInit } from '@/core/desktop/ui/useDesktopInit.ts'
2025-08-21 16:57:42 +08:00
import AppIcon from '@/core/desktop/ui/components/AppIcon.vue'
2025-08-19 14:56:38 +08:00
2025-08-19 16:59:58 +08:00
const props = defineProps<{ process: DesktopProcess }>()
// console.log(props.process)
2025-08-21 16:57:42 +08:00
const { appIconsRef, gridStyle, gridTemplate } = useDesktopInit('.desktop-container')
2025-08-19 14:56:38 +08:00
2025-08-19 16:59:58 +08:00
XSystem.instance.eventManages.addEventListener(
DesktopEventEnum.onDesktopRootDomResize,
(width, height) => {
console.log(width, height)
notificationApi.create({
title: '桌面通知',
content: `桌面尺寸变化${width}x${height}}`,
duration: 2000,
})
},
)
2025-08-19 14:56:38 +08:00
const iconsInit = () => {
const icons = document.querySelectorAll<HTMLDivElement>('div.icon-container')
const container = document.querySelector<HTMLDivElement>('.desktop-container')!
icons.forEach((icon: HTMLDivElement) => {
useIconDrag(icon, container)
})
}
</script>
<style lang="scss" scoped>
.desktop-root {
@apply w-full h-full flex flex-col;
.desktop-container {
2025-08-21 16:57:42 +08:00
@apply w-full flex-1 grid grid-auto-flow-col pos-relative;
2025-08-19 14:56:38 +08:00
.icon-container {
2025-08-21 16:57:42 +08:00
width: 100%;
height: 100%;
2025-08-20 09:59:19 +08:00
@apply flex flex-col items-center justify-center rounded bg-gray-200;
2025-08-19 14:56:38 +08:00
}
}
.task-bar {
@apply w-full h-[40px] bg-gray-200;
2025-08-20 09:59:19 +08:00
flex-shrink: 0;
2025-08-19 14:56:38 +08:00
}
}
</style>