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

118 lines
2.7 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 Market extends Donut
  6. {
  7. protected $labels = ['东沟岭市场', '铜鼓岭市场', '华园菜市', '平西市场'];
  8. protected $market;
  9. public function __construct($market)
  10. {
  11. $this->market = $market;
  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),$color->warning(),'rebeccapurple'];
  19. //$this->title('<small>配送数据</small>');
  20. $this->height = 153;
  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->market);
  43. // 图表数据
  44. $this->withChart($this->market);
  45. $this->withContent($this->market[0], $this->market[1], $this->market[2], $this->market[3]);
  46. }
  47. /**
  48. * 设置图表数据.
  49. *
  50. * @param array $data
  51. *
  52. * @return $this
  53. */
  54. public function withChart(array $data)
  55. {
  56. return $this->chart([
  57. 'series' => $data
  58. ]);
  59. }
  60. /**
  61. * 设置卡片头部内容.
  62. *
  63. * @param mixed $desktop
  64. * @param mixed $mobile
  65. *
  66. * @return $this
  67. */
  68. protected function withContent($s1, $s2, $s3, $s4)
  69. {
  70. $blue = Admin::color()->alpha('blue2', 0.5);
  71. $style = 'margin-bottom: 8px';
  72. $labelWidth = 120;
  73. return $this->content(
  74. <<<HTML
  75. <div class="d-flex pl-1 pr-1 " style="{$style}">
  76. <div style="width: {$labelWidth}px">
  77. <i class="fa fa-circle text-primary"></i> {$this->labels[0]}
  78. </div>
  79. <div>{$s1}</div>
  80. </div>
  81. <div class="d-flex pl-1 pr-1" style="{$style}">
  82. <div style="width: {$labelWidth}px">
  83. <i class="fa fa-circle" style="color: $blue"></i> {$this->labels[1]}
  84. </div>
  85. <div>{$s2}</div>
  86. </div>
  87. <div class="d-flex pl-1 pr-1 " style="{$style}">
  88. <div style="width: {$labelWidth}px">
  89. <i class="fa fa-circle text-warning"></i> {$this->labels[2]}
  90. </div>
  91. <div>{$s3}</div>
  92. </div>
  93. <div class="d-flex pl-1 pr-1" style="{$style}">
  94. <div style="width: {$labelWidth}px">
  95. <i class="fa fa-circle" style="color: rebeccapurple"></i> {$this->labels[3]}
  96. </div>
  97. <div>{$s4}</div>
  98. </div>
  99. HTML
  100. );
  101. }
  102. }