76 lines
2.2 KiB
Plaintext
76 lines
2.2 KiB
Plaintext
import { BusinessError } from '@kit.BasicServicesKit';
|
|
import { window } from '@kit.ArkUI';
|
|
import { mwsInfo } from '../DispWinInfo/DispWinInfo'
|
|
|
|
//窗体信息
|
|
export class SubWinInfo{
|
|
name?:string;
|
|
page?:string;
|
|
subWin?:window.Window;
|
|
subOpt?:window.SubWindowOptions;
|
|
subPointX?:number=200;
|
|
subPointY?:number=200;
|
|
width?:number=0;
|
|
height?:number=0;
|
|
constructor(name?: string, page?: string,width?: number,height?: number) {
|
|
this.name = name;
|
|
this.page = page;
|
|
this.width = width;
|
|
this.height = height;
|
|
}
|
|
}
|
|
|
|
//窗体保存容器
|
|
let subWins:Map<string,SubWinInfo>=new Map<string,SubWinInfo>;
|
|
|
|
export async function CreateAndShowSubWindow(subWinInfo:SubWinInfo) {
|
|
try {
|
|
if(mwsInfo.winStage==null){
|
|
console.error('Failed to create the subwindow. Cause: windowStage is null');
|
|
return;
|
|
}
|
|
let options: window.SubWindowOptions = {
|
|
title: subWinInfo.name as string,
|
|
decorEnabled: true,
|
|
isModal: false,
|
|
maximizeSupported: false,
|
|
outlineEnabled:true,
|
|
};
|
|
|
|
console.info('SubWindow Size:',subWinInfo.width,subWinInfo.height)
|
|
await mwsInfo.winStage.createSubWindowWithOptions(subWinInfo.name as string, options).then((data) => {
|
|
console.info("页面路径:", subWinInfo.page);
|
|
subWinInfo.subWin = data;
|
|
//子窗口显示位置
|
|
data.moveWindowTo(subWinInfo.subPointX, subWinInfo.subPointY)
|
|
//子窗口重置大小
|
|
data.resize(subWinInfo.width,subWinInfo.height);
|
|
data.setUIContent(subWinInfo.page, (err: BusinessError) => {
|
|
if (err.code) {
|
|
console.error("加载页面失败:", err);
|
|
return;
|
|
}
|
|
})
|
|
// 显示窗口
|
|
data.showWindow((err) => {
|
|
if (err.code) {
|
|
console.error("显示窗口失败:", err);
|
|
}
|
|
});
|
|
data.setResizeByDragEnabled(false);
|
|
})
|
|
subWins[subWinInfo.name as string]=subWinInfo;
|
|
} catch (error) {
|
|
console.error('Failed to create or show sub window:', (error as BusinessError).message);
|
|
}
|
|
}
|
|
|
|
export function CloseSubWindow() {
|
|
try {
|
|
console.info('Sub window closed.');
|
|
} catch (error) {
|
|
console.error('Failed to close sub window:', (error as BusinessError).message);
|
|
}
|
|
}
|
|
|