海南旅游SAAS
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.

111 lines
2.2 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <?php
  2. namespace App\Admin\Metrics\Examples;
  3. use App\Models\Agent;
  4. use App\Models\Guide;
  5. use App\Models\Supplier;
  6. use Dcat\Admin\Admin;
  7. use Dcat\Admin\Widgets\Metrics\Donut;
  8. class NewDevices extends Donut
  9. {
  10. protected $labels = ['代理商', '供应商', '地接'];
  11. /**
  12. * 初始化卡片内容
  13. */
  14. protected function init()
  15. {
  16. parent::init();
  17. $color = Admin::color();
  18. $colors = [$color->primary(), $color->alpha('blue2', 0.5),Admin::color()->yellow()];
  19. $this->title('入驻比例');;
  20. $this->chartLabels($this->labels);
  21. // 设置图表颜色
  22. $this->chartColors($colors);
  23. }
  24. /**
  25. * 渲染模板
  26. *
  27. * @return string
  28. */
  29. public function render()
  30. {
  31. $this->fill();
  32. return parent::render();
  33. }
  34. /**
  35. * 写入数据.
  36. *
  37. * @return void
  38. */
  39. public function fill()
  40. {
  41. $agent = Agent::query()->count();
  42. $supplier = Supplier::query()->count();
  43. $guide = Guide::query()->count();
  44. $this->withContent($agent, $supplier, $guide);
  45. // 图表数据
  46. $this->withChart([$agent, $supplier, $guide]);
  47. }
  48. /**
  49. * 设置图表数据.
  50. *
  51. * @param array $data
  52. *
  53. * @return $this
  54. */
  55. public function withChart(array $data)
  56. {
  57. return $this->chart([
  58. 'series' => $data
  59. ]);
  60. }
  61. /**
  62. * 设置卡片头部内容.
  63. *
  64. * @param mixed $desktop
  65. * @param mixed $mobile
  66. *
  67. * @return $this
  68. */
  69. protected function withContent($desktop, $mobile, $unkonw)
  70. {
  71. $blue = Admin::color()->alpha('blue2', 0.5);
  72. $yellow = Admin::color()->yellow();
  73. $style = 'margin-bottom: 8px';
  74. $labelWidth = 120;
  75. return $this->content(
  76. <<<HTML
  77. <div class="d-flex pl-1 pr-1 pt-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>{$desktop}</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>{$mobile}</div>
  88. </div>
  89. <div class="d-flex pl-1 pr-1" style="{$style}">
  90. <div style="width: {$labelWidth}px">
  91. <i class="fa fa-circle" style="color: $yellow"></i> {$this->labels[2]}
  92. </div>
  93. <div>{$unkonw}</div>
  94. </div>
  95. HTML
  96. );
  97. }
  98. }