device.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'device/device/index' + location.search,
  8. add_url: 'device/device/add',
  9. edit_url: 'device/device/edit',
  10. del_url: 'device/device/del',
  11. multi_url: 'device/device/multi',
  12. import_url: 'device/device/import',
  13. task_url: 'device/device/task',
  14. table: 'device',
  15. }
  16. });
  17. var table = $("#table");
  18. // 初始化表格
  19. table.bootstrapTable({
  20. url: $.fn.bootstrapTable.defaults.extend.index_url,
  21. pk: 'id',
  22. sortName: 'id',
  23. fixedColumns: true,
  24. fixedRightNumber: 1,
  25. columns: [
  26. [
  27. {checkbox: true},
  28. {field: 'id', title: __('Id')},
  29. {field: 'group.name', title: __('设备分组')},
  30. {field: 'number', title: __('Number')},
  31. {field: 'task.name', title: __('任务')},
  32. {
  33. field: 'status', title: __('状态'), formatter: function (value, row, index) {
  34. if (row.status < 1) {
  35. return '已停止';
  36. } else {
  37. return '运行中';
  38. }
  39. }
  40. },
  41. {field: 'successions', title: __('Successions')},
  42. {field: 'maxsuccessions', title: __('Maxsuccessions')},
  43. {
  44. field: 'prevtime',
  45. title: __('Prevtime'),
  46. operate: 'RANGE',
  47. addclass: 'datetimerange',
  48. autocomplete: false,
  49. formatter: Table.api.formatter.datetime
  50. },
  51. {
  52. field: 'logintime',
  53. title: __('Logintime'),
  54. operate: 'RANGE',
  55. addclass: 'datetimerange',
  56. autocomplete: false,
  57. formatter: Table.api.formatter.datetime
  58. },
  59. {field: 'loginip', title: __('Loginip'), operate: 'LIKE'},
  60. {field: 'joinip', title: __('Joinip'), operate: 'LIKE'},
  61. {
  62. field: 'jointime',
  63. title: __('Jointime'),
  64. operate: 'RANGE',
  65. addclass: 'datetimerange',
  66. autocomplete: false,
  67. formatter: Table.api.formatter.datetime
  68. },
  69. {
  70. field: 'createtime',
  71. title: __('Createtime'),
  72. operate: 'RANGE',
  73. addclass: 'datetimerange',
  74. autocomplete: false,
  75. formatter: Table.api.formatter.datetime
  76. },
  77. {
  78. field: 'updatetime',
  79. title: __('Updatetime'),
  80. operate: 'RANGE',
  81. addclass: 'datetimerange',
  82. autocomplete: false,
  83. formatter: Table.api.formatter.datetime
  84. },
  85. {
  86. field: 'status',
  87. title: __('Status'),
  88. searchList: {"30": __('Status 30')},
  89. formatter: Table.api.formatter.status
  90. },
  91. {
  92. field: 'operate',
  93. title: __('Operate'),
  94. table: table,
  95. events: Table.api.events.operate,
  96. formatter: Table.api.formatter.operate
  97. }
  98. ]
  99. ]
  100. });
  101. // 为表格绑定事件
  102. Table.api.bindevent(table);
  103. // 点击任务
  104. $(document).on("click", ".btn-task", function () {
  105. var selectedData = $('#table').bootstrapTable('getSelections');
  106. var selectedIds = selectedData.map(function (item) {
  107. return item.id;
  108. });
  109. var url = $.fn.bootstrapTable.defaults.extend.task_url + '?ids=' + selectedIds.join(',');
  110. Fast.api.open(url, '任务', {
  111. area: ['500px', '380px'],
  112. })
  113. });
  114. },
  115. add: function () {
  116. Controller.api.bindevent();
  117. },
  118. edit: function () {
  119. Controller.api.bindevent();
  120. },
  121. task: function () {
  122. Controller.api.bindevent();
  123. var urlParams = new URLSearchParams(window.location.search);
  124. var ids = urlParams.get('ids');
  125. $('input[name="row[ids]"]').val(ids);
  126. },
  127. api: {
  128. bindevent: function () {
  129. Form.api.bindevent($("form[role=form]"));
  130. }
  131. }
  132. };
  133. return Controller;
  134. });