ActionSheet动作面板

从底部弹出的模态框,提供和当前场景相关的 2 个以上的操作动作,也支持提供标题和描述。内置固定的展示样式、不支持特别灵活的修改。

规则

  • 提供清晰的退出按钮。
  • 可高亮破坏性操作,e.g. 将『删除』处理成红色文本。
  • 不要放置过多内容,避免面板纵向滚动。

代码演示

基本用法

最简单的用法。

  1. import { Component } from '@angular/core';
  2. import { ActionSheetService, ToastService } from 'ng-zorro-antd-mobile';
  3. import { en_US, ru_RU, zh_CN, sv_SE, da_DK } from 'ng-zorro-antd-mobile';
  4. @Component({
  5. selector: 'demo-action-sheet-basic',
  6. template: `
  7. <WingBlank>
  8. <div Button (onClick)="showActionSheet(message)">showActionSheet</div>
  9. <WhiteSpace></WhiteSpace>
  10. <div Button (onClick)="showShareActionSheet()">showShareActionSheet</div>
  11. <WhiteSpace></WhiteSpace>
  12. <div Button (onClick)="showShareActionSheetMulpitleLine()">showShareActionSheetMulpitleLine</div>
  13. <ng-template #message>
  14. <div class="am-action-sheet-message">123</div>
  15. </ng-template>
  16. </WingBlank>
  17. `
  18. })
  19. export class DemoActionSheetBasicComponent {
  20. dataList = [
  21. { url: 'OpHiXAcYzmPQHcdlLFrc', title: '发送给朋友' },
  22. { url: 'wvEzCMiDZjthhAOcwTOu', title: '新浪微博' },
  23. { url: 'cTTayShKtEIdQVEMuiWt', title: '生活圈' },
  24. { url: 'umnHwvEgSyQtXlZjNJTt', title: '微信好友' },
  25. { url: 'SxpunpETIwdxNjcJamwB', title: 'QQ' }
  26. ].map(obj => ({
  27. icon: `<img src="https://gw.alipayobjects.com/zos/rmsportal/${obj.url}.png" style="width:36px"/>`,
  28. title: obj.title
  29. }));
  30. constructor(private _actionSheet: ActionSheetService, private _toast: ToastService) {}
  31. showActionSheet = message => {
  32. const BUTTONS = ['Operation1', 'Operation2', 'Operation2', 'Delete', 'Cancel'];
  33. ActionSheetService.showActionSheetWithOptions(
  34. {
  35. options: BUTTONS,
  36. cancelButtonIndex: BUTTONS.length - 1,
  37. destructiveButtonIndex: BUTTONS.length - 2,
  38. title: 'title',
  39. message: message,
  40. maskClosable: true
  41. },
  42. buttonIndex => {
  43. console.log(buttonIndex);
  44. }
  45. );
  46. }
  47. showShareActionSheet = () => {
  48. ActionSheetService.showShareActionSheetWithOptions(
  49. {
  50. options: this.dataList,
  51. message: 'I am description, description, description',
  52. locale: zh_CN
  53. },
  54. buttonIndex => {
  55. return new Promise(resolve => {
  56. ToastService.info('closed after 1000ms');
  57. setTimeout(resolve, 1000);
  58. });
  59. }
  60. );
  61. }
  62. showShareActionSheetMulpitleLine = () => {
  63. const data = [[...this.dataList, this.dataList[2]], [this.dataList[3], this.dataList[4]]];
  64. ActionSheetService.showShareActionSheetWithOptions(
  65. {
  66. options: data,
  67. message: 'I am description, description, description',
  68. locale: en_US
  69. },
  70. (buttonIndex, rowIndex) => {
  71. console.log(buttonIndex);
  72. }
  73. );
  74. }
  75. }

ActionSheet 动作面板 - 图1

API

static showActionSheetWithOptions(options: Object, callback: Function)

显示 action sheet,options对象必须包含以下的一个或者多个:

  • options (array of strings) - 按钮标题列表 (required)
  • cancelButtonIndex (int) - 按钮列表中取消按钮的索引位置
  • destructiveButtonIndex (int) - 按钮列表中破坏性按钮(一般为删除)的索引位置
  • title (string) - 顶部标题
  • message (string/React.element) - 顶部标题下的简要消息
  • maskClosable (bool) - 点击蒙层是否允许关闭,默认允许 callback函数支持返回 Promise

static showShareActionSheetWithOptions(options: Object, callback: Function)

显示分享 action sheet,options对象必须包含以下的一个或者多个:

  • options (array of {icon: TemplateRef | innerHTML, title: string}) - 分享按钮列表 (required)

    • 可以是二维数组,能显示多行按钮,例如[[{icon,title},…],…]表示两行两列。当为二维数组时callback有两个参数,第一个为序列、第二个为序列。
  • cancelButtonText (string) - 取消按钮文案,默认为Cancel

  • title (string) - 顶部标题

  • message (string/React.element) - 顶部标题下的简要消息

  • maskClosable (bool) - 点击蒙层是否允许关闭,默认允许

  • locale - 国际化,可覆盖全局LocaleProvider的配置 | Object: { dismissText }

  • callback函数支持返回 Promise

static showShareActionSheetWithOptions(options: Object, failureCallback: Function, successCallback: Function)

显示分享 action sheet,options对象必须包含以下的一个或者多个:

  • options:
    • message(string): 顶部标题下的简要消息
    • title(string): 顶部标题
    • url(string): 分享的 url
    • excludedActivityTypes(array): 指定在actionsheet中不显示的活动
  • Callback:
    • failureCallback(error): 分享失败调用;
    • successCallback(completed, method):分享成功调用;

static close() - programmatically close.