tsb_log_page.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. --[[
  2. @module tsb_log_page
  3. @summary 本机日志页面
  4. @version 1.0
  5. @date 2026.03.04
  6. @author 李一玮
  7. @usage
  8. 本文件是设备日志页面,展示设备的日志信息。
  9. ]]
  10. local tsb_log_page = {}
  11. -- 页面UI元素
  12. local main_container = nil
  13. local common_ui = require("tsb_common_page")
  14. -- 创建UI
  15. function tsb_log_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 = 0xFFCCBC,
  31. })
  32. airui.label({
  33. parent = title_bar,
  34. text = "本机日志",
  35. x = 190,
  36. y = 8,
  37. w = 200,
  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_log_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 log_container = airui.container({
  57. parent = scroll_container,
  58. x = 0,
  59. y = 50,
  60. w = 480,
  61. h = 215,
  62. color = 0xFFFFFF,
  63. })
  64. -- 日志内容显示
  65. local log_content = airui.textarea({
  66. parent = log_container,
  67. x = 5,
  68. y = 5,
  69. w = 470,
  70. h = 205,
  71. max_len = 10000,
  72. text = "[2024-07-02 09:30:46] app start\n" ..
  73. "[2024-07-02 09:30:47] init done\n" ..
  74. "[2024-07-02 09:30:48] connect success\n" ..
  75. "[2024-07-02 09:30:50] start monitor\n" ..
  76. "[2024-07-02 09:31:00] detect device 1\n" ..
  77. "[2024-07-02 09:31:10] detect device 2\n" ..
  78. "[2024-07-02 09:31:20] upload success\n" ..
  79. "[2024-07-02 09:31:30] system running\n" ..
  80. "[2024-07-02 09:31:30] system status: normal\n",
  81. })
  82. --------------------- 控制按钮 ------------------------
  83. -- 开始检测按钮
  84. local start_btn = airui.button({
  85. parent = scroll_container,
  86. x = 10,
  87. y = 10,
  88. w = 120,
  89. h = 35,
  90. text = "查看本机日志",
  91. --stype = { bg_color = 0x2B6FF1,border_color = 0x2B6FF1, text_color = 0xFFFFFF, radius = 8 },
  92. on_click = function(self)
  93. log.info("devlog", "开始检测按钮被点击")
  94. end
  95. })
  96. -- 清空按钮
  97. -- local clear_btn = airui.button({
  98. -- parent = scroll_container,
  99. -- x = 120,
  100. -- y = 10,
  101. -- w = 80,
  102. -- h = 35,
  103. -- text = "清空",
  104. -- on_click = function(self)
  105. -- log.info("devlog", "清空按钮被点击")
  106. -- -- 清空日志内容
  107. -- log_content:set_text(" ")
  108. -- end
  109. -- })
  110. ---------------------------------------------------
  111. ---------------------------------------------------
  112. -- 底部信息
  113. common_ui.create_status_bar(main_container)
  114. end
  115. -- 初始化页面
  116. function tsb_log_page.init(params)
  117. tsb_log_page.create_ui()
  118. end
  119. -- 清理页面
  120. function tsb_log_page.cleanup()
  121. if main_container then
  122. main_container:destroy()
  123. main_container = nil
  124. end
  125. end
  126. return tsb_log_page