logs.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'upload', 'jstree'], function ($, undefined, Backend, Table, Form, Upload) {
  2. var elTree = $('#treeview');// 目录元素
  3. var table = $("#table"); // 表格元素
  4. var Controller = {
  5. // 是否启动过表格
  6. startTable: false,
  7. action: {
  8. 'index': "general/logs/index",
  9. // 操作的文件路径
  10. 'filePath': '',
  11. },
  12. index: function () {
  13. Table.api.init({
  14. extend: {
  15. index_url: 'general/logs/index',
  16. del_url: 'general/logs/del?file_paths'+Controller.action.filePath,
  17. table: '',
  18. detail_url: 'general/logs/index'
  19. },
  20. search: false,
  21. advancedSearch: false,
  22. pagination: false,
  23. responseHandler: function (res) {
  24. var info = res.info;
  25. document.getElementById('info-size').innerHTML = info.size;
  26. document.getElementById('info-update_time').innerHTML = info.update_time;
  27. return res;
  28. },
  29. columns: [
  30. [
  31. {checkbox: true},
  32. {
  33. field: 'id',
  34. title: 'Id',
  35. sortable: true,
  36. operate: false,
  37. },
  38. {
  39. field: 'level',
  40. title: 'Level',
  41. searchList: {
  42. 'error': 'ERROR',
  43. 'notice': 'NOTICE',
  44. 'info': 'INFO',
  45. 'debug': 'DEBUG',
  46. 'sql': 'SQL'
  47. },
  48. formatter: function (value) {
  49. var label_class;
  50. switch (value) {
  51. case 'ERROR':
  52. label_class = 'danger';
  53. break;
  54. case 'NOTICE':
  55. label_class = 'warning';
  56. break;
  57. default:
  58. label_class = 'info';
  59. break;
  60. }
  61. return '<span class="label label-' + label_class + '">' + value + '</span>';
  62. }
  63. },
  64. {
  65. field: 'method',
  66. title: __('Method'),
  67. searchList: {
  68. 'get': 'GET',
  69. 'post': 'POST',
  70. 'put': 'PUT',
  71. 'patch': 'PATCH',
  72. 'delete': 'DELETE',
  73. 'copy': 'COPY',
  74. 'head': 'HEAD',
  75. 'options': 'OPTIONS',
  76. 'purge': 'PURGE',
  77. 'view': 'VIEW',
  78. },
  79. },
  80. {
  81. field: 'url',
  82. title: __('Url'),
  83. formatter: function (value) {
  84. var str = value.substr(0, 50);
  85. var tail = value.length > 50 ? '...' : '';
  86. str += tail;
  87. // return '<a class="btn-dialog" href="' + value + '" title="Url">' + str + '</a>';
  88. return '<a class="" href="javascript:;" title="Url">' + str + '</a>';
  89. },
  90. },
  91. {
  92. field: 'time',
  93. title: __('Time'),
  94. addclass: 'datetimerange',
  95. formatter: Table.api.formatter.datetime,
  96. },
  97. {field: 'operate', title: __('Operate'), table: table, events: Controller.api.events.operate, formatter: Table.api.formatter.operate, buttons: [
  98. {
  99. name: 'detail',
  100. text: '详情',
  101. title: '详情',
  102. icon: 'fa fa-list',
  103. classname: 'btn btn-xs btn-success btn-detail',
  104. },
  105. ]}
  106. ]
  107. ],
  108. });
  109. Controller.api.bindevent();
  110. },
  111. api: {
  112. events: {
  113. operate: {
  114. 'click .btn-delone': function (e, value, row, index) {
  115. e.stopPropagation();
  116. e.preventDefault();
  117. var that = this;
  118. var top = $(that).offset().top - $(window).scrollTop();
  119. var left = $(that).offset().left - $(window).scrollLeft() - 260;
  120. if (top + 154 > $(window).height()) {
  121. top = top - 154;
  122. }
  123. if ($(window).width() < 480) {
  124. top = left = undefined;
  125. }
  126. Layer.confirm(
  127. __('Are you sure you want to delete this item?'),
  128. {icon: 3, title: __('Warning'), offset: [top, left], shadeClose: true},
  129. function (index) {
  130. var table = $(that).closest('table');
  131. var options = table.bootstrapTable('getOptions');
  132. Table.api.multi("del", row[options.pk], table, that);
  133. Layer.close(index);
  134. }
  135. );
  136. },
  137. 'click .btn-detail': function (e, value, row, index) {
  138. var content = '<div style="white-space: pre-wrap;background: #333;color: #fff; padding: 10px;padding-top: 3px;min-height: 600px;">' + row.content + '</div>';
  139. layer.open({
  140. type: 1,
  141. title: '详细信息',
  142. fixed: true, //不固定
  143. maxmin: true,
  144. area: ['800px', '600px'],
  145. content: content,
  146. shade: 0
  147. });
  148. }
  149. }
  150. },
  151. // 修改表格数据
  152. diyForm: function (file_paths) {
  153. var params = '?file_paths=' + file_paths;
  154. var url = Controller.action.index + params;
  155. if (file_paths.indexOf('_cli.log') > -1) {
  156. Fast.api.ajax(url, function (data) {
  157. var content = '<div style="white-space: pre-wrap;background: #333;color: #fff; padding: 10px;padding-top: 3px;min-height: 600px;">' + data + '</div>';
  158. layer.open({
  159. type: 1,
  160. title: 'cli日志信息',
  161. fixed: true, //不固定
  162. maxmin: true,
  163. area: ['800px', '600px'],
  164. content: content,
  165. shade: 0
  166. });
  167. });
  168. return true;
  169. }
  170. if (this.startTable) {
  171. table.bootstrapTable('refresh', {url: url});
  172. } else {
  173. table.bootstrapTable({
  174. url: url,
  175. });
  176. Table.api.bindevent(table);
  177. this.startTable = true;
  178. }
  179. },
  180. bindevent: function () {
  181. elTree.jstree("destroy");
  182. Controller.api.rendertree(nodeData);
  183. $(document).on("click", "#expandall", function () {
  184. elTree.jstree($(this).prop("checked") ? "open_all" : "close_all");
  185. });
  186. // 开关目录
  187. $(document).on("click", "a.btn-channel", function () {
  188. $("#right-content").toggleClass("col-md-9", $("#left-content").hasClass("hidden"));
  189. $("#left-content").toggleClass("hidden");
  190. });
  191. },
  192. rendertree: function (content) {
  193. elTree
  194. .on("changed.jstree", function (e, data) {
  195. if (data.action == 'model' || (data.node && data.node.type == 'file')) {
  196. Controller.action.filePath = data.selected[0];
  197. Controller.api.diyForm(data.selected[0]);
  198. Table.api.init({
  199. extend: {
  200. del_url: encodeURI('general/logs/del?file_paths=' + Controller.action.filePath),
  201. }
  202. });
  203. }
  204. })
  205. .jstree({
  206. "themes": {"stripes": true},
  207. "checkbox": {
  208. "keep_selected_style": false,
  209. },
  210. "types": {
  211. "folder": {
  212. "icon": "jstree-folder",
  213. },
  214. "file": {
  215. "icon": "jstree-file",
  216. }
  217. },
  218. "plugins": ["types"],
  219. "core": {
  220. 'check_callback': false,
  221. "data": content
  222. }
  223. });
  224. }
  225. }
  226. };
  227. return Controller;
  228. });