dialogtable.blade.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <span class="{{ $class }}">
  2. <span style="cursor: pointer" class="switch-dialog">{!! $button !!}</span>
  3. <template>
  4. <div {!! $attributes !!}>
  5. <div class="p-2 dialog-body">{!! $table !!}</div>
  6. @if($footer)
  7. <div class="dialog-footer layui-layer-btn">{!! $footer !!}</div>
  8. @endif
  9. </div>
  10. </template>
  11. </span>
  12. <script init=".{{ $class }}">
  13. var area = screen.width <= 850 ? ['100%', '100%',] : '{{ $width }}',
  14. offset = screen.width <= 850 ? 0 : '70px',
  15. _tb = '.async-table', _container = '.dialog-table',
  16. _id, _temp, _btnId;
  17. setId(id);
  18. function hidden(index) {
  19. {!! $events['hidden'] !!}
  20. getLayer(index).find(_container).trigger('dialog:hidden');
  21. }
  22. function open(btn) {
  23. var index = layer.open({
  24. type: 1,
  25. title: '{!! $title !!}',
  26. area: area,
  27. offset: offset,
  28. maxmin: false,
  29. resize: false,
  30. content: $(_temp).html(),
  31. success: function(layero, index) {
  32. var $c = getLayer(index).find(_container),
  33. $t = getLayer(index).find(_tb);
  34. $c.attr('layer', index);
  35. setDataId($c);
  36. setMaxHeight(index);
  37. {!! $events['shown'] !!}
  38. @if(!empty($events['load']))
  39. $t.on('table:loaded', function (event) { {!! $events['load'] !!} });
  40. @endif
  41. setTimeout(function () {
  42. Dcat.grid.AsyncTable({container: $t});
  43. $t.trigger('table:load');
  44. }, 100);
  45. $c.trigger('dialog:shown');
  46. $c.on('dialog:open', openDialog);
  47. $c.on('dialog:close', closeDialog)
  48. },
  49. cancel: function (index) {
  50. btn && btn.removeAttr('layer');
  51. hidden(index)
  52. }
  53. });
  54. btn && btn.attr('layer', index);
  55. }
  56. function setDataId(obj) {
  57. if (! obj.attr('data-id')) {
  58. obj.attr('data-id', id);
  59. }
  60. }
  61. function setId(val) {
  62. if (! val) return;
  63. _id = '#' + val;
  64. _temp = _id + ' template';
  65. _btnId = _id + ' .switch-dialog';
  66. }
  67. function openDialog () {
  68. setId($(this).attr('data-id'));
  69. setDataId($(this));
  70. if (! $(this).attr('layer')) {
  71. open($(this));
  72. }
  73. }
  74. function getLayer(index) {
  75. return $('#layui-layer'+index)
  76. }
  77. function closeDialog() {
  78. var index = $(this).attr('layer');
  79. getLayer(index).find(_container).removeAttr('layer');
  80. $(_btnId).removeAttr('layer');
  81. if (index) {
  82. layer.close(index);
  83. hidden(index);
  84. }
  85. }
  86. function setMaxHeight(index) {
  87. var maxHeight = ($(window).height() - 250);
  88. if (maxHeight < 250) {
  89. maxHeight = maxHeight + 120;
  90. }
  91. getLayer(index).find('.layui-layer-content').css({'max-height': maxHeight});
  92. }
  93. $(_btnId).on('click', openDialog);
  94. </script>