tsb_mqtt_page.lua 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. --[[
  2. @module tsb_mqtt_page
  3. @summary MQTT配置页面
  4. @version 1.0
  5. @date 2026.03.05
  6. @author 李一玮
  7. @usage
  8. 本文件是MQTT配置页面,展示MQTT配置的各种用法。
  9. ]]
  10. local tsb_mqtt_page = {}
  11. -- 页面UI元素
  12. local main_container = nil
  13. local common_ui = require("tsb_common_page")
  14. -- 创建UI
  15. function tsb_mqtt_page.create_ui()
  16. main_container = airui.container({
  17. x = 0,
  18. y = 0,
  19. w = 480,
  20. h = 320,
  21. color = 0xFFFFFF,
  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 = 0xFFB74D,
  32. })
  33. airui.label({
  34. parent = title_bar,
  35. text = "MQTT配置",
  36. x = 195,
  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_mqtt_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 = 260,
  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 = "当前lora信道",
  89. x = 10,
  90. y = 10,
  91. w = 100,
  92. h = 30,
  93. font_size = 14,
  94. })
  95. -- 当前lora信道值
  96. local current_channel_label = airui.label({
  97. parent = scroll_container,
  98. text = "1",
  99. x = 110,
  100. y = 10,
  101. w = 30,
  102. h = 30,
  103. font_size = 14,
  104. })
  105. -- 设置lora信道标签
  106. airui.label({
  107. parent = scroll_container,
  108. text = "设置lora信道",
  109. x = 150,
  110. y = 10,
  111. w = 100,
  112. h = 30,
  113. font_size = 14,
  114. })
  115. -- 设置lora信道下拉框
  116. local channel_dropdown = airui.dropdown({
  117. parent = scroll_container,
  118. x = 250,
  119. y = 3,
  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. --------------------- 输入框区域 ------------------------
  130. -- 左侧输入框容器
  131. local left_container = airui.container({
  132. parent = scroll_container,
  133. x = 10,
  134. y = 40,
  135. w = 230,
  136. h = 230,
  137. color = 0xFFFFFF,
  138. })
  139. -- 左侧第一组:一级设备类型
  140. airui.label({
  141. parent = left_container,
  142. text = "一级设备类型:",
  143. x = 0,
  144. y = 0,
  145. w = 100,
  146. h = 20,
  147. font_size = 14,
  148. })
  149. local device_type_input = airui.textarea({
  150. parent = left_container,
  151. x = 0,
  152. y = 20,
  153. w = 150,
  154. h = 30,
  155. text = "",
  156. keyboard = keyboard1
  157. })
  158. -- 左侧第二组:一级设备SN
  159. airui.label({
  160. parent = left_container,
  161. text = "一级设备SN:",
  162. x = 0,
  163. y = 55,
  164. w = 100,
  165. h = 20,
  166. font_size = 14,
  167. })
  168. local device_sn_input = airui.textarea({
  169. parent = left_container,
  170. x = 0,
  171. y = 75,
  172. w = 150,
  173. h = 30,
  174. text = "",
  175. keyboard = keyboard1,
  176. })
  177. -- 左侧第三组:目标设备类型
  178. airui.label({
  179. parent = left_container,
  180. text = "目标设备类型:",
  181. x = 0,
  182. y = 110,
  183. w = 100,
  184. h = 20,
  185. font_size = 14,
  186. })
  187. local target_type_input = airui.textarea({
  188. parent = left_container,
  189. x = 0,
  190. y = 130,
  191. w = 150,
  192. h = 30,
  193. text = "",
  194. keyboard = keyboard1,
  195. })
  196. -- 左侧第四组:目标设备SN
  197. airui.label({
  198. parent = left_container,
  199. text = "目标设备SN",
  200. x = 0,
  201. y = 165,
  202. w = 100,
  203. h = 20,
  204. font_size = 14,
  205. })
  206. local target_sn_input = airui.textarea({
  207. parent = left_container,
  208. x = 0,
  209. y = 185,
  210. w = 150,
  211. h = 30,
  212. text = "",
  213. keyboard = keyboard1,
  214. })
  215. -- 右侧输入框容器
  216. local right_container = airui.container({
  217. parent = scroll_container,
  218. x = 240,
  219. y = 40,
  220. w = 230,
  221. h = 230,
  222. color = 0xFFFFFF,
  223. })
  224. -- 右侧第一组:服务器地址
  225. airui.label({
  226. parent = right_container,
  227. text = "服务器地址:",
  228. x = 0,
  229. y = 0,
  230. w = 100,
  231. h = 20,
  232. font_size = 14,
  233. })
  234. local server_addr_input = airui.textarea({
  235. parent = right_container,
  236. x = 0,
  237. y = 20,
  238. w = 220,
  239. h = 30,
  240. text = "",
  241. keyboard = keyboard2,
  242. })
  243. -- 右侧第二组:服务器端口
  244. airui.label({
  245. parent = right_container,
  246. text = "服务器端口:",
  247. x = 0,
  248. y = 55,
  249. w = 100,
  250. h = 20,
  251. font_size = 14,
  252. })
  253. local server_port_input = airui.textarea({
  254. parent = right_container,
  255. x = 0,
  256. y = 75,
  257. w = 220,
  258. h = 30,
  259. text = "",
  260. keyboard = keyboard1,
  261. })
  262. -- 右侧第三组:服务器用户名
  263. airui.label({
  264. parent = right_container,
  265. text = "服务器用户名:",
  266. x = 0,
  267. y = 110,
  268. w = 100,
  269. h = 20,
  270. font_size = 14,
  271. })
  272. local server_user_input = airui.textarea({
  273. parent = right_container,
  274. x = 0,
  275. y = 130,
  276. w = 220,
  277. h = 30,
  278. text = "",
  279. keyboard = keyboard2,
  280. })
  281. -- 右侧第四组:服务器密码
  282. airui.label({
  283. parent = right_container,
  284. text = "服务器密码:",
  285. x = 0,
  286. y = 165,
  287. w = 100,
  288. h = 20,
  289. font_size = 14,
  290. })
  291. local server_pass_input = airui.textarea({
  292. parent = right_container,
  293. x = 0,
  294. y = 185,
  295. w = 220,
  296. h = 30,
  297. text = "",
  298. keyboard = keyboard2,
  299. })
  300. ---------------------------------------------------
  301. --------------------- 提示信息 ------------------------
  302. airui.label({
  303. parent = scroll_container,
  304. text = "一级设备SN和目标设备SN同时写1代表全量配置(仅LORA模式)",
  305. x = 10,
  306. y = 280,
  307. w = 460,
  308. h = 20,
  309. font_size = 12,
  310. color = 0x757575,
  311. })
  312. ---------------------------------------------------
  313. --------------------- 控制按钮区 ------------------------
  314. -- 串口发送标签
  315. airui.label({
  316. parent = scroll_container,
  317. text = "串口发送",
  318. x = 15,
  319. y = 312,
  320. w = 80,
  321. h = 30,
  322. font_size = 14,
  323. })
  324. -- 串口发送开关
  325. local serial_switch = airui.switch({
  326. parent = scroll_container,
  327. x = 80,
  328. y = 310,
  329. w = 50,
  330. h = 20,
  331. checked = false,
  332. on_change = function(self)
  333. log.info("UART SEND", self:get_state() and "开启" or "关闭")
  334. end
  335. })
  336. -- 串口发送提示信息
  337. airui.label({
  338. parent = scroll_container,
  339. text = "默认为LORA模式,可选串口发送",
  340. x = 140,
  341. y = 312,
  342. w = 200,
  343. h = 20,
  344. font_size = 12,
  345. color = 0x757575,
  346. })
  347. -- 新配置下发按钮
  348. local new_config_btn = airui.button({
  349. parent = scroll_container,
  350. x = 10,
  351. y = 340,
  352. w = 100,
  353. h = 35,
  354. text = "新配置下发",
  355. style = { bg_color = 0x2B6FF1,border_color = 0x2B6FF1, text_color = 0xFFFFFF, radius = 8 },
  356. on_click = function(self)
  357. log.info("mqtt_config", "新配置下发按钮被点击")
  358. end
  359. })
  360. -- 恢复默认配置按钮
  361. local default_config_btn = airui.button({
  362. parent = scroll_container,
  363. x = 120,
  364. y = 340,
  365. w = 120,
  366. h = 35,
  367. text = "恢复默认配置",
  368. on_click = function(self)
  369. log.info("mqtt_config", "恢复默认配置按钮被点击")
  370. end
  371. })
  372. -- 执行结果
  373. airui.label({
  374. parent = scroll_container,
  375. text = "执行结果:",
  376. x = 300,
  377. y = 347,
  378. w = 80,
  379. h = 30,
  380. font_size = 16,
  381. })
  382. -- 执行结果值
  383. local result_label = airui.label({
  384. parent = scroll_container,
  385. text = "成功",
  386. x = 380,
  387. y = 347,
  388. w = 100,
  389. h = 30,
  390. font_size = 16,
  391. })
  392. ---------------------------------------------------
  393. -- 底部信息
  394. common_ui.create_status_bar(main_container)
  395. end
  396. -- 初始化页面
  397. function tsb_mqtt_page.init(params)
  398. tsb_mqtt_page.create_ui()
  399. end
  400. -- 清理页面
  401. function tsb_mqtt_page.cleanup()
  402. if main_container then
  403. main_container:destroy()
  404. main_container = nil
  405. end
  406. end
  407. return tsb_mqtt_page