col_set_modal.ejs 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <!--弹出列设置-->
  2. <div class="modal fade" id="custom-col-set" data-backdrop="static">
  3. <div class="modal-dialog" role="document">
  4. <div class="modal-content">
  5. <div class="modal-header">
  6. <h5 class="modal-title">列设置</h5>
  7. </div>
  8. <div class="modal-body">
  9. <table class="table table-hover table-bordered" id="custom-col-set-table">
  10. </table>
  11. </div>
  12. <form class="modal-footer" >
  13. <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">关闭</button>
  14. <button type="button" class="btn btn-primary btn-sm" id="custom-col-set-ok">确定修改</button>
  15. </form>
  16. </div>
  17. </div>
  18. </div>
  19. <script>
  20. const customColSet = (function () {
  21. const loadLocalColSet = function(setting, cache) {
  22. if (!cache) {
  23. const cacheStr = setting.key ? getLocalCache(setting.key) : '';
  24. cache = cacheStr ? JSON.parse(cacheStr) : [];
  25. }
  26. for (const col of setting.colSet) {
  27. if (col.fixed && col.fixed.indexOf(col.field) > 0) {
  28. col.show = 1;
  29. } else {
  30. const selfSet = cache.find(x => { return x.field === col.field; });
  31. col.show = selfSet ? selfSet.show : 1;
  32. }
  33. }
  34. return setting.colSet;
  35. }
  36. const getColSetTableHtml = function(setting) {
  37. const html = [];
  38. html.push('<tr class="text-center"><th>列名</th><th width="50px">显示</th></tr>');
  39. for (const col of setting.colSet) {
  40. html.push(`<tr class="text-center" code="${col.field}">`);
  41. html.push(`<td>${col.name}</td>`);
  42. if (col.fixed && col.fixed.indexOf('show') >= 0) {
  43. html.push(` <td>
  44. <div class="form-check form-check-inline">
  45. <input class="form-check-input" type="checkbox" id="inlineCheckbox-${col.field}" checked="" disabled="">
  46. <label class="form-check-label" for="inlineCheckbox-${col.field}"></label>
  47. </div>
  48. </td>`);
  49. } else {
  50. html.push(` <td>
  51. <div class="form-check form-check-inline">
  52. <input class="form-check-input" type="checkbox" id="inlineCheckbox-${col.field}" ${ (col.show ? 'checked' : '') } >
  53. <label class="form-check-label" for="inlineCheckbox-${col.field}"></label>
  54. </div>
  55. </td>`)
  56. }
  57. html.push('</tr>');
  58. }
  59. $('#custom-col-set-table').html(html.join(''));
  60. }
  61. const show = function(setting) {
  62. loadLocalColSet(setting);
  63. getColSetTableHtml(setting);
  64. $('#custom-col-set-ok').bind('click', function() {
  65. const trs = $('tr[code]', '#custom-col-set');
  66. const colSet = [];
  67. for (const tr of trs) {
  68. colSet.push({ field: $(tr).attr('code'), show: $('input[type=checkbox]', tr)[0].checked});
  69. }
  70. setLocalCache(setting.key, JSON.stringify(colSet));
  71. if (setting.afterSet) setting.afterSet(loadLocalColSet(setting, colSet));
  72. $('#custom-col-set').modal('hide');
  73. });
  74. $('#custom-col-set').modal('show');
  75. }
  76. return { show, loadLocalColSet }
  77. })();
  78. </script>