vf107/src/view/mainView.js
@@ -21,7 +21,8 @@
const mainView = {
    authComplete: false, // 认证是否完成,用于控制UI更新
    verifiedUsers: {}, // 存储已核验成功的用户信息
    eventListenersRegistered: false // 事件监听器是否已注册
    eventListenersRegistered: false, // 事件监听器是否已注册
    resetTimerId: null // 存储重置用户UI的定时器ID
}
// 加载主视图的方法
@@ -30,8 +31,8 @@
    // 例如更新设备信息、气体浓度数据等
    try {
        // 更新设备信息
        let config = screen.getConfig()
        let sn = config["sys.sn"] || ""
        let screenConfig = screen.getConfig()
        let sn = screenConfig["sys.sn"] || ""
        // 直接从net模块获取IP地址,确保获取到最新的IP
        let ip = ""
        try {
@@ -41,8 +42,8 @@
                ip = param.ip
            }
        } catch (error) {
            // 出错时使用config中的IP
            ip = config["net.ip"] || ""
            // 出错时使用screenConfig中的IP
            ip = screenConfig["net.ip"] || ""
        }
        // 通过mainView对象访问标签
        if (mainView.snInfoLbl && mainView.ipInfoLbl) {
@@ -81,8 +82,8 @@
    // 更新设备信息(SN和IP)
    function updateDeviceInfo() {
        let config = screen.getConfig()
        let sn = config["sys.sn"] || ""
        let screenConfig = screen.getConfig()
        let sn = screenConfig["sys.sn"] || ""
        // 直接从net模块获取IP地址,确保获取到最新的IP
        let ip = ""
        try {
@@ -92,8 +93,8 @@
                ip = param.ip
            }
        } catch (error) {
            // 出错时使用config中的IP
            ip = config["net.ip"] || ""
            // 出错时使用screenConfig中的IP
            ip = screenConfig["net.ip"] || ""
        }
        // 通过mainView对象访问标签
        if (mainView.snInfoLbl && mainView.ipInfoLbl) {
@@ -109,11 +110,11 @@
    // 更新库区名称和仓号(只在程序启动和配置修改时调用)
    function updateWarehouseInfo() {
        let config = screen.getConfig()
        let screenConfig = screen.getConfig()
        // 获取仓号信息
        let houseName = config["houseName"] || "01号仓"
        let houseName = screenConfig["houseName"] || "01号仓"
        // 获取库区名称
        let GranaryName = config["GranaryName"] || "中央储备粮某某直属库"
        let GranaryName = screenConfig["GranaryName"] || "中央储备粮某某直属库"
        logger.info(`[mainView]: 更新库区名称和仓号: 仓号=${houseName}, 库区名称=${GranaryName}`)
        // 更新顶部标题栏的库区名称
        if (mainView.headerLbl) {
@@ -131,8 +132,8 @@
    // 更新网络图标
    function updateNetworkIcon() {
        try {
            let config = screen.getConfig()
            let netType = config["net.type"] || 1
            let screenConfig = screen.getConfig()
            let netType = screenConfig["net.type"] || 1
            let isConnected = net.isConnected()
            
            // 隐藏所有网络图标
@@ -293,9 +294,9 @@
                logger.info('[mainView]: accessRes事件触发, result=' + result + ', data=' + JSON.stringify(data))
                
                // 清除之前的定时器
                if (resetTimerId) {
                    std.clearTimeout(resetTimerId)
                    resetTimerId = null
                if (mainView.resetTimerId) {
                    std.clearTimeout(mainView.resetTimerId)
                    mainView.resetTimerId = null
                    logger.info('[mainView]: 清除之前的重置定时器')
                }
                
@@ -415,7 +416,7 @@
                }
                
                // 设置1分钟后重置用户UI的定时器
                resetTimerId = std.setTimeout(() => {
                mainView.resetTimerId = std.setTimeout(() => {
                    logger.info('[mainView]: 1分钟定时器触发,重置用户UI')
                    // 触发通行解锁完成事件,通知UI重置
                    bus.fire("accessUnlockComplete")
@@ -439,6 +440,11 @@
                            let dualAuthInfo = data.dualAuthInfo
                            logger.info('[mainView]: 双人认证成功,更新用户UI, user1=' + dualAuthInfo.firstUserId + ', user2=' + dualAuthInfo.secondUserId)
                            
                            // 存储已核验成功的用户信息
                            mainView.verifiedUsers[1] = dualAuthInfo.firstUserId
                            mainView.verifiedUsers[2] = dualAuthInfo.secondUserId
                            logger.info('[mainView]: 存储双人认证用户信息, user1=' + dualAuthInfo.firstUserId + ', user2=' + dualAuthInfo.secondUserId)
                            // 更新用户1的UI
                            mainView.updateUserUI(1, dualAuthInfo.firstUserId, true, data.firstUserFileName || fileName)
                            
@@ -449,12 +455,21 @@
                            let dualAuthInfo = data.dualAuthInfo
                            logger.info('[mainView]: 第一用户认证成功,等待第二用户认证,更新用户UI, user1=' + dualAuthInfo.firstUserId)
                            
                            // 存储已核验成功的用户信息
                            mainView.verifiedUsers[1] = dualAuthInfo.firstUserId
                            logger.info('[mainView]: 存储第一用户认证信息, user1=' + dualAuthInfo.firstUserId)
                            // 更新用户1的UI
                            mainView.updateUserUI(1, dualAuthInfo.firstUserId, true, data.firstUserFileName || fileName)
                        } else {
                            // 单人认证,更新用户1的UI
                            if (data.userId) {
                                logger.info('[mainView]: 单人认证成功,更新用户UI, userId=' + data.userId)
                                // 存储已核验成功的用户信息
                                mainView.verifiedUsers[1] = data.userId
                                logger.info('[mainView]: 存储单人认证用户信息, user1=' + data.userId)
                                mainView.updateUserUI(1, data.userId, true, fileName)
                            }
                        }
@@ -653,8 +668,7 @@
            logger.info('[mainView]: 事件监听器注册完成')
        }
        // 存储定时器ID
        let resetTimerId = null
        // 获取气体浓度和状态信息
        grainService.checkGasConcentration()
@@ -785,8 +799,8 @@
        const headerLbl = dxui.Label.build('headerLbl', headerBox)
        mainView.headerLbl = headerLbl
        // 从配置中获取库区名称
        const config = screen.getConfig()
        const GranaryName = config['GranaryName'] || '中央储备粮某某直属库'
        const screenConfig = screen.getConfig()
        const GranaryName = screenConfig['GranaryName'] || '中央储备粮某某直属库'
        headerLbl.text(GranaryName)
        headerLbl.textFont(viewUtils.font(30)) // 增大字体
        headerLbl.textColor(0xffffff)
@@ -795,7 +809,7 @@
        const warehouseLbl = dxui.Label.build('warehouseLbl', overlayBox)
        mainView.warehouseLbl = warehouseLbl
        // 从配置中获取仓号信息
        const houseName = config['houseName'] || '01号仓'
        const houseName = screenConfig['houseName'] || '01号仓'
        warehouseLbl.text(houseName)
        warehouseLbl.textFont(viewUtils.font(30, dxui.Utils.FONT_STYLE.BOLD))
        warehouseLbl.textColor(0x000000)
@@ -1385,6 +1399,18 @@
        // 设置按钮点击事件
        mode1Btn.on(dxui.Utils.EVENT.CLICK, () => {
            logger.info('允许进仓模式按钮点击')
            const isSafeInputControlEnabled = config.get('safeInputControl') === 1
            if (!isSafeInputControlEnabled) {
                logger.info('[grain]: 安全入仓联动控制功能未启用')
                // 触发未启用弹窗
                bus.fire('showAccessResult', {
                faceAuth: true,
                gasConcentration: true,
                accessAllowed: false,
                message: "*安全入仓联动控制功能未启用*"
                })
                return false
            }
            // 检查是否有用户已核验成功
            if (!mainView.verifiedUsers[1] && !mainView.verifiedUsers[2]) {
                // 显示弹窗通知
@@ -1410,6 +1436,18 @@
    
        inBtn.on(dxui.Utils.EVENT.CLICK, () => {
            logger.info('入仓按钮点击')
            const isSafeInputControlEnabled = config.get('safeInputControl') === 1
            if (!isSafeInputControlEnabled) {
                logger.info('[grain]: 安全入仓联动控制功能未启用')
                // 触发未启用弹窗
                bus.fire('showAccessResult', {
                faceAuth: true,
                gasConcentration: true,
                accessAllowed: false,
                message: "*安全入仓联动控制功能未启用*"
                })
                return false
            }
            // 检查是否有用户已核验成功
            if (!mainView.verifiedUsers[1] && !mainView.verifiedUsers[2]) {
                // 显示弹窗通知
@@ -1436,6 +1474,18 @@
    
        outBtn.on(dxui.Utils.EVENT.CLICK, () => {
            logger.info('出仓按钮点击')
            const isSafeInputControlEnabled = config.get('safeInputControl') === 1
            if (!isSafeInputControlEnabled) {
                logger.info('[grain]: 安全入仓联动控制功能未启用')
                // 触发未启用弹窗
                bus.fire('showAccessResult', {
                faceAuth: true,
                gasConcentration: true,
                accessAllowed: false,
                message: "*安全入仓联动控制功能未启用*"
                })
                return false
            }
            // 检查是否有用户已核验成功
            if (!mainView.verifiedUsers[1] && !mainView.verifiedUsers[2]) {
                // 显示弹窗通知
@@ -1462,6 +1512,18 @@
    
        mode2Btn.on(dxui.Utils.EVENT.CLICK, () => {
            logger.info('冬季通风模式按钮点击')
            const isSafeInputControlEnabled = config.get('safeInputControl') === 1
            if (!isSafeInputControlEnabled) {
                logger.info('[grain]: 安全入仓联动控制功能未启用')
                // 触发未启用弹窗
                bus.fire('showAccessResult', {
                faceAuth: true,
                gasConcentration: true,
                accessAllowed: false,
                message: "*安全入仓联动控制功能未启用*"
                })
                return false
            }
            // 检查是否有用户已核验成功
            if (!mainView.verifiedUsers[1] && !mainView.verifiedUsers[2]) {
                // 显示弹窗通知
@@ -1470,6 +1532,49 @@
                    gasConcentration: true,
                    accessAllowed: false,
                    message: "*联动控制操作无权限*"
                })
                // 播放语音提示
                driver.audio.play('/app/code/resource/CN/wav/control_f.wav')
                return
            }
            // 检查是否有科长权限
            let hasSectionChief = false
            // 检查用户1
            if (mainView.verifiedUsers[1]) {
                let user1 = sqliteService.d1_person.find({ userId: mainView.verifiedUsers[1] })
                if (user1 && user1.length > 0) {
                    try {
                        let userType = JSON.parse(user1[0].extra).type || 0
                        if (userType === 1) {
                            hasSectionChief = true
                        }
                    } catch (error) {
                        logger.error("解析用户1类型失败")
                    }
                }
            }
            // 检查用户2
            if (!hasSectionChief && mainView.verifiedUsers[2]) {
                let user2 = sqliteService.d1_person.find({ userId: mainView.verifiedUsers[2] })
                if (user2 && user2.length > 0) {
                    try {
                        let userType = JSON.parse(user2[0].extra).type || 0
                        if (userType === 1) {
                            hasSectionChief = true
                        }
                    } catch (error) {
                        logger.error("解析用户2类型失败")
                    }
                }
            }
            // 如果没有科长权限,显示核验失败
            if (!hasSectionChief) {
                // 显示弹窗通知
                bus.fire('showAccessResult', {
                    faceAuth: false,
                    gasConcentration: true,
                    accessAllowed: false,
                    message: "*无科长权限,禁止操作*"
                })
                // 播放语音提示
                driver.audio.play('/app/code/resource/CN/wav/control_f.wav')
@@ -1487,6 +1592,18 @@
    
        startBtn.on(dxui.Utils.EVENT.CLICK, () => {
            logger.info('启动按钮点击')
            const isSafeInputControlEnabled = config.get('safeInputControl') === 1
            if (!isSafeInputControlEnabled) {
                logger.info('[grain]: 安全入仓联动控制功能未启用')
                // 触发未启用弹窗
                bus.fire('showAccessResult', {
                faceAuth: true,
                gasConcentration: true,
                accessAllowed: false,
                message: "*安全入仓联动控制功能未启用*"
                })
                return false
            }
            // 检查是否有用户已核验成功
            if (!mainView.verifiedUsers[1] && !mainView.verifiedUsers[2]) {
                // 显示弹窗通知
@@ -1513,6 +1630,18 @@
    
        stopBtn.on(dxui.Utils.EVENT.CLICK, () => {
            logger.info('关闭按钮点击')
            const isSafeInputControlEnabled = config.get('safeInputControl') === 1
            if (!isSafeInputControlEnabled) {
                logger.info('[grain]: 安全入仓联动控制功能未启用')
                // 触发未启用弹窗
                bus.fire('showAccessResult', {
                faceAuth: true,
                gasConcentration: true,
                accessAllowed: false,
                message: "*安全入仓联动控制功能未启用*"
                })
                return false
            }
            // 检查是否有用户已核验成功
            if (!mainView.verifiedUsers[1] && !mainView.verifiedUsers[2]) {
                // 显示弹窗通知
@@ -1539,6 +1668,18 @@
    
        mode3Btn.on(dxui.Utils.EVENT.CLICK, () => {
            logger.info('禁止进仓模式按钮点击')
            const isSafeInputControlEnabled = config.get('safeInputControl') === 1
            if (!isSafeInputControlEnabled) {
                logger.info('[grain]: 安全入仓联动控制功能未启用')
                // 触发未启用弹窗
                bus.fire('showAccessResult', {
                faceAuth: true,
                gasConcentration: true,
                accessAllowed: false,
                message: "*安全入仓联动控制功能未启用*"
                })
                return false
            }
            // 检查是否有用户已核验成功
            if (!mainView.verifiedUsers[1] && !mainView.verifiedUsers[2]) {
                // 显示弹窗通知
@@ -1547,6 +1688,49 @@
                    gasConcentration: true,
                    accessAllowed: false,
                    message: "*联动控制操作无权限*"
                })
                // 播放语音提示
                driver.audio.play('/app/code/resource/CN/wav/control_f.wav')
                return
            }
            // 检查是否有科长权限
            let hasSectionChief = false
            // 检查用户1
            if (mainView.verifiedUsers[1]) {
                let user1 = sqliteService.d1_person.find({ userId: mainView.verifiedUsers[1] })
                if (user1 && user1.length > 0) {
                    try {
                        let userType = JSON.parse(user1[0].extra).type || 0
                        if (userType === 1) {
                            hasSectionChief = true
                        }
                    } catch (error) {
                        logger.error("解析用户1类型失败")
                    }
                }
            }
            // 检查用户2
            if (!hasSectionChief && mainView.verifiedUsers[2]) {
                let user2 = sqliteService.d1_person.find({ userId: mainView.verifiedUsers[2] })
                if (user2 && user2.length > 0) {
                    try {
                        let userType = JSON.parse(user2[0].extra).type || 0
                        if (userType === 1) {
                            hasSectionChief = true
                        }
                    } catch (error) {
                        logger.error("解析用户2类型失败")
                    }
                }
            }
            // 如果没有科长权限,显示核验失败
            if (!hasSectionChief) {
                // 显示弹窗通知
                bus.fire('showAccessResult', {
                    faceAuth: false,
                    gasConcentration: true,
                    accessAllowed: false,
                    message: "*无科长权限,禁止操作*"
                })
                // 播放语音提示
                driver.audio.play('/app/code/resource/CN/wav/control_f.wav')
@@ -1564,6 +1748,18 @@
    
        emergencyInBtn.on(dxui.Utils.EVENT.CLICK, () => {
            logger.info('紧急入仓按钮点击')
            const isSafeInputControlEnabled = config.get('safeInputControl') === 1
            if (!isSafeInputControlEnabled) {
                logger.info('[grain]: 安全入仓联动控制功能未启用')
                // 触发未启用弹窗
                bus.fire('showAccessResult', {
                faceAuth: true,
                gasConcentration: true,
                accessAllowed: false,
                message: "*安全入仓联动控制功能未启用*"
                })
                return false
            }
            // 检查是否有用户已核验成功
            if (!mainView.verifiedUsers[1] && !mainView.verifiedUsers[2]) {
                // 显示弹窗通知
@@ -1590,6 +1786,18 @@
    
        emergencyOutBtn.on(dxui.Utils.EVENT.CLICK, () => {
            logger.info('出仓按钮点击')
            const isSafeInputControlEnabled = config.get('safeInputControl') === 1
            if (!isSafeInputControlEnabled) {
                logger.info('[grain]: 安全入仓联动控制功能未启用')
                // 触发未启用弹窗
                bus.fire('showAccessResult', {
                faceAuth: true,
                gasConcentration: true,
                accessAllowed: false,
                message: "*安全入仓联动控制功能未启用*"
                })
                return false
            }
            // 检查是否有用户已核验成功
            if (!mainView.verifiedUsers[1] && !mainView.verifiedUsers[2]) {
                // 显示弹窗通知
@@ -1616,6 +1824,18 @@
    
        lightOnBtn.on(dxui.Utils.EVENT.CLICK, () => {
            logger.info('开灯按钮点击')
            const isSafeInputControlEnabled = config.get('safeInputControl') === 1
            if (!isSafeInputControlEnabled) {
                logger.info('[grain]: 安全入仓联动控制功能未启用')
                // 触发未启用弹窗
                bus.fire('showAccessResult', {
                faceAuth: true,
                gasConcentration: true,
                accessAllowed: false,
                message: "*安全入仓联动控制功能未启用*"
                })
                return false
            }
            // 检查是否有用户已核验成功
            if (!mainView.verifiedUsers[1] && !mainView.verifiedUsers[2]) {
                // 显示弹窗通知
@@ -1642,6 +1862,18 @@
    
        lightOffBtn.on(dxui.Utils.EVENT.CLICK, () => {
            logger.info('关灯按钮点击')
            const isSafeInputControlEnabled = config.get('safeInputControl') === 1
            if (!isSafeInputControlEnabled) {
                logger.info('[grain]: 安全入仓联动控制功能未启用')
                // 触发未启用弹窗
                bus.fire('showAccessResult', {
                faceAuth: true,
                gasConcentration: true,
                accessAllowed: false,
                message: "*安全入仓联动控制功能未启用*"
                })
                return false
            }
            // 检查是否有用户已核验成功
            if (!mainView.verifiedUsers[1] && !mainView.verifiedUsers[2]) {
                // 显示弹窗通知