vf107/src/view/mainView.js
@@ -21,7 +21,8 @@
const mainView = {
    authComplete: false, // 认证是否完成,用于控制UI更新
    verifiedUsers: {}, // 存储已核验成功的用户信息
    eventListenersRegistered: false // 事件监听器是否已注册
    eventListenersRegistered: false, // 事件监听器是否已注册
    resetTimerId: null // 存储重置用户UI的定时器ID
}
// 加载主视图的方法
@@ -30,19 +31,19 @@
    // 例如更新设备信息、气体浓度数据等
    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 {
            let netType = config["net.type"] || 1
            let netMode = net.getModeByCard(netType)
            if (netMode && netMode.param && netMode.param.ip) {
                ip = netMode.param.ip
            // 使用getNetParam()方法获取最新的网络参数
            let param = net.getNetParam()
            if (param && param.ip) {
                ip = param.ip
            }
        } catch (error) {
            // 出错时使用config中的IP
            ip = config["net.ip"] || ""
            // 出错时使用screenConfig中的IP
            ip = screenConfig["net.ip"] || ""
        }
        // 通过mainView对象访问标签
        if (mainView.snInfoLbl && mainView.ipInfoLbl) {
@@ -81,19 +82,19 @@
    // 更新设备信息(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 {
            let netType = config["net.type"] || 1
            let netMode = net.getModeByCard(netType)
            if (netMode && netMode.param && netMode.param.ip) {
                ip = netMode.param.ip
            // 使用getNetParam()方法获取最新的网络参数
            let param = net.getNetParam()
            if (param && param.ip) {
                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) {
@@ -125,6 +126,33 @@
            mainView.warehouseLbl.text(houseName)
        } else {
            logger.error('[mainView]: warehouseLbl不存在')
        }
    }
    // 更新网络图标
    function updateNetworkIcon() {
        try {
            let screenConfig = screen.getConfig()
            let netType = screenConfig["net.type"] || 1
            let isConnected = net.isConnected()
            // 隐藏所有网络图标
            if (topView.ethShow) topView.ethShow.hide()
            if (topView.wifiShow) topView.wifiShow.hide()
            if (topView._4gShow) topView._4gShow.hide()
            // 根据网络类型和连接状态显示对应的图标
            if (isConnected) {
                if (netType === 1) { // 以太网
                    if (topView.ethShow) topView.ethShow.show()
                } else if (netType === 2) { // WiFi
                    if (topView.wifiShow) topView.wifiShow.show()
                } else if (netType === 4) { // 4G
                    if (topView._4gShow) topView._4gShow.show()
                }
            }
        } catch (error) {
            logger.error('[mainView]: 更新网络图标失败:', error)
        }
    }
@@ -148,6 +176,8 @@
        // 程序启动时更新库区名称和仓号
        updateWarehouseInfo()
        // 初始化网络图标
        updateNetworkIcon()
        // 只注册一次事件监听器
        if (!mainView.eventListenersRegistered) {
@@ -158,9 +188,11 @@
                onStatusChange: function(netType, status) {
                    // 网络状态变化时更新IP信息
                    updateDeviceInfo()
                    // 更新网络图标
                    updateNetworkIcon()
                }
            })
            // 启动网络事件循环
            std.setInterval(() => {
                try {
@@ -262,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]: 清除之前的重置定时器')
                }
                
@@ -384,7 +416,7 @@
                }
                
                // 设置1分钟后重置用户UI的定时器
                resetTimerId = std.setTimeout(() => {
                mainView.resetTimerId = std.setTimeout(() => {
                    logger.info('[mainView]: 1分钟定时器触发,重置用户UI')
                    // 触发通行解锁完成事件,通知UI重置
                    bus.fire("accessUnlockComplete")
@@ -408,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)
                            
@@ -418,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)
                            }
                        }
@@ -622,8 +668,7 @@
            logger.info('[mainView]: 事件监听器注册完成')
        }
        // 存储定时器ID
        let resetTimerId = null
        // 获取气体浓度和状态信息
        grainService.checkGasConcentration()
@@ -754,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)
@@ -764,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)
@@ -803,9 +848,10 @@
        oxygenValueContainer.flexAlign(dxui.Utils.FLEX_ALIGN.CENTER, dxui.Utils.FLEX_ALIGN.CENTER, dxui.Utils.FLEX_ALIGN.CENTER)
        oxygenValueContainer.obj.lvObjSetStylePadGap(5, dxui.Utils.ENUM._LV_STYLE_STATE_CMP_SAME)
        
        // 氧气数值部分
        const oxygenValue = dxui.Label.build('oxygenValue', oxygenValueContainer)
        oxygenValue.text('20')
        oxygenValue.text('-')
        oxygenValue.textFont(viewUtils.font(20, dxui.Utils.FONT_STYLE.BOLD))
        oxygenValue.textColor(0xffffff)
        mainView.oxygenValue = oxygenValue // 设置为mainView属性
@@ -865,7 +911,7 @@
        
        // 磷化氢数值部分
        const ph3Value = dxui.Label.build('ph3Value', ph3ValueContainer)
        ph3Value.text('0')
        ph3Value.text('-')
        ph3Value.textFont(viewUtils.font(20, dxui.Utils.FONT_STYLE.BOLD))
        ph3Value.textColor(0xffffff)
        mainView.ph3Value = ph3Value // 设置为mainView属性
@@ -909,7 +955,7 @@
        
        // 二氧化碳数值部分
        const co2Value = dxui.Label.build('co2Value', co2ValueContainer)
        co2Value.text('400')
        co2Value.text('-')
        co2Value.textFont(viewUtils.font(20, dxui.Utils.FONT_STYLE.BOLD))
        co2Value.textColor(0xffffff)
        mainView.co2Value = co2Value // 设置为mainView属性
@@ -1353,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]) {
                // 显示弹窗通知
@@ -1378,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]) {
                // 显示弹窗通知
@@ -1404,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]) {
                // 显示弹窗通知
@@ -1430,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]) {
                // 显示弹窗通知
@@ -1438,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')
@@ -1455,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]) {
                // 显示弹窗通知
@@ -1481,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]) {
                // 显示弹窗通知
@@ -1507,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]) {
                // 显示弹窗通知
@@ -1515,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')
@@ -1532,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]) {
                // 显示弹窗通知
@@ -1558,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]) {
                // 显示弹窗通知
@@ -1584,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]) {
                // 显示弹窗通知
@@ -1610,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]) {
                // 显示弹窗通知