TotalUsers.php 2.1 KB

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