tsb_ywy_page.lua 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. --[[
  2. @module tsb_ywy_page
  3. @summary 液位仪演示页面
  4. @version 1.0
  5. @date 2026.02.05
  6. @author 江访
  7. @usage
  8. 本文件是液位仪演示页面,展示液位仪的各种用法。
  9. ]]
  10. local tsb_ywy_page = {}
  11. local common_ui = require("tsb_common_page")
  12. -- 页面UI元素
  13. local main_container = nil
  14. -- 创建UI
  15. function tsb_ywy_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 = 0x4CAF50,
  31. })
  32. airui.label({
  33. parent = title_bar,
  34. text = "液位仪",
  35. x = 210,
  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_ywy_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. --------------------- 第一排控制区 ------------------------
  56. local control_container = airui.container({
  57. parent = scroll_container,
  58. x = 0,
  59. y = 0,
  60. w = 480,
  61. h = 80,
  62. color = 0xFFFFFF,
  63. })
  64. -- 波特率标签
  65. airui.label({
  66. parent = control_container,
  67. text = "波特率:",
  68. x = 10,
  69. y = 28,
  70. w = 60,
  71. h = 30,
  72. font_size = 15,
  73. })
  74. -- 波特率下拉框
  75. local baudrate_dropdown = airui.dropdown({
  76. parent = control_container,
  77. x = 70,
  78. y = 20,
  79. w = 120,
  80. h = 35,
  81. options = {"2400", "4800", "9600", "19200", "38400", "57600", "115200"},
  82. default_index = 2, -- 默认选择9600
  83. on_change = function(self,idx)
  84. log.info("baudrate", "选择了波特率:" .. self.options[idx + 1])
  85. end
  86. })
  87. -- 液位仪查询按钮
  88. local query_btn = airui.button({
  89. parent = control_container,
  90. x = 220,
  91. y = 20,
  92. w = 100,
  93. h = 35,
  94. text = "液位仪查询",
  95. on_click = function(self)
  96. log.info("ywy_page", "点击液位仪查询按钮")
  97. _G.show_page("tsb_ywy_1_page")
  98. end
  99. })
  100. -- 液位仪透传按钮
  101. local passthrough_btn = airui.button({
  102. parent = control_container,
  103. x = 340,
  104. y = 20,
  105. w = 100,
  106. h = 35,
  107. text = "液位仪透传",
  108. on_click = function(self)
  109. log.info("ywy_page", "点击液位仪透传按钮")
  110. _G.show_page("tsb_ywy_2_page")
  111. end
  112. })
  113. ---------------------------------------------------
  114. -- 底部信息
  115. common_ui.create_status_bar(main_container)
  116. end
  117. -- 初始化页面
  118. function tsb_ywy_page.init(params)
  119. tsb_ywy_page.create_ui()
  120. end
  121. -- 清理页面
  122. function tsb_ywy_page.cleanup()
  123. -- 停止定时器
  124. common_ui.cleanup()
  125. if main_container then
  126. main_container:destroy()
  127. main_container = nil
  128. end
  129. end
  130. return tsb_ywy_page