tsb_upgrade_page.lua 11 KB

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