tsb_upgrade_page.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. --[[
  2. @module tsb_upgrade_page
  3. @summary 升级演示页面
  4. @version 1.0
  5. @date 2026.03.05
  6. @author 李一玮
  7. @usage
  8. 本文件是升级演示页面,展示升级演示的各种用法。
  9. ]]
  10. local tsb_upgrade_page = {}
  11. -- 页面UI元素
  12. local main_container = nil
  13. local common_ui = require("tsb_common_page")
  14. -- 创建UI
  15. function tsb_upgrade_page.create_ui()
  16. main_container = airui.container({
  17. x = 0,
  18. y = 0,
  19. w = 480,
  20. h = 320,
  21. color = 0xF5F5F5,
  22. })
  23. --------------------- 标题栏 ------------------------
  24. local title_bar = airui.container({
  25. parent = main_container,
  26. x = 0,
  27. y = 0,
  28. w = 480,
  29. h = 30,
  30. color = 0x66BB6A,
  31. })
  32. airui.label({
  33. parent = title_bar,
  34. text = "升级界面",
  35. x = 200,
  36. y = 8,
  37. w = 80,
  38. h = 20,
  39. font_size = 16,
  40. color = 0xFFFFFF,
  41. })
  42. -- 标题栏公共信息展示
  43. common_ui.add_battery_display(title_bar)
  44. common_ui.create_back_button(title_bar, tsb_upgrade_page.cleanup)
  45. ---------------------------------------------------
  46. -- 滚动容器
  47. local scroll_container = airui.container({
  48. parent = main_container,
  49. x = 0,
  50. y = 30,
  51. w = 480,
  52. h = 270,
  53. color = 0xFFFFFF,
  54. })
  55. local keyboard1 = airui.keyboard({
  56. x = 0,
  57. y = 0,
  58. w = 480,
  59. h = 160, -- x, y, 键盘默认打开ALIGN_BOTTOM_MID,位置从中下方开始计算
  60. mode = "numeric", -- 键盘模式,可选 "text"/"upper"/"lower"/"numeric"
  61. auto_hide = true, -- 自动隐藏键盘
  62. preview = true,
  63. preview_height = 35,
  64. bg_color = 0xf1f1f1, -- 键盘背景颜色为灰色,可选,不设置则透明
  65. on_commit = function() -- 确认事件回调,只有在按下确认键时才会触发
  66. log.info("keyboard", "commit")
  67. end
  68. })
  69. -- 设备类型标签
  70. airui.label({
  71. parent = scroll_container,
  72. text = "设备类型:",
  73. x = 10,
  74. y = 12,
  75. w = 80,
  76. h = 30,
  77. font_size = 16,
  78. })
  79. -- 设备类型下拉框
  80. local device_type_dropdown = airui.dropdown({
  81. parent = scroll_container,
  82. x = 90,
  83. y = 5,
  84. w = 100,
  85. h = 30,
  86. options = {"0101", "0102", "0201", "0202", "0301", "0302", "0103", "0104", "0902", "0904"},
  87. default_index = 0,
  88. on_change = function(self,idx)
  89. log.info("upgrade_device_type", "选择了设备类型:" .. self.options[idx + 1])
  90. end
  91. })
  92. -- 当前lora信道标签
  93. airui.label({
  94. parent = scroll_container,
  95. text = "当前lora信道:",
  96. x = 255,
  97. y = 12,
  98. w = 120,
  99. h = 30,
  100. font_size = 16,
  101. })
  102. -- 当前lora信道值
  103. local current_channel_label = airui.label({
  104. parent = scroll_container,
  105. text = "1",
  106. x = 400,
  107. y = 12,
  108. w = 30,
  109. h = 30,
  110. font_size = 16,
  111. })
  112. airui.label({
  113. parent = scroll_container,
  114. text = "设置lora信道:",
  115. x = 255,
  116. y = 50,
  117. w = 120,
  118. h = 30,
  119. font_size = 16,
  120. })
  121. -- 设置lora信道下拉框
  122. local channel_dropdown = airui.dropdown({
  123. parent = scroll_container,
  124. x = 380,
  125. y = 45,
  126. w = 70,
  127. h = 30,
  128. options = {"1", "2", "3", "4", "5", "6"},
  129. default_index = 0, -- 默认选择1
  130. on_change = function(self,idx)
  131. log.info("mqtt_channel", "选择了信道:" .. self.options[idx + 1])
  132. end
  133. })
  134. -- 设备SN标签
  135. airui.label({
  136. parent = scroll_container,
  137. text = "设备SN:",
  138. x = 10,
  139. y = 50,
  140. w = 70,
  141. h = 30,
  142. font_size = 16,
  143. })
  144. -- 设备SN输入框
  145. local device_sn_input = airui.textarea({
  146. parent = scroll_container,
  147. x = 90,
  148. y = 40,
  149. w = 100,
  150. h = 35,
  151. text = "",
  152. keyboard = keyboard1
  153. })
  154. ---------------------------------------------------
  155. -- 先声明开关变量
  156. local target_upgrade_switch
  157. local broadcast_upgrade_switch
  158. -- 定向升级标签
  159. airui.label({
  160. parent = scroll_container,
  161. text = "定向升级",
  162. x = 10,
  163. y = 92,
  164. w = 70,
  165. h = 30,
  166. font_size = 16,
  167. })
  168. -- 定向升级开关
  169. target_upgrade_switch = airui.switch({
  170. parent = scroll_container,
  171. x = 80,
  172. y = 87,
  173. w = 55,
  174. h = 25,
  175. checked = true, -- 默认定向升级开
  176. on_change = function(self)
  177. local checked = self:get_state()
  178. log.info("定向升级开关", checked and "开启" or "关闭")
  179. -- 互斥逻辑:如果定向升级开启,则关闭广播升级
  180. if checked and broadcast_upgrade_switch then
  181. broadcast_upgrade_switch:set_state(false)
  182. end
  183. end
  184. })
  185. -- 广播升级标签
  186. airui.label({
  187. parent = scroll_container,
  188. text = "广播升级",
  189. x = 160,
  190. y = 92,
  191. w = 70,
  192. h = 30,
  193. font_size = 16,
  194. })
  195. -- 广播升级开关
  196. broadcast_upgrade_switch = airui.switch({
  197. parent = scroll_container,
  198. x = 230,
  199. y = 87,
  200. w = 55,
  201. h = 25,
  202. checked = false, -- 默认广播升级关
  203. on_change = function(self)
  204. local checked = self:get_state()
  205. log.info("广播升级开关", checked and "开启" or "关闭")
  206. -- 互斥逻辑:如果广播升级开启,则关闭定向升级
  207. if checked and target_upgrade_switch then
  208. target_upgrade_switch:set_state(false)
  209. end
  210. end
  211. })
  212. ---------------------------------------------------
  213. --------------------- 第四行控制区 ------------------------
  214. -- 提示信息容器
  215. local info_container = airui.container({
  216. parent = scroll_container,
  217. x = 10,
  218. y = 130,
  219. w = 250,
  220. h = 130,
  221. color = 0xF5F5F5,
  222. radius = 5,
  223. })
  224. -- 提示信息
  225. airui.label({
  226. parent = info_container,
  227. text = "提示信息:",
  228. x = 10,
  229. y = 10,
  230. w = 230,
  231. h = 20,
  232. font_size = 15,
  233. color = 0x66BB6A,
  234. })
  235. airui.label({
  236. parent = info_container,
  237. text = "1. 确保设备已连接到网络",
  238. x = 10,
  239. y = 40,
  240. w = 230,
  241. h = 20,
  242. font_size = 12,
  243. color = 0x666666,
  244. })
  245. airui.label({
  246. parent = info_container,
  247. text = "2. 选择正确的设备类型和SN",
  248. x = 10,
  249. y = 60,
  250. w = 230,
  251. h = 20,
  252. font_size = 12,
  253. color = 0x666666,
  254. })
  255. airui.label({
  256. parent = info_container,
  257. text = "3. 选择升级方式(定向或广播)",
  258. x = 10,
  259. y = 80,
  260. w = 230,
  261. h = 20,
  262. font_size = 12,
  263. color = 0x666666,
  264. })
  265. airui.label({
  266. parent = info_container,
  267. text = "4. ......",
  268. x = 10,
  269. y = 100,
  270. w = 230,
  271. h = 20,
  272. font_size = 12,
  273. color = 0x666666,
  274. })
  275. -- 操作按钮区
  276. -- 开始升级按钮
  277. local start_upgrade_btn = airui.button({
  278. parent = scroll_container,
  279. x = 300,
  280. y = 140,
  281. w = 150,
  282. h = 30,
  283. text = "开始升级",
  284. style = { bg_color = 0x2B6FF1,border_color = 0x2B6FF1, text_color = 0xFFFFFF, radius = 8 },
  285. on_click = function(self)
  286. log.info("upgrade_start", "开始升级按钮被点击")
  287. end
  288. })
  289. -- 停止升级按钮
  290. local stop_upgrade_btn = airui.button({
  291. parent = scroll_container,
  292. x = 300,
  293. y = 180,
  294. w = 150,
  295. h = 30,
  296. text = "停止升级",
  297. on_click = function(self)
  298. log.info("upgrade_stop", "停止升级按钮被点击")
  299. end
  300. })
  301. -- 查看升级状态按钮
  302. local check_status_btn = airui.button({
  303. parent = scroll_container,
  304. x = 300,
  305. y = 220,
  306. w = 150,
  307. h = 30,
  308. text = "查看升级状态",
  309. on_click = function(self)
  310. log.info("upgrade_check", "查看升级状态按钮被点击")
  311. -- 弹出新窗口显示升级状态表格
  312. local status_window = airui.container({
  313. x = 20,
  314. y = 35,
  315. w = 440,
  316. h = 255,
  317. color = 0xFFFFFF,
  318. radius = 5,
  319. border_width = 2,
  320. border_color = 0x66BB6A,
  321. })
  322. -- 窗口标题
  323. airui.label({
  324. parent = status_window,
  325. text = "升级状态",
  326. x = 190,
  327. y = 15,
  328. w = 80,
  329. h = 30,
  330. font_size = 16,
  331. color = 0x66BB6A,--0xE91E63
  332. })
  333. -- 创建表格
  334. local status_table = airui.table({
  335. parent = status_window,
  336. x = 10,
  337. y = 40,
  338. w = 420,
  339. h = 200,
  340. row_count = 6,
  341. col_count = 5,
  342. col_width = {70, 120, 120, 120, 120},
  343. })
  344. -- 设置表头
  345. local headers = {"序号", "设备类型", "设备SN", "软件版本", "升级状态"}
  346. for i, header in ipairs(headers) do
  347. status_table:set_cell_text(0, i-1, header)
  348. end
  349. -- 示例数据
  350. local status_data = {
  351. {"1", "0101", "SN001", "V1.0.0", "升级中"},
  352. {"2", "0202", "SN002", "V1.1.0", "已完成"},
  353. {"3", "0201", "SN003", "V1.0.0", "失败"},
  354. }
  355. -- 填充表格数据
  356. for i, data in ipairs(status_data) do
  357. for j, value in ipairs(data) do
  358. status_table:set_cell_text(i, j-1, value)
  359. end
  360. end
  361. -- 关闭按钮
  362. local close_btn = airui.button({
  363. parent = status_window,
  364. x = 390,
  365. y = 5,
  366. w = 40,
  367. h = 25,
  368. text = "关闭",
  369. on_click = function(self)
  370. status_window:destroy()
  371. end
  372. })
  373. end
  374. })
  375. ---------------------------------------------------
  376. -- 底部信息
  377. common_ui.create_status_bar(main_container)
  378. end
  379. -- 初始化页面
  380. function tsb_upgrade_page.init(params)
  381. tsb_upgrade_page.create_ui()
  382. end
  383. -- 清理页面
  384. function tsb_upgrade_page.cleanup()
  385. if main_container then
  386. main_container:destroy()
  387. main_container = nil
  388. end
  389. end
  390. return tsb_upgrade_page