保存一下
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
export interface IconType {
|
||||
export interface IDesktopAppIcon {
|
||||
name: string;
|
||||
icon: string;
|
||||
path: string;
|
||||
col: number;
|
||||
row: number;
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,8 @@
|
||||
>
|
||||
<div ref="desktopRootDom" class="desktop-root">
|
||||
<div class="desktop-container">
|
||||
<div v-for="icon in iconArr" class="icon-container"
|
||||
:style="`grid-row: ${icon.row}/${icon.row + 1};grid-column: ${icon.col}/${icon.col + 1}};`">{{ icon.icon }}</div>
|
||||
<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>
|
||||
</div>
|
||||
<div class="task-bar"></div>
|
||||
</div>
|
||||
@@ -20,16 +20,15 @@ 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'
|
||||
import { onMounted, ref, useTemplateRef, watchEffect } from 'vue'
|
||||
import type { IconType } from '@/core/desktop/types/IconType.ts'
|
||||
import type { IDesktopAppIcon } from '@/core/desktop/types/IDesktopAppIcon.ts'
|
||||
import { useDesktopInit } from '@/core/desktop/ui/useDesktopInit.ts'
|
||||
|
||||
const props = defineProps<{ process: DesktopProcess }>()
|
||||
// console.log(props.process)
|
||||
|
||||
const { colCount, rowCount } = useDesktopInit('.desktop-container')
|
||||
const { colCount, rowCount, appIconsRef } = useDesktopInit('.desktop-container')
|
||||
|
||||
const iconArr: IconType[] = [
|
||||
const iconArr: IDesktopAppIcon[] = [
|
||||
{
|
||||
name: '文件管理器',
|
||||
icon: '🗂',
|
||||
@@ -96,12 +95,13 @@ $icon-height: 110px;
|
||||
.icon-container {
|
||||
width: $icon-width;
|
||||
height: $icon-height;
|
||||
@apply flex flex-col items-center justify-center rounded text-white bg-gray-200;
|
||||
@apply flex flex-col items-center justify-center rounded bg-gray-200;
|
||||
}
|
||||
}
|
||||
|
||||
.task-bar {
|
||||
@apply w-full h-[40px] bg-gray-200;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
import XSystem from '@/core/XSystem.ts'
|
||||
import type { IconType } from '@/core/desktop/types/IconType.ts'
|
||||
import { nextTick, onMounted, onUnmounted, reactive, toRefs, useTemplateRef } from 'vue'
|
||||
import type { IDesktopAppIcon } from '@/core/desktop/types/IDesktopAppIcon.ts'
|
||||
import {
|
||||
nextTick,
|
||||
onMounted,
|
||||
onUnmounted,
|
||||
reactive,
|
||||
toRefs,
|
||||
useTemplateRef,
|
||||
watch,
|
||||
watchEffect,
|
||||
} from 'vue'
|
||||
import { DesktopEventEnum } from '@/core/events/EventTypes.ts'
|
||||
import { useDraggable } from '@vueuse/core'
|
||||
|
||||
@@ -19,11 +28,11 @@ export function useDesktopInit(containerStr: string) {
|
||||
const containerRect = entry.contentRect
|
||||
gridTemplate.colCount = Math.floor(containerRect.width / gridTemplate.cellWidth);
|
||||
gridTemplate.rowCount = Math.floor(containerRect.height / (gridTemplate.cellHeight));
|
||||
console.log('resize', gridTemplate)
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
container = document.querySelector(containerStr)!
|
||||
console.log( container)
|
||||
ro.observe(container)
|
||||
})
|
||||
onUnmounted(() => {
|
||||
@@ -31,12 +40,11 @@ export function useDesktopInit(containerStr: string) {
|
||||
})
|
||||
|
||||
// 有桌面图标的app
|
||||
const apps = XSystem.instance.processManages.processInfos.filter(processInfo => !processInfo.isJustProcess)
|
||||
console.log(apps)
|
||||
const icons: IconType[] = apps.map((processInfo, index) => {
|
||||
// 左上角坐标原点,从上到下从左到右
|
||||
const x = Math.floor(index / gridTemplate.rowCount)
|
||||
const y = index % gridTemplate.rowCount
|
||||
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
|
||||
return {
|
||||
name: processInfo.name,
|
||||
icon: processInfo.icon,
|
||||
@@ -45,8 +53,20 @@ export function useDesktopInit(containerStr: string) {
|
||||
row: y
|
||||
}
|
||||
})
|
||||
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)
|
||||
})
|
||||
|
||||
return {
|
||||
...toRefs(gridTemplate)
|
||||
...toRefs(gridTemplate),
|
||||
appIconsRef
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user