LogsController.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace backend\modules\admin\controllers;
  3. use Yii;
  4. use backend\models\LogsApi;
  5. /**
  6. * 系统日志
  7. */
  8. class LogsController extends BaseController
  9. {
  10. /**
  11. * 列表页
  12. * @return string
  13. */
  14. public function actionIndex()
  15. {
  16. return $this->render('index');
  17. }
  18. /**
  19. * AJAX获取数据
  20. */
  21. public function actionAjax()
  22. {
  23. $get = Yii::$app->request->get();
  24. $orderInt = isset($get['order'][0]['column']) ? (int) $get['order'][0]['column'] : 1;
  25. $order = isset($get['columns'][$orderInt]['data']) ? $get['columns'][$orderInt]['data'] : '';
  26. $orderBy = isset($get['order'][0]['dir']) ? $get['order'][0]['dir'] : 'desc';
  27. $search = isset($get['search']['value']) ? trim($get['search']['value']) : '';
  28. $start = isset($get['start']) ? (int) $get['start'] : 0;
  29. $length = isset($get['length']) ? (int) $get['length'] : 20;
  30. $draw = isset($get['draw']) ? $get['draw'] : 1;
  31. $params = [
  32. 'order' => $order,
  33. 'orderBy' => $orderBy,
  34. 'search' => $search,
  35. 'start' => $start,
  36. 'length' => $length,
  37. 'draw' => $draw,
  38. ];
  39. $api = new LogsApi();
  40. $result = $api->getList($params);
  41. echo json_encode($result['data']);
  42. }
  43. /**
  44. * 查看日志
  45. */
  46. public function actionView()
  47. {
  48. $path = trim(Yii::$app->request->get('path'));
  49. $api = new LogsApi();
  50. $result = $api->view(['path' => $path]);
  51. echo $result['data']['contents'];
  52. }
  53. /**
  54. * 清空日志
  55. */
  56. public function actionTruncate()
  57. {
  58. $path = trim(Yii::$app->request->get('path'));
  59. $api = new LogsApi();
  60. $result = $api->truncate(['path' => $path]);
  61. }
  62. }