134 lines
4.6 KiB
Plaintext
134 lines
4.6 KiB
Plaintext
import { window } from "@kit.ArkUI";
|
|
import { hilog } from "@kit.PerformanceAnalysisKit";
|
|
import { InfoWinMargin,MainWinMargin, InitGlobalDWI, mdwInfo } from "../pages/dispwininfo/DispWinInfo";
|
|
import common from "@ohos.app.ability.common";
|
|
|
|
const DOMAIN = 0x0000;
|
|
|
|
export enum LoadPageType{
|
|
STAGE,
|
|
WIN
|
|
}
|
|
//设置窗口在屏幕上显示位置
|
|
function SetDisplayPosition (x:number,y:number){
|
|
//设置窗口显示位置
|
|
if(mdwInfo.win){
|
|
mdwInfo.win.moveWindowTo(x, y)
|
|
console.info(`MainWindow SetDisplayPosition:x:${x}-y:${y} `);
|
|
}else{
|
|
console.error(`MainWindow SetDisplayPosition Error: win is nullptr!`);
|
|
}
|
|
}
|
|
//设置窗口的大小尺寸
|
|
function SetWinSize (width:number,height:number){
|
|
//设置窗口大小
|
|
if(mdwInfo.win){
|
|
mdwInfo.win.resize(mdwInfo.winWidth, mdwInfo.winHeight, (err) => {
|
|
if (err.code) {
|
|
console.error(`Failed to resize the window. Code: ${err.code}, message: ${err.message}`);
|
|
return;
|
|
}
|
|
console.info(`Succeeded in resizing the window to ${mdwInfo.winWidth}x${mdwInfo.winHeight}.`);
|
|
});
|
|
}else{
|
|
console.error(`MainWindow SetWinSize Error: win is nullptr!`);
|
|
}
|
|
}
|
|
function SetBackgroundColor(){
|
|
if(mdwInfo.win){
|
|
mdwInfo.win.setWindowBackgroundColor('#D9FFFFFF');
|
|
mdwInfo.win.setWindowContainerColor('#D9FFFFFF', '#FFFFFFFF');
|
|
}
|
|
}
|
|
//窗口的事件监听
|
|
function InitWinEventHub(ctx:common.UIAbilityContext){
|
|
if(mdwInfo.win==undefined||mdwInfo.winStage==undefined){
|
|
return;
|
|
}
|
|
//当窗口大小改变事件触发
|
|
mdwInfo.win.on('windowSizeChange', (ChangeData) => {
|
|
// if Size Change save to AppStorage
|
|
//mdwInfo.winWidth = ChangeData.width;
|
|
//mdwInfo.winHeight = ChangeData.height;
|
|
console.info('Succeeded in enabling the listener for window size changes. Data:' + ChangeData.width,
|
|
ChangeData.height);
|
|
});
|
|
if(ctx){
|
|
ctx.eventHub.on('EMIT_LOADMAINPAGE', (data: Object) => {
|
|
let runType=data as LoadPageType;
|
|
InitLoadMainPage(runType);
|
|
});
|
|
}
|
|
}
|
|
//初始化加载信息页面
|
|
export function InitLoadInfoPage(){
|
|
//加载页面
|
|
if(mdwInfo.winStage){
|
|
mdwInfo.winStage.loadContent('pages/Info', (err) => {
|
|
if (err.code) {
|
|
hilog.error(DOMAIN, 'Tag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err));
|
|
return;
|
|
}
|
|
SetWinSize(mdwInfo.winWidth,mdwInfo.winHeight)
|
|
SetDisplayPosition((mdwInfo.displayWidth-InfoWinMargin[0])/4.16,(mdwInfo.displayHeight-InfoWinMargin[1])/4.16);
|
|
SetBackgroundColor();
|
|
hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.');
|
|
});
|
|
}else{
|
|
console.error(`InitLoadInfoPage winStage Error: win is nullptr!`);
|
|
}
|
|
}
|
|
//WinStage加载软件Info页面
|
|
export function InitLoadMainPage(rType:LoadPageType){
|
|
//加载页面
|
|
if(rType==LoadPageType.STAGE){
|
|
if(mdwInfo.winStage){
|
|
mdwInfo.winStage.loadContent('pages/Index', (err) => {
|
|
if (err.code) {
|
|
hilog.error(DOMAIN, 'Tag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err));
|
|
return;
|
|
}
|
|
mdwInfo.winWidth=mdwInfo.displayWidth-MainWinMargin[0];
|
|
mdwInfo.winHeight=mdwInfo.displayHeight-MainWinMargin[1]*2;
|
|
SetWinSize(mdwInfo.winWidth,mdwInfo.winHeight)
|
|
SetDisplayPosition(MainWinMargin[0]/2,MainWinMargin[1]/2);
|
|
SetBackgroundColor();
|
|
hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.');
|
|
});
|
|
}else{
|
|
console.error(`InitLoadInfoPage winStage Error: win is nullptr!`);
|
|
}
|
|
}else if(rType==LoadPageType.WIN){
|
|
if(mdwInfo.win){
|
|
mdwInfo.win.setUIContent('pages/Index', (err) => {
|
|
if (err.code) {
|
|
hilog.error(DOMAIN, 'Tag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err));
|
|
return;
|
|
}
|
|
mdwInfo.winWidth=mdwInfo.displayWidth-MainWinMargin[0];
|
|
mdwInfo.winHeight=mdwInfo.displayHeight-MainWinMargin[1]*2;
|
|
SetWinSize(mdwInfo.winWidth,mdwInfo.winHeight)
|
|
SetDisplayPosition(MainWinMargin[0]/2,MainWinMargin[1]/2);
|
|
SetBackgroundColor();
|
|
hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.');
|
|
});
|
|
mdwInfo.win.showWindow();
|
|
}else{
|
|
console.error(`InitLoadInfoPage winStage Error: win is nullptr!`);
|
|
}
|
|
}
|
|
}
|
|
|
|
//初始化显示信息页面
|
|
export function InitInfoWindow(winStage: window.WindowStage,ctx:common.UIAbilityContext){
|
|
//通过WindowStage获取MainWindow
|
|
winStage.getMainWindow((err, data) => {
|
|
if (err.code) {
|
|
console.error(`Failed to obtain the main window. Code: ${err.code}, message: ${err.message}`);
|
|
return;
|
|
}
|
|
InitGlobalDWI(winStage);
|
|
InitLoadInfoPage();
|
|
InitWinEventHub(ctx);
|
|
});
|
|
} |