Report.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace App\Admin\Metrics\Examples;
  3. use App\Models\Team;
  4. use App\Models\UserReport;
  5. use Dcat\Admin\Widgets\Metrics\Card;
  6. use Illuminate\Contracts\Support\Renderable;
  7. use Illuminate\Http\Request;
  8. class Report extends Card
  9. {
  10. /**
  11. * 卡片底部内容.
  12. *
  13. * @var string|Renderable|\Closure
  14. */
  15. protected $footer;
  16. /**
  17. * 初始化卡片.
  18. */
  19. protected function init()
  20. {
  21. parent::init();
  22. $this->title(trans('admin-home.Pending_report'));
  23. }
  24. /**
  25. * 处理请求.
  26. *
  27. * @param Request $request
  28. *
  29. * @return void
  30. */
  31. public function handle(Request $request)
  32. {
  33. $total_team = UserReport::query()->where(['status'=>0])->count();
  34. $this->content($total_team);
  35. }
  36. /**
  37. * @param int $percent
  38. *
  39. * @return $this
  40. */
  41. public function up($percent)
  42. {
  43. return $this->footer(
  44. "<i class=\"feather icon-trending-up text-success\"></i> {$percent}% Increase"
  45. );
  46. }
  47. /**
  48. * @param int $percent
  49. *
  50. * @return $this
  51. */
  52. public function down($percent)
  53. {
  54. return $this->footer(
  55. "<i class=\"feather icon-trending-down text-danger\"></i> {$percent}% Decrease"
  56. );
  57. }
  58. /**
  59. * 设置卡片底部内容.
  60. *
  61. * @param string|Renderable|\Closure $footer
  62. *
  63. * @return $this
  64. */
  65. public function footer($footer)
  66. {
  67. $this->footer = $footer;
  68. return $this;
  69. }
  70. /**
  71. * 渲染卡片内容.
  72. *
  73. * @return string
  74. */
  75. public function renderContent()
  76. {
  77. $content = parent::renderContent();
  78. return <<<HTML
  79. <div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px;cursor: pointer" onclick="location.href='/admin/report'">
  80. <h2 class="ml-1 font-lg-1" style="font-size: 48px!important;">{$content}</h2>
  81. </div>
  82. HTML;
  83. }
  84. /**
  85. * 渲染卡片底部内容.
  86. *
  87. * @return string
  88. */
  89. public function renderFooter()
  90. {
  91. return $this->toString($this->footer);
  92. }
  93. }