tsb_channel_page.lua 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. bg_color = 0xf1f1f1, -- 键盘背景颜色为灰色,可选,不设置则透明
  64. on_commit = function() -- 确认事件回调,只有在按下确认键时才会触发
  65. log.info("keyboard", "commit")
  66. end
  67. })
  68. local keyboard2 = airui.keyboard({
  69. x = 0,
  70. y = 0,
  71. w = 480,
  72. h = 160, -- x, y, 键盘默认打开ALIGN_BOTTOM_MID,位置从中下方开始计算
  73. mode = "lower", -- 键盘模式,可选 "text"/"upper"/"lower"/"numeric"
  74. auto_hide = true, -- 自动隐藏键盘
  75. bg_color = 0xf1f1f1, -- 键盘背景颜色为灰色,可选,不设置则透明
  76. on_commit = function() -- 确认事件回调,只有在按下确认键时才会触发
  77. log.info("keyboard", "commit")
  78. end
  79. })
  80. --------------------- 第一行控制区 ------------------------
  81. -- 当前lora信道标签
  82. airui.label({
  83. parent = scroll_container,
  84. text = "当前调试宝信道:",
  85. x = 10,
  86. y = 15,
  87. w = 120,
  88. h = 30,
  89. font_size = 15,
  90. })
  91. -- 当前lora信道值
  92. local current_channel_label = airui.label({
  93. parent = scroll_container,
  94. text = "1",
  95. x = 135,
  96. y = 15,
  97. w = 30,
  98. h = 30,
  99. font_size = 15,
  100. })
  101. -- 设置lora信道标签
  102. airui.label({
  103. parent = scroll_container,
  104. text = "设置调试宝信道:",
  105. x = 180,
  106. y = 15,
  107. w = 130,
  108. h = 30,
  109. font_size = 15,
  110. })
  111. -- 设置lora信道下拉框
  112. local channel_dropdown = airui.dropdown({
  113. parent = scroll_container,
  114. x = 310,
  115. y = 8,
  116. w = 70,
  117. h = 30,
  118. options = {"1", "2", "3", "4", "5", "6"},
  119. default_index = 0, -- 默认选择1
  120. on_change = function(self,idx)
  121. log.info("mqtt_channel", "选择了信道:" .. self.options[idx + 1])
  122. end
  123. })
  124. -- 目标设备类型标签
  125. airui.label({
  126. parent = scroll_container,
  127. text = "目标设备类型:",
  128. x = 10,
  129. y = 60,
  130. w = 100,
  131. h = 30,
  132. font_size = 15,
  133. })
  134. -- 目标设备类型下拉框
  135. local device_type_dropdown = airui.dropdown({
  136. parent = scroll_container,
  137. x = 120,
  138. y = 50,
  139. w = 100,
  140. h = 35,
  141. options = {"路由器", "连接器"},
  142. default_index = 0, -- 默认选择路由器
  143. on_change = function(self,idx)
  144. log.info("device_type", "选择了设备类型:" .. self.options[idx + 1])
  145. end
  146. })
  147. airui.label({
  148. parent = scroll_container,
  149. text = "目标设备SN:",
  150. x = 10,
  151. y = 110,
  152. w = 100,
  153. h = 30,
  154. font_size = 15,
  155. })
  156. -- 连接器SN输入框
  157. local sn_input = airui.textarea({
  158. parent = scroll_container,
  159. x = 120,
  160. y = 100,
  161. w = 100,
  162. h = 35,
  163. text = "",
  164. max_length = 5,
  165. keyboard = keyboard1
  166. })
  167. airui.label({
  168. parent = scroll_container,
  169. text = "切换到信道:",
  170. x = 10,
  171. y = 160,
  172. w = 100,
  173. h = 20,
  174. font_size = 15,
  175. })
  176. local channel1_dropdown = airui.dropdown({
  177. parent = scroll_container,
  178. x = 120,
  179. y = 150,
  180. w = 70,
  181. h = 35,
  182. options = {"1", "2", "3", "4", "5", "6"},
  183. default_index = 0, -- 默认选择1
  184. on_change = function(self,idx)
  185. log.info("mqtt_channel", "选择了信道:" .. self.options[idx + 1])
  186. end
  187. })
  188. ---------------------------------------------------
  189. -- 新配置下发按钮
  190. local new_config_btn = airui.button({
  191. parent = scroll_container,
  192. x = 30,
  193. y = 200,
  194. w = 100,
  195. h = 35,
  196. text = "指令下发",
  197. --stype = { bg_color = 0x2B6FF1,border_color = 0x2B6FF1, text_color = 0xFFFFFF, radius = 8 },
  198. on_click = function(self)
  199. log.info("mqtt_config", "新配置下发按钮被点击")
  200. end
  201. })
  202. -- 恢复默认配置按钮
  203. -- local default_config_btn = airui.button({
  204. -- parent = scroll_container,
  205. -- x = 120,
  206. -- y = 230,
  207. -- w = 120,
  208. -- h = 35,
  209. -- text = "恢复默认配置",
  210. -- on_click = function(self)
  211. -- log.info("mqtt_config", "恢复默认配置按钮被点击")
  212. -- end
  213. -- })
  214. -- 执行结果
  215. airui.label({
  216. parent = scroll_container,
  217. text = "执行结果:",
  218. x = 270,
  219. y = 210,
  220. w = 80,
  221. h = 30,
  222. font_size = 16,
  223. })
  224. -- 执行结果值
  225. local result_label = airui.label({
  226. parent = scroll_container,
  227. text = "成功",
  228. x = 350,
  229. y = 210,
  230. w = 100,
  231. h = 30,
  232. font_size = 16,
  233. })
  234. ---------------------------------------------------
  235. -- 底部信息
  236. common_ui.create_status_bar(main_container)
  237. end
  238. -- 初始化页面
  239. function tsb_channel_page.init(params)
  240. tsb_channel_page.create_ui()
  241. end
  242. -- 清理页面
  243. function tsb_channel_page.cleanup()
  244. if main_container then
  245. main_container:destroy()
  246. main_container = nil
  247. end
  248. end
  249. return tsb_channel_page