| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- --[[
- @module tsb_firm_page
- @summary 固件下载页面
- @version 1.0
- @date 2026.03.05
- @author 李一玮
- @usage
- 本文件是固件下载页面,展示固件下载的各种用法。
- ]]
- local tsb_firm_page = {}
- -- 页面UI元素
- local main_container = nil
- local download_progress = 0
- local download_bar = nil
- local download_timer = nil
- local common_ui = require("tsb_common_page")
- -- 创建UI
- function tsb_firm_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 = 0x2196F3,
- })
- airui.label({
- parent = title_bar,
- text = "固件包下载",
- x = 190,
- y = 8,
- w = 120,
- h = 20,
- font_size = 16,
- color = 0xFFFFFF,
- })
- -- 标题栏公共信息展示
- common_ui.add_battery_display(title_bar)
- common_ui.create_back_button(title_bar, tsb_firm_page.cleanup)
- ---------------------------------------------------
- -- 滚动容器
- local scroll_container = airui.container({
- parent = main_container,
- x = 0,
- y = 30,
- w = 480,
- h = 270,
- color = 0xFFFFFF,
- })
- common_ui.add_battery_display(scroll_container)
- --------------------- 第一行控制区 ------------------------
- -- 设备类型标签
- airui.label({
- parent = scroll_container,
- text = "设备类型:",
- x = 10,
- y = 18,
- w = 80,
- h = 30,
- font_size = 16,
- })
- -- 设备类型下拉框
- local device_type_dropdown = airui.dropdown({
- parent = scroll_container,
- x = 90,
- y = 10,
- 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("firm_device_type", "选择了设备类型:" .. self.options[idx + 1])
- end
- })
- -- 固件类型标签
- airui.label({
- parent = scroll_container,
- text = "固件类型:",
- x = 230,
- y = 18,
- w = 80,
- h = 30,
- font_size = 16,
- })
- -- 固件类型下拉框
- local firmware_type_dropdown = airui.dropdown({
- parent = scroll_container,
- x = 310,
- y = 10,
- w = 100,
- h = 30,
- options = {"产测", "app", "boot"},
- default_index = 1, -- 默认选择app
- on_change = function(self,idx)
- log.info("firm_type", "选择了固件类型:" .. self.options[idx + 1])
- end
- })
- ---------------------------------------------------
- --------------------- 第二行控制区 ------------------------
- -- 先声明开关变量
- local flash_package_switch
- local upgrade_package_switch
- -- 刷机包标签
- airui.label({
- parent = scroll_container,
- text = "刷机包",
- x = 10,
- y = 57,
- w = 60,
- h = 30,
- font_size = 16,
- })
- -- 刷机包开关
- flash_package_switch = airui.switch({
- parent = scroll_container,
- x = 70,
- y = 55,
- w = 50,
- h = 20,
- checked = true,
- on_change = function(self)
- local checked = self:get_state()
- log.info("刷机包开关", checked and "开启" or "关闭")
- -- 互斥逻辑:如果刷机包开启,则关闭升级包
- if checked and upgrade_package_switch then
- upgrade_package_switch:set_state(false)
- end
- end
- })
- -- 升级包标签
- airui.label({
- parent = scroll_container,
- text = "升级包",
- x = 140,
- y = 57,
- w = 60,
- h = 30,
- font_size = 16,
- })
- -- 升级包开关
- upgrade_package_switch = airui.switch({
- parent = scroll_container,
- x = 200,
- y = 55,
- w = 50,
- h = 20,
- checked = false,
- on_change = function(self)
- local checked = self:get_state()
- log.info("升级包开关", checked and "开启" or "关闭")
- -- 互斥逻辑:如果升级包开启,则关闭刷机包
- if checked and flash_package_switch then
- flash_package_switch:set_state(false)
- end
- end
- })
- ---------------------------------------------------
- --------------------- 第三行控制区 ------------------------
- -- 固件版本标签
- airui.label({
- parent = scroll_container,
- text = "固件版本",
- x = 10,
- y = 97,
- w = 80,
- h = 30,
- font_size = 16,
- })
- -- 固件版本下拉框
- local firmware_version_dropdown = airui.dropdown({
- parent = scroll_container,
- x = 90,
- y = 90,
- w = 150,
- h = 30,
- options = {"V1.0.0", "V1.1.0", "V2.0.0"}, -- 示例版本,实际可根据需要修改
- default_index = 0,
- on_change = function(self,idx)
- log.info("firm_version", "选择了固件版本:" .. self.options[idx + 1])
- end
- })
- ---------------------------------------------------
- --------------------- 操作按钮区 -----------------------
- -- 下载进度条
- download_bar = airui.bar({
- parent = scroll_container,
- x = 5,
- y = 240,
- w = 470,
- h = 20,
- value = 0,
- min = 0,
- max = 100,
- radius = 5,
- indicator_color = 0x2196F3,
- show_progress_text = true,
- progress_text_format = "%d%%",
- })
- -- 下载固件包按钮
- local download_btn = airui.button({
- parent = scroll_container,
- x = 170,
- y = 140,
- w = 150,
- h = 40,
- text = "下载固件包",
- stype = { bg_color = 0x2B6FF1,border_color = 0x2B6FF1, text_color = 0xFFFFFF, radius = 8 },
- on_click = function(self)
- log.info("firm_download", "下载固件包按钮被点击")
- -- 重置进度
- download_bar:set_value(0, true)
-
- -- 开始下载动画
- if download_timer then
- sys.timerStop(download_timer)
- download_timer = nil
- end
-
- download_timer = sys.timerLoopStart(function()
- local current = download_bar:get_value()
- if current >= 100 then
- current = 0
- else
- current = current + 5
- end
- download_bar:set_value(current, true) -- 启用动画
-
- if current >= 100 then
- sys.timerStop(download_timer)
- download_timer = nil
- -- 下载完成,显示消息框
- local msg = airui.msgbox({
- title = "系统提示",
- text = "下载完成",
- buttons = { "确定" },
- on_action = function(self, label)
- log.info("firm_download", "下载完成消息框被点击: " .. label)
- self:hide()
- download_bar:set_value(0, true)
- end
- })
- msg:show()
- end
- end, 200)
- end
- })
- -- 去刷机按钮
- local flash_btn = airui.button({
- parent = scroll_container,
- x = 30,
- y = 190,
- w = 150,
- h = 40,
- text = "去刷机",
- on_click = function(self)
- log.info("firm_flash_btn", "去刷机按钮被点击")
- -- 跳转到刷机页面
- --tsb_firm_page.cleanup()
- show_page("tsb_reflash_page")
- end
- })
- -- 去升级按钮
- local upgrade_btn = airui.button({
- parent = scroll_container,
- x = 300,
- y = 190,
- w = 150,
- h = 40,
- text = "去升级",
- on_click = function(self)
- log.info("firm_upgrade_btn", "去升级按钮被点击")
- -- 跳转到升级页面
- --tsb_firm_page.cleanup()
- show_page("tsb_upgrade_page")
- end
- })
- ---------------------------------------------------
-
- -- 底部信息
- common_ui.create_status_bar(main_container)
- end
- -- 初始化页面
- function tsb_firm_page.init(params)
- tsb_firm_page.create_ui()
- end
- -- 清理页面
- function tsb_firm_page.cleanup()
- if download_timer then
- sys.timerStop(download_timer)
- download_timer = nil
- end
- if main_container then
- main_container:destroy()
- main_container = nil
- end
- end
- return tsb_firm_page
|