TotalTeam.php 2.0 KB

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