保存一下
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
import type { IProcessInfo } from '@/core/process/IProcessInfo.ts'
|
import type { IProcessInfo } from '@/core/process/IProcessInfo.ts'
|
||||||
import type { IWindowForm } from '@/core/window/IWindowForm.ts'
|
import type { IWindowForm } from '@/core/window/IWindowForm.ts'
|
||||||
|
import type { IEventBuilder } from '@/core/events/IEventBuilder.ts'
|
||||||
|
import type { IProcessEvent } from '@/core/process/types/ProcessEvent.ts'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 进程接口
|
* 进程接口
|
||||||
@@ -11,6 +13,7 @@ export interface IProcess {
|
|||||||
get processInfo(): IProcessInfo;
|
get processInfo(): IProcessInfo;
|
||||||
/** 进程的窗体列表 */
|
/** 进程的窗体列表 */
|
||||||
get windowForms(): Map<string, IWindowForm>;
|
get windowForms(): Map<string, IWindowForm>;
|
||||||
|
get event(): IEventBuilder<IProcessEvent>;
|
||||||
/**
|
/**
|
||||||
* 打开窗体
|
* 打开窗体
|
||||||
* @param startName 窗体启动名
|
* @param startName 窗体启动名
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ import type { IProcess } from '@/core/process/IProcess.ts'
|
|||||||
import type { IProcessInfo } from '@/core/process/IProcessInfo.ts'
|
import type { IProcessInfo } from '@/core/process/IProcessInfo.ts'
|
||||||
import type { IWindowForm } from '@/core/window/IWindowForm.ts'
|
import type { IWindowForm } from '@/core/window/IWindowForm.ts'
|
||||||
import { processManager } from '@/core/process/ProcessManager.ts'
|
import { processManager } from '@/core/process/ProcessManager.ts'
|
||||||
|
import { EventBuilderImpl } from '@/core/events/impl/EventBuilderImpl.ts'
|
||||||
|
import type { IEventBuilder } from '@/core/events/IEventBuilder.ts'
|
||||||
|
import type { IProcessEvent } from '@/core/process/types/ProcessEvent.ts'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 进程
|
* 进程
|
||||||
@@ -13,6 +16,7 @@ export default class ProcessImpl implements IProcess {
|
|||||||
private readonly _processInfo: IProcessInfo;
|
private readonly _processInfo: IProcessInfo;
|
||||||
// 当前进程的窗体集合
|
// 当前进程的窗体集合
|
||||||
private _windowForms: Map<string, IWindowForm> = new Map();
|
private _windowForms: Map<string, IWindowForm> = new Map();
|
||||||
|
private _event: IEventBuilder<IProcessEvent> = new EventBuilderImpl<IProcessEvent>()
|
||||||
|
|
||||||
public get id() {
|
public get id() {
|
||||||
return this._id;
|
return this._id;
|
||||||
@@ -23,6 +27,9 @@ export default class ProcessImpl implements IProcess {
|
|||||||
public get windowForms() {
|
public get windowForms() {
|
||||||
return this._windowForms;
|
return this._windowForms;
|
||||||
}
|
}
|
||||||
|
public get event() {
|
||||||
|
return this._event;
|
||||||
|
}
|
||||||
|
|
||||||
constructor(info: IProcessInfo) {
|
constructor(info: IProcessInfo) {
|
||||||
console.log(`AppProcess: ${info.name}`)
|
console.log(`AppProcess: ${info.name}`)
|
||||||
@@ -30,6 +37,8 @@ export default class ProcessImpl implements IProcess {
|
|||||||
|
|
||||||
const startName = info.startName;
|
const startName = info.startName;
|
||||||
|
|
||||||
|
this.initEvent();
|
||||||
|
|
||||||
processManager.registerProcess(this);
|
processManager.registerProcess(this);
|
||||||
// 通过设置 isJustProcess 为 true,则不会创建窗体
|
// 通过设置 isJustProcess 为 true,则不会创建窗体
|
||||||
if (!info.isJustProcess) {
|
if (!info.isJustProcess) {
|
||||||
@@ -37,6 +46,15 @@ export default class ProcessImpl implements IProcess {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private initEvent() {
|
||||||
|
this.event.addEventListener('onProcessWindowFormExit', (id: string) => {
|
||||||
|
this.windowForms.delete(id)
|
||||||
|
if(this.windowForms.size === 0) {
|
||||||
|
processManager.removeProcess(this)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
public openWindowForm(startName: string) {
|
public openWindowForm(startName: string) {
|
||||||
const info = this._processInfo.windowFormConfigs.find(item => item.name === startName);
|
const info = this._processInfo.windowFormConfigs.find(item => item.name === startName);
|
||||||
if (!info) throw new Error(`未找到窗体:${startName}`);
|
if (!info) throw new Error(`未找到窗体:${startName}`);
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import type { IEventMap } from '@/core/events/IEventBuilder.ts'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 进程的事件
|
* 进程的事件
|
||||||
* <p>onProcessExit - 进程退出</p>
|
* <p>onProcessExit - 进程退出</p>
|
||||||
@@ -6,9 +8,17 @@
|
|||||||
* <p>onProcessWindowFormFocus - 进程的窗体获取焦点</p>
|
* <p>onProcessWindowFormFocus - 进程的窗体获取焦点</p>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
type TAppProcessEvent =
|
type TProcessEvent =
|
||||||
'onProcessExit' |
|
'onProcessExit' |
|
||||||
'onProcessWindowFormOpen' |
|
'onProcessWindowFormOpen' |
|
||||||
'onProcessWindowFormExit' |
|
'onProcessWindowFormExit' |
|
||||||
'onProcessWindowFormFocus' |
|
'onProcessWindowFormFocus' |
|
||||||
'onProcessWindowFormBlur'
|
'onProcessWindowFormBlur'
|
||||||
|
|
||||||
|
export interface IProcessEvent extends IEventMap {
|
||||||
|
/**
|
||||||
|
* 进程的窗体退出
|
||||||
|
* @param id 窗体id
|
||||||
|
*/
|
||||||
|
onProcessWindowFormExit: (id: string) => void
|
||||||
|
}
|
||||||
@@ -5,12 +5,13 @@ import type { IWindowForm } from '@/core/window/IWindowForm.ts'
|
|||||||
import type { IWindowFormConfig } from '@/core/window/types/IWindowFormConfig.ts'
|
import type { IWindowFormConfig } from '@/core/window/types/IWindowFormConfig.ts'
|
||||||
import type { WindowFormPos } from '@/core/window/types/WindowFormTypes.ts'
|
import type { WindowFormPos } from '@/core/window/types/WindowFormTypes.ts'
|
||||||
import { processManager } from '@/core/process/ProcessManager.ts'
|
import { processManager } from '@/core/process/ProcessManager.ts'
|
||||||
import { DraggableResizable } from '@/core/utils/DraggableResizable.ts'
|
|
||||||
import { DraggableResizableWindow } from '@/core/utils/DraggableResizableWindow.ts'
|
import { DraggableResizableWindow } from '@/core/utils/DraggableResizableWindow.ts'
|
||||||
|
|
||||||
export default class WindowFormImpl implements IWindowForm {
|
export default class WindowFormImpl implements IWindowForm {
|
||||||
private readonly _id: string = uuidV4();
|
private readonly _id: string = uuidV4();
|
||||||
private readonly _procId: string;
|
private readonly _procId: string;
|
||||||
|
private dom: HTMLElement;
|
||||||
|
private drw: DraggableResizableWindow;
|
||||||
private pos: WindowFormPos = { x: 0, y: 0 };
|
private pos: WindowFormPos = { x: 0, y: 0 };
|
||||||
private width: number = 0;
|
private width: number = 0;
|
||||||
private height: number = 0;
|
private height: number = 0;
|
||||||
@@ -38,63 +39,65 @@ export default class WindowFormImpl implements IWindowForm {
|
|||||||
this.createWindowFrom();
|
this.createWindowFrom();
|
||||||
}
|
}
|
||||||
|
|
||||||
public createWindowFrom() {
|
private createWindowFrom() {
|
||||||
const dom = document.createElement('div');
|
this.dom = document.createElement('div');
|
||||||
dom.style.position = 'absolute';
|
this.dom.style.position = 'absolute';
|
||||||
dom.style.left = `${this.pos.x}px`;
|
this.dom.style.width = `${this.width}px`;
|
||||||
dom.style.top = `${this.pos.y}px`;
|
this.dom.style.height = `${this.height}px`;
|
||||||
dom.style.width = `${this.width}px`;
|
this.dom.style.zIndex = '100';
|
||||||
dom.style.height = `${this.height}px`;
|
this.dom.style.backgroundColor = 'white';
|
||||||
dom.style.zIndex = '100';
|
this.dom.classList.add('flex', 'flex-col', 'rd-[4px]')
|
||||||
dom.style.backgroundColor = 'white';
|
const header = document.createElement('div');
|
||||||
const div = document.createElement('div');
|
header.style.width = '100%';
|
||||||
div.style.width = '100%';
|
header.style.height = '20px';
|
||||||
div.style.height = '20px';
|
header.style.backgroundColor = 'red';
|
||||||
div.style.backgroundColor = 'red';
|
this.dom.appendChild(header)
|
||||||
dom.appendChild(div)
|
|
||||||
const bt1 = document.createElement('button');
|
const bt1 = document.createElement('button');
|
||||||
bt1.innerText = '最小化';
|
bt1.innerText = '最小化';
|
||||||
bt1.addEventListener('click', () => {
|
bt1.addEventListener('click', () => {
|
||||||
win.minimize();
|
this.drw.minimize();
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
win.restore();
|
this.drw.restore();
|
||||||
}, 2000)
|
}, 2000)
|
||||||
})
|
})
|
||||||
div.appendChild(bt1)
|
header.appendChild(bt1)
|
||||||
const bt2 = document.createElement('button');
|
const bt2 = document.createElement('button');
|
||||||
bt2.innerText = '最大化';
|
bt2.innerText = '最大化';
|
||||||
bt2.addEventListener('click', () => {
|
bt2.addEventListener('click', () => {
|
||||||
win.maximize();
|
this.drw.maximize();
|
||||||
})
|
})
|
||||||
div.appendChild(bt2)
|
header.appendChild(bt2)
|
||||||
const bt3 = document.createElement('button');
|
const bt3 = document.createElement('button');
|
||||||
bt3.innerText = '关闭';
|
bt3.innerText = '关闭';
|
||||||
bt3.addEventListener('click', () => {
|
bt3.addEventListener('click', () => {
|
||||||
this.desktopRootDom.removeChild(dom)
|
this.closeWindowForm();
|
||||||
win.destroy();
|
|
||||||
this.proc?.windowForms.delete(this.id);
|
|
||||||
processManager.removeProcess(this.proc!)
|
|
||||||
})
|
})
|
||||||
div.appendChild(bt3)
|
header.appendChild(bt3)
|
||||||
const bt4 = document.createElement('button');
|
const bt4 = document.createElement('button');
|
||||||
bt4.innerText = '恢复';
|
bt4.innerText = '恢复';
|
||||||
bt4.addEventListener('click', (e) => {
|
bt4.addEventListener('click', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
win.restore();
|
this.drw.restore();
|
||||||
})
|
})
|
||||||
div.appendChild(bt4)
|
header.appendChild(bt4)
|
||||||
|
|
||||||
|
|
||||||
const win = new DraggableResizableWindow({
|
this.drw = new DraggableResizableWindow({
|
||||||
target: dom,
|
target: this.dom,
|
||||||
handle: div,
|
handle: header,
|
||||||
snapAnimation: true,
|
snapAnimation: true,
|
||||||
snapThreshold: 20,
|
snapThreshold: 20,
|
||||||
boundary: document.body,
|
boundary: document.body,
|
||||||
taskbarElementId: '#taskbar',
|
taskbarElementId: '#taskbar',
|
||||||
})
|
})
|
||||||
|
|
||||||
this.desktopRootDom.appendChild(dom);
|
this.desktopRootDom.appendChild(this.dom);
|
||||||
|
}
|
||||||
|
|
||||||
|
private closeWindowForm() {
|
||||||
|
this.drw.destroy();
|
||||||
|
this.desktopRootDom.removeChild(this.dom);
|
||||||
|
this.proc?.event.notifyEvent('onProcessWindowFormExit', this.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user