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

108 lines
2.8 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">
<div class="desktop-container">
2025-08-20 09:59:19 +08:00
<div v-for="icon in appIconsRef" class="icon-container"
:style="`grid-row: ${icon.row}/${icon.row + 1};grid-column: ${icon.col}/${icon.col + 1}};`">{{ icon.name }}</div>
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-19 16:59:58 +08:00
const props = defineProps<{ process: DesktopProcess }>()
// console.log(props.process)
2025-08-20 09:59:19 +08:00
const { colCount, rowCount, appIconsRef } = useDesktopInit('.desktop-container')
2025-08-19 14:56:38 +08:00
2025-08-20 09:59:19 +08:00
const iconArr: IDesktopAppIcon[] = [
2025-08-19 14:56:38 +08:00
{
name: '文件管理器',
icon: '🗂',
path: '/',
col: 1,
2025-08-19 16:59:58 +08:00
row: 1,
2025-08-19 14:56:38 +08:00
},
{
name: '浏览器',
icon: '🌐',
path: '/',
col: 1,
2025-08-19 16:59:58 +08:00
row: 2,
2025-08-19 14:56:38 +08:00
},
{
name: '记事本',
icon: '📄',
path: '/',
col: 1,
2025-08-19 16:59:58 +08:00
row: 3,
2025-08-19 14:56:38 +08:00
},
{
name: '音乐播放器',
icon: '🎵',
path: '/',
col: 1,
2025-08-19 16:59:58 +08:00
row: 4,
},
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>
$icon-width: 80px;
$icon-height: 110px;
.desktop-root {
@apply w-full h-full flex flex-col;
.desktop-container {
@apply w-full flex-1 grid gap-4 grid-auto-flow-col p-4 pos-relative;
grid-template-columns: repeat(auto-fill, minmax($icon-width, 1fr));
grid-template-rows: repeat(auto-fill, minmax($icon-height, 1fr));
.icon-container {
width: $icon-width;
height: $icon-height;
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>