72 lines
2.1 KiB
Plaintext
72 lines
2.1 KiB
Plaintext
import { BusinessError } from '@kit.BasicServicesKit';
|
|
import { window} from '@kit.ArkUI';
|
|
import { mwInfo, mwsInfo } from '../DispWinInfo/DispWinInfo'
|
|
let subWindow: window.Window | undefined = undefined;
|
|
|
|
export class WinInfo{
|
|
name:string|undefined=undefined;
|
|
page:string|undefined=undefined;
|
|
width:number=0;
|
|
height:number=0;
|
|
constructor(name?: string, page?: string,width?: number,height?: number) {
|
|
this.name = name??undefined;
|
|
this.page = page ?? undefined;
|
|
this.width = width ?? 0;
|
|
this.height = height ?? 0;
|
|
}
|
|
}
|
|
|
|
export async function CreateAndShowSubWindow(winInfo:WinInfo) {
|
|
try {
|
|
if(mwsInfo.winStage==null){
|
|
console.error('Failed to create the subwindow. Cause: windowStage is null');
|
|
return;
|
|
}
|
|
let options: window.SubWindowOptions = {
|
|
title: winInfo.name as string,
|
|
decorEnabled: true,
|
|
isModal: false,
|
|
maximizeSupported: false,
|
|
outlineEnabled:true,
|
|
};
|
|
|
|
console.info('SubWindow Size:',winInfo.width,winInfo.height)
|
|
await mwsInfo.winStage.createSubWindowWithOptions('subWindow', options).then((data) => {
|
|
subWindow = data;
|
|
//子窗口创建成功后,设置子窗口的位置、大小及相关属性等。
|
|
subWindow.moveWindowTo(200, 200)
|
|
//子窗口重置大小
|
|
console.info("页面路径:", winInfo.page);
|
|
subWindow.resize(winInfo.width,winInfo.height);
|
|
subWindow.setUIContent(winInfo.page, (err: BusinessError) => {
|
|
if (err.code) {
|
|
console.error("加载页面失败:", err);
|
|
return;
|
|
}
|
|
})
|
|
// 显示窗口
|
|
subWindow.showWindow((err) => {
|
|
if (err.code) {
|
|
console.error("显示窗口失败:", err);
|
|
}
|
|
});
|
|
subWindow.setResizeByDragEnabled(false);
|
|
})
|
|
} catch (error) {
|
|
console.error('Failed to create or show sub window:', (error as BusinessError).message);
|
|
}
|
|
}
|
|
|
|
export function CloseSubWindow() {
|
|
if (subWindow) {
|
|
try {
|
|
subWindow.destroy();
|
|
subWindow = undefined;
|
|
console.info('Sub window closed.');
|
|
} catch (error) {
|
|
console.error('Failed to close sub window:', (error as BusinessError).message);
|
|
}
|
|
}
|
|
}
|
|
|