模态窗 (Modal)

基本使用

  1. use Dcat\Admin\Widgets\Modal;
  2. $modal = Modal::make()
  3. ->lg()
  4. ->title('标题')
  5. ->body(view(...))
  6. ->button('<button class="btn btn-primary">点击打开弹窗</button>');
  7. return view(..., ['modal' => $modal]);

功能

标题 (title)

设置弹窗标题

  1. $modal->title('标题');

内容 (body)

设置弹窗内容,此方法接受一个参数,允许传入stringCloureIlluminate\Contracts\Support\Renderable以及Dcat\Admin\Contracts\LazyRenderable类型值

  1. // 传入字符串
  2. $modal->body('字符串');
  3. // 传入闭包,注意闭包必须返回字符串类型值或空值
  4. $modal->body(function () {
  5. return view(...)->render();
  6. });
  7. // 传入 Renderable
  8. use Dcat\Admin\Widgets\
  9. $modal->body(view(...));
  10. $modal->body(Card::make());
  11. // 传入 LazyRenderable
  12. $modal->body(PostTable::make());

底部内容 (footer)

设置弹窗底部内容,此方法接受一个参数,允许传入stringCloureIlluminate\Contracts\Support\Renderable以及Dcat\Admin\Contracts\LazyRenderable类型值,用法同上

  1. $modal->footer('字符串');
  2. $modal->footer(view(...));

尺寸

默认 500px

  1. // 800px
  2. $modal->lg();
  3. // 1140px
  4. $modal->xl();

按钮 (button)

设置按钮

事件监听

支持事件

  • onShow 弹窗显示事件
  • onShown 弹窗已显示事件
  • onHide 弹窗隐藏事件
  • onHidden 弹窗已隐藏事件

用法示例

  1. use Dcat\Admin\Admin;
  2. $modal->onShow(
  3. <<<JS
  4. console.log('显示弹窗', target, $(this));
  5. JS
  6. );
  7. $modal->onHide(
  8. <<<JS
  9. console.log('隐藏弹窗', target, $(this));
  10. JS
  11. );

垂直居中 (centered)

设置弹窗垂直居中

  1. $modal = Modal::make()
  2. ->xl()
  3. ->centered() // 设置弹窗垂直居中
  4. ->title(...)
  5. ->body(...);

内容可滚动 (scrollable)

设置弹窗内容可滚动

  1. $modal = Modal::make()
  2. ->xl()
  3. ->scrollable() // 设置弹窗内容可滚动
  4. ->title(...)
  5. ->body(...);

表单弹窗

参考文档 工具表单 - 弹窗