From 6c99394a567c301e9a32128fe812249e93e92083 Mon Sep 17 00:00:00 2001 From: lemon <15040771@qq.com> Date: Thu, 2 Sep 2021 19:10:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A5=E9=A9=BB=E6=AF=94=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Metrics/Examples/NewDevices.php | 145 ++++++++++++---------- 1 file changed, 78 insertions(+), 67 deletions(-) diff --git a/app/Admin/Metrics/Examples/NewDevices.php b/app/Admin/Metrics/Examples/NewDevices.php index 3406d9d..8b873df 100644 --- a/app/Admin/Metrics/Examples/NewDevices.php +++ b/app/Admin/Metrics/Examples/NewDevices.php @@ -2,86 +2,91 @@ namespace App\Admin\Metrics\Examples; +use App\Models\Agent; +use App\Models\Guide; +use App\Models\Supplier; use Dcat\Admin\Admin; use Dcat\Admin\Widgets\Metrics\Donut; class NewDevices extends Donut { - protected $labels = ['Desktop', 'Mobile']; + protected $labels = ['代理商', '供应商', '地接']; - /** - * 初始化卡片内容 - */ - protected function init() - { - parent::init(); + /** + * 初始化卡片内容 + */ + protected function init() + { + parent::init(); - $color = Admin::color(); - $colors = [$color->primary(), $color->alpha('blue2', 0.5)]; + $color = Admin::color(); + $colors = [$color->primary(), $color->alpha('blue2', 0.5),Admin::color()->yellow()]; - $this->title('New Devices'); - $this->subTitle('Last 30 days'); - $this->chartLabels($this->labels); - // 设置图表颜色 - $this->chartColors($colors); - } + $this->title('入驻比例');; + $this->chartLabels($this->labels); + // 设置图表颜色 + $this->chartColors($colors); + } - /** - * 渲染模板 - * - * @return string - */ - public function render() - { - $this->fill(); + /** + * 渲染模板 + * + * @return string + */ + public function render() + { + $this->fill(); - return parent::render(); - } + return parent::render(); + } - /** - * 写入数据. - * - * @return void - */ - public function fill() - { - $this->withContent(44.9, 28.6); + /** + * 写入数据. + * + * @return void + */ + public function fill() + { + $agent = Agent::query()->count(); + $supplier = Supplier::query()->count(); + $guide = Guide::query()->count(); + $this->withContent($agent, $supplier, $guide); - // 图表数据 - $this->withChart([44.9, 28.6]); - } + // 图表数据 + $this->withChart([$agent, $supplier, $guide]); + } - /** - * 设置图表数据. - * - * @param array $data - * - * @return $this - */ - public function withChart(array $data) - { - return $this->chart([ - 'series' => $data - ]); - } + /** + * 设置图表数据. + * + * @param array $data + * + * @return $this + */ + public function withChart(array $data) + { + return $this->chart([ + 'series' => $data + ]); + } - /** - * 设置卡片头部内容. - * - * @param mixed $desktop - * @param mixed $mobile - * - * @return $this - */ - protected function withContent($desktop, $mobile) - { - $blue = Admin::color()->alpha('blue2', 0.5); + /** + * 设置卡片头部内容. + * + * @param mixed $desktop + * @param mixed $mobile + * + * @return $this + */ + protected function withContent($desktop, $mobile, $unkonw) + { + $blue = Admin::color()->alpha('blue2', 0.5); + $yellow = Admin::color()->yellow(); + $style = 'margin-bottom: 8px'; + $labelWidth = 120; - $style = 'margin-bottom: 8px'; - $labelWidth = 120; - - return $this->content( - <<content( + <<
{$this->labels[0]} @@ -94,7 +99,13 @@ class NewDevices extends Donut
{$mobile}
+
+
+ {$this->labels[2]} +
+
{$unkonw}
+
HTML - ); - } + ); + } }