Tickets.php 2.4 KB

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