| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429 |
- --[[
- @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
|