dialogtable.blade.php 3.4 KB

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