链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
2.9 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Admin\Actions\Metrics;
  3. use Dcat\Admin\Admin;
  4. use Dcat\Admin\Widgets\Metrics\Donut;
  5. class Shipping extends Donut
  6. {
  7. protected $labels = ['站内配送', '用户自提', '配送占比', '自提占比'];
  8. protected $shipping;
  9. public function __construct($shipping)
  10. {
  11. $this->shipping = $shipping;
  12. parent::__construct($title = null, $icon = null);
  13. }
  14. public function init()
  15. {
  16. parent::init(); // TODO: Change the autogenerated stub
  17. $color = Admin::color();
  18. $colors = [$color->primary(), $color->alpha('blue2', 0.5)];
  19. //$this->title('<small>配送数据</small>');
  20. $this->height = 152;
  21. $this->chartLabels($this->labels);
  22. // 设置图表颜色
  23. $this->chartColors($colors);
  24. }
  25. /**
  26. * 渲染模板
  27. *
  28. * @return string
  29. */
  30. public function render()
  31. {
  32. $this->fill();
  33. return parent::render(); // TODO: Change the autogenerated stub
  34. }
  35. /**
  36. * 写入数据.
  37. *
  38. * @return void
  39. */
  40. public function fill()
  41. {
  42. $total = array_sum($this->shipping);
  43. $s3 = $this->shipping[0]>0?sprintf("%.1f", ($this->shipping[0] / $total) * 100) . '%':'0%';
  44. $s4 = $this->shipping[0]>0?sprintf("%.1f", ($this->shipping[1] / $total) * 100) . '%':'0%';
  45. // 图表数据
  46. $this->withChart($this->shipping);
  47. $this->withContent($this->shipping[0], $this->shipping[1], $s3, $s4);
  48. }
  49. /**
  50. * 设置图表数据.
  51. *
  52. * @param array $data
  53. *
  54. * @return $this
  55. */
  56. public function withChart(array $data)
  57. {
  58. return $this->chart([
  59. 'series' => $data
  60. ]);
  61. }
  62. /**
  63. * 设置卡片头部内容.
  64. *
  65. * @param mixed $desktop
  66. * @param mixed $mobile
  67. *
  68. * @return $this
  69. */
  70. protected function withContent($s1, $s2, $s3, $s4)
  71. {
  72. $blue = Admin::color()->alpha('blue2', 0.5);
  73. $style = 'margin-bottom: 8px';
  74. $labelWidth = 120;
  75. return $this->content(
  76. <<<HTML
  77. <div class="d-flex pl-1 pr-1 " style="{$style}">
  78. <div style="width: {$labelWidth}px">
  79. <i class="fa fa-circle text-primary"></i> {$this->labels[0]}
  80. </div>
  81. <div>{$s1}</div>
  82. </div>
  83. <div class="d-flex pl-1 pr-1" style="{$style}">
  84. <div style="width: {$labelWidth}px">
  85. <i class="fa fa-circle" style="color: $blue"></i> {$this->labels[1]}
  86. </div>
  87. <div>{$s2}</div>
  88. </div>
  89. <div class="d-flex pl-1 pr-1 pt-1" style="{$style}">
  90. <div style="width: {$labelWidth}px">
  91. <i class="fa fa-circle text-primary"></i> {$this->labels[2]}
  92. </div>
  93. <div>{$s3}</div>
  94. </div>
  95. <div class="d-flex pl-1 pr-1" style="{$style}">
  96. <div style="width: {$labelWidth}px">
  97. <i class="fa fa-circle" style="color: $blue"></i> {$this->labels[3]}
  98. </div>
  99. <div>{$s4}</div>
  100. </div>
  101. HTML
  102. );
  103. }
  104. }