tabview_page.lua 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. --[[
  2. @module tabview_page
  3. @summary 选项卡组件演示页面
  4. @version 1.0
  5. @date 2026.01.30
  6. @author 江访
  7. @usage 本文件是选项卡组件的演示页面,展示选项卡的各种用法。
  8. ]]
  9. local tabview_page = {}
  10. ----------------------------------------------------------------
  11. -- 页面UI元素
  12. ----------------------------------------------------------------
  13. local main_container = nil
  14. ----------------------------------------------------------------
  15. -- 创建UI
  16. ----------------------------------------------------------------
  17. function tabview_page.create_ui()
  18. main_container = airui.container({
  19. x = 0,
  20. y = 0,
  21. w = 320,
  22. h = 480,
  23. color = 0xF5F5F5,
  24. })
  25. -- 标题栏
  26. local title_bar = airui.container({
  27. parent = main_container,
  28. x = 0,
  29. y = 0,
  30. w = 320,
  31. h = 50,
  32. color = 0xFF5722,
  33. })
  34. airui.label({
  35. parent = title_bar,
  36. text = "选项卡组件演示",
  37. x = 10,
  38. y = 15,
  39. w = 200,
  40. h = 20,
  41. font_size = 16,
  42. color = 0xFFFFFF,
  43. })
  44. -- 返回按钮
  45. local back_btn = airui.button({
  46. parent = title_bar,
  47. x = 250,
  48. y = 10,
  49. w = 60,
  50. h = 30,
  51. text = "返回",
  52. on_click = function(self)
  53. go_back()
  54. end
  55. })
  56. -- 滚动容器
  57. local scroll_container = airui.container({
  58. parent = main_container,
  59. x = 0,
  60. y = 60,
  61. w = 320,
  62. h = 370,
  63. color = 0xF5F5F5,
  64. })
  65. local current_y = 10
  66. --------------------------------------------------------------------
  67. -- 示例1: 基本选项卡
  68. --------------------------------------------------------------------
  69. airui.label({
  70. parent = scroll_container,
  71. text = "示例1: 基本选项卡",
  72. x = 10,
  73. y = current_y,
  74. w = 300,
  75. h = 20,
  76. font_size = 14,
  77. })
  78. current_y = current_y + 25
  79. local basic_tabview = airui.tabview({
  80. parent = scroll_container,
  81. x = 20,
  82. y = current_y,
  83. w = 280,
  84. h = 180,
  85. tabs = { "首页", "消息", "设置" },
  86. active = 0,
  87. })
  88. current_y = current_y + 180 + 10
  89. local tab1_content = basic_tabview:get_content(0)
  90. if tab1_content then
  91. airui.label({
  92. parent = tab1_content,
  93. text = "这是首页内容",
  94. x = 20,
  95. y = 20,
  96. w = 240,
  97. h = 30,
  98. font_size = 14,
  99. })
  100. local home_info = airui.label({
  101. parent = tab1_content,
  102. text = "欢迎使用选项卡组件",
  103. x = 20,
  104. y = 60,
  105. w = 240,
  106. h = 30,
  107. font_size = 12,
  108. color = 0x666666,
  109. })
  110. end
  111. local tab2_content = basic_tabview:get_content(1)
  112. if tab2_content then
  113. airui.label({
  114. parent = tab2_content,
  115. text = "这是消息页面",
  116. x = 20,
  117. y = 20,
  118. w = 240,
  119. h = 30,
  120. font_size = 14,
  121. })
  122. local msg_btn = airui.button({
  123. parent = tab2_content,
  124. x = 20,
  125. y = 60,
  126. w = 100,
  127. h = 40,
  128. text = "新消息",
  129. on_click = function(self)
  130. log.info("tabview", "新消息按钮被点击")
  131. local msg = airui.msgbox({
  132. text = "收到新消息",
  133. buttons = { "确定" },
  134. timeout = 1500,
  135. on_action = function(self, label)
  136. self:hide()
  137. end
  138. })
  139. msg:show()
  140. end
  141. })
  142. end
  143. local tab3_content = basic_tabview:get_content(2)
  144. if tab3_content then
  145. airui.label({
  146. parent = tab3_content,
  147. text = "这是设置页面",
  148. x = 20,
  149. y = 20,
  150. w = 240,
  151. h = 30,
  152. font_size = 14,
  153. })
  154. local setting_switch = airui.switch({
  155. parent = tab3_content,
  156. x = 20,
  157. y = 60,
  158. w = 60,
  159. h = 30,
  160. checked = true,
  161. on_change = function(self)
  162. log.info("tabview", "设置开关: " .. tostring(self:get_state()))
  163. local status = self:get_state() and "开启" or "关闭"
  164. local msg = airui.msgbox({
  165. text = "通知已" .. status,
  166. buttons = { "确定" },
  167. timeout = 1500,
  168. on_action = function(self, label)
  169. self:hide()
  170. end
  171. })
  172. msg:show()
  173. end
  174. })
  175. airui.label({
  176. parent = tab3_content,
  177. text = "启用通知",
  178. x = 90,
  179. y = 65,
  180. w = 100,
  181. h = 20,
  182. font_size = 12,
  183. })
  184. end
  185. --------------------------------------------------------------------
  186. -- 示例2: 嵌套选项卡
  187. --------------------------------------------------------------------
  188. airui.label({
  189. parent = scroll_container,
  190. text = "示例2: 嵌套选项卡",
  191. x = 10,
  192. y = current_y,
  193. w = 300,
  194. h = 20,
  195. font_size = 14,
  196. })
  197. current_y = current_y + 25
  198. local nested_container = airui.container({
  199. parent = scroll_container,
  200. x = 20,
  201. y = current_y,
  202. w = 280,
  203. h = 180,
  204. color = 0xFCE4EC,
  205. radius = 8,
  206. })
  207. current_y = current_y + 180 + 10
  208. airui.label({
  209. parent = nested_container,
  210. text = "主容器中的嵌套选项卡",
  211. x = 20,
  212. y = 10,
  213. w = 240,
  214. h = 20,
  215. font_size = 12,
  216. })
  217. local inner_tabview = airui.tabview({
  218. parent = nested_container,
  219. x = 10,
  220. y = 40,
  221. w = 260,
  222. h = 130,
  223. tabs = { "子页1", "子页2" },
  224. active = 0,
  225. })
  226. local inner_content1 = inner_tabview:get_content(0)
  227. if inner_content1 then
  228. airui.label({
  229. parent = inner_content1,
  230. text = "第一个子页面内容",
  231. x = 20,
  232. y = 20,
  233. w = 220,
  234. h = 30,
  235. font_size = 12,
  236. })
  237. end
  238. local inner_content2 = inner_tabview:get_content(1)
  239. if inner_content2 then
  240. airui.label({
  241. parent = inner_content2,
  242. text = "第二个子页面内容",
  243. x = 20,
  244. y = 20,
  245. w = 220,
  246. h = 30,
  247. font_size = 12,
  248. })
  249. end
  250. --------------------------------------------------------------------
  251. -- 示例3: 多选项卡演示
  252. --------------------------------------------------------------------
  253. airui.label({
  254. parent = scroll_container,
  255. text = "示例3: 多选项卡演示",
  256. x = 10,
  257. y = current_y,
  258. w = 300,
  259. h = 20,
  260. font_size = 14,
  261. })
  262. current_y = current_y + 25
  263. local multi_tabview = airui.tabview({
  264. parent = scroll_container,
  265. x = 20,
  266. y = current_y,
  267. w = 280,
  268. h = 150,
  269. tabs = { "标签A", "标签B", "标签C", "标签D" },
  270. active = 0,
  271. })
  272. current_y = current_y + 150 + 10
  273. for i = 0, 3 do
  274. local tab_content = multi_tabview:get_content(i)
  275. if tab_content then
  276. airui.label({
  277. parent = tab_content,
  278. text = "这是标签" .. string.char(65 + i) .. "的内容",
  279. x = 20,
  280. y = 20,
  281. w = 240,
  282. h = 30,
  283. font_size = 12,
  284. })
  285. end
  286. end
  287. end
  288. ----------------------------------------------------------------
  289. -- 初始化页面
  290. ----------------------------------------------------------------
  291. function tabview_page.init(params)
  292. tabview_page.create_ui()
  293. end
  294. ----------------------------------------------------------------
  295. -- 清理页面
  296. ----------------------------------------------------------------
  297. function tabview_page.cleanup()
  298. if main_container then
  299. main_container:destroy()
  300. main_container = nil
  301. end
  302. end
  303. return tabview_page