修改
This commit is contained in:
@@ -19,4 +19,9 @@ export interface IProcess {
|
||||
* @param startName 窗体启动名
|
||||
*/
|
||||
openWindowForm(startName: string): void;
|
||||
/**
|
||||
* 关闭窗体
|
||||
* @param id 窗体id
|
||||
*/
|
||||
closeWindowForm(id: string): void;
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ export default class ProcessImpl implements IProcess {
|
||||
}
|
||||
|
||||
private initEvent() {
|
||||
this.event.addEventListener('onProcessWindowFormExit', (id: string) => {
|
||||
this.event.addEventListener('processWindowFormExit', (id: string) => {
|
||||
this.windowForms.delete(id)
|
||||
if(this.windowForms.size === 0) {
|
||||
processManager.removeProcess(this)
|
||||
@@ -58,7 +58,20 @@ export default class ProcessImpl implements IProcess {
|
||||
public openWindowForm(startName: string) {
|
||||
const info = this._processInfo.windowFormConfigs.find(item => item.name === startName);
|
||||
if (!info) throw new Error(`未找到窗体:${startName}`);
|
||||
const window = new WindowFormImpl(this, info);
|
||||
this._windowForms.set(window.id, window);
|
||||
const wf = new WindowFormImpl(this, info);
|
||||
this._windowForms.set(wf.id, wf);
|
||||
}
|
||||
|
||||
public closeWindowForm(id: string) {
|
||||
try {
|
||||
const wf = this._windowForms.get(id);
|
||||
if (!wf) throw new Error(`未找到窗体:${id}`);
|
||||
this.windowForms.delete(id)
|
||||
if(this.windowForms.size === 0) {
|
||||
processManager.removeProcess(this)
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('关闭窗体失败', e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,5 +20,5 @@ export interface IProcessEvent extends IEventMap {
|
||||
* 进程的窗体退出
|
||||
* @param id 窗体id
|
||||
*/
|
||||
onProcessWindowFormExit: (id: string) => void
|
||||
processWindowFormExit: (id: string) => void
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
import { AService } from '@/core/service/kernel/AService.ts'
|
||||
import type { IWindowForm } from '@/core/window/IWindowForm.ts'
|
||||
import WindowFormImpl from '@/core/window/impl/WindowFormImpl.ts'
|
||||
import type { IProcess } from '@/core/process/IProcess.ts'
|
||||
import type { IWindowFormConfig } from '@/core/window/types/IWindowFormConfig.ts'
|
||||
|
||||
interface IWindow {
|
||||
id: string;
|
||||
@@ -13,67 +17,47 @@ interface IWindow {
|
||||
}
|
||||
|
||||
export class WindowFormService extends AService {
|
||||
private windows: Map<string, IWindow> = new Map();
|
||||
private zCounter = 1;
|
||||
private windows: Map<string, IWindowForm> = new Map();
|
||||
|
||||
constructor() {
|
||||
super("WindowForm");
|
||||
super("WindowFormService");
|
||||
console.log('WindowFormService - 服务注册')
|
||||
}
|
||||
|
||||
createWindow(title: string, config?: Partial<IWindow>): IWindow {
|
||||
const id = `win-${Date.now()}-${Math.random()}`;
|
||||
const win: IWindow = {
|
||||
id,
|
||||
title,
|
||||
x: config?.x ?? 100,
|
||||
y: config?.y ?? 100,
|
||||
width: config?.width ?? 400,
|
||||
height: config?.height ?? 300,
|
||||
zIndex: this.zCounter++,
|
||||
minimized: false,
|
||||
maximized: false
|
||||
};
|
||||
this.windows.set(id, win);
|
||||
this.sm.broadcast("WindowFrom:created", win);
|
||||
return win;
|
||||
public createWindow(proc: IProcess, info: IWindowFormConfig): IWindowForm {
|
||||
const window = new WindowFormImpl(proc, info);
|
||||
this.windows.set(window.id, window);
|
||||
return window;
|
||||
}
|
||||
|
||||
closeWindow(id: string) {
|
||||
public closeWindow(id: string) {
|
||||
if (this.windows.has(id)) {
|
||||
this.windows.delete(id);
|
||||
this.sm.broadcast("WindowFrom:closed", id);
|
||||
}
|
||||
}
|
||||
|
||||
focusWindow(id: string) {
|
||||
public focusWindow(id: string) {
|
||||
const win = this.windows.get(id);
|
||||
if (win) {
|
||||
win.zIndex = this.zCounter++;
|
||||
this.sm.broadcast("WindowFrom:focused", win);
|
||||
}
|
||||
}
|
||||
|
||||
minimizeWindow(id: string) {
|
||||
public minimizeWindow(id: string) {
|
||||
const win = this.windows.get(id);
|
||||
if (win) {
|
||||
win.minimized = true;
|
||||
this.sm.broadcast("WindowFrom:minimized", win);
|
||||
}
|
||||
}
|
||||
|
||||
maximizeWindow(id: string) {
|
||||
public maximizeWindow(id: string) {
|
||||
const win = this.windows.get(id);
|
||||
if (win) {
|
||||
win.maximized = !win.maximized;
|
||||
this.sm.broadcast("WindowFrom:maximized", win);
|
||||
}
|
||||
}
|
||||
|
||||
getWindows(): IWindow[] {
|
||||
return Array.from(this.windows.values()).sort((a, b) => a.zIndex - b.zIndex);
|
||||
}
|
||||
|
||||
onMessage(event: string, data?: any) {
|
||||
console.log(`[WindowService] 收到事件:`, event, data);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,4 @@ export interface IWindowForm {
|
||||
get windowFormEle(): HTMLElement;
|
||||
/** 窗体状态 */
|
||||
get windowFormState(): TWindowFormState;
|
||||
/** 关闭窗体 */
|
||||
closeWindowForm(): void;
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import XSystem from '../../XSystem.ts'
|
||||
import type { IProcess } from '@/core/process/IProcess.ts'
|
||||
import type { IWindowForm } from '@/core/window/IWindowForm.ts'
|
||||
import type { IWindowFormConfig } from '@/core/window/types/IWindowFormConfig.ts'
|
||||
import type { WindowFormPos } from '@/core/window/types/WindowFormTypes.ts'
|
||||
import type { TWindowFormState, WindowFormPos } from '@/core/window/types/WindowFormTypes.ts'
|
||||
import { processManager } from '@/core/process/ProcessManager.ts'
|
||||
import { DraggableResizableWindow } from '@/core/utils/DraggableResizableWindow.ts'
|
||||
import '../css/window-form.scss'
|
||||
@@ -13,31 +13,43 @@ import { wfem } from '@/core/events/WindowFormEventManager.ts'
|
||||
import type { IObservable } from '@/core/state/IObservable.ts'
|
||||
import { ObservableImpl } from '@/core/state/impl/ObservableImpl.ts'
|
||||
|
||||
export interface IWindowFormDataState {
|
||||
/** 窗体id */
|
||||
id: string;
|
||||
/** 窗体进程id */
|
||||
procId: string;
|
||||
/** 进程名称唯一 */
|
||||
name: string;
|
||||
/** 窗体位置x (左上角) */
|
||||
x: number;
|
||||
/** 窗体位置y (左上角) */
|
||||
y: number;
|
||||
/** 窗体宽度 */
|
||||
width: number;
|
||||
/** 窗体高度 */
|
||||
height: number;
|
||||
/** 窗体状态 'default' | 'minimized' | 'maximized' */
|
||||
state: TWindowFormState;
|
||||
/** 窗体是否已关闭 */
|
||||
closed: boolean;
|
||||
}
|
||||
|
||||
export default class WindowFormImpl implements IWindowForm {
|
||||
private readonly _id: string = uuidV4()
|
||||
private readonly _procId: string
|
||||
private readonly _proc: IProcess;
|
||||
private dom: HTMLElement
|
||||
private drw: DraggableResizableWindow
|
||||
private pos: WindowFormPos = { x: 0, y: 0 }
|
||||
private width: number
|
||||
private height: number
|
||||
private _state: IObservable<{ x: number, y: number }> = new ObservableImpl({
|
||||
x: 0,
|
||||
y: 0,
|
||||
})
|
||||
private _data: IObservable<IWindowFormDataState>;
|
||||
|
||||
public get id() {
|
||||
return this._id
|
||||
}
|
||||
public get proc() {
|
||||
return processManager.findProcessById(this._procId)
|
||||
return this._proc
|
||||
}
|
||||
private get desktopRootDom() {
|
||||
return XSystem.instance.desktopRootDom
|
||||
}
|
||||
private get sm() {
|
||||
return serviceManager.getService('WindowForm')
|
||||
}
|
||||
public get windowFormEle() {
|
||||
return this.dom
|
||||
}
|
||||
@@ -46,27 +58,35 @@ export default class WindowFormImpl implements IWindowForm {
|
||||
}
|
||||
|
||||
constructor(proc: IProcess, config: IWindowFormConfig) {
|
||||
this._procId = proc.id
|
||||
this._proc = proc
|
||||
console.log('WindowForm')
|
||||
this.pos = {
|
||||
|
||||
this._data = new ObservableImpl<IWindowFormDataState>({
|
||||
id: this.id,
|
||||
procId: proc.id,
|
||||
name: proc.processInfo.name,
|
||||
x: config.left ?? 0,
|
||||
y: config.top ?? 0,
|
||||
}
|
||||
this.width = config.width ?? 200
|
||||
this.height = config.height ?? 100
|
||||
width: config.width ?? 200,
|
||||
height: config.height ?? 100,
|
||||
state: 'default',
|
||||
closed: false
|
||||
})
|
||||
|
||||
this.createWindowFrom()
|
||||
this.initEvent()
|
||||
this.createWindowFrom()
|
||||
}
|
||||
|
||||
private initEvent() {
|
||||
wfem.addEventListener('windowFormClose', this.windowFormCloseFun)
|
||||
}
|
||||
|
||||
private windowFormCloseFun = (id: string) => {
|
||||
if (id === this.id) {
|
||||
this._data.subscribeKey('closed', (state) => {
|
||||
console.log('closed', state)
|
||||
this.closeWindowForm()
|
||||
}
|
||||
this._proc.closeWindowForm(this.id)
|
||||
})
|
||||
|
||||
// this._data.subscribeKey(['x', 'y'], (state) => {
|
||||
// console.log('x,y', state)
|
||||
// })
|
||||
}
|
||||
|
||||
private createWindowFrom() {
|
||||
@@ -96,8 +116,8 @@ export default class WindowFormImpl implements IWindowForm {
|
||||
|
||||
// this.desktopRootDom.appendChild(this.dom);
|
||||
const wf = document.createElement('window-form-element')
|
||||
wf.pos = this._state
|
||||
wf.wid = this.id
|
||||
wf.wfData = this._data
|
||||
wf.dragContainer = document.body
|
||||
wf.snapDistance = 20
|
||||
wf.taskbarElementId = '#taskbar'
|
||||
@@ -111,21 +131,24 @@ export default class WindowFormImpl implements IWindowForm {
|
||||
console.log('windowForm:stateChange:restore', e)
|
||||
})
|
||||
wf.addManagedEventListener('windowForm:close', () => {
|
||||
this.closeWindowForm()
|
||||
// this.closeWindowForm()
|
||||
})
|
||||
this.dom = wf
|
||||
this.desktopRootDom.appendChild(this.dom)
|
||||
wfem.notifyEvent('windowFormFocus', this.id)
|
||||
}
|
||||
|
||||
public closeWindowForm() {
|
||||
private closeWindowForm() {
|
||||
// this.drw.destroy();
|
||||
this.desktopRootDom.removeChild(this.dom)
|
||||
this.proc?.event.notifyEvent('onProcessWindowFormExit', this.id)
|
||||
wfem.removeEventListener('windowFormClose', this.windowFormCloseFun)
|
||||
this._data.dispose()
|
||||
// wfem.notifyEvent('windowFormClose', this.id)
|
||||
}
|
||||
|
||||
public minimize() {}
|
||||
public maximize() {}
|
||||
public restore() {}
|
||||
|
||||
private createWindowFormEle() {
|
||||
const template = document.createElement('template')
|
||||
template.innerHTML = `
|
||||
|
||||
@@ -4,6 +4,7 @@ import wfStyle from './wf.scss?inline'
|
||||
import type { TWindowFormState } from '@/core/window/types/WindowFormTypes.ts'
|
||||
import { wfem } from '@/core/events/WindowFormEventManager.ts'
|
||||
import type { IObservable } from '@/core/state/IObservable.ts'
|
||||
import type { IWindowFormDataState } from '@/core/window/impl/WindowFormImpl.ts'
|
||||
|
||||
/** 拖拽移动开始的回调 */
|
||||
type TDragStartCallback = (x: number, y: number) => void;
|
||||
@@ -84,7 +85,7 @@ export class WindowFormElement extends LitElement {
|
||||
@property({ type: Number }) maxHeight?: number
|
||||
@property({ type: Number }) minHeight?: number
|
||||
@property({ type: String }) taskbarElementId?: string
|
||||
@property({ type: Object }) pos: IObservable<{ x: number, y: number }>;
|
||||
@property({ type: Object }) wfData: IObservable<IWindowFormDataState>;
|
||||
|
||||
private _listeners: Array<{ type: string; handler: EventListener }> = []
|
||||
|
||||
@@ -107,6 +108,19 @@ export class WindowFormElement extends LitElement {
|
||||
private animationFrame?: number
|
||||
private resizing = false
|
||||
|
||||
// private get x() {
|
||||
// return this.wfData.state.x
|
||||
// }
|
||||
// private set x(value: number) {
|
||||
// this.wfData.patch({ x: value })
|
||||
// }
|
||||
// private get y() {
|
||||
// return this.wfData.state.y
|
||||
// }
|
||||
// private set y(value: number) {
|
||||
// this.wfData.patch({ y: value })
|
||||
// }
|
||||
|
||||
// private windowFormState: TWindowFormState = 'default';
|
||||
/** 元素信息 */
|
||||
private targetBounds: IElementRect
|
||||
@@ -687,6 +701,7 @@ export class WindowFormElement extends LitElement {
|
||||
composed: true,
|
||||
}),
|
||||
)
|
||||
this.wfData.state.closed = true
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user