Tickets.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. * @param Request $request
  28. *
  29. * @return mixed|void
  30. */
  31. public function handle(Request $request)
  32. {
  33. switch ($request->get('option')) {
  34. case '365':
  35. case '30':
  36. case '28':
  37. case '7':
  38. default:
  39. // 卡片内容
  40. $this->withContent(162);
  41. // 卡片底部
  42. $this->withFooter(29, 63, '1d');
  43. // 图表数据
  44. $this->withChart(83);
  45. }
  46. }
  47. /**
  48. * 设置图表数据.
  49. *
  50. * @param int $data
  51. *
  52. * @return $this
  53. */
  54. public function withChart(int $data)
  55. {
  56. return $this->chart([
  57. 'series' => [$data],
  58. ]);
  59. }
  60. /**
  61. * 卡片内容
  62. *
  63. * @param string $content
  64. *
  65. * @return $this
  66. */
  67. public function withContent($content)
  68. {
  69. return $this->content(
  70. <<<HTML
  71. <div class="d-flex flex-column flex-wrap text-center">
  72. <h1 class="font-lg-2 mt-2 mb-0">{$content}</h1>
  73. <small>Tickets</small>
  74. </div>
  75. HTML
  76. );
  77. }
  78. /**
  79. * 卡片底部内容.
  80. *
  81. * @param string $new
  82. * @param string $open
  83. * @param string $response
  84. *
  85. * @return $this
  86. */
  87. public function withFooter($new, $open, $response)
  88. {
  89. return $this->footer(
  90. <<<HTML
  91. <div class="d-flex justify-content-between p-1" style="padding-top: 0!important;">
  92. <div class="text-center">
  93. <p>New Tickets</p>
  94. <span class="font-lg-1">{$new}</span>
  95. </div>
  96. <div class="text-center">
  97. <p>Open Tickets</p>
  98. <span class="font-lg-1">{$open}</span>
  99. </div>
  100. <div class="text-center">
  101. <p>Response Time</p>
  102. <span class="font-lg-1">{$response}</span>
  103. </div>
  104. </div>
  105. HTML
  106. );
  107. }
  108. }