保存一下

This commit is contained in:
2025-08-19 16:59:58 +08:00
parent 9c9387f6c2
commit e8749e3efa
8 changed files with 94 additions and 55 deletions

View File

@@ -31,7 +31,6 @@ export default class XSystem {
public initialization(dom: HTMLDivElement) { public initialization(dom: HTMLDivElement) {
this.run('basic-system', BasicSystemProcess).then(() => { this.run('basic-system', BasicSystemProcess).then(() => {
this.run('desktop', DesktopProcess).then((proc) => { this.run('desktop', DesktopProcess).then((proc) => {
console.log(proc)
proc.mount(dom) proc.mount(dom)
}) })
}) })

View File

@@ -72,7 +72,8 @@ export class DesktopProcess extends AppProcess {
} }
public mount(dom: HTMLDivElement) { public mount(dom: HTMLDivElement) {
if (this._isMounted) return; console.log('DesktopProcess: start mount')
if (this._isMounted) return
this._width = window.innerWidth this._width = window.innerWidth
this._height = window.innerHeight this._height = window.innerHeight
window.addEventListener( window.addEventListener(
@@ -80,18 +81,18 @@ export class DesktopProcess extends AppProcess {
debounce(() => { debounce(() => {
this.width = window.innerWidth this.width = window.innerWidth
this.height = window.innerHeight this.height = window.innerHeight
}, 300), }, 300)
) )
dom.style.zIndex = '0'; dom.style.zIndex = '0';
dom.style.width = `${this._width}px` dom.style.width = `${this._width}px`
dom.style.height = `${this._height}px` dom.style.height = `${this._height}px`
this._desktopRootDom = dom; this._desktopRootDom = dom
const app = createApp(DesktopComponent, { process: this }) const app = createApp(DesktopComponent, { process: this })
app.use(naiveUi) app.use(naiveUi)
app.mount(dom) app.mount(dom)
this._isMounted = true; this._isMounted = true
} }
} }

View File

@@ -1,8 +1,12 @@
<template> <template>
<n-config-provider :config-provider-props="configProviderProps" class="w-full h-full pos-relative"> <n-config-provider
:config-provider-props="configProviderProps"
class="w-full h-full pos-relative"
>
<div ref="desktopRootDom" class="desktop-root"> <div ref="desktopRootDom" class="desktop-root">
<div class="desktop-container"> <div class="desktop-container">
<div v-for="icon in iconArr" class="icon-container">{{ icon.icon }}</div> <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> </div>
<div class="task-bar"></div> <div class="task-bar"></div>
</div> </div>
@@ -16,12 +20,14 @@ import { notificationApi } from '@/core/common/naive-ui/discrete-api.ts'
import { configProviderProps } from '@/core/common/naive-ui/theme.ts' import { configProviderProps } from '@/core/common/naive-ui/theme.ts'
import { DesktopEventEnum } from '@/core/events/EventTypes.ts' import { DesktopEventEnum } from '@/core/events/EventTypes.ts'
import { useIconDrag } from '@/core/desktop/utils/useIconDrag.ts' import { useIconDrag } from '@/core/desktop/utils/useIconDrag.ts'
import { onMounted } from 'vue' import { onMounted, ref, useTemplateRef, watchEffect } from 'vue'
import type { IconType } from '@/core/desktop/types/IconType.ts' import type { IconType } from '@/core/desktop/types/IconType.ts'
import { useDesktopInit } from '@/core/desktop/ui/useDesktopInit.ts' import { useDesktopInit } from '@/core/desktop/ui/useDesktopInit.ts'
const props = defineProps<{process: DesktopProcess}>() const props = defineProps<{ process: DesktopProcess }>()
console.log(props.process) // console.log(props.process)
const { colCount, rowCount } = useDesktopInit('.desktop-container')
const iconArr: IconType[] = [ const iconArr: IconType[] = [
{ {
@@ -29,35 +35,42 @@ const iconArr: IconType[] = [
icon: '🗂', icon: '🗂',
path: '/', path: '/',
col: 1, col: 1,
row: 1 row: 1,
}, },
{ {
name: '浏览器', name: '浏览器',
icon: '🌐', icon: '🌐',
path: '/', path: '/',
col: 1, col: 1,
row: 2 row: 2,
}, },
{ {
name: '记事本', name: '记事本',
icon: '📄', icon: '📄',
path: '/', path: '/',
col: 1, col: 1,
row: 3 row: 3,
}, },
{ {
name: '音乐播放器', name: '音乐播放器',
icon: '🎵', icon: '🎵',
path: '/', path: '/',
col: 1, col: 1,
row: 4 row: 4,
} },
] ]
XSystem.instance.eventManages.addEventListener(DesktopEventEnum.onDesktopRootDomResize, (width, height) => { XSystem.instance.eventManages.addEventListener(
console.log(width, height) DesktopEventEnum.onDesktopRootDomResize,
notificationApi.create({ title: '桌面通知', content: `桌面尺寸变化${width}x${height}}`, duration: 2000 }) (width, height) => {
}) console.log(width, height)
notificationApi.create({
title: '桌面通知',
content: `桌面尺寸变化${width}x${height}}`,
duration: 2000,
})
},
)
const iconsInit = () => { const iconsInit = () => {
const icons = document.querySelectorAll<HTMLDivElement>('div.icon-container') const icons = document.querySelectorAll<HTMLDivElement>('div.icon-container')
@@ -66,13 +79,6 @@ const iconsInit = () => {
useIconDrag(icon, container) useIconDrag(icon, container)
}) })
} }
onMounted(() => {
const container = document.querySelector<HTMLDivElement>('.desktop-container')!
console.log(container.getBoundingClientRect())
// iconsInit()
const { col, row } = useDesktopInit(container)
console.log(col.value, row.value)
})
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@@ -1,26 +1,31 @@
import XSystem from '@/core/XSystem.ts' import XSystem from '@/core/XSystem.ts'
import type { IconType } from '@/core/desktop/types/IconType.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 { DesktopEventEnum } from '@/core/events/EventTypes.ts'
import { useDraggable } from '@vueuse/core' import { useDraggable } from '@vueuse/core'
export function useDesktopInit(container: HTMLElement) { export function useDesktopInit(containerStr: string) {
let container:HTMLElement
const gridTemplate = reactive({ const gridTemplate = reactive({
cellWidth: 90, cellWidth: 90,
cellHeight: 110, cellHeight: 110,
gap: 10, gap: 10,
col: 1, colCount: 1,
row: 1 rowCount: 1
}) })
const ro = new ResizeObserver(entries => { const ro = new ResizeObserver(entries => {
const entry= entries[0] const entry= entries[0]
const containerRect = entry.contentRect const containerRect = entry.contentRect
gridTemplate.col = Math.floor(containerRect.width / gridTemplate.cellWidth); gridTemplate.colCount = Math.floor(containerRect.width / gridTemplate.cellWidth);
gridTemplate.row = Math.floor(containerRect.height / (gridTemplate.cellHeight)); gridTemplate.rowCount = Math.floor(containerRect.height / (gridTemplate.cellHeight));
console.log(1111) })
onMounted(() => {
container = document.querySelector(containerStr)!
console.log( container)
ro.observe(container)
}) })
ro.observe(container)
onUnmounted(() => { onUnmounted(() => {
ro.unobserve(container) ro.unobserve(container)
}) })
@@ -28,17 +33,20 @@ export function useDesktopInit(container: HTMLElement) {
// 有桌面图标的app // 有桌面图标的app
const apps = XSystem.instance.processManages.processInfos.filter(processInfo => !processInfo.isJustProcess) const apps = XSystem.instance.processManages.processInfos.filter(processInfo => !processInfo.isJustProcess)
console.log(apps) 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 { return {
name: processInfo.name, name: processInfo.name,
icon: processInfo.icon, icon: processInfo.icon,
path: processInfo.startName, path: processInfo.startName,
col: 0, col: x,
row: 0 row: y
} }
}) })
return { return {
...toRefs(gridTemplate), ...toRefs(gridTemplate)
} }
} }

View File

@@ -1,31 +1,56 @@
import type { IEventMap } from '@/core/events/IEventBuilder.ts' import type { IEventMap } from '@/core/events/IEventBuilder.ts'
/**
* 桌面进程事件枚举
* @description
* <p>onDesktopRootDomResize - 桌面根dom尺寸改变</p>
* <p>onDesktopProcessInitialize - 桌面进程初始化完成</p>
*/
export enum DesktopEventEnum { export enum DesktopEventEnum {
onDesktopRootDomResize = 'onDesktopRootDomResize' /** 桌面进程初始化完成 */
} onDesktopRootDomResize = 'onDesktopRootDomResize',
/** 桌面进程初始化完成 */
export type DesktopEventParams = { onDesktopProcessInitialize = 'onDesktopProcessInitialize'
[DesktopEventEnum.onDesktopRootDomResize]: (width: number, height: number) => void
} }
/**
* 基础系统进程事件枚举
* @description
* <p>onAuthenticationChange - 认证状态改变</p>
* <p>onBasicSystemProcessInitialize - 主题改变</p>
*/
export enum BasicSystemEventEnum { export enum BasicSystemEventEnum {
/** 基础系统进程初始化完成 */
onBasicSystemProcessInitialize = 'onBasicSystemProcessInitialize',
/** 认证状态改变 */
onAuthChange = 'onAuthChange', onAuthChange = 'onAuthChange',
/** 主题改变 */
onThemeChange = 'onThemeChange' onThemeChange = 'onThemeChange'
} }
export type BasicSystemEventParams = { /**
[BasicSystemEventEnum.onAuthChange]: () => {}, * 桌面进程的事件
[BasicSystemEventEnum.onThemeChange]: (theme: string) => void * @description
} * <p>onDesktopRootDomResize - 桌面根dom尺寸改变</p>
* <p>onDesktopProcessInitialize - 桌面进程初始化完成</p>
export type AllEventParams = BasicSystemEventParams & DesktopEventParams */
export interface IDesktopEvent extends IEventMap { export interface IDesktopEvent extends IEventMap {
/** 桌面根dom尺寸改变 */
[DesktopEventEnum.onDesktopRootDomResize]: (width: number, height: number) => void [DesktopEventEnum.onDesktopRootDomResize]: (width: number, height: number) => void
/** 桌面进程初始化完成 */
[DesktopEventEnum.onDesktopProcessInitialize]: () => void
} }
/**
* 系统进程的事件
* @description
* <p>onAuthChange - 认证状态改变</p>
* <p>onThemeChange - 主题改变</p>
*/
export interface IBasicSystemEvent extends IEventMap { export interface IBasicSystemEvent extends IEventMap {
/** 认证状态改变 */
[BasicSystemEventEnum.onAuthChange]: () => {}, [BasicSystemEventEnum.onAuthChange]: () => {},
/** 主题改变 */
[BasicSystemEventEnum.onThemeChange]: (theme: string) => void [BasicSystemEventEnum.onThemeChange]: (theme: string) => void
} }

View File

@@ -1,5 +1,5 @@
import type { Version } from '../common/types/Version.ts' import type { Version } from '../common/types/Version.ts'
import type { AppProcessInfoParams } from '../process/types/AppProcessInfoParams.ts' import type { IAppProcessInfoParams } from './types/IAppProcessInfoParams.ts'
import type { WindowFormConfig } from '../window/types/WindowFormConfig.ts' import type { WindowFormConfig } from '../window/types/WindowFormConfig.ts'
export class AppProcessInfo { export class AppProcessInfo {
@@ -58,7 +58,7 @@ export class AppProcessInfo {
*/ */
private readonly _windowFormConfigs: Array<WindowFormConfig>; private readonly _windowFormConfigs: Array<WindowFormConfig>;
constructor(info: AppProcessInfoParams) { constructor(info: IAppProcessInfoParams) {
this._name = info.name; this._name = info.name;
this._title = info.title || ''; this._title = info.title || '';
this._description = info.description || ''; this._description = info.description || '';

View File

@@ -2,7 +2,7 @@ import type AppProcess from './AppProcess.ts'
import { AppProcessInfo } from '@/core/process/AppProcessInfo.ts' import { AppProcessInfo } from '@/core/process/AppProcessInfo.ts'
import { BasicSystemProcessInfo } from '@/core/system/BasicSystemProcessInfo.ts' import { BasicSystemProcessInfo } from '@/core/system/BasicSystemProcessInfo.ts'
import { DesktopProcessInfo } from '@/core/desktop/DesktopProcessInfo.ts' import { DesktopProcessInfo } from '@/core/desktop/DesktopProcessInfo.ts'
import type { AppProcessInfoParams } from '@/core/process/types/AppProcessInfoParams.ts' import type { IAppProcessInfoParams } from '@/core/process/types/IAppProcessInfoParams.ts'
/** /**
* 进程管理 * 进程管理
@@ -23,7 +23,7 @@ export default class ProcessManages {
public loadAppProcessInfos() { public loadAppProcessInfos() {
console.log('加载所有进程信息') console.log('加载所有进程信息')
// 添加内置进程 // 添加内置进程
const apps = import.meta.glob<AppProcessInfoParams>('../apps/**/*.json', { eager: true }) const apps = import.meta.glob<IAppProcessInfoParams>('../apps/**/*.json', { eager: true })
const internalProcessInfos: AppProcessInfo[] = Object.values(apps).map(data => new AppProcessInfo(data)) const internalProcessInfos: AppProcessInfo[] = Object.values(apps).map(data => new AppProcessInfo(data))
this._processInfos.push(BasicSystemProcessInfo) this._processInfos.push(BasicSystemProcessInfo)

View File

@@ -4,7 +4,7 @@ import type { WindowFormConfig } from '../../window/types/WindowFormConfig.ts'
/** /**
* *
*/ */
export interface AppProcessInfoParams { export interface IAppProcessInfoParams {
/** 应用进程名称 */ /** 应用进程名称 */
name: string; name: string;
/** 应用进程标题 */ /** 应用进程标题 */