NewUsers.stub 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace DummyNamespace;
  3. use Dcat\Admin\Widgets\Metrics\LineChartCard;
  4. use Illuminate\Http\Request;
  5. class NewUsers extends LineChartCard
  6. {
  7. /**
  8. * @var string
  9. */
  10. protected $label = 'New Users';
  11. /**
  12. * 初始化卡片内容
  13. *
  14. * @return void
  15. */
  16. protected function init()
  17. {
  18. parent::init();
  19. $this->title($this->label);
  20. $this->dropdown([
  21. '7' => 'Last 7 Days',
  22. '28' => 'Last 28 Days',
  23. '30' => 'Last Month',
  24. '365' => 'Last Year',
  25. ]);
  26. }
  27. /**
  28. * 处理请求
  29. *
  30. * @param Request $request
  31. *
  32. * @return mixed|void
  33. */
  34. public function handle(Request $request)
  35. {
  36. switch ($request->get('option')) {
  37. case '365':
  38. case '30':
  39. case '28':
  40. case '7':
  41. default:
  42. // 卡片内容
  43. $this->withContent('89.2k');
  44. // 图表数据
  45. $this->withChart([28, 40, 36, 52, 38, 60, 55,]);
  46. }
  47. }
  48. /**
  49. * 设置图表数据.
  50. *
  51. * @param array $data
  52. *
  53. * @return $this
  54. */
  55. public function withChart(array $data)
  56. {
  57. return $this->chart([
  58. 'series' => [
  59. [
  60. 'name' => $this->label,
  61. 'data' => $data,
  62. ],
  63. ],
  64. ]);
  65. }
  66. /**
  67. * 设置卡片内容.
  68. *
  69. * @param string $content
  70. *
  71. * @return $this
  72. */
  73. public function withContent($content)
  74. {
  75. return $this->content(
  76. <<<HTML
  77. <div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">
  78. <h2 class="ml-1 font-large-1">{$content}</h2>
  79. <span class="mb-0 mr-1 text-80">{$this->label}</span>
  80. </div>
  81. HTML
  82. );
  83. }
  84. }