log.js 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. define(["jquery", "easy-admin"], function ($, ea) {
  2. var init = {
  3. table_elem: '#currentTable',
  4. table_render_id: 'currentTableRenderId',
  5. index_url: 'system.log/index',
  6. export_url: 'system.log/export',
  7. deleteMonthLog_url: 'system.log/deleteMonthLog',
  8. };
  9. return {
  10. index: function () {
  11. var util = layui.util;
  12. ea.table.render({
  13. init: init,
  14. lineStyle: 'height: auto;word-break: break-all;',
  15. toolbar: ['refresh', 'export',
  16. [{
  17. text: '框架日志',
  18. url: 'system.log/record',
  19. method: 'open',
  20. auth: 'record',
  21. class: 'layui-btn layui-btn-sm',
  22. icon: 'fa fa-book',
  23. extend: 'data-width="95%" data-height="95%"'
  24. }, {
  25. text: '删除部分日志',
  26. url: 'system.log/deleteMonthLog',
  27. method: 'open',
  28. auth: 'deleteMonthLog',
  29. class: 'layui-btn layui-btn-sm layui-btn-danger',
  30. icon: 'fa fa-remove',
  31. extend: 'data-width="35%" data-height="42%"'
  32. },]
  33. ],
  34. cols: [[
  35. {field: 'id', width: 80, title: 'ID', search: false},
  36. {field: 'month', width: 80, title: '日志月份', hide: true, search: 'time', timeType: 'month', searchValue: util.toDateString(new Date(), 'yyyy-MM')},
  37. {
  38. field: 'admin.username', width: 100, title: '后台用户', search: false, templet: function (res) {
  39. let admin = res.admin
  40. return admin ? admin.username : '-'
  41. }
  42. },
  43. {field: 'method', width: 100, title: '请求方法'},
  44. {field: 'title', minWidth: 180, title: '请求标题'},
  45. {field: 'ip', width: 150, title: 'IP地址'},
  46. {field: 'url', minWidth: 150, title: '路由地址', align: "left"},
  47. {
  48. field: 'content', minWidth: 200, title: '请求数据', align: "left", templet: function (res) {
  49. let html = '<div class="layui-colla-item">' +
  50. '<div class="layui-colla-title">点击预览</div>' +
  51. '<div class="layui-colla-content">' + prettyFormat(JSON.stringify(res.content)) + '</div>' +
  52. '</div>'
  53. return '<div class="layui-collapse" lay-accordion>' + html + '</div>'
  54. }
  55. },
  56. {
  57. field: 'response', minWidth: 200, title: '回调数据', align: "left", templet: function (res) {
  58. let html = '<div class="layui-colla-item">' +
  59. '<div class="layui-colla-title">点击预览</div>' +
  60. '<div class="layui-colla-content">' + prettyFormat(JSON.stringify(res.response)) + '</div>' +
  61. '</div>'
  62. return '<div class="layui-collapse" lay-accordion>' + html + '</div>'
  63. }
  64. },
  65. {field: 'create_time', minWidth: 100, title: '创建时间', search: 'range'},
  66. ]],
  67. done: function () {
  68. layui.element.render('collapse')
  69. }
  70. });
  71. ea.listen();
  72. },
  73. deleteMonthLog: function () {
  74. layui.form.on('submit(submit)', function (data) {
  75. let field = data.field
  76. let options = {
  77. url: ea.url(init.deleteMonthLog_url),
  78. data: field,
  79. }
  80. ea.msg.confirm('确认执行该操作?重要数据请先做好相关备份!', function () {
  81. ea.request.post(options, function (rs) {
  82. let msg = rs.msg || '未知~'
  83. layer.msg(msg.replace(/\n/g, '<br>'), {shade: 0.3, shadeClose: true, time: 2000})
  84. })
  85. })
  86. })
  87. }
  88. };
  89. });