Skip to content

前端消息与弹窗

DANGER

暴露公共提示组件,可在前端任意位置调用,例如:

  1. app.js 中调用
  2. 在自定义页面中使用 parent.msg.xxx 的形式调用
  3. 也可在自定义按钮的返回 JS 中调用
  4. erupt-websocket 推送时调用

INFO

注:1.12.15 及以上版本支持

全局提示组件

javascript
window.msg.info('This is a normal message');
window.msg.success('This is a normal message');
window.msg.error('This is a normal message');
window.msg.warning('This is a normal message');

// loading
let loading = window.msg.loading('This is a normal message', { nzDuration: 2500 });
// 手动关闭 loading
window.msg.remove(loading.messageId);

弹窗提示组件

javascript
window.modal.info({
  nzTitle: 'This is a notification message',
  nzContent: '<p>some messages...some messages...</p>',
  nzOnOk: () => console.log('Info OK')
})
window.modal.success({
  nzTitle: 'This is a notification message',
  nzContent: '<p>some messages...some messages...</p>',
  nzOnOk: () => console.log('Info OK')
})
window.modal.error({
  nzTitle: 'This is a notification message',
  nzContent: '<p>some messages...some messages...</p>',
  nzOnOk: () => console.log('Info OK')
})
window.modal.warning({
  nzTitle: 'This is a notification message',
  nzContent: '<p>some messages...some messages...</p>',
  nzOnOk: () => console.log('Info OK')
})
window.modal.confirm({
  nzTitle: 'Are you sure delete this task?',
  nzContent: '<b style="color: red;">Some descriptions</b>',
  nzOkText: 'Yes',
  nzOkType: 'primary',
  nzOkDanger: true,
  nzOnOk: () => console.log('OK'),
  nzCancelText: 'No',
  nzOnCancel: () => console.log('Cancel')
})

// 关闭所有弹窗
window.modal.closeAll();

通知提示组件

javascript
window.notify.blank('title', 'content', [options]) // 不带图标的提示
window.notify.success('title', 'content', {
  nzPlacement: 'bottom'
})
window.notify.error('title', 'content')
window.notify.info('title', 'content')
window.notify.warning('title', 'content')

options 参数

参数说明类型默认值
nzDuration持续时间(毫秒),设为 0 时不自动消失number4500
nzMaxStack同一时间可展示的最大提示数量number8
nzPauseOnHover鼠标移上时禁止自动移除booleantrue
nzAnimate开关动画效果booleantrue
nzTop消息从顶部弹出时距顶部的位置string24px
nzBottom消息从底部弹出时距底部的位置string24px
nzPlacement弹出位置:topLeft topRight bottomLeft bottomRight top bottomstringtopRight
nzDirection通知的文字方向'ltr' | 'rtl'-

在组件中渲染 HTML

1.12.23 及以上版本支持

提示组件、弹窗组件、通知组件的内容参数默认只接收普通文本,如需渲染 HTML,需用 window.safeHtml 包裹告知框架标签安全可渲染:

javascript
window.msg.error(window.safeHtml(`
    提示xxx错误
    <button style="margin-left:20px" onclick="window.location.hash = '/xxx'">查看</button>
`), {
    nzDuration: 5000
})

Released under the Apache-2.0 License.