Tickets.php 2.5 KB

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