跳转到正文

对话框触发器 ​

通过触发按钮或 zui.Modal.open() 动态创建对话框,支持 Ajax HTML、iframe 页面和本地内容。

Ajax 对话框 ​

在对话框触发按钮上通过 data-url 指定内容地址。下面的示例加载一段包含 .modal-dialog 的 HTML。

将“完整代码”中的配套内容保存到示例页面所在目录下的 assets/modal/ajax-modal.html,也可下载配套 HTML 文件。通过 HTTP 服务访问页面;使用其他地址时,同步修改按钮的 data-url 和 JS 中的 url。

也可通过 zui.Modal.open() 打开同一个 Ajax 内容文件:

js
zui.Modal.open({
    url: './assets/modal/ajax-modal.html',
});

iframe 对话框 ​

通过 data-type="iframe" 指定 iframe 对话框,通过 data-url 指定内容页面地址。

将“完整代码”中的完整 HTML 页面保存到示例页面所在目录下的 assets/modal/iframe-modal.html,也可下载配套页面。示例使用同源页面,通过 HTTP 服务访问;调整地址时同步修改 data-url 和 JS 中的 url。

也可通过 zui.Modal.open() 打开同一个 iframe 页面:

js
zui.Modal.open({
    type: 'iframe',
    title: '发布计划',
    url: './assets/modal/iframe-modal.html',
});

自定义信息提示弹窗 ​

在对话框触发按钮上通过 data-title 属性指定对话框标题,通过 data-content 属性指定对话框内容。

也可通过 zui.Modal.open() 指定标题和本地内容,需显式设置 type: 'custom':

js
zui.Modal.open({
    type: 'custom',
    title: '发布准备完成',
    content: '客户门户 v1.2 已通过验收,计划于周五 18:00 发布。',
});

系统对话框 ​

警告框 ​

通过 zui.Modal.alert() 方法可以打开一个警告框,该方法定义如下:

ts
/* 直接指定要提示的消息文本 */
Modal.alert(message: string): Promise<string | undefined>;

/* 通过一个选项对象定义个性化警告框 */
Modal.alert(options: ModalAlertOptions): Promise<string | undefined>;

其中参数定义如下:

  • message:要提示的消息文本;
  • options:一个警告框选项对象 ModalAlertOptions,定义如下:
ts
interface ModalAlertOptions extends ModalCustomOptions {
    /* 提示消息 */
    message: string | {html: string};

    /* 提示消息前的图标名称 */
    icon?: string;

    /* 提示消息图标类名 */
    iconClass?: string;

    /* 自定义提示按钮 */
    actions?: ToolbarItemOptions[] | string | string[];

    /* 当点击提示按钮时的回调函数 */
    onClickAction?: (item: ToolbarItemOptions, modal: Modal) => false | void;
}

该方法会通过 Promise 异步返回用户点击的按钮名称。

下面为一个示例:

确认框 ​

通过 zui.Modal.confirm() 方法可以打开一个确认框,该方法定义如下:

ts
/* 直接指定要提示的消息文本 */
Modal.confirm(message: string): Promise<boolean>;

/* 通过一个选项对象定义个性化对话框 */
Modal.confirm(options: Partial<ModalConfirmOptions>): Promise<boolean>;

其中参数定义如下:

  • message:要提示的消息文本;
  • options:一个确认框选项对象,支持 ModalConfirmOptions 的部分属性,定义如下:
ts
interface ModalConfirmOptions extends ModalAlertOptions {
    /* 当用户点击确认或取消时的回调函数 */
    onResult?: (confirmed: boolean, modal: Modal) => void;
}

该方法会通过 Promise 异步返回确认结果:点击确认返回 true,取消或关闭对话框返回 false。下面的示例将结果显示在按钮下方,仅演示选择结果。

下面为一个示例: