链街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.

99 lines
2.2 KiB

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 = 150;
  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. // 图表数据
  43. $this->withChart($this->shipping);
  44. $this->withContent($this->shipping[0], $this->shipping[1]);
  45. }
  46. /**
  47. * 设置图表数据.
  48. *
  49. * @param array $data
  50. *
  51. * @return $this
  52. */
  53. public function withChart(array $data)
  54. {
  55. return $this->chart([
  56. 'series' => $data
  57. ]);
  58. }
  59. /**
  60. * 设置卡片头部内容.
  61. *
  62. * @param mixed $desktop
  63. * @param mixed $mobile
  64. *
  65. * @return $this
  66. */
  67. protected function withContent($s1, $s2)
  68. {
  69. $blue = Admin::color()->alpha('blue2', 0.5);
  70. $style = 'margin-bottom: 8px';
  71. $labelWidth = 120;
  72. return $this->content(
  73. <<<HTML
  74. <div class="d-flex pl-1 pr-1 pt-1" style="{$style}">
  75. <div style="width: {$labelWidth}px">
  76. <i class="fa fa-circle text-primary"></i> {$this->labels[0]}
  77. </div>
  78. <div>{$s1}</div>
  79. </div>
  80. <div class="d-flex pl-1 pr-1" style="{$style}">
  81. <div style="width: {$labelWidth}px">
  82. <i class="fa fa-circle" style="color: $blue"></i> {$this->labels[1]}
  83. </div>
  84. <div>{$s2}</div>
  85. </div>
  86. HTML
  87. );
  88. }
  89. }