修改
This commit is contained in:
@@ -1,6 +1,15 @@
|
||||
import type { IProcess } from '@/core/process/IProcess.ts'
|
||||
import type { TWindowFormState } from '@/core/window/types/WindowFormTypes.ts'
|
||||
|
||||
export interface IWindowForm {
|
||||
/** 窗体id */
|
||||
get id(): string;
|
||||
/** 窗体所属的进程 */
|
||||
get proc(): IProcess | undefined;
|
||||
/** 窗体元素 */
|
||||
get windowFormEle(): HTMLElement;
|
||||
/** 窗体状态 */
|
||||
get windowFormState(): TWindowFormState;
|
||||
/** 关闭窗体 */
|
||||
closeWindowForm(): void;
|
||||
}
|
||||
@@ -14,8 +14,8 @@ export default class WindowFormImpl implements IWindowForm {
|
||||
private dom: HTMLElement;
|
||||
private drw: DraggableResizableWindow;
|
||||
private pos: WindowFormPos = { x: 0, y: 0 };
|
||||
private width: number = 0;
|
||||
private height: number = 0;
|
||||
private width: number;
|
||||
private height: number;
|
||||
|
||||
public get id() {
|
||||
return this._id;
|
||||
@@ -26,6 +26,12 @@ export default class WindowFormImpl implements IWindowForm {
|
||||
private get desktopRootDom() {
|
||||
return XSystem.instance.desktopRootDom;
|
||||
}
|
||||
public get windowFormEle() {
|
||||
return this.dom;
|
||||
}
|
||||
public get windowFormState() {
|
||||
return this.drw.windowFormState
|
||||
}
|
||||
|
||||
constructor(proc: IProcess, config: IWindowFormConfig) {
|
||||
this._procId = proc.id;
|
||||
@@ -34,20 +40,21 @@ export default class WindowFormImpl implements IWindowForm {
|
||||
x: config.left ?? 0,
|
||||
y: config.top ?? 0
|
||||
}
|
||||
this.width = config.width ?? 0;
|
||||
this.height = config.height ?? 0;
|
||||
this.width = config.width ?? 200;
|
||||
this.height = config.height ?? 100;
|
||||
|
||||
this.createWindowFrom();
|
||||
}
|
||||
|
||||
private createWindowFrom() {
|
||||
this.dom = this.windowFormEle();
|
||||
this.dom = this.createWindowFormEle();
|
||||
this.dom.style.position = 'absolute';
|
||||
this.dom.style.width = `${this.width}px`;
|
||||
this.dom.style.height = `${this.height}px`;
|
||||
this.dom.style.zIndex = '10';
|
||||
|
||||
const header = this.dom.querySelector('.title-bar') as HTMLElement;
|
||||
const content = this.dom.querySelector('.window-content') as HTMLElement;
|
||||
this.drw = new DraggableResizableWindow({
|
||||
target: this.dom,
|
||||
handle: header,
|
||||
@@ -67,13 +74,13 @@ export default class WindowFormImpl implements IWindowForm {
|
||||
this.desktopRootDom.appendChild(this.dom);
|
||||
}
|
||||
|
||||
private closeWindowForm() {
|
||||
public closeWindowForm() {
|
||||
this.drw.destroy();
|
||||
this.desktopRootDom.removeChild(this.dom);
|
||||
this.proc?.event.notifyEvent('onProcessWindowFormExit', this.id)
|
||||
}
|
||||
|
||||
private windowFormEle() {
|
||||
private createWindowFormEle() {
|
||||
const template = document.createElement('template');
|
||||
template.innerHTML = `
|
||||
<div class="window">
|
||||
@@ -85,10 +92,7 @@ export default class WindowFormImpl implements IWindowForm {
|
||||
<div class="close btn" title="关闭">×</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="window-content">
|
||||
<p>这是一个纯静态的 Windows 风格窗体示例。</p>
|
||||
<p>你可以在这里放置任何内容。</p>
|
||||
</div>
|
||||
<div class="window-content"></div>
|
||||
</div>
|
||||
`
|
||||
const fragment = template.content.cloneNode(true) as DocumentFragment;
|
||||
@@ -99,7 +103,7 @@ export default class WindowFormImpl implements IWindowForm {
|
||||
|
||||
windowElement.querySelector('.btn.maximize')
|
||||
?.addEventListener('click', () => {
|
||||
if (this.drw.windowState === 'maximized') {
|
||||
if (this.drw.windowFormState === 'maximized') {
|
||||
this.drw.restore()
|
||||
} else {
|
||||
this.drw.maximize()
|
||||
|
||||
@@ -5,3 +5,6 @@ export interface WindowFormPos {
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
/** 窗口状态 */
|
||||
export type TWindowFormState = 'default' | 'minimized' | 'maximized';
|
||||
|
||||
Reference in New Issue
Block a user