| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441 |
- --[[
- @module msgbox_page
- @summary 消息框组件演示页面
- @version 1.0
- @date 2026.02.05
- @author 江访
- @usage 本文件是消息框组件的演示页面,展示消息框的各种用法。
- ]]
- local msgbox_page = {}
- ----------------------------------------------------------------
- -- 页面UI元素
- ----------------------------------------------------------------
- local main_container = nil
- ----------------------------------------------------------------
- -- 辅助函数:创建带标题的容器
- ----------------------------------------------------------------
- local function create_demo_container(parent, title, x, y, width, height)
- local container = airui.container({
- parent = parent,
- x = x,
- y = y,
- w = width,
- h = height,
- color = 0xFFFFFF,
- radius = 8,
- })
- airui.label({
- parent = container,
- text = title,
- x = 10,
- y = 5,
- w = width - 20,
- h = 25,
- color = 0x333333,
- font_size = 14,
- })
- return container
- end
- ----------------------------------------------------------------
- -- 创建UI
- ----------------------------------------------------------------
- function msgbox_page.create_ui()
- main_container = airui.container({
- x = 0,
- y = 0,
- w = 320,
- h = 480,
- color = 0xF5F5F5,
- })
- -- 标题栏
- local title_bar = airui.container({
- parent = main_container,
- x = 0,
- y = 0,
- w = 320,
- h = 50,
- color = 0xE91E63,
- })
- airui.label({
- parent = title_bar,
- text = "消息框组件演示",
- x = 10,
- y = 15,
- w = 200,
- h = 20,
- font_size = 16,
- color = 0xFFFFFF,
- })
- -- 返回按钮
- local back_btn = airui.button({
- parent = title_bar,
- x = 250,
- y = 10,
- w = 60,
- h = 30,
- text = "返回",
- on_click = function(self)
- go_back()
- end
- })
- -- 滚动容器
- local scroll_container = airui.container({
- parent = main_container,
- x = 0,
- y = 60,
- w = 320,
- h = 370,
- color = 0xF5F5F5,
- })
- local current_y = 10
- --------------------------------------------------------------------
- -- 示例1: 基本消息框
- --------------------------------------------------------------------
- local demo1_container = create_demo_container(scroll_container, "示例1: 基本消息框", 10, current_y, 300, 100)
- current_y = current_y + 100 + 10
- airui.label({
- parent = demo1_container,
- text = "显示基本消息框",
- x = 10,
- y = 30,
- w = 280,
- h = 20,
- color = 0x666666,
- font_size = 12,
- })
- local basic_msg_btn = airui.button({
- parent = demo1_container,
- x = 80,
- y = 60,
- w = 140,
- h = 40,
- text = "显示消息",
- on_click = function(self)
- local msg = airui.msgbox({
- text = "这是一个基本消息框",
- buttons = { "确定" },
- on_action = function(self, label)
- log.info("msgbox", "点击了: " .. label)
- self:hide()
- end
- })
- msg:show()
- end
- })
- --------------------------------------------------------------------
- -- 示例2: 带标题的消息框
- --------------------------------------------------------------------
- local demo2_container = create_demo_container(scroll_container, "示例2: 带标题消息框", 10, current_y, 300, 100)
- current_y = current_y + 100 + 10
- airui.label({
- parent = demo2_container,
- text = "显示带标题的消息框",
- x = 10,
- y = 30,
- w = 280,
- h = 20,
- color = 0x666666,
- font_size = 12,
- })
- local title_msg_btn = airui.button({
- parent = demo2_container,
- x = 80,
- y = 60,
- w = 140,
- h = 40,
- text = "带标题消息",
- on_click = function(self)
- local msg = airui.msgbox({
- title = "系统提示",
- text = "操作成功完成!",
- buttons = { "确定" },
- on_action = function(self, label)
- log.info("msgbox", "点击了: " .. label)
- self:hide()
- end
- })
- msg:show()
- end
- })
- --------------------------------------------------------------------
- -- 示例3: 多个按钮的消息框
- --------------------------------------------------------------------
- local demo3_container = create_demo_container(scroll_container, "示例3: 多个按钮消息框", 10, current_y, 300, 120)
- current_y = current_y + 120 + 10
- airui.label({
- parent = demo3_container,
- text = "显示带有确认和取消按钮的消息框",
- x = 10,
- y = 30,
- w = 280,
- h = 20,
- color = 0x666666,
- font_size = 12,
- })
- local multi_msg_btn = airui.button({
- parent = demo3_container,
- x = 80,
- y = 60,
- w = 140,
- h = 40,
- text = "确认对话框",
- on_click = function(self)
- local msg = airui.msgbox({
- title = "确认操作",
- text = "确定要删除这个文件吗?",
- buttons = { "取消", "确定" },
- on_action = function(self, label)
- log.info("msgbox", "点击了: " .. label)
- if label == "确定" then
- log.info("msgbox", "执行删除操作")
- local confirm_msg = airui.msgbox({
- text = "文件已删除",
- buttons = { "确定" },
- timeout = 1500,
- on_action = function(self, label)
- self:hide()
- end
- })
- confirm_msg:show()
- else
- log.info("msgbox", "操作已取消")
- end
- self:hide()
- end
- })
- msg:show()
- end
- })
- --------------------------------------------------------------------
- -- 示例4: 自动关闭的消息框
- --------------------------------------------------------------------
- local demo4_container = create_demo_container(scroll_container, "示例4: 自动关闭消息框", 10, current_y, 300, 100)
- current_y = current_y + 100 + 10
- airui.label({
- parent = demo4_container,
- text = "显示3秒后自动关闭的消息框",
- x = 10,
- y = 30,
- w = 280,
- h = 20,
- color = 0x666666,
- font_size = 12,
- })
- local auto_msg_btn = airui.button({
- parent = demo4_container,
- x = 80,
- y = 60,
- w = 140,
- h = 40,
- text = "显示3秒",
- on_click = function(self)
- local msg = airui.msgbox({
- text = "这条消息将在3秒后自动关闭",
- buttons = { "确定" },
- timeout = 3000,
- on_action = function(self, label)
- log.info("msgbox", "消息框被点击: " .. label)
- self:hide()
- end
- })
- msg:show()
- end
- })
- --------------------------------------------------------------------
- -- 示例5: 自定义按钮的消息框
- --------------------------------------------------------------------
- local demo5_container = create_demo_container(scroll_container, "示例5: 自定义按钮", 10, current_y, 300, 120)
- current_y = current_y + 120 + 10
- airui.label({
- parent = demo5_container,
- text = "显示带有自定义按钮的消息框",
- x = 10,
- y = 30,
- w = 280,
- h = 20,
- color = 0x666666,
- font_size = 12,
- })
- local custom_msg_btn = airui.button({
- parent = demo5_container,
- x = 80,
- y = 60,
- w = 140,
- h = 40,
- text = "自定义按钮",
- on_click = function(self)
- local msg = airui.msgbox({
- title = "选择操作",
- text = "请选择一个操作:",
- buttons = { "保存", "另存为", "取消" },
- on_action = function(self, label)
- local action_msg = airui.msgbox({
- text = "选择了: " .. label,
- buttons = { "确定" },
- timeout = 1500,
- on_action = function(self, label)
- self:hide()
- end
- })
- action_msg:show()
- log.info("msgbox", "选择了操作: " .. label)
- self:hide()
- end
- })
- msg:show()
- end
- })
- --------------------------------------------------------------------
- -- 示例6: 多行文本消息框
- --------------------------------------------------------------------
- local demo6_container = create_demo_container(scroll_container, "示例6: 多行文本消息", 10, current_y, 300, 120)
- current_y = current_y + 120 + 10
- airui.label({
- parent = demo6_container,
- text = "显示多行文本消息框",
- x = 10,
- y = 30,
- w = 280,
- h = 20,
- color = 0x666666,
- font_size = 12,
- })
- local multiline_msg_btn = airui.button({
- parent = demo6_container,
- x = 80,
- y = 60,
- w = 140,
- h = 40,
- text = "多行消息",
- on_click = function(self)
- local msg = airui.msgbox({
- title = "详细信息",
- text = "这是第一行文本\n这是第二行文本\n这是第三行文本\n消息框支持多行显示",
- buttons = { "确定" },
- on_action = function(self, label)
- log.info("msgbox", "多行消息被确认")
- self:hide()
- end
- })
- msg:show()
- end
- })
- --------------------------------------------------------------------
- -- 示例7: 消息框链式调用
- --------------------------------------------------------------------
- local demo7_container = create_demo_container(scroll_container, "示例7: 链式调用", 10, current_y, 300, 140)
- current_y = current_y + 140 + 10
- airui.label({
- parent = demo7_container,
- text = "显示链式调用的消息框",
- x = 10,
- y = 30,
- w = 280,
- h = 20,
- color = 0x666666,
- font_size = 12,
- })
- local chain_msg_btn = airui.button({
- parent = demo7_container,
- x = 80,
- y = 60,
- w = 140,
- h = 40,
- text = "链式消息",
- on_click = function(self)
- local msg1 = airui.msgbox({
- title = "第一步",
- text = "这是第一步操作",
- buttons = { "下一步" },
- on_action = function(self, label)
- self:hide()
- local msg2 = airui.msgbox({
- title = "第二步",
- text = "这是第二步操作",
- buttons = { "下一步" },
- on_action = function(self, label)
- self:hide()
- local msg3 = airui.msgbox({
- title = "完成",
- text = "所有步骤已完成",
- buttons = { "确定" },
- timeout = 2000,
- on_action = function(self, label)
- self:hide()
- end
- })
- msg3:show()
- end
- })
- msg2:show()
- end
- })
- msg1:show()
- end
- })
- -- 底部信息
- airui.label({
- parent = main_container,
- text = "提示: 点击按钮显示不同类型的消息框",
- x = 10,
- y = 440,
- w = 300,
- h = 20,
- color = 0x666666,
- font_size = 12,
- })
- end
- ----------------------------------------------------------------
- -- 初始化页面
- ----------------------------------------------------------------
- function msgbox_page.init(params)
- msgbox_page.create_ui()
- end
- ----------------------------------------------------------------
- -- 清理页面
- ----------------------------------------------------------------
- function msgbox_page.cleanup()
- if main_container then
- main_container:destroy()
- main_container = nil
- end
- end
- return msgbox_page
|