lgq
2026-03-31 e491cdb48129752324c4e3764f99bd9203c56dec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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.alsa.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, 400)
    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, 480)
    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.alsa.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.alsa.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