--[[ @module tsb_ywy_1_page @summary 液位仪查询演示页面 @version 1.0 @date 2026.03.16 @author 李一玮 @usage 本文件是液位仪查询演示页面,展示液位仪查询的各种用法。 ]] local tsb_ywy_1_page = {} local common_ui = require("tsb_common_page") -- 页面UI元素 local main_container = nil -- 创建UI function tsb_ywy_1_page.create_ui() main_container = airui.container({ x = 0, y = 0, w = 480, h = 320, color = 0xF5F5F5, }) --------------------- 标题栏 ------------------------ local title_bar = airui.container({ parent = main_container, x = 0, y = 0, w = 480, h = 30, color = 0x4CAF50, }) airui.label({ parent = title_bar, text = "液位仪查询", x = 200, y = 8, w = 120, h = 20, font_size = 16, color = 0xFFFFFF, }) -- 标题栏公共信息展示 common_ui.add_battery_display(title_bar) common_ui.create_back_button(title_bar, tsb_ywy_1_page.cleanup) --------------------------------------------------- -- 滚动容器 local scroll_container = airui.container({ parent = main_container, x = 0, y = 30, w = 480, h = 290, color = 0xFFFFFF, }) ------------------- 分页内容区 ------------------------ --液位仪查询页面 local query_page = airui.container({ parent = scroll_container, x = 0, y = 0, w = 480, h = 290, color = 0xFFFFFF,--0xE8F5E9 }) --------------------- 总罐数和查询按钮 ------------------------ local top_container = airui.container({ parent = query_page, x = 0, y = 5, w = 480, h = 40, color = 0xFFFFFF, }) -- 总罐数标签 airui.label({ parent = top_container, text = "总罐数", x = 10, y = 10, w = 60, h = 30, font_size = 15, }) -- 总罐数值 local total_tanks_label = airui.label({ parent = top_container, text = "12", x = 70, y = 10, w = 40, h = 30, font_size = 15, }) -- 单位标签 airui.label({ parent = top_container, text = "个", x = 100, y = 10, w = 20, h = 30, font_size = 15, }) -- A口查询按钮 local a_query_btn = airui.button({ parent = top_container, x = 210, y = 1, w = 80, h = 30, text = "A口查询", on_click = function(self) log.info("ywy_query", "A口查询按钮被点击") end }) -- B口查询按钮 local b_query_btn = airui.button({ parent = top_container, x = 300, y = 1, w = 80, h = 30, text = "B口查询", on_click = function(self) log.info("ywy_query", "B口查询按钮被点击") end }) -- 485查询按钮 local rs485_query_btn = airui.button({ parent = top_container, x = 390, y = 1, w = 80, h = 30, text = "485查询", on_click = function(self) log.info("ywy_query", "485查询按钮被点击") end }) ------------------------------------------------- ------------------- 表格区域 ------------------------ local table_container = airui.container({ parent = query_page, x = 0, y = 40, w = 480, h = 220, color = 0xE8F5E9, }) -- 创建表格 local tank_table = airui.table({ parent = table_container, x = 0, y = 0, w = 480, h = 220, rows = 11, -- 10个罐 + 表头 cols = 10, col_width = {70, 100, 100, 100, 70, 70, 70, 80, 70, 150}, -- 调整列宽以适应内容,确保表头横向显示 border_color = 0x4CAF50, }) -- 设置表头 local headers = {"罐号", "油水体积1", "油水体积2", "剩余体积", "油高", "水高", "温度", "水体积", "串口", "读取时间"} for i, header in ipairs(headers) do tank_table:set_cell_text(0, i-1, header) end -- 示例数据 local tank_data = { {"1", "14919.52", "14767.34", "12080.47", "16577.25", "0.00", "28.50", "0.00", "A口", "2024/07/02 09:30:46"}, {"2", "20292.46", "20085.48", "6707.53", "22547.17", "0.00", "28.50", "0.00", "A口", "2024/07/02 09:30:46"}, {"3", "10936.19", "10824.64", "16063.80", "12151.32", "0.00", "28.50", "0.00", "A口", "2024/07/02 09:30:46"}, {"4", "22748.73", "22516.69", "4251.26", "25276.37", "0.00", "28.50", "0.00", "A口", "2024/07/02 09:30:46"}, {"5", "7282.67", "7208.38", "19717.32", "8091.85", "0.00", "28.50", "0.00", "A口", "2024/07/02 09:30:46"}, {"6", "14497.98", "14350.10", "12502.01", "16108.87", "0.00", "28.50", "0.00", "A口", "2024/07/02 09:30:46"}, {"7", "1984.31", "1964.07", "25015.68", "2204.79", "0.00", "28.50", "0.00", "A口", "2024/07/02 09:30:46"}, {"8", "9565.87", "9468.30", "17434.12", "10628.75", "0.00", "28.50", "0.00", "A口", "2024/07/02 09:30:46"}, {"9", "15678.90", "15432.10", "11234.56", "17890.12", "0.00", "28.50", "0.00", "A口", "2024/07/02 09:30:46"}, {"10", "8765.43", "8654.32", "18976.54", "9876.54", "0.00", "28.50", "0.00", "A口", "2024/07/02 09:30:46"}, } -- 填充表格数据 for i, data in ipairs(tank_data) do for j, value in ipairs(data) do tank_table:set_cell_text(i, j-1, value) end end ------------------------------------------------- ------------------- 执行结果和日志按钮 ------------------------ local bottom_container = airui.container({ parent = query_page, x = 0, y = 260, w = 480, h = 30, color = 0xFFFFFF, }) -- 执行结果标签 airui.label({ parent = bottom_container, text = "执行结果:", x = 10, y = 10, w = 80, h = 20, font_size = 15, }) -- 执行结果值 local result_label = airui.label({ parent = bottom_container, text = "执行成功", x = 90, y = 10, w = 100, h = 20, font_size = 15, }) -- 日志窗口 local log_window = airui.container({ parent = scroll_container, x = 20, y = 5, w = 440, h = 250, color = 0xF1F8E9, radius = 0, }) -- 日志窗口标题栏 local log_title_bar = airui.container({ parent = log_window, x = 0, y = 0, w = 440, h = 30, color = 0x4CAF50, }) airui.label({ parent = log_title_bar, text = "原始日志", x = 10, y = 8, w = 150, h = 20, font_size = 15, color = 0xFFFFFF, }) -- 关闭按钮 local close_btn = airui.button({ parent = log_title_bar, x = 408, y = 2, w = 30, h = 28, text = "X", on_click = function(self) log_window:hide() end }) -- 日志内容区域 local log_content = airui.textarea({ parent = log_window, x = 10, y = 40, w = 420, h = 200, text = "00 01 02 03 04 05 06 07\n" .. "08 09 0A 0B 0C 0D 0E 0F\n" .. "10 11 12 13 14 15 16 17\n" .. "18 19 1A 1B 1C 1D 1E 1F\n" .. "20 21 22 23 24 25 26 27\n" .. "28 29 2A 2B 2C 2D 2E 2F\n" .. "30 31 32 33 34 35 36 37\n" .. "38 39 3A 3B 3C 3D 3E 3F", }) log_window:hide() -- 查看原始日志按钮 local log_btn = airui.button({ parent = bottom_container, x = 375, y = 1, w = 100, h = 27, text = "查看原始日志", on_click = function(self) log.info("ywy_query", "查看原始日志按钮被点击") -- 显示日志窗口 log_window:open() end }) --------------------------------------------------- -- 底部信息 --common_ui.create_status_bar(main_container) end -- 初始化页面 function tsb_ywy_1_page.init(params) tsb_ywy_1_page.create_ui() end -- 清理页面 function tsb_ywy_1_page.cleanup() -- 停止定时器 common_ui.cleanup() if main_container then main_container:destroy() main_container = nil end end return tsb_ywy_1_page