index.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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: 'apilog/index' + location.search,
  8. del_url: 'apilog/index/del',
  9. table: 'wx_apilog',
  10. }
  11. });
  12. var table = $("#table");
  13. // 初始化表格
  14. table.bootstrapTable({
  15. url: $.fn.bootstrapTable.defaults.extend.index_url,
  16. pk: 'id',
  17. sortName: 'id',
  18. columns: [
  19. [
  20. { checkbox: true },
  21. { field: 'id', title: __('Id') },
  22. { field: 'username', title: __('UserName'), formatter: Table.api.formatter.search },
  23. { field: 'url', title: __('Url'), formatter: Table.api.formatter.url },
  24. {
  25. field: 'method', title: __('Method'),
  26. searchList: { "GET": "GET", "POST": "POST", "PUT": "PUT", "DELETE": "DELETE" },
  27. formatter: Table.api.formatter.normal
  28. },
  29. {
  30. field: 'ip', title: __('Ip'), formatter: function (value, row, index) {
  31. var html = '<a class="btn btn-xs btn-ip bg-success" data-toggle="tooltip" data-original-title="点击搜索' + value + '"><i class="fa fa-map-marker"></i> ' + value + '</a>';
  32. if (row.banip == false)
  33. html += '<a class="btn btn-xs btn-dialog btn-banip" data-status=0><i class="fa fa-toggle-on" data-toggle="tooltip" data-original-title="点击禁止该IP访问"></i></a>';
  34. else {
  35. html += '<a class="btn btn-xs btn-dialog btn-banip" data-status=1><i class="fa fa-toggle-off" data-toggle="tooltip" data-original-title="点击允许该IP访问"></i></a>';
  36. }
  37. return html;
  38. },
  39. events: Controller.api.events.ip
  40. },
  41. {
  42. field: 'ua', title: __('Ua'), formatter: function (value, row, index) {
  43. return '<a class="btn btn-xs btn-browser">' + ((!value) ? '' : (value.split(" ")[0])) + '</a>';
  44. },
  45. events: Controller.api.events.browser
  46. },
  47. { field: 'controller', title: __('Controller') },
  48. { field: 'action', title: __('Action') },
  49. { field: 'time', title: __('Time'), sortable: true },
  50. { field: 'code', title: __('Code'), formatter: Table.api.formatter.search },
  51. {
  52. field: 'createtime', title: __('Createtime'), operate: 'RANGE', sortable: true, addclass: 'datetimerange',
  53. formatter: Table.api.formatter.datetime
  54. },
  55. {
  56. field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
  57. buttons: [{
  58. name: 'detail',
  59. text: __('Detail'),
  60. icon: 'fa fa-list',
  61. classname: 'btn btn-info btn-xs btn-detail btn-dialog',
  62. url: 'apilog/index/detail'
  63. }
  64. ],
  65. }
  66. ]
  67. ]
  68. });
  69. // 为表格绑定事件
  70. Table.api.bindevent(table);
  71. // 清空数据按钮
  72. $(".btn-clear").click(function () {
  73. layer.confirm('该操作将清空所有数据,清空后不可恢复,确认操作吗?', function () {
  74. layer.closeAll();
  75. Fast.api.ajax({
  76. url: 'apilog/index/clear',
  77. loading: true,
  78. }, function (data, ret) {
  79. table.bootstrapTable('refresh');
  80. }
  81. );
  82. })
  83. });
  84. },
  85. add: function () {
  86. Controller.api.bindevent();
  87. },
  88. edit: function () {
  89. Controller.api.bindevent();
  90. },
  91. api: {
  92. bindevent: function () {
  93. Form.api.bindevent($("form[role=form]"));
  94. },
  95. events: {
  96. ip: {
  97. 'click .btn-ip': function (e, value, row, index) {
  98. e.stopPropagation();
  99. var container = $("#table").data("bootstrap.table").$container;
  100. $("form.form-commonsearch [name='ip']", container).val(value);
  101. $("form.form-commonsearch", container).trigger('submit');
  102. },
  103. 'click .btn-banip': function (e, value, row, index) {
  104. e.stopPropagation();
  105. if (row.banip == false)
  106. layer.prompt({ title: '请输入封禁时长(分钟),0为永久封禁', value: '0' }, function (text, index) {
  107. layer.close(index);
  108. $.post('apilog/index/banip', { status: 0, ip: value, time: text }, function (res) {
  109. if (res.code == 1) {
  110. $('#table').bootstrapTable('refresh');
  111. }
  112. })
  113. });
  114. else {
  115. $.post('apilog/index/banip', { status: 1, ip: value }, function (res) {
  116. if (res.code == 1) {
  117. $('#table').bootstrapTable('refresh');
  118. }
  119. })
  120. }
  121. }
  122. },
  123. browser: {
  124. 'click .btn-browser': function (e, value, row, index) {
  125. e.stopPropagation();
  126. var container = $("#table").data("bootstrap.table").$container;
  127. $("form.form-commonsearch [name='ua']", container).val(value);
  128. $("form.form-commonsearch", container).trigger('submit');
  129. }
  130. },
  131. }
  132. }
  133. };
  134. return Controller;
  135. });