import dxui from '../../dxmodules/dxUi.js' import std from '../../dxmodules/dxStd.js' import viewUtils from "./viewUtils.js" import topView from './topView.js' import mainView from './mainView.js' import screen from '../screen.js' import logger from '../../dxmodules/dxLogger.js' import driver from '../driver.js' import config from '../../dxmodules/dxConfig.js' const emergencyPwdView = {} emergencyPwdView.init = function () { /**************************************************创建屏幕*****************************************************/ const screenMain = dxui.View.build('emergencyPwdView', dxui.Utils.LAYER.MAIN) emergencyPwdView.screenMain = screenMain screenMain.scroll(false) screenMain.bgColor(0xffffff) screenMain.on(dxui.Utils.ENUM.LV_EVENT_SCREEN_LOADED, () => { topView.changeTheme(true) // 播放应急通行语音提示 try { driver.audio.play(`/app/code/resource/${config.get("base.language") == "CN" ? "CN" : "EN"}/wav/emergency.wav`) logger.info('[emergencyPwdView]: 播放应急通行语音提示') } catch (error) { logger.error('[emergencyPwdView]: 播放语音提示失败: ' + error.message) } emergencyPwdView.timer = std.setInterval(() => { let count = dxui.Utils.GG.NativeDisp.lvDispGetInactiveTime() if (count > 15 * 1000) { std.clearInterval(emergencyPwdView.timer) emergencyPwdView.timer = null dxui.loadMain(mainView.screenMain) } }, 1000) pwdInput.send(dxui.Utils.EVENT.CLICK) pwdInput.send(dxui.Utils.EVENT.FOCUSED) }) screenMain.on(dxui.Utils.ENUM.LV_EVENT_SCREEN_UNLOADED, () => { if (emergencyPwdView.timer) { std.clearInterval(emergencyPwdView.timer) } // 清空验证结果提示 if (emergencyPwdView.resultLbl) { emergencyPwdView.resultLbl.text(' ') } }) const titleBox = viewUtils.title(screenMain, mainView.screenMain, 'emergencyPwdViewTitle', '应急密码通行') titleBox.align(dxui.Utils.ALIGN.TOP_MID, 0, 70) const pwdInput = viewUtils.input(screenMain, 'emergencyPwdInput', 2, undefined, '请输入应急密码') pwdInput.align(dxui.Utils.ALIGN.TOP_MID, 0, 211) pwdInput.setPasswordMode(true) const eyeFill = viewUtils.imageBtn(screenMain, screenMain.id + 'eye_fill', '/app/code/resource/image/eye-fill.png') eyeFill.alignTo(pwdInput, dxui.Utils.ALIGN.RIGHT_MID, 0, 0) eyeFill.on(dxui.Utils.EVENT.CLICK, () => { pwdInput.setPasswordMode(true) eyeFill.hide() eyeOff.show() }) eyeFill.hide() const eyeOff = viewUtils.imageBtn(screenMain, screenMain.id + 'eye_off', '/app/code/resource/image/eye-off.png') eyeOff.alignTo(pwdInput, dxui.Utils.ALIGN.RIGHT_MID, 0, 0) eyeOff.on(dxui.Utils.EVENT.CLICK, () => { pwdInput.setPasswordMode(false) eyeFill.show() eyeOff.hide() }) // 添加提示文本 const hintText1 = dxui.Label.build('hintText1', screenMain) hintText1.text('1.应急开门无视仓内气体浓度是否达标,请自行确保开门入仓安全。') hintText1.textFont(viewUtils.font(24)) hintText1.textColor(0xff0000) hintText1.align(dxui.Utils.ALIGN.TOP_MID, 0, 350) hintText1.longMode(dxui.Utils.LABEL_LONG_MODE.BREAK) hintText1.width(680) const hintText2 = dxui.Label.build('hintText2', screenMain) hintText2.text('2.气调仓或熏蒸仓请务必佩戴专业设备,确保入仓安全。') hintText2.textFont(viewUtils.font(24)) hintText2.textColor(0xff0000) hintText2.align(dxui.Utils.ALIGN.TOP_MID, 0, 500) hintText2.longMode(dxui.Utils.LABEL_LONG_MODE.BREAK) hintText2.width(680) // 验证结果提示 const resultLbl = dxui.Label.build('resultLbl', screenMain) resultLbl.text(' ') resultLbl.textFont(viewUtils.font(32)) resultLbl.textColor(0x000000) resultLbl.align(dxui.Utils.ALIGN.TOP_MID, 0, 580) emergencyPwdView.resultLbl = resultLbl const emergencyAccessBtn = viewUtils.bottomBtn(screenMain, 'emergencyAccessBtn', '应急密码通行', () => { // 确认密码 const pwd = pwdInput.text() const result = screen.pwdAccess(pwd) if (result) { // 密码验证通过 logger.info('[emergencyPwdView]: 应急密码验证通过') resultLbl.text('应急密码验证通过,正在开仓...') resultLbl.textColor(0x008000) // 开继电器 try { driver.gpio.open() // 打开继电器并在指定时间后自动关闭 logger.info(`[emergencyPwdView]: 打开继电器成功`) resultLbl.text('应急密码验证通过,已开仓!') } catch (error) { logger.error(`[emergencyPwdView]: 打开继电器失败: ${error.message}`) } // 语音提示 driver.audio.play(`/app/code/resource/${config.get("base.language") == "CN" ? "CN" : "EN"}/wav/emergency_s.wav`) // 延迟返回主界面 std.setTimeout(() => { dxui.loadMain(mainView.screenMain) }, 3000) } else { // 密码验证失败 logger.info('[emergencyPwdView]: 应急密码验证失败') resultLbl.text('应急密码错误,请重新输入') resultLbl.textColor(0xff0000) // 语音提示 driver.audio.play(`/app/code/resource/${config.get("base.language") == "CN" ? "CN" : "EN"}/wav/emergency_f.wav`) } }) emergencyAccessBtn.align(dxui.Utils.ALIGN.BOTTOM_MID, 0, -83) } export default emergencyPwdView