中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
如何实现一个验证码弹窗子窗口
微信扫码分享
// WindowModel.ets createSubWindow() { if (this.windowStage === undefined) { Logger.error('Failed to create the subWindow.'); return; } // 创建子窗口 this.windowStage.createSubWindow(CommonConstants.SUB_WINDOW_NAME, (err, data: window.Window) => { if (err.code) { Logger.error(`Failed to create the window. Code:${err.code}, message:${err.message}`); return; } // 获取子窗口实例 this.subWindowClass = data; // 获取屏幕宽高 let screenWidth = display.getDefaultDisplaySync().width; let screenHeight = display.getDefaultDisplaySync().height; // 根据子窗口宽高比计算子窗口宽高 let windowWidth = screenWidth * CommonConstants.SUB_WINDOW_WIDTH_RATIO; let windowHeight = windowWidth / CommonConstants.SUB_WINDOW_ASPECT_RATIO; // 计算子窗口起始坐标 let moveX = (screenWidth - windowWidth) / 2; let moveY = screenHeight - windowHeight; // 将子窗口移动到起始坐标处 this.subWindowClass.moveWindowTo(moveX, moveY, (err) => { if (err.code) { Logger.error(`Failed to move the window. Code:${err.code}, message:${err.message}`); return; } }); // 设置子窗口的宽高 this.subWindowClass.resize(windowWidth, windowHeight, (err) => { if (err.code) { Logger.error(`Failed to change the window size. Code:${err.code}, message:${err.message}`); return; } }); // 设置子窗口展示的页面内容 this.subWindowClass.setUIContent(CommonConstants.VERIFY_PAGE_URL, (err) => { if (err.code) { Logger.error(`Failed to load the content. Code:${err.code}, message:${err.message}`); return; } if (this.subWindowClass === undefined) { Logger.error('subWindowClass is undefined.'); return; } // 设置子窗口背景颜色 this.subWindowClass.setWindowBackgroundColor('#00000000'); // 显示子窗口 this.subWindowClass.showWindow((err) => { if (err.code) { Logger.error(`Failed to show the window. Code:${err.code}, essage:${err.message}`); return; } }); }); }); }