Ranking.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. namespace UCore\DcatAdmin\Metrics\Examples;
  3. use Dcat\Admin\Widgets\Metrics\RadialBar;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Support\Str;
  6. /**
  7. * 排行榜
  8. *
  9. */
  10. class Ranking extends RadialBar
  11. {
  12. protected $chartPullRight = false;
  13. protected $contentWidth = [ 11, 0 ];
  14. /**
  15. * 排行榜 排名颜色
  16. *
  17. * @var string[]
  18. */
  19. protected $rankClass = [
  20. 'text-primary',
  21. 'text-warning',
  22. 'text-danger',
  23. 'text-secondary',
  24. 'text-secondary',
  25. 'text-secondary',
  26. 'text-secondary',
  27. 'text-secondary',
  28. 'text-secondary',
  29. 'text-secondary',
  30. 'text-secondary',
  31. 'text-secondary',
  32. 'text-secondary',
  33. 'text-secondary',
  34. 'text-secondary',
  35. 'text-secondary',
  36. 'text-secondary',
  37. 'text-secondary',
  38. 'text-secondary',
  39. 'text-secondary',
  40. 'text-secondary',
  41. 'text-secondary',
  42. 'text-secondary',
  43. 'text-secondary',
  44. 'text-secondary',
  45. 'text-secondary',
  46. 'text-secondary',
  47. 'text-secondary',
  48. 'text-secondary',
  49. 'text-secondary',
  50. 'text-secondary',
  51. 'text-secondary',
  52. 'text-secondary',
  53. 'text-secondary',
  54. 'text-secondary',
  55. 'text-secondary',
  56. 'text-secondary',
  57. 'text-secondary',
  58. 'text-secondary',
  59. 'text-secondary',
  60. 'text-secondary',
  61. ];
  62. /**
  63. * 初始化卡片内容
  64. */
  65. protected function init()
  66. {
  67. $this->id('metric-card-' . Str::random(8));
  68. $this->class('card');
  69. // $this->title('订单排行榜');
  70. $this->dropdown([
  71. '1' => '最近 1 天',
  72. '7' => '最近 7 天',
  73. '14' => '最近 14 天',
  74. '30' => '最近 30 天',
  75. '90' => '最近 90 天'
  76. ]);
  77. }
  78. /**
  79. * 处理请求
  80. *
  81. * @param Request $request
  82. *
  83. * @return mixed|void
  84. */
  85. public function handle(Request $request)
  86. {
  87. $data = $this->getData($request->get('option', 1));
  88. // 卡片内容
  89. $this->withContent($data);
  90. }
  91. /**
  92. * 获取数据 - 子类需要重写此方法
  93. *
  94. * @param string $option
  95. * @return array
  96. */
  97. protected function getData($option)
  98. {
  99. // 默认示例数据
  100. return [
  101. ['rank' => '1', 'title' => '示例项目1', 'number' => '100'],
  102. ['rank' => '2', 'title' => '示例项目2', 'number' => '80'],
  103. ['rank' => '3', 'title' => '示例项目3', 'number' => '60'],
  104. ];
  105. }
  106. /**
  107. * 卡片内容.
  108. *
  109. * @param int $finished
  110. * @param int $pending
  111. * @param int $rejected
  112. *
  113. * @return $this
  114. */
  115. public function withContent($list)
  116. {
  117. $listString = '';
  118. foreach ($list as $i => $value) {
  119. $rank = $value['rank'];
  120. $color = $this->rankClass[$i];
  121. $name = $value['title'];
  122. $number = $value['number'];
  123. $listString .= <<<HTML
  124. <div class="chart-info d-flex justify-content-between mb-1 mr-1" >
  125. <div class="series-info d-flex align-items-center">
  126. <i class=" $color" style="width: 20px"> {$rank} </i>
  127. &nbsp;&nbsp;
  128. <span class="text-bold-600 ml-50"> {$name} </span>
  129. </div>
  130. <div class="product-result">
  131. <span>{$number}</span>
  132. </div>
  133. </div>
  134. HTML;
  135. }
  136. return $this->content(
  137. <<<HTML
  138. <div class="col-12 d-flex flex-column flex-wrap mt-1 text-center" style="padding-left:16px;padding-right:0px;">
  139. $listString
  140. </div>
  141. HTML
  142. );
  143. }
  144. }