tsb_mqtt_page.lua 10 KB

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