index.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /* @var $this \yii\web\View */
  3. $this->title = '公告';
  4. ?>
  5. <?php $this->beginBlock('header_script'); ?>
  6. <link href="<?= STATIC_URL ?>/ui/css/plugins/dataTables/datatables.min.css" rel="stylesheet">
  7. <style>
  8. label.error {
  9. display: none !important;
  10. }
  11. #datatables {
  12. width: 100% !important;
  13. }
  14. .table-responsive tbody tr {
  15. cursor: pointer;
  16. }
  17. </style>
  18. <?php $this->endBlock(); ?>
  19. <div class="row">
  20. <div class="col-md-3">
  21. <?= $this->render('/common/_left_menu.php') ?>
  22. </div>
  23. <div class="col-md-9">
  24. <div class="ibox">
  25. <div class="ibox-title">
  26. <h2>公告</h2>
  27. </div>
  28. <div class="ibox-content">
  29. <div class="table-responsive">
  30. <table id="datatables"
  31. class="table table-striped table-bordered table-hover dataTables-example">
  32. <thead>
  33. <tr>
  34. <th>标题</th>
  35. <th>发布时间</th>
  36. <th>是否已读</th>
  37. </tr>
  38. </thead>
  39. </table>
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. <?php $this->beginBlock('footer_script'); ?>
  46. <script src = "<?= STATIC_URL ?>/ui/js/plugins/dataTables/datatables.min.js" ></script>
  47. <script>
  48. var table
  49. $(document).ready(function () {
  50. table = $('#datatables').DataTable({
  51. 'aLengthMenu': [[20, 50, 100], [20, 50, 100]],
  52. language: {
  53. 'sProcessing': '处理中...',
  54. 'sLengthMenu': '显示 _MENU_ 项结果',
  55. 'sZeroRecords': '没有匹配结果',
  56. 'sInfo': '显示第 _START_ 至 _END_ 项结果,共 _TOTAL_ 项',
  57. 'sInfoEmpty': '显示第 0 至 0 项结果,共 0 项',
  58. 'sInfoFiltered': '(由 _MAX_ 项结果过滤)',
  59. 'sInfoPostFix': '',
  60. 'sSearch': '搜索:',
  61. 'sUrl': '',
  62. 'sEmptyTable': '表中数据为空',
  63. 'sLoadingRecords': '载入中...',
  64. 'sInfoThousands': ',',
  65. 'oPaginate': {
  66. 'sFirst': '首页',
  67. 'sPrevious': '上页',
  68. 'sNext': '下页',
  69. 'sLast': '末页'
  70. },
  71. 'oAria': {
  72. 'sSortAscending': ': 以升序排列此列',
  73. 'sSortDescending': ': 以降序排列此列'
  74. }
  75. },
  76. 'processing': true,
  77. 'serverSide': true,
  78. 'ajax': '<?= \yii\helpers\Url::to(['/ib/notice/notice-ajax']) ?>',
  79. 'order': [[1, 'desc']],
  80. 'columns': [{
  81. 'data': 'title',
  82. 'orderable': false
  83. },
  84. {
  85. 'data': 'in_time'
  86. },
  87. {
  88. 'data': 'isRead'
  89. }],
  90. columnDefs: [{
  91. targets: 1,
  92. render: function (data, type, row, meta) {
  93. return timeStamp2String(parseInt(data))
  94. },
  95. 'orderable': true
  96. }, {
  97. targets: 2,
  98. render: function (data, type, row, meta) {
  99. if (data) {
  100. return '<span class="label">已读</span>'
  101. } else {
  102. return '<span class="label label-danger">未读</span>'
  103. }
  104. },
  105. 'orderable': false
  106. }],
  107. 'sPaginationType': 'full_numbers',
  108. dom: '<"html5buttons"B>lTfgitp',
  109. buttons: [{
  110. extend: 'copy'
  111. },
  112. {
  113. extend: 'csv'
  114. },
  115. {
  116. extend: 'excel'
  117. },
  118. {
  119. extend: 'pdf'
  120. },
  121. {
  122. extend: 'print',
  123. customize: function (win) {
  124. $(win.document.body).addClass('white-bg')
  125. $(win.document.body).css('font-size', '10px')
  126. $(win.document.body).find('table').addClass('compact').css('font-size', 'inherit')
  127. }
  128. }]
  129. })
  130. $('#datatables tbody').on('click', 'tr',
  131. function () {
  132. if ($(this).hasClass('selected')) {
  133. $(this).removeClass('selected')
  134. } else {
  135. table.$('tr.selected').removeClass('selected')
  136. $(this).addClass('selected')
  137. }
  138. var data = table.row('.selected').data()
  139. if (data != undefined) {
  140. var url = '/ib/notice/nview?id=' + data.id
  141. window.location.href = url
  142. }
  143. })
  144. })
  145. </script>
  146. <?php $this->endBlock(); ?>