--[[ @module tsb_upgrade_page @summary 升级演示页面 @version 1.0 @date 2026.03.05 @author 李一玮 @usage 本文件是升级演示页面,展示升级演示的各种用法。 ]] local tsb_upgrade_page = {} -- 页面UI元素 local main_container = nil local common_ui = require("tsb_common_page") -- 创建UI function tsb_upgrade_page.create_ui() main_container = airui.container({ x = 0, y = 0, w = 480, h = 320, color = 0xF5F5F5, }) --------------------- 标题栏 ------------------------ local title_bar = airui.container({ parent = main_container, x = 0, y = 0, w = 480, h = 30, color = 0x66BB6A, }) airui.label({ parent = title_bar, text = "升级界面", x = 200, y = 8, w = 80, h = 20, font_size = 16, color = 0xFFFFFF, }) -- 标题栏公共信息展示 common_ui.add_battery_display(title_bar) common_ui.create_back_button(title_bar, tsb_upgrade_page.cleanup) --------------------------------------------------- -- 滚动容器 local scroll_container = airui.container({ parent = main_container, x = 0, y = 30, w = 480, h = 270, color = 0xFFFFFF, }) local keyboard1 = airui.keyboard({ x = 0, y = 0, w = 480, h = 160, -- x, y, 键盘默认打开ALIGN_BOTTOM_MID,位置从中下方开始计算 mode = "numeric", -- 键盘模式,可选 "text"/"upper"/"lower"/"numeric" auto_hide = true, -- 自动隐藏键盘 bg_color = 0xf1f1f1, -- 键盘背景颜色为灰色,可选,不设置则透明 on_commit = function() -- 确认事件回调,只有在按下确认键时才会触发 log.info("keyboard", "commit") end }) -- 设备类型标签 airui.label({ parent = scroll_container, text = "设备类型:", x = 10, y = 12, w = 80, h = 30, font_size = 16, }) -- 设备类型下拉框 local device_type_dropdown = airui.dropdown({ parent = scroll_container, x = 90, y = 5, w = 100, h = 30, options = {"0101", "0102", "0201", "0202", "0301", "0302", "0103", "0104", "0902", "0904"}, default_index = 0, on_change = function(self,idx) log.info("upgrade_device_type", "选择了设备类型:" .. self.options[idx + 1]) end }) -- 当前lora信道标签 airui.label({ parent = scroll_container, text = "当前lora信道:", x = 255, y = 12, w = 120, h = 30, font_size = 16, }) -- 当前lora信道值 local current_channel_label = airui.label({ parent = scroll_container, text = "1", x = 400, y = 12, w = 30, h = 30, font_size = 16, }) airui.label({ parent = scroll_container, text = "设置lora信道:", x = 255, y = 50, w = 120, h = 30, font_size = 16, }) -- 设置lora信道下拉框 local channel_dropdown = airui.dropdown({ parent = scroll_container, x = 380, y = 45, w = 70, h = 30, options = {"1", "2", "3", "4", "5", "6"}, default_index = 0, -- 默认选择1 on_change = function(self,idx) log.info("mqtt_channel", "选择了信道:" .. self.options[idx + 1]) end }) -- 设备SN标签 airui.label({ parent = scroll_container, text = "设备SN:", x = 10, y = 50, w = 70, h = 30, font_size = 16, }) -- 设备SN输入框 local device_sn_input = airui.textarea({ parent = scroll_container, x = 90, y = 40, w = 100, h = 35, text = "", keyboard = keyboard1 }) --------------------------------------------------- -- 先声明开关变量 local target_upgrade_switch local broadcast_upgrade_switch -- 定向升级标签 airui.label({ parent = scroll_container, text = "定向升级", x = 10, y = 92, w = 70, h = 30, font_size = 16, }) -- 定向升级开关 target_upgrade_switch = airui.switch({ parent = scroll_container, x = 80, y = 87, w = 55, h = 25, checked = true, -- 默认定向升级开 on_change = function(self) local checked = self:get_state() log.info("定向升级开关", checked and "开启" or "关闭") -- 互斥逻辑:如果定向升级开启,则关闭广播升级 if checked and broadcast_upgrade_switch then broadcast_upgrade_switch:set_state(false) end end }) -- 广播升级标签 airui.label({ parent = scroll_container, text = "广播升级", x = 160, y = 92, w = 70, h = 30, font_size = 16, }) -- 广播升级开关 broadcast_upgrade_switch = airui.switch({ parent = scroll_container, x = 230, y = 87, w = 55, h = 25, checked = false, -- 默认广播升级关 on_change = function(self) local checked = self:get_state() log.info("广播升级开关", checked and "开启" or "关闭") -- 互斥逻辑:如果广播升级开启,则关闭定向升级 if checked and target_upgrade_switch then target_upgrade_switch:set_state(false) end end }) --------------------------------------------------- --------------------- 第四行控制区 ------------------------ -- 提示信息容器 local info_container = airui.container({ parent = scroll_container, x = 10, y = 130, w = 250, h = 130, color = 0xF5F5F5, radius = 5, }) -- 提示信息 airui.label({ parent = info_container, text = "提示信息:", x = 10, y = 10, w = 230, h = 20, font_size = 15, color = 0x66BB6A, }) airui.label({ parent = info_container, text = "1. 确保设备已连接到网络", x = 10, y = 40, w = 230, h = 20, font_size = 12, color = 0x666666, }) airui.label({ parent = info_container, text = "2. 选择正确的设备类型和SN", x = 10, y = 60, w = 230, h = 20, font_size = 12, color = 0x666666, }) airui.label({ parent = info_container, text = "3. 选择升级方式(定向或广播)", x = 10, y = 80, w = 230, h = 20, font_size = 12, color = 0x666666, }) airui.label({ parent = info_container, text = "4. ......", x = 10, y = 100, w = 230, h = 20, font_size = 12, color = 0x666666, }) -- 操作按钮区 -- 开始升级按钮 local start_upgrade_btn = airui.button({ parent = scroll_container, x = 300, y = 140, w = 150, h = 30, text = "开始升级", stype = { bg_color = 0x2B6FF1,border_color = 0x2B6FF1, text_color = 0xFFFFFF, radius = 8 }, on_click = function(self) log.info("upgrade_start", "开始升级按钮被点击") end }) -- 停止升级按钮 local stop_upgrade_btn = airui.button({ parent = scroll_container, x = 300, y = 180, w = 150, h = 30, text = "停止升级", on_click = function(self) log.info("upgrade_stop", "停止升级按钮被点击") end }) -- 查看升级状态按钮 local check_status_btn = airui.button({ parent = scroll_container, x = 300, y = 220, w = 150, h = 30, text = "查看升级状态", on_click = function(self) log.info("upgrade_check", "查看升级状态按钮被点击") -- 弹出新窗口显示升级状态表格 local status_window = airui.container({ x = 20, y = 35, w = 440, h = 255, color = 0xFFFFFF, radius = 5, border_width = 2, border_color = 0x66BB6A, }) -- 窗口标题 airui.label({ parent = status_window, text = "升级状态", x = 190, y = 15, w = 80, h = 30, font_size = 16, color = 0x66BB6A,--0xE91E63 }) -- 创建表格 local status_table = airui.table({ parent = status_window, x = 10, y = 40, w = 420, h = 200, row_count = 6, col_count = 5, col_width = {70, 120, 120, 120, 120}, }) -- 设置表头 local headers = {"序号", "设备类型", "设备SN", "软件版本", "升级状态"} for i, header in ipairs(headers) do status_table:set_cell_text(0, i-1, header) end -- 示例数据 local status_data = { {"1", "0101", "SN001", "V1.0.0", "升级中"}, {"2", "0202", "SN002", "V1.1.0", "已完成"}, {"3", "0201", "SN003", "V1.0.0", "失败"}, } -- 填充表格数据 for i, data in ipairs(status_data) do for j, value in ipairs(data) do status_table:set_cell_text(i, j-1, value) end end -- 关闭按钮 local close_btn = airui.button({ parent = status_window, x = 390, y = 5, w = 40, h = 25, text = "关闭", on_click = function(self) status_window:destroy() end }) end }) --------------------------------------------------- -- 底部信息 common_ui.create_status_bar(main_container) end -- 初始化页面 function tsb_upgrade_page.init(params) tsb_upgrade_page.create_ui() end -- 清理页面 function tsb_upgrade_page.cleanup() if main_container then main_container:destroy() main_container = nil end end return tsb_upgrade_page