tsb_ywy_1_page.lua 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. --[[
  2. @module tsb_ywy_1_page
  3. @summary 液位仪查询演示页面
  4. @version 1.0
  5. @date 2026.03.16
  6. @author 李一玮
  7. @usage
  8. 本文件是液位仪查询演示页面,展示液位仪查询的各种用法。
  9. ]]
  10. local tsb_ywy_1_page = {}
  11. local common_ui = require("tsb_common_page")
  12. -- 页面UI元素
  13. local main_container = nil
  14. -- 创建UI
  15. function tsb_ywy_1_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 = 200,
  36. y = 8,
  37. w = 120,
  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_1_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 = 290,
  53. color = 0xFFFFFF,
  54. })
  55. ------------------- 分页内容区 ------------------------
  56. --液位仪查询页面
  57. local query_page = airui.container({
  58. parent = scroll_container,
  59. x = 0,
  60. y = 0,
  61. w = 480,
  62. h = 290,
  63. color = 0xFFFFFF,--0xE8F5E9
  64. })
  65. --------------------- 总罐数和查询按钮 ------------------------
  66. local top_container = airui.container({
  67. parent = query_page,
  68. x = 0,
  69. y = 5,
  70. w = 480,
  71. h = 40,
  72. color = 0xFFFFFF,
  73. })
  74. -- 总罐数标签
  75. airui.label({
  76. parent = top_container,
  77. text = "总罐数",
  78. x = 10,
  79. y = 10,
  80. w = 60,
  81. h = 30,
  82. font_size = 15,
  83. })
  84. -- 总罐数值
  85. local total_tanks_label = airui.label({
  86. parent = top_container,
  87. text = "12",
  88. x = 70,
  89. y = 10,
  90. w = 40,
  91. h = 30,
  92. font_size = 15,
  93. })
  94. -- 单位标签
  95. airui.label({
  96. parent = top_container,
  97. text = "个",
  98. x = 100,
  99. y = 10,
  100. w = 20,
  101. h = 30,
  102. font_size = 15,
  103. })
  104. -- A口查询按钮
  105. local a_query_btn = airui.button({
  106. parent = top_container,
  107. x = 210,
  108. y = 1,
  109. w = 80,
  110. h = 30,
  111. text = "A口查询",
  112. on_click = function(self)
  113. log.info("ywy_query", "A口查询按钮被点击")
  114. end
  115. })
  116. -- B口查询按钮
  117. local b_query_btn = airui.button({
  118. parent = top_container,
  119. x = 300,
  120. y = 1,
  121. w = 80,
  122. h = 30,
  123. text = "B口查询",
  124. on_click = function(self)
  125. log.info("ywy_query", "B口查询按钮被点击")
  126. end
  127. })
  128. -- 485查询按钮
  129. local rs485_query_btn = airui.button({
  130. parent = top_container,
  131. x = 390,
  132. y = 1,
  133. w = 80,
  134. h = 30,
  135. text = "485查询",
  136. on_click = function(self)
  137. log.info("ywy_query", "485查询按钮被点击")
  138. end
  139. })
  140. -------------------------------------------------
  141. ------------------- 表格区域 ------------------------
  142. local table_container = airui.container({
  143. parent = query_page,
  144. x = 0,
  145. y = 40,
  146. w = 480,
  147. h = 220,
  148. color = 0xE8F5E9,
  149. })
  150. -- 创建表格
  151. local tank_table = airui.table({
  152. parent = table_container,
  153. x = 0,
  154. y = 0,
  155. w = 480,
  156. h = 220,
  157. rows = 11, -- 10个罐 + 表头
  158. cols = 10,
  159. col_width = {70, 100, 100, 100, 70, 70, 70, 80, 70, 150}, -- 调整列宽以适应内容,确保表头横向显示
  160. border_color = 0x4CAF50,
  161. })
  162. -- 设置表头
  163. local headers = {"罐号", "油水体积1", "油水体积2", "剩余体积", "油高", "水高", "温度", "水体积", "串口", "读取时间"}
  164. for i, header in ipairs(headers) do
  165. tank_table:set_cell_text(0, i-1, header)
  166. end
  167. -- 示例数据
  168. local tank_data = {
  169. {"1", "14919.52", "14767.34", "12080.47", "16577.25", "0.00", "28.50", "0.00", "A口", "2024/07/02 09:30:46"},
  170. {"2", "20292.46", "20085.48", "6707.53", "22547.17", "0.00", "28.50", "0.00", "A口", "2024/07/02 09:30:46"},
  171. {"3", "10936.19", "10824.64", "16063.80", "12151.32", "0.00", "28.50", "0.00", "A口", "2024/07/02 09:30:46"},
  172. {"4", "22748.73", "22516.69", "4251.26", "25276.37", "0.00", "28.50", "0.00", "A口", "2024/07/02 09:30:46"},
  173. {"5", "7282.67", "7208.38", "19717.32", "8091.85", "0.00", "28.50", "0.00", "A口", "2024/07/02 09:30:46"},
  174. {"6", "14497.98", "14350.10", "12502.01", "16108.87", "0.00", "28.50", "0.00", "A口", "2024/07/02 09:30:46"},
  175. {"7", "1984.31", "1964.07", "25015.68", "2204.79", "0.00", "28.50", "0.00", "A口", "2024/07/02 09:30:46"},
  176. {"8", "9565.87", "9468.30", "17434.12", "10628.75", "0.00", "28.50", "0.00", "A口", "2024/07/02 09:30:46"},
  177. {"9", "15678.90", "15432.10", "11234.56", "17890.12", "0.00", "28.50", "0.00", "A口", "2024/07/02 09:30:46"},
  178. {"10", "8765.43", "8654.32", "18976.54", "9876.54", "0.00", "28.50", "0.00", "A口", "2024/07/02 09:30:46"},
  179. }
  180. -- 填充表格数据
  181. for i, data in ipairs(tank_data) do
  182. for j, value in ipairs(data) do
  183. tank_table:set_cell_text(i, j-1, value)
  184. end
  185. end
  186. -------------------------------------------------
  187. ------------------- 执行结果和日志按钮 ------------------------
  188. local bottom_container = airui.container({
  189. parent = query_page,
  190. x = 0,
  191. y = 260,
  192. w = 480,
  193. h = 30,
  194. color = 0xFFFFFF,
  195. })
  196. -- 执行结果标签
  197. airui.label({
  198. parent = bottom_container,
  199. text = "执行结果:",
  200. x = 10,
  201. y = 10,
  202. w = 80,
  203. h = 20,
  204. font_size = 15,
  205. })
  206. -- 执行结果值
  207. local result_label = airui.label({
  208. parent = bottom_container,
  209. text = "执行成功",
  210. x = 90,
  211. y = 10,
  212. w = 100,
  213. h = 20,
  214. font_size = 15,
  215. })
  216. -- 日志窗口
  217. local log_window = airui.container({
  218. parent = scroll_container,
  219. x = 20,
  220. y = 5,
  221. w = 440,
  222. h = 250,
  223. color = 0xF1F8E9,
  224. radius = 0,
  225. })
  226. -- 日志窗口标题栏
  227. local log_title_bar = airui.container({
  228. parent = log_window,
  229. x = 0,
  230. y = 0,
  231. w = 440,
  232. h = 30,
  233. color = 0x4CAF50,
  234. })
  235. airui.label({
  236. parent = log_title_bar,
  237. text = "原始日志",
  238. x = 10,
  239. y = 8,
  240. w = 150,
  241. h = 20,
  242. font_size = 15,
  243. color = 0xFFFFFF,
  244. })
  245. -- 关闭按钮
  246. local close_btn = airui.button({
  247. parent = log_title_bar,
  248. x = 408,
  249. y = 2,
  250. w = 30,
  251. h = 28,
  252. text = "X",
  253. on_click = function(self)
  254. log_window:hide()
  255. end
  256. })
  257. -- 日志内容区域
  258. local log_content = airui.textarea({
  259. parent = log_window,
  260. x = 10,
  261. y = 40,
  262. w = 420,
  263. h = 200,
  264. text = "00 01 02 03 04 05 06 07\n" ..
  265. "08 09 0A 0B 0C 0D 0E 0F\n" ..
  266. "10 11 12 13 14 15 16 17\n" ..
  267. "18 19 1A 1B 1C 1D 1E 1F\n" ..
  268. "20 21 22 23 24 25 26 27\n" ..
  269. "28 29 2A 2B 2C 2D 2E 2F\n" ..
  270. "30 31 32 33 34 35 36 37\n" ..
  271. "38 39 3A 3B 3C 3D 3E 3F",
  272. })
  273. log_window:hide()
  274. -- 查看原始日志按钮
  275. local log_btn = airui.button({
  276. parent = bottom_container,
  277. x = 375,
  278. y = 1,
  279. w = 100,
  280. h = 27,
  281. text = "查看原始日志",
  282. on_click = function(self)
  283. log.info("ywy_query", "查看原始日志按钮被点击")
  284. -- 显示日志窗口
  285. log_window:open()
  286. end
  287. })
  288. ---------------------------------------------------
  289. -- 底部信息
  290. --common_ui.create_status_bar(main_container)
  291. end
  292. -- 初始化页面
  293. function tsb_ywy_1_page.init(params)
  294. tsb_ywy_1_page.create_ui()
  295. end
  296. -- 清理页面
  297. function tsb_ywy_1_page.cleanup()
  298. -- 停止定时器
  299. common_ui.cleanup()
  300. if main_container then
  301. main_container:destroy()
  302. main_container = nil
  303. end
  304. end
  305. return tsb_ywy_1_page