tsb_channel_page.lua 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. --[[
  2. @module tsb_channel_page
  3. @summary 信道切换页面
  4. @version 1.0
  5. @date 2026.03.05
  6. @author 李一玮
  7. @usage
  8. 本文件是信道切换页面,展示信道切换的各种用法。
  9. ]]
  10. local tsb_channel_page = {}
  11. -- 页面UI元素
  12. local main_container = nil
  13. local common_ui = require("tsb_common_page")
  14. -- 创建UI
  15. function tsb_channel_page.create_ui()
  16. main_container = airui.container({
  17. x = 0,
  18. y = 0,
  19. w = 480,
  20. h = 320,
  21. color = 0xF5F5F5,
  22. color_opacity = 0
  23. })
  24. --------------------- 标题栏 ------------------------
  25. local title_bar = airui.container({
  26. parent = main_container,
  27. x = 0,
  28. y = 0,
  29. w = 480,
  30. h = 30,
  31. color = 0x7E57C2,
  32. })
  33. airui.label({
  34. parent = title_bar,
  35. text = "信道切换",
  36. x = 190,
  37. y = 8,
  38. w = 100,
  39. h = 20,
  40. font_size = 16,
  41. color = 0xFFFFFF,
  42. })
  43. -- 标题栏公共信息展示
  44. common_ui.add_battery_display(title_bar)
  45. common_ui.create_back_button(title_bar, tsb_channel_page.cleanup)
  46. ---------------------------------------------------
  47. -- 滚动容器
  48. local scroll_container = airui.container({
  49. parent = main_container,
  50. x = 0,
  51. y = 30,
  52. w = 480,
  53. h = 270,
  54. color = 0xFFFFFF,
  55. })
  56. local keyboard1 = airui.keyboard({
  57. x = 0,
  58. y = 0,
  59. w = 480,
  60. h = 160, -- x, y, 键盘默认打开ALIGN_BOTTOM_MID,位置从中下方开始计算
  61. mode = "numeric", -- 键盘模式,可选 "text"/"upper"/"lower"/"numeric"
  62. auto_hide = true, -- 自动隐藏键盘
  63. preview = true,
  64. preview_height = 35,
  65. bg_color = 0xf1f1f1, -- 键盘背景颜色为灰色,可选,不设置则透明
  66. on_commit = function() -- 确认事件回调,只有在按下确认键时才会触发
  67. log.info("keyboard", "commit")
  68. end
  69. })
  70. local keyboard2 = airui.keyboard({
  71. x = 0,
  72. y = 0,
  73. w = 480,
  74. h = 160, -- x, y, 键盘默认打开ALIGN_BOTTOM_MID,位置从中下方开始计算
  75. mode = "lower", -- 键盘模式,可选 "text"/"upper"/"lower"/"numeric"
  76. auto_hide = true, -- 自动隐藏键盘
  77. preview = true,
  78. preview_height = 35,
  79. bg_color = 0xf1f1f1, -- 键盘背景颜色为灰色,可选,不设置则透明
  80. on_commit = function() -- 确认事件回调,只有在按下确认键时才会触发
  81. log.info("keyboard", "commit")
  82. end
  83. })
  84. --------------------- 第一行控制区 ------------------------
  85. -- 当前lora信道标签
  86. airui.label({
  87. parent = scroll_container,
  88. text = "当前调试宝信道:",
  89. x = 10,
  90. y = 15,
  91. w = 120,
  92. h = 30,
  93. font_size = 15,
  94. })
  95. -- 当前lora信道值
  96. local current_channel_label = airui.label({
  97. parent = scroll_container,
  98. text = "1",
  99. x = 135,
  100. y = 15,
  101. w = 30,
  102. h = 30,
  103. font_size = 15,
  104. })
  105. -- 设置lora信道标签
  106. airui.label({
  107. parent = scroll_container,
  108. text = "设置调试宝信道:",
  109. x = 180,
  110. y = 15,
  111. w = 130,
  112. h = 30,
  113. font_size = 15,
  114. })
  115. -- 设置lora信道下拉框
  116. local channel_dropdown = airui.dropdown({
  117. parent = scroll_container,
  118. x = 310,
  119. y = 8,
  120. w = 70,
  121. h = 30,
  122. options = {"1", "2", "3", "4", "5", "6"},
  123. default_index = 0, -- 默认选择1
  124. on_change = function(self,idx)
  125. log.info("mqtt_channel", "选择了信道:" .. self.options[idx + 1])
  126. end
  127. })
  128. -- 目标设备类型标签
  129. airui.label({
  130. parent = scroll_container,
  131. text = "目标设备类型:",
  132. x = 10,
  133. y = 60,
  134. w = 100,
  135. h = 30,
  136. font_size = 15,
  137. })
  138. -- 目标设备类型下拉框
  139. local device_type_dropdown = airui.dropdown({
  140. parent = scroll_container,
  141. x = 120,
  142. y = 50,
  143. w = 100,
  144. h = 35,
  145. options = {"路由器", "连接器"},
  146. default_index = 0, -- 默认选择路由器
  147. on_change = function(self,idx)
  148. log.info("device_type", "选择了设备类型:" .. self.options[idx + 1])
  149. end
  150. })
  151. airui.label({
  152. parent = scroll_container,
  153. text = "目标设备SN:",
  154. x = 10,
  155. y = 110,
  156. w = 100,
  157. h = 30,
  158. font_size = 15,
  159. })
  160. -- 连接器SN输入框
  161. local sn_input = airui.textarea({
  162. parent = scroll_container,
  163. x = 120,
  164. y = 100,
  165. w = 100,
  166. h = 35,
  167. text = "",
  168. max_length = 5,
  169. keyboard = keyboard1
  170. })
  171. airui.label({
  172. parent = scroll_container,
  173. text = "切换到信道:",
  174. x = 10,
  175. y = 160,
  176. w = 100,
  177. h = 20,
  178. font_size = 15,
  179. })
  180. local channel1_dropdown = airui.dropdown({
  181. parent = scroll_container,
  182. x = 120,
  183. y = 150,
  184. w = 70,
  185. h = 35,
  186. options = {"1", "2", "3", "4", "5", "6"},
  187. default_index = 0, -- 默认选择1
  188. on_change = function(self,idx)
  189. log.info("mqtt_channel", "选择了信道:" .. self.options[idx + 1])
  190. end
  191. })
  192. ---------------------------------------------------
  193. -- 新配置下发按钮
  194. local new_config_btn = airui.button({
  195. parent = scroll_container,
  196. x = 30,
  197. y = 200,
  198. w = 100,
  199. h = 35,
  200. text = "指令下发",
  201. --style = { bg_color = 0x2B6FF1,border_color = 0x2B6FF1, text_color = 0xFFFFFF, radius = 8 },
  202. on_click = function(self)
  203. log.info("mqtt_config", "新配置下发按钮被点击")
  204. end
  205. })
  206. -- 恢复默认配置按钮
  207. -- local default_config_btn = airui.button({
  208. -- parent = scroll_container,
  209. -- x = 120,
  210. -- y = 230,
  211. -- w = 120,
  212. -- h = 35,
  213. -- text = "恢复默认配置",
  214. -- on_click = function(self)
  215. -- log.info("mqtt_config", "恢复默认配置按钮被点击")
  216. -- end
  217. -- })
  218. -- 执行结果
  219. airui.label({
  220. parent = scroll_container,
  221. text = "执行结果:",
  222. x = 270,
  223. y = 210,
  224. w = 80,
  225. h = 30,
  226. font_size = 16,
  227. })
  228. -- 执行结果值
  229. local result_label = airui.label({
  230. parent = scroll_container,
  231. text = "成功",
  232. x = 350,
  233. y = 210,
  234. w = 100,
  235. h = 30,
  236. font_size = 16,
  237. })
  238. ---------------------------------------------------
  239. -- 底部信息
  240. common_ui.create_status_bar(main_container)
  241. end
  242. -- 初始化页面
  243. function tsb_channel_page.init(params)
  244. tsb_channel_page.create_ui()
  245. end
  246. -- 清理页面
  247. function tsb_channel_page.cleanup()
  248. if main_container then
  249. main_container:destroy()
  250. main_container = nil
  251. end
  252. end
  253. return tsb_channel_page