Compare commits
3 Commits
68bdabf928
...
e3ff2045ea
| Author | SHA1 | Date | |
|---|---|---|---|
| e3ff2045ea | |||
| fd4f9aa66b | |||
| 62b4ae7379 |
@@ -1,9 +1,5 @@
|
|||||||
import ProcessImpl from './process/impl/ProcessImpl.ts'
|
|
||||||
import { isUndefined } from 'lodash'
|
|
||||||
import { BasicSystemProcess } from '@/core/system/BasicSystemProcess.ts'
|
import { BasicSystemProcess } from '@/core/system/BasicSystemProcess.ts'
|
||||||
import { DesktopProcess } from '@/core/desktop/DesktopProcess.ts'
|
import { DesktopProcess } from '@/core/desktop/DesktopProcess.ts'
|
||||||
import type { IProcess } from '@/core/process/IProcess.ts'
|
|
||||||
import type { IProcessInfo } from '@/core/process/IProcessInfo.ts'
|
|
||||||
import { ObservableWeakRefImpl } from '@/core/state/impl/ObservableWeakRefImpl.ts'
|
import { ObservableWeakRefImpl } from '@/core/state/impl/ObservableWeakRefImpl.ts'
|
||||||
import type { IObservable } from '@/core/state/IObservable.ts'
|
import type { IObservable } from '@/core/state/IObservable.ts'
|
||||||
import { NotificationService } from '@/core/service/services/NotificationService.ts'
|
import { NotificationService } from '@/core/service/services/NotificationService.ts'
|
||||||
@@ -44,35 +40,10 @@ export default class XSystem {
|
|||||||
|
|
||||||
public initialization(dom: HTMLDivElement) {
|
public initialization(dom: HTMLDivElement) {
|
||||||
this._desktopRootDom = dom
|
this._desktopRootDom = dom
|
||||||
this.run('basic-system', BasicSystemProcess).then(() => {
|
processManager.runProcess('basic-system', BasicSystemProcess).then(() => {
|
||||||
this.run('desktop', DesktopProcess).then((proc) => {
|
processManager.runProcess('desktop', DesktopProcess).then((proc) => {
|
||||||
proc.mount(dom)
|
proc.mount(dom)
|
||||||
// console.log(dom.querySelector('.desktop-root'))
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 运行进程
|
|
||||||
public async run<T extends IProcess = IProcess>(
|
|
||||||
proc: string | IProcessInfo,
|
|
||||||
constructor?: new (info: IProcessInfo) => T,
|
|
||||||
): Promise<T> {
|
|
||||||
let info = typeof proc === 'string' ? processManager.findProcessInfoByName(proc)! : proc
|
|
||||||
if (isUndefined(info)) {
|
|
||||||
throw new Error(`未找到进程信息:${proc}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 是单例应用
|
|
||||||
if (info.singleton) {
|
|
||||||
let process = processManager.findProcessByName(info.name)
|
|
||||||
if (process) {
|
|
||||||
return process as T
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建进程
|
|
||||||
let process = isUndefined(constructor) ? new ProcessImpl(info) : new constructor(info)
|
|
||||||
|
|
||||||
return process as T
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { debounce } from 'lodash'
|
|||||||
import type { IProcessInfo } from '@/core/process/IProcessInfo.ts'
|
import type { IProcessInfo } from '@/core/process/IProcessInfo.ts'
|
||||||
import { eventManager } from '@/core/events/EventManager.ts'
|
import { eventManager } from '@/core/events/EventManager.ts'
|
||||||
import { processManager } from '@/core/process/ProcessManager.ts'
|
import { processManager } from '@/core/process/ProcessManager.ts'
|
||||||
|
import './ui/DesktopElement.ts'
|
||||||
|
|
||||||
export class DesktopProcess extends ProcessImpl {
|
export class DesktopProcess extends ProcessImpl {
|
||||||
private _desktopRootDom: HTMLElement;
|
private _desktopRootDom: HTMLElement;
|
||||||
@@ -91,6 +92,13 @@ export class DesktopProcess extends ProcessImpl {
|
|||||||
app.use(naiveUi)
|
app.use(naiveUi)
|
||||||
app.mount(dom)
|
app.mount(dom)
|
||||||
|
|
||||||
|
// this.initDesktop(dom)
|
||||||
|
|
||||||
this._isMounted = true
|
this._isMounted = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private initDesktop(dom: HTMLDivElement) {
|
||||||
|
const d = document.createElement('desktop-element')
|
||||||
|
dom.appendChild(d)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -22,13 +22,13 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { DesktopProcess } from '@/core/desktop/DesktopProcess.ts'
|
import type { DesktopProcess } from '@/core/desktop/DesktopProcess.ts'
|
||||||
import XSystem from '@/core/XSystem.ts'
|
|
||||||
import { notificationApi } from '@/core/common/naive-ui/discrete-api.ts'
|
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 { useDesktopInit } from '@/core/desktop/ui/hooks/useDesktopInit.ts'
|
import { useDesktopInit } from '@/core/desktop/ui/hooks/useDesktopInit.ts'
|
||||||
import AppIcon from '@/core/desktop/ui/components/AppIcon.vue'
|
import AppIcon from '@/core/desktop/ui/components/AppIcon.vue'
|
||||||
import type { IDesktopAppIcon } from '@/core/desktop/types/IDesktopAppIcon.ts'
|
import type { IDesktopAppIcon } from '@/core/desktop/types/IDesktopAppIcon.ts'
|
||||||
import { eventManager } from '@/core/events/EventManager.ts'
|
import { eventManager } from '@/core/events/EventManager.ts'
|
||||||
|
import { processManager } from '@/core/process/ProcessManager.ts'
|
||||||
|
|
||||||
const props = defineProps<{ process: DesktopProcess }>()
|
const props = defineProps<{ process: DesktopProcess }>()
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ const onContextMenu = (e: MouseEvent) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const runApp = (appIcon: IDesktopAppIcon) => {
|
const runApp = (appIcon: IDesktopAppIcon) => {
|
||||||
XSystem.instance.run(appIcon.name)
|
processManager.runProcess(appIcon.name)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
35
src/core/desktop/ui/DesktopElement.ts
Normal file
35
src/core/desktop/ui/DesktopElement.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import { css, html, LitElement, unsafeCSS } from 'lit'
|
||||||
|
import { customElement } from 'lit/decorators.js'
|
||||||
|
import desktopStyle from './css/desktop.scss?inline'
|
||||||
|
|
||||||
|
@customElement('desktop-element')
|
||||||
|
export class DesktopElement extends LitElement {
|
||||||
|
static override styles = css`
|
||||||
|
${unsafeCSS(desktopStyle)}
|
||||||
|
`
|
||||||
|
|
||||||
|
private onContextMenu = (e: MouseEvent) => {
|
||||||
|
e.preventDefault()
|
||||||
|
e.stopPropagation()
|
||||||
|
console.log('contextmenu')
|
||||||
|
}
|
||||||
|
|
||||||
|
override render() {
|
||||||
|
return html`
|
||||||
|
<div class="desktop-root" @contextmenu=${this.onContextMenu}>
|
||||||
|
<div class="desktop-container">
|
||||||
|
<div class="desktop-icons-container"
|
||||||
|
:style="gridStyle">
|
||||||
|
<AppIcon v-for="(appIcon, i) in appIconsRef" :key="i"
|
||||||
|
:iconInfo="appIcon" :gridTemplate="gridTemplate"
|
||||||
|
@dblclick="runApp(appIcon)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="task-bar">
|
||||||
|
<div id="taskbar" class="w-[80px] h-full flex justify-center items-center bg-blue">测试</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
}
|
||||||
|
}
|
||||||
17
src/core/desktop/ui/components/DesktopAppIconElement.ts
Normal file
17
src/core/desktop/ui/components/DesktopAppIconElement.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { css, html, LitElement } from 'lit'
|
||||||
|
|
||||||
|
export class DesktopAppIconElement extends LitElement {
|
||||||
|
static override styles = css`
|
||||||
|
:host {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
@apply flex flex-col items-center justify-center bg-gray-200;
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
override render() {
|
||||||
|
return html`<div class="desktop-app-icon">
|
||||||
|
<slot></slot>
|
||||||
|
</div>`
|
||||||
|
}
|
||||||
|
}
|
||||||
31
src/core/desktop/ui/css/desktop.scss
Normal file
31
src/core/desktop/ui/css/desktop.scss
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
*,
|
||||||
|
*::before,
|
||||||
|
*::after {
|
||||||
|
box-sizing: border-box; /* 使用更直观的盒模型 */
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$taskBarHeight: 40px;
|
||||||
|
|
||||||
|
.desktop-root {
|
||||||
|
@apply w-full h-full flex flex-col;
|
||||||
|
|
||||||
|
.desktop-container {
|
||||||
|
@apply w-full h-full flex-1 p-2 pos-relative;
|
||||||
|
background-image: url("../imgs/desktop-bg-2.jpeg");
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-size: cover;
|
||||||
|
height: calc(100% - #{$taskBarHeight});
|
||||||
|
}
|
||||||
|
|
||||||
|
.desktop-icons-container {
|
||||||
|
@apply w-full h-full flex-1 grid grid-auto-flow-col pos-relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.task-bar {
|
||||||
|
@apply w-full bg-gray-200 flex justify-center items-center;
|
||||||
|
height: $taskBarHeight;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -36,6 +36,10 @@ export interface WindowFormEvent extends IEventMap {
|
|||||||
* @param data 窗口数据
|
* @param data 窗口数据
|
||||||
*/
|
*/
|
||||||
windowFormDataUpdate: (data: IWindowFormDataUpdateParams) => void;
|
windowFormDataUpdate: (data: IWindowFormDataUpdateParams) => void;
|
||||||
|
/**
|
||||||
|
* 窗口创建完成
|
||||||
|
*/
|
||||||
|
windowFormCreated: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IWindowFormDataUpdateParams {
|
interface IWindowFormDataUpdateParams {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type ProcessImpl from './ProcessImpl.ts'
|
import ProcessImpl from './ProcessImpl.ts'
|
||||||
import { ProcessInfoImpl } from '@/core/process/impl/ProcessInfoImpl.ts'
|
import { ProcessInfoImpl } from '@/core/process/impl/ProcessInfoImpl.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'
|
||||||
@@ -6,6 +6,8 @@ import type { IAppProcessInfoParams } from '@/core/process/types/IAppProcessInfo
|
|||||||
import type { IProcessManager } from '@/core/process/IProcessManager.ts'
|
import type { IProcessManager } from '@/core/process/IProcessManager.ts'
|
||||||
import type { IProcess } from '@/core/process/IProcess.ts'
|
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 { processManager } from '@/core/process/ProcessManager.ts'
|
||||||
|
import { isUndefined } from 'lodash'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 进程管理
|
* 进程管理
|
||||||
@@ -35,6 +37,29 @@ export default class ProcessManagerImpl implements IProcessManager {
|
|||||||
this._processInfos.push(...internalProcessInfos)
|
this._processInfos.push(...internalProcessInfos)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async runProcess<T extends IProcess = IProcess>(
|
||||||
|
proc: string | IProcessInfo,
|
||||||
|
constructor?: new (info: IProcessInfo) => T,
|
||||||
|
): Promise<T> {
|
||||||
|
let info = typeof proc === 'string' ? this.findProcessInfoByName(proc) : proc
|
||||||
|
if (isUndefined(info)) {
|
||||||
|
throw new Error(`未找到进程信息:${proc}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 是单例应用
|
||||||
|
if (info.singleton) {
|
||||||
|
let process = this.findProcessByName(info.name)
|
||||||
|
if (process) {
|
||||||
|
return process as T
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建进程
|
||||||
|
let process = isUndefined(constructor) ? new ProcessImpl(info) : new constructor(info)
|
||||||
|
|
||||||
|
return process as T
|
||||||
|
}
|
||||||
|
|
||||||
// 添加进程
|
// 添加进程
|
||||||
public registerProcess(process: ProcessImpl) {
|
public registerProcess(process: ProcessImpl) {
|
||||||
this._processPool.set(process.id, process);
|
this._processPool.set(process.id, process);
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
$titleBarHeight: 40px;
|
|
||||||
|
|
||||||
/* 窗体容器 */
|
|
||||||
.window {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
border: 1px solid #666;
|
|
||||||
box-shadow: 0 0 10px rgba(0,0,0,0.5);
|
|
||||||
background-color: #ffffff;
|
|
||||||
overflow: hidden;
|
|
||||||
border-radius: 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 标题栏 */
|
|
||||||
.title-bar {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
user-select: none;
|
|
||||||
width: 100%;
|
|
||||||
height: $titleBarHeight;
|
|
||||||
|
|
||||||
.title {
|
|
||||||
display: block;
|
|
||||||
padding: 0 5px;
|
|
||||||
flex-grow: 1;
|
|
||||||
overflow: hidden;
|
|
||||||
white-space: nowrap;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
font-size: 18px;
|
|
||||||
line-height: $titleBarHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
.window-controls {
|
|
||||||
display: flex;
|
|
||||||
gap: 2px;
|
|
||||||
flex-shrink: 0;
|
|
||||||
|
|
||||||
.btn {
|
|
||||||
width: 40px;
|
|
||||||
height: 40px;
|
|
||||||
padding: 0;
|
|
||||||
cursor: pointer;
|
|
||||||
font-size: 24px;
|
|
||||||
color: black;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
transition: background-color 0.3s ease;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
@apply bg-gray-200;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 窗体内容 */
|
|
||||||
.window-content {
|
|
||||||
width: 100%;
|
|
||||||
height: calc(100% - #{$titleBarHeight});
|
|
||||||
background-color: #e0e0e0;
|
|
||||||
}
|
|
||||||
@@ -4,10 +4,7 @@ import type { IProcess } from '@/core/process/IProcess.ts'
|
|||||||
import type { IWindowForm } from '@/core/window/IWindowForm.ts'
|
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 { TWindowFormState, 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 { DraggableResizableWindow } from '@/core/utils/DraggableResizableWindow.ts'
|
||||||
import '../css/window-form.scss'
|
|
||||||
import { serviceManager } from '@/core/service/kernel/ServiceManager.ts'
|
|
||||||
import '../ui/WindowFormElement.ts'
|
import '../ui/WindowFormElement.ts'
|
||||||
import { wfem } from '@/core/events/WindowFormEventManager.ts'
|
import { wfem } from '@/core/events/WindowFormEventManager.ts'
|
||||||
import type { IObservable } from '@/core/state/IObservable.ts'
|
import type { IObservable } from '@/core/state/IObservable.ts'
|
||||||
@@ -20,6 +17,8 @@ export interface IWindowFormDataState {
|
|||||||
procId: string;
|
procId: string;
|
||||||
/** 进程名称唯一 */
|
/** 进程名称唯一 */
|
||||||
name: string;
|
name: string;
|
||||||
|
/** 窗体标题 */
|
||||||
|
title: string;
|
||||||
/** 窗体位置x (左上角) */
|
/** 窗体位置x (左上角) */
|
||||||
x: number;
|
x: number;
|
||||||
/** 窗体位置y (左上角) */
|
/** 窗体位置y (左上角) */
|
||||||
@@ -65,6 +64,7 @@ export default class WindowFormImpl implements IWindowForm {
|
|||||||
id: this.id,
|
id: this.id,
|
||||||
procId: proc.id,
|
procId: proc.id,
|
||||||
name: proc.processInfo.name,
|
name: proc.processInfo.name,
|
||||||
|
title: config.title ?? '未命名',
|
||||||
x: config.left ?? 0,
|
x: config.left ?? 0,
|
||||||
y: config.top ?? 0,
|
y: config.top ?? 0,
|
||||||
width: config.width ?? 200,
|
width: config.width ?? 200,
|
||||||
@@ -83,106 +83,30 @@ export default class WindowFormImpl implements IWindowForm {
|
|||||||
this.closeWindowForm()
|
this.closeWindowForm()
|
||||||
this._proc.closeWindowForm(this.id)
|
this._proc.closeWindowForm(this.id)
|
||||||
})
|
})
|
||||||
|
|
||||||
// this._data.subscribeKey(['x', 'y'], (state) => {
|
|
||||||
// console.log('x,y', state)
|
|
||||||
// })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private createWindowFrom() {
|
private createWindowFrom() {
|
||||||
// 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,
|
|
||||||
// snapAnimation: true,
|
|
||||||
// snapThreshold: 20,
|
|
||||||
// boundaryElement: document.body,
|
|
||||||
// taskbarElementId: '#taskbar',
|
|
||||||
// onWindowStateChange: (state) => {
|
|
||||||
// if (state === 'maximized') {
|
|
||||||
// this.dom.style.borderRadius = '0px';
|
|
||||||
// } else {
|
|
||||||
// this.dom.style.borderRadius = '5px';
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// })
|
|
||||||
|
|
||||||
// this.desktopRootDom.appendChild(this.dom);
|
|
||||||
const wf = document.createElement('window-form-element')
|
const wf = document.createElement('window-form-element')
|
||||||
wf.wid = this.id
|
wf.wid = this.id
|
||||||
wf.wfData = this._data
|
wf.wfData = this._data
|
||||||
|
wf.title = this._data.state.title
|
||||||
wf.dragContainer = document.body
|
wf.dragContainer = document.body
|
||||||
wf.snapDistance = 20
|
wf.snapDistance = 20
|
||||||
wf.taskbarElementId = '#taskbar'
|
wf.taskbarElementId = '#taskbar'
|
||||||
wf.addManagedEventListener('windowForm:stateChange:minimize', (e) => {
|
|
||||||
console.log('windowForm:stateChange:minimize', e)
|
|
||||||
})
|
|
||||||
wf.addManagedEventListener('windowForm:stateChange:maximize', (e) => {
|
|
||||||
console.log('windowForm:stateChange:maximize', e)
|
|
||||||
})
|
|
||||||
wf.addManagedEventListener('windowForm:stateChange:restore', (e) => {
|
|
||||||
console.log('windowForm:stateChange:restore', e)
|
|
||||||
})
|
|
||||||
wf.addManagedEventListener('windowForm:close', () => {
|
|
||||||
// this.closeWindowForm()
|
|
||||||
})
|
|
||||||
this.dom = wf
|
this.dom = wf
|
||||||
this.desktopRootDom.appendChild(this.dom)
|
this.desktopRootDom.appendChild(this.dom)
|
||||||
wfem.notifyEvent('windowFormFocus', this.id)
|
Promise.resolve().then(() => {
|
||||||
|
wfem.notifyEvent('windowFormCreated')
|
||||||
|
wfem.notifyEvent('windowFormFocus', this.id)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private closeWindowForm() {
|
private closeWindowForm() {
|
||||||
// this.drw.destroy();
|
|
||||||
this.desktopRootDom.removeChild(this.dom)
|
this.desktopRootDom.removeChild(this.dom)
|
||||||
this._data.dispose()
|
this._data.dispose()
|
||||||
// wfem.notifyEvent('windowFormClose', this.id)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public minimize() {}
|
public minimize() {}
|
||||||
public maximize() {}
|
public maximize() {}
|
||||||
public restore() {}
|
public restore() {}
|
||||||
|
|
||||||
private createWindowFormEle() {
|
|
||||||
const template = document.createElement('template')
|
|
||||||
template.innerHTML = `
|
|
||||||
<div class="window">
|
|
||||||
<div class="title-bar">
|
|
||||||
<div class="title">我的窗口</div>
|
|
||||||
<div class="window-controls">
|
|
||||||
<div class="minimize btn" title="最小化"">-</div>
|
|
||||||
<div class="maximize btn" title="最大化">□</div>
|
|
||||||
<div class="close btn" title="关闭">×</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="window-content"></div>
|
|
||||||
</div>
|
|
||||||
`
|
|
||||||
const fragment = template.content.cloneNode(true) as DocumentFragment
|
|
||||||
const windowElement = fragment.firstElementChild as HTMLElement
|
|
||||||
|
|
||||||
windowElement
|
|
||||||
.querySelector('.btn.minimize')
|
|
||||||
?.addEventListener('click', () => this.drw.minimize())
|
|
||||||
|
|
||||||
windowElement.querySelector('.btn.maximize')?.addEventListener('click', () => {
|
|
||||||
if (this.drw.windowFormState === 'maximized') {
|
|
||||||
this.drw.restore()
|
|
||||||
} else {
|
|
||||||
this.drw.maximize()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
windowElement
|
|
||||||
.querySelector('.btn.close')
|
|
||||||
?.addEventListener('click', () => this.closeWindowForm())
|
|
||||||
|
|
||||||
return windowElement
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { LitElement, html, css, unsafeCSS } from 'lit'
|
import { LitElement, html, css, unsafeCSS } from 'lit'
|
||||||
import { customElement, property } from 'lit/decorators.js';
|
import { customElement, property } from 'lit/decorators.js';
|
||||||
import wfStyle from './wf.scss?inline'
|
import wfStyle from './css/wf.scss?inline'
|
||||||
import type { TWindowFormState } from '@/core/window/types/WindowFormTypes.ts'
|
import type { TWindowFormState } from '@/core/window/types/WindowFormTypes.ts'
|
||||||
import { wfem } from '@/core/events/WindowFormEventManager.ts'
|
import { wfem } from '@/core/events/WindowFormEventManager.ts'
|
||||||
import type { IObservable } from '@/core/state/IObservable.ts'
|
import type { IObservable } from '@/core/state/IObservable.ts'
|
||||||
@@ -50,7 +50,7 @@ interface IElementRect {
|
|||||||
left: number;
|
left: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface WindowFormEventMap {
|
export interface WindowFormEventMap extends HTMLElementEventMap {
|
||||||
'windowForm:dragStart': CustomEvent<TDragStartCallback>;
|
'windowForm:dragStart': CustomEvent<TDragStartCallback>;
|
||||||
'windowForm:dragMove': CustomEvent<TDragMoveCallback>;
|
'windowForm:dragMove': CustomEvent<TDragMoveCallback>;
|
||||||
'windowForm:dragEnd': CustomEvent<TDragEndCallback>;
|
'windowForm:dragEnd': CustomEvent<TDragEndCallback>;
|
||||||
@@ -80,14 +80,14 @@ export class WindowFormElement extends LitElement {
|
|||||||
@property({ type: Number }) snapDistance = 0 // 吸附距离
|
@property({ type: Number }) snapDistance = 0 // 吸附距离
|
||||||
@property({ type: Boolean }) snapAnimation = true // 吸附动画
|
@property({ type: Boolean }) snapAnimation = true // 吸附动画
|
||||||
@property({ type: Number }) snapAnimationDuration = 300 // 吸附动画时长 ms
|
@property({ type: Number }) snapAnimationDuration = 300 // 吸附动画时长 ms
|
||||||
@property({ type: Number }) maxWidth?: number
|
@property({ type: Number }) maxWidth?: number = Infinity
|
||||||
@property({ type: Number }) minWidth?: number
|
@property({ type: Number }) minWidth?: number = 0
|
||||||
@property({ type: Number }) maxHeight?: number
|
@property({ type: Number }) maxHeight?: number = Infinity
|
||||||
@property({ type: Number }) minHeight?: number
|
@property({ type: Number }) minHeight?: number = 0
|
||||||
@property({ type: String }) taskbarElementId?: string
|
@property({ type: String }) taskbarElementId?: string
|
||||||
@property({ type: Object }) wfData: IObservable<IWindowFormDataState>;
|
@property({ type: Object }) wfData: IObservable<IWindowFormDataState>;
|
||||||
|
|
||||||
private _listeners: Array<{ type: string; handler: EventListener }> = []
|
private _listeners: Array<{ type: string; original: Function; wrapped: EventListener }> = []
|
||||||
|
|
||||||
// ==== 拖拽/缩放状态(内部变量,不触发渲染) ====
|
// ==== 拖拽/缩放状态(内部变量,不触发渲染) ====
|
||||||
private dragging = false
|
private dragging = false
|
||||||
@@ -141,22 +141,58 @@ export class WindowFormElement extends LitElement {
|
|||||||
return root
|
return root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public addManagedEventListener<K extends keyof WindowFormEventMap>(
|
||||||
|
type: K,
|
||||||
|
handler: (this: WindowFormElement, ev: WindowFormEventMap[K]) => any,
|
||||||
|
options?: boolean | AddEventListenerOptions
|
||||||
|
): void
|
||||||
|
public addManagedEventListener<K extends keyof WindowFormEventMap>(
|
||||||
|
type: K,
|
||||||
|
handler: (ev: WindowFormEventMap[K]) => any,
|
||||||
|
options?: boolean | AddEventListenerOptions
|
||||||
|
): void
|
||||||
/**
|
/**
|
||||||
* 添加受管理的事件监听
|
* 添加受管理的事件监听
|
||||||
* @param type 事件类型
|
* @param type 事件类型
|
||||||
* @param handler 事件处理函数
|
* @param handler 事件处理函数
|
||||||
*/
|
*/
|
||||||
public addManagedEventListener(type: string, handler: EventListener) {
|
public addManagedEventListener<K extends keyof WindowFormEventMap>(
|
||||||
this.addEventListener(type, handler)
|
type: K,
|
||||||
this._listeners.push({ type, handler })
|
handler:
|
||||||
|
| ((this: WindowFormElement, ev: WindowFormEventMap[K]) => any)
|
||||||
|
| ((ev: WindowFormEventMap[K]) => any),
|
||||||
|
options?: boolean | AddEventListenerOptions
|
||||||
|
) {
|
||||||
|
const wrapped: EventListener = (ev: Event) => {
|
||||||
|
(handler as any).call(this, ev as WindowFormEventMap[K])
|
||||||
|
}
|
||||||
|
|
||||||
|
this.addEventListener(type, wrapped, options)
|
||||||
|
this._listeners.push({ type, original: handler, wrapped })
|
||||||
|
}
|
||||||
|
|
||||||
|
public removeManagedEventListener<K extends keyof WindowFormEventMap>(
|
||||||
|
type: K,
|
||||||
|
handler:
|
||||||
|
| ((this: WindowFormElement, ev: WindowFormEventMap[K]) => any)
|
||||||
|
| ((ev: WindowFormEventMap[K]) => any)
|
||||||
|
) {
|
||||||
|
const index = this._listeners.findIndex(
|
||||||
|
l => l.type === type && l.original === handler
|
||||||
|
)
|
||||||
|
if (index !== -1) {
|
||||||
|
const { type: t, wrapped } = this._listeners[index]
|
||||||
|
this.removeEventListener(t, wrapped)
|
||||||
|
this._listeners.splice(index, 1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 移除所有受管理事件监听
|
* 移除所有受管理事件监听
|
||||||
*/
|
*/
|
||||||
public removeAllManagedListeners() {
|
public removeAllManagedListeners() {
|
||||||
for (const { type, handler } of this._listeners) {
|
for (const { type, wrapped } of this._listeners) {
|
||||||
this.removeEventListener(type, handler)
|
this.removeEventListener(type, wrapped)
|
||||||
}
|
}
|
||||||
this._listeners = []
|
this._listeners = []
|
||||||
}
|
}
|
||||||
@@ -863,4 +899,6 @@ declare global {
|
|||||||
interface HTMLElementTagNameMap {
|
interface HTMLElementTagNameMap {
|
||||||
'window-form-element': WindowFormElement;
|
'window-form-element': WindowFormElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface WindowFormElementEventMap extends WindowFormEventMap {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
*,
|
||||||
|
*::before,
|
||||||
|
*::after {
|
||||||
|
box-sizing: border-box; /* 使用更直观的盒模型 */
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
:host {
|
:host {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
@@ -42,40 +50,44 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.titlebar {
|
.titlebar {
|
||||||
height: var(--titlebar-height, 32px);
|
height: var(--titlebar-height);
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding: 0 8px;
|
padding: 0 8px;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
background: linear-gradient(#f2f2f2, #e9e9e9);
|
background: linear-gradient(#f2f2f2, #e9e9e9);
|
||||||
border-bottom: 1px solid rgba(0,0,0,0.06);
|
border-bottom: 1px solid rgba(0,0,0,0.06);
|
||||||
|
|
||||||
|
.title {
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
flex: 1;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
color: #111;
|
||||||
|
}
|
||||||
|
|
||||||
|
.controls {
|
||||||
|
display: flex; gap: 6px;
|
||||||
|
|
||||||
|
button.ctrl {
|
||||||
|
width: 34px;
|
||||||
|
height: 24px;
|
||||||
|
border: none;
|
||||||
|
background: transparent;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-weight: 600;
|
||||||
|
font-size: 12px;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: rgba(0,0,0,0.06);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.title {
|
|
||||||
font-size: 13px;
|
|
||||||
font-weight: 600;
|
|
||||||
flex: 1;
|
|
||||||
white-space: nowrap;
|
|
||||||
overflow: hidden;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
color: #111;
|
|
||||||
}
|
|
||||||
|
|
||||||
.controls { display: flex; gap: 6px; }
|
|
||||||
|
|
||||||
button.ctrl {
|
|
||||||
width: 34px;
|
|
||||||
height: 24px;
|
|
||||||
border: none;
|
|
||||||
background: transparent;
|
|
||||||
border-radius: 4px;
|
|
||||||
cursor: pointer;
|
|
||||||
font-weight: 600;
|
|
||||||
font-size: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
button.ctrl:hover { background: rgba(0,0,0,0.06); }
|
|
||||||
|
|
||||||
.content { flex: 1; overflow: auto; padding: 12px; background: transparent; }
|
.content { flex: 1; overflow: auto; padding: 12px; background: transparent; }
|
||||||
|
|
||||||
.resizer { position: absolute; z-index: 20; }
|
.resizer { position: absolute; z-index: 20; }
|
||||||
@@ -87,16 +99,3 @@ button.ctrl:hover { background: rgba(0,0,0,0.06); }
|
|||||||
.resizer.tl { width: 12px; height: 12px; left: -6px; top: -6px; cursor: nwse-resize; }
|
.resizer.tl { width: 12px; height: 12px; left: -6px; top: -6px; cursor: nwse-resize; }
|
||||||
.resizer.br { width: 12px; height: 12px; right: -6px; bottom: -6px; cursor: nwse-resize; }
|
.resizer.br { width: 12px; height: 12px; right: -6px; bottom: -6px; cursor: nwse-resize; }
|
||||||
.resizer.bl { width: 12px; height: 12px; left: -6px; bottom: -6px; cursor: nesw-resize; }
|
.resizer.bl { width: 12px; height: 12px; left: -6px; bottom: -6px; cursor: nesw-resize; }
|
||||||
|
|
||||||
.minimized {
|
|
||||||
height: var(--titlebar-height, 32px);
|
|
||||||
width: 200px;
|
|
||||||
display: inline-flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 8px;
|
|
||||||
padding: 0 8px;
|
|
||||||
border-radius: 4px;
|
|
||||||
background: linear-gradient(#f6f6f6,#efefef);
|
|
||||||
border: 1px solid rgba(0,0,0,0.06);
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user