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

118 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
  1. <?php
  2. namespace App\AdminAgent\Metrics\Examples;
  3. use App\Models\User;
  4. use Dcat\Admin\Admin;
  5. use Dcat\Admin\Widgets\Metrics\Donut;
  6. use Illuminate\Support\Arr;
  7. class NewDevices extends Donut
  8. {
  9. protected $labels = ['男性', '女性', '未知'];
  10. /**
  11. * 初始化卡片内容
  12. */
  13. protected function init()
  14. {
  15. parent::init();
  16. $color = Admin::color();
  17. $colors = [$color->primary(), $color->alpha('blue2', 0.5)];
  18. $this->title('用户性别');;
  19. $this->chartLabels($this->labels);
  20. // 设置图表颜色
  21. $this->chartColors($colors);
  22. }
  23. /**
  24. * 渲染模板
  25. *
  26. * @return string
  27. */
  28. public function render()
  29. {
  30. $this->fill();
  31. return parent::render();
  32. }
  33. /**
  34. * 写入数据.
  35. *
  36. * @return void
  37. */
  38. public function fill()
  39. {
  40. $gender = User::query()->where('agent_id', Admin::user()->id)->pluck('gender');
  41. $man = $woman = $unkonw = 0;
  42. foreach ($gender as $v) {
  43. if ($v == 1) {
  44. $man++;
  45. } elseif ($v == 2) {
  46. $woman++;
  47. } else {
  48. $unkonw++;
  49. }
  50. }
  51. $this->withContent($man, $woman, $unkonw);
  52. // 图表数据
  53. $this->withChart([$man,$woman, $unkonw]);
  54. }
  55. /**
  56. * 设置图表数据.
  57. *
  58. * @param array $data
  59. *
  60. * @return $this
  61. */
  62. public function withChart(array $data)
  63. {
  64. return $this->chart([
  65. 'series' => $data
  66. ]);
  67. }
  68. /**
  69. * 设置卡片头部内容.
  70. *
  71. * @param mixed $desktop
  72. * @param mixed $mobile
  73. *
  74. * @return $this
  75. */
  76. protected function withContent($desktop, $mobile, $unkonw)
  77. {
  78. $blue = Admin::color()->alpha('blue2', 0.5);
  79. $yellow = Admin::color()->yellow();
  80. $style = 'margin-bottom: 8px';
  81. $labelWidth = 120;
  82. return $this->content(
  83. <<<HTML
  84. <div class="d-flex pl-1 pr-1 pt-1" style="{$style}">
  85. <div style="width: {$labelWidth}px">
  86. <i class="fa fa-circle text-primary"></i> {$this->labels[0]}
  87. </div>
  88. <div>{$desktop}</div>
  89. </div>
  90. <div class="d-flex pl-1 pr-1" style="{$style}">
  91. <div style="width: {$labelWidth}px">
  92. <i class="fa fa-circle" style="color: $blue"></i> {$this->labels[1]}
  93. </div>
  94. <div>{$mobile}</div>
  95. </div>
  96. <div class="d-flex pl-1 pr-1" style="{$style}">
  97. <div style="width: {$labelWidth}px">
  98. <i class="fa fa-circle" style="color: $yellow"></i> {$this->labels[2]}
  99. </div>
  100. <div>{$unkonw}</div>
  101. </div>
  102. HTML
  103. );
  104. }
  105. }