Dialog

dialogs.build()返回的对话框对象,内置一些事件用于响应用户的交互,也可以获取对话框的状态和信息。

事件: show

  • dialog {Dialog} 对话框

对话框显示时会触发的事件。例如:

1dialogs
2    .build({
3        title: "标题",
4    })
5    .on("show", (dialog) => {
6        toast("对话框显示了");
7    })
8    .show();

事件: cancel

  • dialog {Dialog} 对话框

对话框被取消时会触发的事件。一个对话框可能按取消按钮、返回键取消或者点击对话框以外区域取消。例如:

1dialogs
2    .build({
3        title: "标题",
4        positive: "确定",
5        negative: "取消",
6    })
7    .on("cancel", (dialog) => {
8        toast("对话框取消了");
9    })
10    .show();

事件: dismiss

  • dialog {Dialog} 对话框

对话框消失时会触发的事件。对话框被取消或者手动调用dialog.dismiss()函数都会触发该事件。例如:

1var d = dialogs
2    .build({
3        title: "标题",
4        positive: "确定",
5        negative: "取消",
6    })
7    .on("dismiss", (dialog) => {
8        toast("对话框消失了");
9    })
10    .show();
11
12setTimeout(() => {
13    d.dismiss();
14}, 5000);

事件: positive

  • dialog {Dialog} 对话框

确定按钮按下时触发的事件。例如:

1var d = dialogs
2    .build({
3        title: "标题",
4        positive: "确定",
5        negative: "取消",
6    })
7    .on("positive", (dialog) => {
8        toast("你点击了确定");
9    })
10    .show();

事件: negative

  • dialog {Dialog} 对话框

取消按钮按下时触发的事件。例如:

1var d = dialogs
2    .build({
3        title: "标题",
4        positive: "确定",
5        negative: "取消",
6    })
7    .on("negative", (dialog) => {
8        toast("你点击了取消");
9    })
10    .show();

事件: neutral

  • dialog {Dialog} 对话框

中性按钮按下时触发的事件。例如:

1var d = dialogs
2    .build({
3        title: "标题",
4        positive: "确定",
5        negative: "取消",
6        neutral: "稍后提示",
7    })
8    .on("positive", (dialog) => {
9        toast("你点击了稍后提示");
10    })
11    .show();

事件: any

  • dialog {Dialog} 对话框
  • action {string} 被点击的按钮,可能的值为:
    • positive 确定按钮
    • negative 取消按钮
    • neutral 中性按钮

任意按钮按下时触发的事件。例如:

1var d = dialogs
2    .build({
3        title: "标题",
4        positive: "确定",
5        negative: "取消",
6        neutral: "稍后提示",
7    })
8    .on("any", (action, dialog) => {
9        if (action == "positive") {
10            toast("你点击了确定");
11        } else if (action == "negative") {
12            toast("你点击了取消");
13        }
14    })
15    .show();

事件: item_select

  • index {number} 被选中的项目索引,从 0 开始
  • item {Object} 被选中的项目
  • dialog {Dialog} 对话框

对话框列表(itemsSelectMode 为"select")的项目被点击选中时触发的事件。例如:

1var d = dialogs
2    .build({
3        title: "请选择",
4        positive: "确定",
5        negative: "取消",
6        items: ["A", "B", "C", "D"],
7        itemsSelectMode: "select",
8    })
9    .on("item_select", (index, item, dialog) => {
10        toast("您选择的是第" + (index + 1) + "项, 选项为" + item);
11    })
12    .show();

事件: single_choice

  • index {number} 被选中的项目索引,从 0 开始
  • item {Object} 被选中的项目
  • dialog {Dialog} 对话框

对话框单选列表(itemsSelectMode 为"singleChoice")的项目被选中并点击确定时触发的事件。例如:

1var d = dialogs
2    .build({
3        title: "请选择",
4        positive: "确定",
5        negative: "取消",
6        items: ["A", "B", "C", "D"],
7        itemsSelectMode: "singleChoice",
8    })
9    .on("item_select", (index, item, dialog) => {
10        toast("您选择的是第" + (index + 1) + "项, 选项为" + item);
11    })
12    .show();

事件: multi_choice

  • indices {Array} 被选中的项目的索引的数组
  • items {Array} 被选中的项目的数组
  • dialog {Dialog} 对话框

对话框多选列表(itemsSelectMode 为"multiChoice")的项目被选中并点击确定时触发的事件。例如:

1var d = dialogs.build({
2    title: "请选择",
3    positive: "确定",
4    negative: "取消",
5    items: ["A", "B", "C", "D"],
6    itemsSelectMode: "multiChoice"
7}).on("item_select", (indices, items, dialog)=>{
8    toast(util.format("您选择的项目为%o, 选项为%o", indices, items);
9}).show();

事件: input

  • text {string} 输入框的内容
  • dialog {Dialog} 对话框

带有输入框的对话框当点击确定时会触发的事件。例如:

1dialogs
2    .build({
3        title: "请输入",
4        positive: "确定",
5        negative: "取消",
6        inputPrefill: "",
7    })
8    .on("input", (text, dialog) => {
9        toast("你输入的是" + text);
10    })
11    .show();

事件: input_change

  • text {string} 输入框的内容
  • dialog {Dialog} 对话框

对话框的输入框的文本发生变化时会触发的事件。例如:

1dialogs
2    .build({
3        title: "请输入",
4        positive: "确定",
5        negative: "取消",
6        inputPrefill: "",
7    })
8    .on("input_change", (text, dialog) => {
9        toast("你输入的是" + text);
10    })
11    .show();

dialog.getProgress()

  • 返回 {number}

获取当前进度条的进度值,是一个整数

dialog.getMaxProgress()

  • 返回 {number}

获取当前进度条的最大进度值,是一个整数

dialog.getActionButton(action)

  • action {string} 动作,包括:
    • positive
    • negative
    • neutral