Skip to content

Commit 0476d90

Browse files
Merge pull request #15 from osindex/develop
🎨 1.card header 支持组件写法;2.content->body() 兼容html写法
2 parents 8407d1c + e3a9175 commit 0476d90

File tree

6 files changed

+46
-28
lines changed

6 files changed

+46
-28
lines changed

docs/components.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,17 @@ $baseForm->item("express_no", "物流单号")->required();
3131
将信息聚合在卡片容器中展示。
3232

3333
```php
34-
Card::make()->content();
34+
$header = '标题 <a style="float:right;">测试</a>'; //html文本
35+
$content = new Content; // 对象
36+
$header = $content->row(function (Row $row) {
37+
$row->column(12, Widgets\Text::make('标题'));
38+
$row->column(12, Form\CSwitch::make()->style(['float' => 'right']));
39+
});
40+
Card::make()->header(function (Content $content)
41+
{
42+
$content->className('mt-10')->body('测试内容'); // 闭包
43+
})->content();
44+
// content同理
3545
```
3646

3747
### Steps 步骤条

resources/js/components/widgets/Card.vue

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22
<el-card
33
:style="attrs.style"
44
:class="attrs.className"
5-
:header="attrs.header"
65
:body-style="attrs.bodyStyle"
76
:shadow="attrs.shadow"
87
>
8+
<div slot="header" class="clearfix">
9+
<component
10+
v-if="attrs.header"
11+
:is="attrs.header.componentName"
12+
:attrs="attrs.header"
13+
/>
14+
</div>
915
<component
1016
v-if="attrs.content"
1117
:is="attrs.content.componentName"

src/Components/Widgets/Card.php

+4-15
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?php
22

3-
43
namespace SmallRuralDog\Admin\Components\Widgets;
54

6-
75
use SmallRuralDog\Admin\Components\Component;
86
use SmallRuralDog\Admin\Layout\Content;
97

@@ -22,13 +20,13 @@ public static function make()
2220
}
2321

2422
/**
25-
* 设置 header 目前只支持String
23+
* 设置 header
2624
* @param string $header
2725
* @return $this
2826
*/
29-
public function header(string $header)
27+
public function header($header)
3028
{
31-
$this->header = $header;
29+
$this->header = instance_content($header);
3230
return $this;
3331
}
3432

@@ -62,17 +60,8 @@ public function shadow(string $shadow)
6260
*/
6361
public function content($content)
6462
{
65-
if ($content instanceof \Closure) {
66-
$c_content = new Content();
67-
call_user_func($content, $c_content);
68-
$this->content = $c_content;
69-
} else {
70-
$this->content = $content;
71-
}
72-
73-
63+
$this->content = instance_content($content);
7464
return $this;
7565
}
7666

77-
7867
}

src/Layout/Content.php

-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
43
namespace SmallRuralDog\Admin\Layout;
54

65
use Closure;
@@ -21,13 +20,11 @@ public static function make()
2120
return new Content();
2221
}
2322

24-
2523
public function body($content)
2624
{
2725
return $this->row($content);
2826
}
2927

30-
3128
public function row($content)
3229
{
3330

@@ -47,7 +44,6 @@ protected function addRow(Row $row)
4744
$this->rows[] = $row;
4845
}
4946

50-
5147
/**
5248
* @param bool $showHeader
5349
* @return $this
@@ -78,5 +74,4 @@ public function description($description)
7874
return $this;
7975
}
8076

81-
8277
}

src/Layout/Row.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
43
namespace SmallRuralDog\Admin\Layout;
54

65
use SmallRuralDog\Admin\Components\Component;
6+
use SmallRuralDog\Admin\Components\Widgets\Html;
77

88
class Row extends Component
99
{
@@ -17,10 +17,12 @@ class Row extends Component
1717

1818
protected $gutter = 0;
1919

20-
2120
public function __construct($content = '')
2221
{
2322
if (!empty($content)) {
23+
if (is_string($content)) {
24+
$this->column(24, Html::make()->html($content));
25+
}
2426
$this->column(24, $content);
2527
}
2628
}
@@ -33,7 +35,6 @@ public function column($width, $content)
3335
return $column;
3436
}
3537

36-
3738
/**
3839
* @param Column $column
3940
*/

src/helpers.php

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

33
use Illuminate\Support\MessageBag;
4+
use SmallRuralDog\Admin\Components\Widgets\Html;
5+
use SmallRuralDog\Admin\Layout\Content;
46

57
if (!function_exists('admin_path')) {
68

@@ -17,7 +19,6 @@ function admin_path($path = '')
1719
}
1820
}
1921

20-
2122
if (!function_exists('admin_base_path')) {
2223
/**
2324
* Get admin url.
@@ -65,13 +66,14 @@ function admin_url($path = '', $parameters = [], $secure = null)
6566
if (!function_exists('admin_file_url')) {
6667
function admin_file_url($path)
6768
{
68-
if (\Illuminate\Support\Str::contains($path,"//")){
69+
if (\Illuminate\Support\Str::contains($path, "//")) {
6970
return $path;
7071
}
7172

7273
return \Storage::disk(config('admin.upload.disk'))->url($path);
7374
}
74-
};
75+
}
76+
;
7577

7678
if (!function_exists('admin_toastr')) {
7779

@@ -102,3 +104,18 @@ function admin_asset($path)
102104
return (config('admin.https') || config('admin.secure')) ? secure_asset($path) : asset($path);
103105
}
104106
}
107+
if (!function_exists('instance_content')) {
108+
109+
function instance_content($content = '')
110+
{
111+
if (is_string($content)) {
112+
return Html::make()->html($content);
113+
} elseif ($content instanceof \Closure) {
114+
$c_content = new Content();
115+
call_user_func($content, $c_content);
116+
return $c_content;
117+
} else {
118+
return $content;
119+
}
120+
}
121+
}

0 commit comments

Comments
 (0)