tsb_firm_page.lua 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. --[[
  2. @module tsb_firm_page
  3. @summary 固件下载页面
  4. @version 1.0
  5. @date 2026.03.05
  6. @author 李一玮
  7. @usage
  8. 本文件是固件下载页面,展示固件下载的各种用法。
  9. ]]
  10. local tsb_firm_page = {}
  11. -- 页面UI元素
  12. local main_container = nil
  13. local download_progress = 0
  14. local download_bar = nil
  15. local download_timer = nil
  16. local common_ui = require("tsb_common_page")
  17. -- 创建UI
  18. function tsb_firm_page.create_ui()
  19. main_container = airui.container({
  20. x = 0,
  21. y = 0,
  22. w = 480,
  23. h = 320,
  24. color = 0xF5F5F5,
  25. })
  26. --------------------- 标题栏 ------------------------
  27. local title_bar = airui.container({
  28. parent = main_container,
  29. x = 0,
  30. y = 0,
  31. w = 480,
  32. h = 30,
  33. color = 0x2196F3,
  34. })
  35. airui.label({
  36. parent = title_bar,
  37. text = "固件包下载",
  38. x = 190,
  39. y = 8,
  40. w = 120,
  41. h = 20,
  42. font_size = 16,
  43. color = 0xFFFFFF,
  44. })
  45. -- 标题栏公共信息展示
  46. common_ui.add_battery_display(title_bar)
  47. common_ui.create_back_button(title_bar, tsb_firm_page.cleanup)
  48. ---------------------------------------------------
  49. -- 滚动容器
  50. local scroll_container = airui.container({
  51. parent = main_container,
  52. x = 0,
  53. y = 30,
  54. w = 480,
  55. h = 270,
  56. color = 0xFFFFFF,
  57. })
  58. common_ui.add_battery_display(scroll_container)
  59. --------------------- 第一行控制区 ------------------------
  60. -- 设备类型标签
  61. airui.label({
  62. parent = scroll_container,
  63. text = "设备类型:",
  64. x = 10,
  65. y = 18,
  66. w = 80,
  67. h = 30,
  68. font_size = 16,
  69. })
  70. -- 设备类型下拉框
  71. local device_type_dropdown = airui.dropdown({
  72. parent = scroll_container,
  73. x = 90,
  74. y = 10,
  75. w = 100,
  76. h = 30,
  77. options = {"0101", "0102", "0201", "0202", "0301", "0302", "0103", "0104", "0902", "0904"},
  78. default_index = 0,
  79. on_change = function(self,idx)
  80. log.info("firm_device_type", "选择了设备类型:" .. self.options[idx + 1])
  81. end
  82. })
  83. -- 固件类型标签
  84. airui.label({
  85. parent = scroll_container,
  86. text = "固件类型:",
  87. x = 230,
  88. y = 18,
  89. w = 80,
  90. h = 30,
  91. font_size = 16,
  92. })
  93. -- 固件类型下拉框
  94. local firmware_type_dropdown = airui.dropdown({
  95. parent = scroll_container,
  96. x = 310,
  97. y = 10,
  98. w = 100,
  99. h = 30,
  100. options = {"产测", "app", "boot"},
  101. default_index = 1, -- 默认选择app
  102. on_change = function(self,idx)
  103. log.info("firm_type", "选择了固件类型:" .. self.options[idx + 1])
  104. end
  105. })
  106. ---------------------------------------------------
  107. --------------------- 第二行控制区 ------------------------
  108. -- 先声明开关变量
  109. local flash_package_switch
  110. local upgrade_package_switch
  111. -- 刷机包标签
  112. airui.label({
  113. parent = scroll_container,
  114. text = "刷机包",
  115. x = 10,
  116. y = 57,
  117. w = 60,
  118. h = 30,
  119. font_size = 16,
  120. })
  121. -- 刷机包开关
  122. flash_package_switch = airui.switch({
  123. parent = scroll_container,
  124. x = 70,
  125. y = 55,
  126. w = 50,
  127. h = 20,
  128. checked = true,
  129. on_change = function(self)
  130. local checked = self:get_state()
  131. log.info("刷机包开关", checked and "开启" or "关闭")
  132. -- 互斥逻辑:如果刷机包开启,则关闭升级包
  133. if checked and upgrade_package_switch then
  134. upgrade_package_switch:set_state(false)
  135. end
  136. end
  137. })
  138. -- 升级包标签
  139. airui.label({
  140. parent = scroll_container,
  141. text = "升级包",
  142. x = 140,
  143. y = 57,
  144. w = 60,
  145. h = 30,
  146. font_size = 16,
  147. })
  148. -- 升级包开关
  149. upgrade_package_switch = airui.switch({
  150. parent = scroll_container,
  151. x = 200,
  152. y = 55,
  153. w = 50,
  154. h = 20,
  155. checked = false,
  156. on_change = function(self)
  157. local checked = self:get_state()
  158. log.info("升级包开关", checked and "开启" or "关闭")
  159. -- 互斥逻辑:如果升级包开启,则关闭刷机包
  160. if checked and flash_package_switch then
  161. flash_package_switch:set_state(false)
  162. end
  163. end
  164. })
  165. ---------------------------------------------------
  166. --------------------- 第三行控制区 ------------------------
  167. -- 固件版本标签
  168. airui.label({
  169. parent = scroll_container,
  170. text = "固件版本",
  171. x = 10,
  172. y = 97,
  173. w = 80,
  174. h = 30,
  175. font_size = 16,
  176. })
  177. -- 固件版本下拉框
  178. local firmware_version_dropdown = airui.dropdown({
  179. parent = scroll_container,
  180. x = 90,
  181. y = 90,
  182. w = 150,
  183. h = 30,
  184. options = {"V1.0.0", "V1.1.0", "V2.0.0"}, -- 示例版本,实际可根据需要修改
  185. default_index = 0,
  186. on_change = function(self,idx)
  187. log.info("firm_version", "选择了固件版本:" .. self.options[idx + 1])
  188. end
  189. })
  190. ---------------------------------------------------
  191. --------------------- 操作按钮区 -----------------------
  192. -- 下载进度条
  193. download_bar = airui.bar({
  194. parent = scroll_container,
  195. x = 5,
  196. y = 240,
  197. w = 470,
  198. h = 20,
  199. value = 0,
  200. min = 0,
  201. max = 100,
  202. radius = 5,
  203. indicator_color = 0x2196F3,
  204. show_progress_text = true,
  205. progress_text_format = "%d%%",
  206. })
  207. -- 下载固件包按钮
  208. local download_btn = airui.button({
  209. parent = scroll_container,
  210. x = 170,
  211. y = 140,
  212. w = 150,
  213. h = 40,
  214. text = "下载固件包",
  215. stype = { bg_color = 0x2B6FF1,border_color = 0x2B6FF1, text_color = 0xFFFFFF, radius = 8 },
  216. on_click = function(self)
  217. log.info("firm_download", "下载固件包按钮被点击")
  218. -- 重置进度
  219. download_bar:set_value(0, true)
  220. -- 开始下载动画
  221. if download_timer then
  222. sys.timerStop(download_timer)
  223. download_timer = nil
  224. end
  225. download_timer = sys.timerLoopStart(function()
  226. local current = download_bar:get_value()
  227. if current >= 100 then
  228. current = 0
  229. else
  230. current = current + 5
  231. end
  232. download_bar:set_value(current, true) -- 启用动画
  233. if current >= 100 then
  234. sys.timerStop(download_timer)
  235. download_timer = nil
  236. -- 下载完成,显示消息框
  237. local msg = airui.msgbox({
  238. title = "系统提示",
  239. text = "下载完成",
  240. buttons = { "确定" },
  241. on_action = function(self, label)
  242. log.info("firm_download", "下载完成消息框被点击: " .. label)
  243. self:hide()
  244. download_bar:set_value(0, true)
  245. end
  246. })
  247. msg:show()
  248. end
  249. end, 200)
  250. end
  251. })
  252. -- 去刷机按钮
  253. local flash_btn = airui.button({
  254. parent = scroll_container,
  255. x = 30,
  256. y = 190,
  257. w = 150,
  258. h = 40,
  259. text = "去刷机",
  260. on_click = function(self)
  261. log.info("firm_flash_btn", "去刷机按钮被点击")
  262. -- 跳转到刷机页面
  263. --tsb_firm_page.cleanup()
  264. show_page("tsb_reflash_page")
  265. end
  266. })
  267. -- 去升级按钮
  268. local upgrade_btn = airui.button({
  269. parent = scroll_container,
  270. x = 300,
  271. y = 190,
  272. w = 150,
  273. h = 40,
  274. text = "去升级",
  275. on_click = function(self)
  276. log.info("firm_upgrade_btn", "去升级按钮被点击")
  277. -- 跳转到升级页面
  278. --tsb_firm_page.cleanup()
  279. show_page("tsb_upgrade_page")
  280. end
  281. })
  282. ---------------------------------------------------
  283. -- 底部信息
  284. common_ui.create_status_bar(main_container)
  285. end
  286. -- 初始化页面
  287. function tsb_firm_page.init(params)
  288. tsb_firm_page.create_ui()
  289. end
  290. -- 清理页面
  291. function tsb_firm_page.cleanup()
  292. if download_timer then
  293. sys.timerStop(download_timer)
  294. download_timer = nil
  295. end
  296. if main_container then
  297. main_container:destroy()
  298. main_container = nil
  299. end
  300. end
  301. return tsb_firm_page