TotalProduct.php 2.1 KB

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