|
|
@@ -22,7 +22,7 @@ class Card extends Widget
|
|
|
* @var array
|
|
|
*/
|
|
|
protected $options = [
|
|
|
- 'icon' => 'feather icon-users',
|
|
|
+ 'icon' => null,
|
|
|
'content' => '',
|
|
|
'style' => 'primary',
|
|
|
'ranges' => [],
|
|
|
@@ -81,7 +81,7 @@ class Card extends Widget
|
|
|
*/
|
|
|
protected $chartCallback;
|
|
|
|
|
|
- public function __construct($icon = 'feather icon-users', $contents = null)
|
|
|
+ public function __construct($icon = null, $contents = null)
|
|
|
{
|
|
|
$this->icon($icon);
|
|
|
$this->content($contents);
|
|
|
@@ -106,20 +106,18 @@ class Card extends Widget
|
|
|
$chart = $this->chart ?: ($this->chart = Chart::make());
|
|
|
|
|
|
// 设置图表高度
|
|
|
- if (empty($this->options['chart']['chart']['height'])) {
|
|
|
- $this->options['chart']['chart']['height'] = $this->options['chartHeight'];
|
|
|
- }
|
|
|
+ $this->options['chart']['chart']['height'] = $this->options['chartHeight'];
|
|
|
|
|
|
+ // 图表配置选项
|
|
|
+ $chart->options($this->options['chart']);
|
|
|
// 颜色
|
|
|
$chart->colors(Admin::color()->get($this->options['style']));
|
|
|
- // 匹配选项
|
|
|
- $chart->options($this->options['chart']);
|
|
|
|
|
|
if ($callback = $this->chartCallback) {
|
|
|
$callback($chart);
|
|
|
}
|
|
|
|
|
|
- $this->chart = $this->variables['chart'] = $chart;
|
|
|
+ $this->variables['chart'] = $chart;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -137,7 +135,7 @@ class Card extends Widget
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 设置图标
|
|
|
+ * 设置图标.
|
|
|
*
|
|
|
* @param string $icon
|
|
|
*
|
|
|
@@ -185,7 +183,7 @@ class Card extends Widget
|
|
|
*
|
|
|
* @return $this
|
|
|
*/
|
|
|
- public function minHeight($value)
|
|
|
+ public function height($value)
|
|
|
{
|
|
|
if (is_numeric($value)) {
|
|
|
$value .= 'px';
|
|
|
@@ -203,10 +201,10 @@ class Card extends Widget
|
|
|
*/
|
|
|
public function chartHeight(int $number)
|
|
|
{
|
|
|
- $this->setUpChart();
|
|
|
-
|
|
|
$this->options['chartHeight'] = $number;
|
|
|
|
|
|
+ $this->setUpChart();
|
|
|
+
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
|
@@ -234,8 +232,6 @@ class Card extends Widget
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * js代码.
|
|
|
- *
|
|
|
* @return mixed
|
|
|
*/
|
|
|
public function script()
|
|
|
@@ -266,11 +262,11 @@ JS
|
|
|
$cardRequestScript = '';
|
|
|
|
|
|
if ($this->chart) {
|
|
|
+ // 有图表的情况下,直接使用图表的js代码.
|
|
|
$this->chart->merge($this)->click($clickable);
|
|
|
} else {
|
|
|
- $this->click($clickable);
|
|
|
-
|
|
|
- $cardRequestScript = $this->buildRequestScript();
|
|
|
+ // 没有图表,需要构建卡片数据请求js代码.
|
|
|
+ $cardRequestScript = $this->click($clickable)->buildRequestScript();
|
|
|
}
|
|
|
|
|
|
// 按钮显示选中文本
|
|
|
@@ -290,7 +286,7 @@ JS;
|
|
|
{
|
|
|
$this->script = $this->script();
|
|
|
|
|
|
- return parent::render(); // TODO: Change the autogenerated stub
|
|
|
+ return parent::render();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -303,7 +299,7 @@ JS;
|
|
|
return [
|
|
|
'status' => 1,
|
|
|
'content' => Helper::render($this->options['content']),
|
|
|
- 'options' => $this->chart ? $this->chart->getOptions() : [],
|
|
|
+ 'options' => optional($this->chart)->getOptions(),
|
|
|
];
|
|
|
}
|
|
|
}
|