Pārlūkot izejas kodu

radial bar card

jqh 5 gadi atpakaļ
vecāks
revīzija
693a4899b3

+ 4 - 0
resources/assets/dcat/sass/components/_layer.scss

@@ -67,6 +67,10 @@
   border-color: $white!important;
 }
 
+.layui-layer-btn a.btn-loading {
+  padding-top: 8px!important;
+}
+
 .layui-layer-btn .layui-layer-btn0 {
   border-color: $primary!important;
   background-color: $primary!important;

+ 1 - 1
resources/assets/dcat/sass/components/_table.scss

@@ -65,7 +65,7 @@ table.data-list-view.dataTable tbody td, table.data-thumb-view.dataTable tbody t
 // 快捷搜索
 .data-list-view-header .table-responsive .top .dataTables_filter .form-control, .data-thumb-view-header .table-responsive .top .dataTables_filter .form-control {
   padding: 1.23rem 2.8rem !important;
-  border-radius: 1.4rem;
+  border-radius: .5rem;
   border: 0;
   box-shadow: $shadow;
 }

+ 5 - 1
resources/dist/dcat/css/dcat-app.css

@@ -2183,7 +2183,7 @@ table.data-thumb-view.dataTable tbody td {
 .data-list-view-header .table-responsive .top .dataTables_filter .form-control,
 .data-thumb-view-header .table-responsive .top .dataTables_filter .form-control {
   padding: 1.23rem 2.8rem !important;
-  border-radius: 1.4rem;
+  border-radius: 0.5rem;
   border: 0;
   box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.08);
 }
@@ -2503,6 +2503,10 @@ table.dataTable.complex-headers tfoot td {
   border-color: #fff !important;
 }
 
+.layui-layer-btn a.btn-loading {
+  padding-top: 8px !important;
+}
+
 .layui-layer-btn .layui-layer-btn0 {
   border-color: #5c6bc6 !important;
   background-color: #5c6bc6 !important;

+ 33 - 0
resources/views/widgets/metrics/radial-bar-card.blade.php

@@ -0,0 +1,33 @@
+<div {!! $attributes !!}>
+    <div class="card-header d-flex justify-content-between pb-0">
+        <h4 class="card-title mb-1">{!! $options['title'] !!}</h4>
+
+        @if(! empty($options['dropdown']))
+        <div class="dropdown chart-dropdown">
+            <button class="btn btn-sm btn-light shadow-0 dropdown-toggle p-0 waves-effect" data-toggle="dropdown">
+                {{ current($options['dropdown']) }}
+            </button>
+            <div class="dropdown-menu dropdown-menu-right">
+                @foreach($options['dropdown'] as $key => $value)
+                    <li class="dropdown-item"><a href="javascript:void(0)" class="select-option" data-option="{{ $key }}">{{ $value }}</a></li>
+                @endforeach
+            </div>
+        </div>
+        @endif
+    </div>
+    <div class="card-content">
+        <div class="card-body pt-0">
+            <div class="row">
+                <div class="metric-content col-sm-2 col-12 d-flex flex-column flex-wrap text-center">
+                    {!! \Dcat\Admin\Support\Helper::render($options['content']) !!}
+                </div>
+                <div class="col-sm-10 col-12 d-flex justify-content-center">
+                    {!! ! empty($chart) ? $chart : '' !!}
+                </div>
+            </div>
+            <div class="chart-info metric-footer d-flex justify-content-between">
+                {!! \Dcat\Admin\Support\Helper::render($options['footer']) !!}
+            </div>
+        </div>
+    </div>
+</div>

+ 177 - 0
src/Widgets/Metrics/RadialBarCard.php

@@ -0,0 +1,177 @@
+<?php
+
+namespace Dcat\Admin\Widgets\Metrics;
+
+use Dcat\Admin\Admin;
+use Dcat\Admin\Support\Helper;
+use Dcat\Admin\Traits\FromApi;
+use Illuminate\Contracts\Support\Renderable;
+
+class RadialBarCard extends Card
+{
+    use FromApi;
+
+    /**
+     * @var string
+     */
+    protected $view = 'admin::widgets.metrics.radial-bar-card';
+
+    /**
+     * @var array
+     */
+    protected $options = [
+        'title' => '',
+        'content' => '',
+        'footer' => '',
+        'dropdown' => [],
+    ];
+
+    /**
+     * @var int
+     */
+    protected $chartHeight = 200;
+
+    /**
+     * @var array
+     */
+    protected $chartOptions = [];
+
+    public function __construct(?string $title = null, $contents = null)
+    {
+        $this->title($title);
+        $this->content($contents);
+
+        $this->defaultChartOptions();
+
+        $this->init();
+    }
+
+    /**
+     * 图表默认配置
+     */
+    protected function defaultChartOptions()
+    {
+        $gradientColor = Admin::color()->success();
+
+        $this->chartOptions = [
+            'chart' => [
+                'type' => 'radialBar',
+            ],
+            'plotOptions' => [
+                'radialBar' => [
+                    'size' => 150,
+                    'startAngle' => -150,
+                    'endAngle' => 150,
+                    'offsetY' => 20,
+                    'hollow' => [
+                        'size' => '65%',
+                    ],
+                    'track' => [
+                        'background' => '#fff',
+                        'strokeWidth' => '100%',
+                    ],
+                    'dataLabels' => [
+                        'value' => [
+                            'offsetY' => 30,
+                            'color' => '#99a2ac',
+                            'fontSize' => '2rem'
+                        ]
+                    ]
+                ],
+            ],
+            'fill' => [
+                'type' => 'gradient',
+                'gradient' => [
+                    'shade' => 'dark',
+                    'type' => 'horizontal',
+                    'shadeIntensity' => 0.5,
+                    'gradientToColors' => [$gradientColor],
+                    'inverseColors' => true,
+                    'opacityFrom' => 1,
+                    'opacityTo' => 1,
+                    'stops' => [0, 100]
+                ],
+            ],
+            'stroke' => [
+                'dashArray' => 8
+            ],
+        ];
+    }
+
+    /**
+     * 设置卡片标题.
+     *
+     * @param string $value
+     *
+     * @return $this
+     */
+    public function title(?string $value)
+    {
+        $this->options['title'] = $value;
+
+        return $this;
+    }
+
+    /**
+     * 设置卡片底部内容.
+     *
+     * @param string|\Closure|Renderable $value
+     *
+     * @return $this
+     */
+    public function footer($value)
+    {
+        $this->options['footer'] = $value;
+
+        return $this;
+    }
+
+    /**
+     * 设置图表label.
+     *
+     * @param string|array $label
+     *
+     * @return $this
+     */
+    public function chartLabels($label)
+    {
+        $this->chartOptions['labels'] = (array) $label;
+
+        $this->setUpChart();
+
+        return $this;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function script()
+    {
+        if (! $this->allowBuildRequest()) {
+            return;
+        }
+
+        $this->fetched(
+            <<<'JS'
+$card.find('.metric-footer').html(response.footer);
+JS
+        );
+
+        return parent::script();
+    }
+
+        /**
+     * 返回卡片数据结果.
+     *
+     * @return array
+     */
+    public function result()
+    {
+        return array_merge(
+            parent::result(),
+            [
+                'footer' => Helper::render($this->options['footer']),
+            ]
+        );
+    }
+}