msgbox_page.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. --[[
  2. @module msgbox_page
  3. @summary 消息框组件演示页面
  4. @version 1.0
  5. @date 2026.02.05
  6. @author 江访
  7. @usage 本文件是消息框组件的演示页面,展示消息框的各种用法。
  8. ]]
  9. local msgbox_page = {}
  10. ----------------------------------------------------------------
  11. -- 页面UI元素
  12. ----------------------------------------------------------------
  13. local main_container = nil
  14. ----------------------------------------------------------------
  15. -- 辅助函数:创建带标题的容器
  16. ----------------------------------------------------------------
  17. local function create_demo_container(parent, title, x, y, width, height)
  18. local container = airui.container({
  19. parent = parent,
  20. x = x,
  21. y = y,
  22. w = width,
  23. h = height,
  24. color = 0xFFFFFF,
  25. radius = 8,
  26. })
  27. airui.label({
  28. parent = container,
  29. text = title,
  30. x = 10,
  31. y = 5,
  32. w = width - 20,
  33. h = 25,
  34. color = 0x333333,
  35. font_size = 14,
  36. })
  37. return container
  38. end
  39. ----------------------------------------------------------------
  40. -- 创建UI
  41. ----------------------------------------------------------------
  42. function msgbox_page.create_ui()
  43. main_container = airui.container({
  44. x = 0,
  45. y = 0,
  46. w = 320,
  47. h = 480,
  48. color = 0xF5F5F5,
  49. })
  50. -- 标题栏
  51. local title_bar = airui.container({
  52. parent = main_container,
  53. x = 0,
  54. y = 0,
  55. w = 320,
  56. h = 50,
  57. color = 0xE91E63,
  58. })
  59. airui.label({
  60. parent = title_bar,
  61. text = "消息框组件演示",
  62. x = 10,
  63. y = 15,
  64. w = 200,
  65. h = 20,
  66. font_size = 16,
  67. color = 0xFFFFFF,
  68. })
  69. -- 返回按钮
  70. local back_btn = airui.button({
  71. parent = title_bar,
  72. x = 250,
  73. y = 10,
  74. w = 60,
  75. h = 30,
  76. text = "返回",
  77. on_click = function(self)
  78. go_back()
  79. end
  80. })
  81. -- 滚动容器
  82. local scroll_container = airui.container({
  83. parent = main_container,
  84. x = 0,
  85. y = 60,
  86. w = 320,
  87. h = 370,
  88. color = 0xF5F5F5,
  89. })
  90. local current_y = 10
  91. --------------------------------------------------------------------
  92. -- 示例1: 基本消息框
  93. --------------------------------------------------------------------
  94. local demo1_container = create_demo_container(scroll_container, "示例1: 基本消息框", 10, current_y, 300, 100)
  95. current_y = current_y + 100 + 10
  96. airui.label({
  97. parent = demo1_container,
  98. text = "显示基本消息框",
  99. x = 10,
  100. y = 30,
  101. w = 280,
  102. h = 20,
  103. color = 0x666666,
  104. font_size = 12,
  105. })
  106. local basic_msg_btn = airui.button({
  107. parent = demo1_container,
  108. x = 80,
  109. y = 60,
  110. w = 140,
  111. h = 40,
  112. text = "显示消息",
  113. on_click = function(self)
  114. local msg = airui.msgbox({
  115. text = "这是一个基本消息框",
  116. buttons = { "确定" },
  117. on_action = function(self, label)
  118. log.info("msgbox", "点击了: " .. label)
  119. self:hide()
  120. end
  121. })
  122. msg:show()
  123. end
  124. })
  125. --------------------------------------------------------------------
  126. -- 示例2: 带标题的消息框
  127. --------------------------------------------------------------------
  128. local demo2_container = create_demo_container(scroll_container, "示例2: 带标题消息框", 10, current_y, 300, 100)
  129. current_y = current_y + 100 + 10
  130. airui.label({
  131. parent = demo2_container,
  132. text = "显示带标题的消息框",
  133. x = 10,
  134. y = 30,
  135. w = 280,
  136. h = 20,
  137. color = 0x666666,
  138. font_size = 12,
  139. })
  140. local title_msg_btn = airui.button({
  141. parent = demo2_container,
  142. x = 80,
  143. y = 60,
  144. w = 140,
  145. h = 40,
  146. text = "带标题消息",
  147. on_click = function(self)
  148. local msg = airui.msgbox({
  149. title = "系统提示",
  150. text = "操作成功完成!",
  151. buttons = { "确定" },
  152. on_action = function(self, label)
  153. log.info("msgbox", "点击了: " .. label)
  154. self:hide()
  155. end
  156. })
  157. msg:show()
  158. end
  159. })
  160. --------------------------------------------------------------------
  161. -- 示例3: 多个按钮的消息框
  162. --------------------------------------------------------------------
  163. local demo3_container = create_demo_container(scroll_container, "示例3: 多个按钮消息框", 10, current_y, 300, 120)
  164. current_y = current_y + 120 + 10
  165. airui.label({
  166. parent = demo3_container,
  167. text = "显示带有确认和取消按钮的消息框",
  168. x = 10,
  169. y = 30,
  170. w = 280,
  171. h = 20,
  172. color = 0x666666,
  173. font_size = 12,
  174. })
  175. local multi_msg_btn = airui.button({
  176. parent = demo3_container,
  177. x = 80,
  178. y = 60,
  179. w = 140,
  180. h = 40,
  181. text = "确认对话框",
  182. on_click = function(self)
  183. local msg = airui.msgbox({
  184. title = "确认操作",
  185. text = "确定要删除这个文件吗?",
  186. buttons = { "取消", "确定" },
  187. on_action = function(self, label)
  188. log.info("msgbox", "点击了: " .. label)
  189. if label == "确定" then
  190. log.info("msgbox", "执行删除操作")
  191. local confirm_msg = airui.msgbox({
  192. text = "文件已删除",
  193. buttons = { "确定" },
  194. timeout = 1500,
  195. on_action = function(self, label)
  196. self:hide()
  197. end
  198. })
  199. confirm_msg:show()
  200. else
  201. log.info("msgbox", "操作已取消")
  202. end
  203. self:hide()
  204. end
  205. })
  206. msg:show()
  207. end
  208. })
  209. --------------------------------------------------------------------
  210. -- 示例4: 自动关闭的消息框
  211. --------------------------------------------------------------------
  212. local demo4_container = create_demo_container(scroll_container, "示例4: 自动关闭消息框", 10, current_y, 300, 100)
  213. current_y = current_y + 100 + 10
  214. airui.label({
  215. parent = demo4_container,
  216. text = "显示3秒后自动关闭的消息框",
  217. x = 10,
  218. y = 30,
  219. w = 280,
  220. h = 20,
  221. color = 0x666666,
  222. font_size = 12,
  223. })
  224. local auto_msg_btn = airui.button({
  225. parent = demo4_container,
  226. x = 80,
  227. y = 60,
  228. w = 140,
  229. h = 40,
  230. text = "显示3秒",
  231. on_click = function(self)
  232. local msg = airui.msgbox({
  233. text = "这条消息将在3秒后自动关闭",
  234. buttons = { "确定" },
  235. timeout = 3000,
  236. on_action = function(self, label)
  237. log.info("msgbox", "消息框被点击: " .. label)
  238. self:hide()
  239. end
  240. })
  241. msg:show()
  242. end
  243. })
  244. --------------------------------------------------------------------
  245. -- 示例5: 自定义按钮的消息框
  246. --------------------------------------------------------------------
  247. local demo5_container = create_demo_container(scroll_container, "示例5: 自定义按钮", 10, current_y, 300, 120)
  248. current_y = current_y + 120 + 10
  249. airui.label({
  250. parent = demo5_container,
  251. text = "显示带有自定义按钮的消息框",
  252. x = 10,
  253. y = 30,
  254. w = 280,
  255. h = 20,
  256. color = 0x666666,
  257. font_size = 12,
  258. })
  259. local custom_msg_btn = airui.button({
  260. parent = demo5_container,
  261. x = 80,
  262. y = 60,
  263. w = 140,
  264. h = 40,
  265. text = "自定义按钮",
  266. on_click = function(self)
  267. local msg = airui.msgbox({
  268. title = "选择操作",
  269. text = "请选择一个操作:",
  270. buttons = { "保存", "另存为", "取消" },
  271. on_action = function(self, label)
  272. local action_msg = airui.msgbox({
  273. text = "选择了: " .. label,
  274. buttons = { "确定" },
  275. timeout = 1500,
  276. on_action = function(self, label)
  277. self:hide()
  278. end
  279. })
  280. action_msg:show()
  281. log.info("msgbox", "选择了操作: " .. label)
  282. self:hide()
  283. end
  284. })
  285. msg:show()
  286. end
  287. })
  288. --------------------------------------------------------------------
  289. -- 示例6: 多行文本消息框
  290. --------------------------------------------------------------------
  291. local demo6_container = create_demo_container(scroll_container, "示例6: 多行文本消息", 10, current_y, 300, 120)
  292. current_y = current_y + 120 + 10
  293. airui.label({
  294. parent = demo6_container,
  295. text = "显示多行文本消息框",
  296. x = 10,
  297. y = 30,
  298. w = 280,
  299. h = 20,
  300. color = 0x666666,
  301. font_size = 12,
  302. })
  303. local multiline_msg_btn = airui.button({
  304. parent = demo6_container,
  305. x = 80,
  306. y = 60,
  307. w = 140,
  308. h = 40,
  309. text = "多行消息",
  310. on_click = function(self)
  311. local msg = airui.msgbox({
  312. title = "详细信息",
  313. text = "这是第一行文本\n这是第二行文本\n这是第三行文本\n消息框支持多行显示",
  314. buttons = { "确定" },
  315. on_action = function(self, label)
  316. log.info("msgbox", "多行消息被确认")
  317. self:hide()
  318. end
  319. })
  320. msg:show()
  321. end
  322. })
  323. --------------------------------------------------------------------
  324. -- 示例7: 消息框链式调用
  325. --------------------------------------------------------------------
  326. local demo7_container = create_demo_container(scroll_container, "示例7: 链式调用", 10, current_y, 300, 140)
  327. current_y = current_y + 140 + 10
  328. airui.label({
  329. parent = demo7_container,
  330. text = "显示链式调用的消息框",
  331. x = 10,
  332. y = 30,
  333. w = 280,
  334. h = 20,
  335. color = 0x666666,
  336. font_size = 12,
  337. })
  338. local chain_msg_btn = airui.button({
  339. parent = demo7_container,
  340. x = 80,
  341. y = 60,
  342. w = 140,
  343. h = 40,
  344. text = "链式消息",
  345. on_click = function(self)
  346. local msg1 = airui.msgbox({
  347. title = "第一步",
  348. text = "这是第一步操作",
  349. buttons = { "下一步" },
  350. on_action = function(self, label)
  351. self:hide()
  352. local msg2 = airui.msgbox({
  353. title = "第二步",
  354. text = "这是第二步操作",
  355. buttons = { "下一步" },
  356. on_action = function(self, label)
  357. self:hide()
  358. local msg3 = airui.msgbox({
  359. title = "完成",
  360. text = "所有步骤已完成",
  361. buttons = { "确定" },
  362. timeout = 2000,
  363. on_action = function(self, label)
  364. self:hide()
  365. end
  366. })
  367. msg3:show()
  368. end
  369. })
  370. msg2:show()
  371. end
  372. })
  373. msg1:show()
  374. end
  375. })
  376. -- 底部信息
  377. airui.label({
  378. parent = main_container,
  379. text = "提示: 点击按钮显示不同类型的消息框",
  380. x = 10,
  381. y = 440,
  382. w = 300,
  383. h = 20,
  384. color = 0x666666,
  385. font_size = 12,
  386. })
  387. end
  388. ----------------------------------------------------------------
  389. -- 初始化页面
  390. ----------------------------------------------------------------
  391. function msgbox_page.init(params)
  392. msgbox_page.create_ui()
  393. end
  394. ----------------------------------------------------------------
  395. -- 清理页面
  396. ----------------------------------------------------------------
  397. function msgbox_page.cleanup()
  398. if main_container then
  399. main_container:destroy()
  400. main_container = nil
  401. end
  402. end
  403. return msgbox_page