dialogtable.blade.php 3.2 KB

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