This commit is contained in:
2025-10-10 13:49:55 +08:00
parent acecffb055
commit 9a90f1258b
2 changed files with 20 additions and 14 deletions

View File

@@ -94,7 +94,7 @@ stateDiagram-v2
| 服务方法 | 参数 | 返回值 | 描述 | | 服务方法 | 参数 | 返回值 | 描述 |
| -------------- | ----------------------- | -------------- | ------------ | | -------------- | ----------------------- | -------------- | ------------ |
| createWindow | appId, config | WindowInstance | 创建新窗体 | | createWindow | appId, config | WindowFormInstance | 创建新窗体 |
| destroyWindow | windowId | boolean | 销毁指定窗体 | | destroyWindow | windowId | boolean | 销毁指定窗体 |
| minimizeWindow | windowId | boolean | 最小化窗体 | | minimizeWindow | windowId | boolean | 最小化窗体 |
| maximizeWindow | windowId | boolean | 最大化窗体 | | maximizeWindow | windowId | boolean | 最大化窗体 |

View File

@@ -94,7 +94,7 @@ export interface WindowConfig {
/** /**
* 窗体实例接口 * 窗体实例接口
*/ */
export interface WindowInstance { export interface WindowFormInstance {
/** /**
* 窗体唯一标识符 * 窗体唯一标识符
*/ */
@@ -156,7 +156,7 @@ export interface WindowEvents extends IEventMap {
* 窗体管理服务类 * 窗体管理服务类
*/ */
export class WindowFormService { export class WindowFormService {
private windowsForm = reactive(new Map<string, WindowInstance>()) private windowsForm = reactive(new Map<string, WindowFormInstance>())
private activeWindowId = ref<string | null>(null) private activeWindowId = ref<string | null>(null)
private nextZIndex = 1000 private nextZIndex = 1000
private eventBus: IEventBuilder<WindowEvents> private eventBus: IEventBuilder<WindowEvents>
@@ -169,11 +169,11 @@ export class WindowFormService {
/** /**
* 创建新窗体 * 创建新窗体
*/ */
async createWindow(appId: string, config: WindowConfig): Promise<WindowInstance> { async createWindow(appId: string, config: WindowConfig): Promise<WindowFormInstance> {
const windowId = uuidv4() const windowId = uuidv4()
const now = new Date() const now = new Date()
const windowInstance: WindowInstance = { const windowInstance: WindowFormInstance = {
id: windowId, id: windowId,
appId, appId,
config, config,
@@ -220,6 +220,9 @@ export class WindowFormService {
if (window.element) { if (window.element) {
window.element.remove() window.element.remove()
} }
if (window.iframe) {
window.iframe.remove()
}
// 从集合中移除 // 从集合中移除
this.windowsForm.delete(windowId) this.windowsForm.delete(windowId)
@@ -405,14 +408,14 @@ export class WindowFormService {
/** /**
* 获取窗体实例 * 获取窗体实例
*/ */
getWindow(windowId: string): WindowInstance | undefined { getWindow(windowId: string): WindowFormInstance | undefined {
return this.windowsForm.get(windowId) return this.windowsForm.get(windowId)
} }
/** /**
* 获取所有窗体 * 获取所有窗体
*/ */
getAllWindows(): WindowInstance[] { getAllWindows(): WindowFormInstance[] {
return Array.from(this.windowsForm.values()) return Array.from(this.windowsForm.values())
} }
@@ -448,7 +451,7 @@ export class WindowFormService {
/** /**
* 创建窗体DOM元素 * 创建窗体DOM元素
*/ */
private async createWindowElement(windowInstance: WindowInstance): Promise<void> { private async createWindowElement(windowInstance: WindowFormInstance): Promise<void> {
const { id, config, appId } = windowInstance const { id, config, appId } = windowInstance
// 创建窗体容器 // 创建窗体容器
@@ -549,7 +552,7 @@ export class WindowFormService {
/** /**
* 创建窗体标题栏 * 创建窗体标题栏
*/ */
private createTitleBar(windowInstance: WindowInstance): HTMLElement { private createTitleBar(windowInstance: WindowFormInstance): HTMLElement {
const titleBar = document.createElement('div') const titleBar = document.createElement('div')
titleBar.className = 'window-title-bar' titleBar.className = 'window-title-bar'
titleBar.style.cssText = ` titleBar.style.cssText = `
@@ -659,7 +662,7 @@ export class WindowFormService {
/** /**
* 添加窗体拖拽功能 * 添加窗体拖拽功能
*/ */
private addDragFunctionality(titleBar: HTMLElement, windowInstance: WindowInstance): void { private addDragFunctionality(titleBar: HTMLElement, windowInstance: WindowFormInstance): void {
let isDragging = false let isDragging = false
let startX = 0 let startX = 0
let startY = 0 let startY = 0
@@ -744,7 +747,10 @@ export class WindowFormService {
/** /**
* 添加窗体调整尺寸功能 * 添加窗体调整尺寸功能
*/ */
private addResizeFunctionality(windowElement: HTMLElement, windowInstance: WindowInstance): void { private addResizeFunctionality(
windowElement: HTMLElement,
windowInstance: WindowFormInstance
): void {
// 初始化调整尺寸状态 // 初始化调整尺寸状态
windowInstance.resizeState = { windowInstance.resizeState = {
isResizing: false, isResizing: false,
@@ -873,7 +879,7 @@ export class WindowFormService {
private addResizeHandleEvents( private addResizeHandleEvents(
handle: HTMLElement, handle: HTMLElement,
windowElement: HTMLElement, windowElement: HTMLElement,
windowInstance: WindowInstance windowInstance: WindowFormInstance
): void { ): void {
const direction = handle.className const direction = handle.className
.split(' ') .split(' ')
@@ -930,7 +936,7 @@ export class WindowFormService {
private updateCursorForResize( private updateCursorForResize(
e: MouseEvent, e: MouseEvent,
windowElement: HTMLElement, windowElement: HTMLElement,
windowInstance: WindowInstance windowInstance: WindowFormInstance
): void { ): void {
if (!windowInstance.resizeState) return if (!windowInstance.resizeState) return
@@ -1150,7 +1156,7 @@ export class WindowFormService {
/** /**
* 加载应用 * 加载应用
*/ */
private async loadApplication(windowInstance: WindowInstance): Promise<void> { private async loadApplication(windowInstance: WindowFormInstance): Promise<void> {
// 动态导入 AppRegistry 检查是否为内置应用 // 动态导入 AppRegistry 检查是否为内置应用
try { try {
// 如果是内置应用,直接返回,不需要等待 // 如果是内置应用,直接返回,不需要等待