Test.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace App\Admin\Metrics\Charts;
  3. use App\Models\Package;
  4. use Dcat\Admin\Admin;
  5. use Dcat\Admin\Widgets\Metrics\Bar;
  6. use Illuminate\Http\Request;
  7. class Test extends Bar
  8. {
  9. /**
  10. * 初始化卡片内容
  11. */
  12. public function init()
  13. {
  14. parent::init();
  15. $color = Admin::color();
  16. $dark35 = $color->dark35();
  17. // 卡片内容宽度
  18. $this->contentWidth(5, 7);
  19. // 标题
  20. $this->title('Avg Sessions');
  21. // 设置下拉选项
  22. // $this->dropdown(Package::pluck('name', 'id'));
  23. // 设置图表颜色
  24. $this->chartColors([
  25. $dark35,
  26. $dark35,
  27. $color->primary(),
  28. $dark35,
  29. $dark35,
  30. $color->info(),
  31. $dark35
  32. ]);
  33. }
  34. /**
  35. * 处理请求
  36. *
  37. * @param Request $request
  38. *
  39. * @return mixed|void
  40. */
  41. public function handle(Request $request)
  42. {
  43. switch ($request->get('option')) {
  44. case '7':
  45. default:
  46. // 卡片内容
  47. $this->withContent('2.7k', '+5.2%');
  48. // 图表数据
  49. $this->withChart([
  50. [
  51. 'name' => 'Sessions',
  52. 'data' => [75, 125, 225, 175, 125, 75, 25],
  53. ],
  54. ]);
  55. }
  56. }
  57. /**
  58. * 设置图表数据.
  59. *
  60. * @param array $data
  61. *
  62. * @return $this
  63. */
  64. public function withChart(array $data)
  65. {
  66. return $this->chart([
  67. 'series' => $data,
  68. ]);
  69. }
  70. /**
  71. * 设置卡片内容.
  72. *
  73. * @param string $title
  74. * @param string $value
  75. * @param string $style
  76. *
  77. * @return $this
  78. */
  79. public function withContent($title, $value, $style = 'success')
  80. {
  81. // 根据选项显示
  82. $label = strtolower(
  83. $this->dropdown[request()->option] ?? 'last 7 days'
  84. );
  85. $minHeight = '183px';
  86. return $this->content(
  87. <<<HTML
  88. <div class="d-flex p-1 flex-column justify-content-between" style="padding-top: 0;width: 100%;height: 100%;min-height: {$minHeight}">
  89. <div class="text-left">
  90. <h1 class="font-large-2 mt-2 mb-0">{$title}</h1>
  91. <h5 class="font-medium-2" style="margin-top: 10px;">
  92. <span class="text-{$style}">{$value} </span>
  93. <span>vs {$label}</span>
  94. </h5>
  95. </div>
  96. <a href="#" class="btn btn-primary shadow waves-effect waves-light">View Details <i class="feather icon-chevrons-right"></i></a>
  97. </div>
  98. HTML
  99. );
  100. }
  101. }