Games.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace App\Admin\Metrics\Examples;
  3. use App\Models\Game;
  4. use Dcat\Admin\Widgets\Metrics\Line;
  5. use Illuminate\Http\Request;
  6. class Games extends Line
  7. {
  8. /**
  9. * 初始化卡片内容
  10. */
  11. protected function init()
  12. {
  13. parent::init();
  14. $this->title(trans('admin-home.Recent_events'));
  15. $this->height(400);
  16. //$this->chartHeight(300);
  17. //$this->chartLabels('Completed Tickets');
  18. // $this->dropdown([
  19. // '7' => 'Last 7 Days',
  20. // '28' => 'Last 28 Days',
  21. // '30' => 'Last Month',
  22. // '365' => 'Last Year',
  23. // ]);
  24. }
  25. /**
  26. * 处理请求
  27. *
  28. * @param Request $request
  29. *
  30. * @return mixed|void
  31. */
  32. public function handle(Request $request)
  33. {
  34. $games = Game::query()->orderByDesc('id')->limit(5)->select(['id','name','begin_time'])->get()->toArray();
  35. $this->withContent($games);
  36. }
  37. /**
  38. * 设置图表数据.
  39. *
  40. * @param int $data
  41. *
  42. * @return $this
  43. */
  44. public function withChart(int $data)
  45. {
  46. return $this->chart([
  47. 'series' => [$data],
  48. ]);
  49. }
  50. /**
  51. * 卡片内容
  52. *
  53. * @param string $content
  54. *
  55. * @return $this
  56. */
  57. public function withContent($content)
  58. {
  59. $str = '';
  60. foreach ($content as $k=>$v){
  61. $str.= '<h4 class="font-lg-12 mt-2 mb-3">'.$v['name'].' &nbsp;&nbsp;&nbsp;&nbsp;'.'<span style="float: right;font-size: 16px">'.trans('admin-home.Start_time').':'.$v['begin_time'].'</span></h4>';
  62. }
  63. return $this->content(
  64. <<<HTML
  65. <div class="justify-content-between align-items-center p-1">
  66. {$str}
  67. </div>
  68. HTML
  69. );
  70. }
  71. /**
  72. * 卡片底部内容.
  73. *
  74. * @param string $new
  75. * @param string $open
  76. * @param string $response
  77. *
  78. * @return $this
  79. */
  80. public function withFooter($new, $open, $response)
  81. {
  82. return $this->footer(
  83. <<<HTML
  84. <div class="d-flex justify-content-between p-1" style="padding-top: 0!important;">
  85. <div class="text-center">
  86. <p>New Tickets</p>
  87. <span class="font-lg-1">{$new}</span>
  88. </div>
  89. <div class="text-center">
  90. <p>Open Tickets</p>
  91. <span class="font-lg-1">{$open}</span>
  92. </div>
  93. <div class="text-center">
  94. <p>Response Time</p>
  95. <span class="font-lg-1">{$response}</span>
  96. </div>
  97. </div>
  98. HTML
  99. );
  100. }
  101. }