Skip to content

Commit 03b47c0

Browse files
author
hikki
committed
1.3
1 parent f32491f commit 03b47c0

File tree

1 file changed

+39
-29
lines changed

1 file changed

+39
-29
lines changed

src/DLPViewer.php

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class DLPViewer
2020
* @param Form $form
2121
* @param string $column 字段名
2222
* @param string $title 名称
23-
* @param array $select 全部选项
24-
* @param array $selected 已选择选项
23+
* @param array $select [[id=>value],[id=>value]...], 所有选择项
24+
* @param array $selected [[id=>value],[id=>value]...], 已选择选项
2525
* @param bool $strict json严格模式 消除json敏感字符问题
2626
*/
2727
public static function makeComponentDot(Form $form, string $column, string $title, array $select = [], array $selected = [],bool $strict = false)
@@ -43,17 +43,23 @@ public static function makeComponentDot(Form $form, string $column, string $titl
4343
/**
4444
* 线
4545
* @param Form $form
46-
* @param string $column 字段名
47-
* @param string $title 名称
48-
* @param array $settings 设置项
49-
* @param array $data 数据
50-
* @param bool $strict json严格模式 消除json敏感字符问题
46+
* @param string $column 字段名
47+
* @param string $title 名称
48+
* @param array $settings 配置项
49+
* $settings = [
50+
* 'column1'=> ['name' => 'name1', 'type' => 'input', 'style' => 'width:60px'],
51+
* 'column2'=> ['name' => 'name2', 'type' => 'text'],
52+
* 'column3'=> ['name' => 'name3', 'type' => 'hidden'],
53+
* ...
54+
* ]
55+
* @param array $data 数据
56+
* @param bool $strict json严格模式 消除json敏感字符问题
5157
*/
5258
public static function makeComponentLine(Form $form, string $column, string $title, array $settings = [], array $data = [], bool $strict = false)
5359
{
54-
if($strict) {
60+
if ($strict) {
5561
$data = DLPHelper::safeJson($data);
56-
}else{
62+
} else {
5763
$data = json_encode($data, JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_APOS);
5864
}
5965
$settings = json_encode($settings, JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_APOS);
@@ -74,29 +80,31 @@ public static function makeComponentLine(Form $form, string $column, string $tit
7480
* setting.xhr_url ajax提交地址
7581
* setting.method ajax提交方法
7682
*/
77-
public static function makeHeadPlaneAction(Grid $grid,array $settings = [
78-
['document_id'=>'','title'=>'','url'=>'','xhr_url'=>'','method'=>'POST']
83+
public static function makeHeadPlaneAction(Grid $grid, array $settings = [
84+
['document_id' => '', 'title' => '', 'url' => '', 'xhr_url' => '', 'method' => 'POST']
7985
])
8086
{
8187
$script = '';
82-
foreach ($settings as $setting){
88+
foreach ($settings as $setting) {
8389
$xhr_url = isset($setting['xhr_url']) ? $setting['xhr_url'] : $setting['url'];
8490
$method = isset($setting['method']) ? $setting['method'] : 'POST';
85-
$script.=<<<EOF
91+
$script .= <<<EOF
8692
$('#{$setting['document_id']}').click(function(){
8793
new ComponentPlane('{$setting['url']}','{$xhr_url}','{$method}');
8894
});
8995
EOF;
9096
Admin::script($script);
91-
$grid->tools->append(new class($setting['title'],$setting['document_id']) extends RowAction {
97+
$grid->tools->append(new class($setting['title'], $setting['document_id']) extends RowAction {
9298
private $title;
9399
private $document_id;
94-
public function __construct($title,$document_id)
100+
101+
public function __construct($title, $document_id)
95102
{
96103
parent::__construct();
97104
$this->title = $title;
98105
$this->document_id = $document_id;
99106
}
107+
100108
public function render()
101109
{
102110
return <<<EOF
@@ -122,16 +130,16 @@ public function render()
122130
* setting.method ajax提交方法
123131
* @param array $disable ['view','edit','delete']
124132
*/
125-
public static function makeRowPlaneAction(Grid $grid,array $settings = [
126-
['document_class'=>'','title'=>'','url'=>'','xhr_url'=>'','method'=>'POST']
127-
],array $disable=[])
133+
public static function makeRowPlaneAction(Grid $grid, array $settings = [
134+
['document_class' => '', 'title' => '', 'url' => '', 'xhr_url' => '', 'method' => 'POST']
135+
], array $disable = [])
128136
{
129137
$script = '';
130-
foreach ($settings as $setting){
138+
foreach ($settings as $setting) {
131139
$url = $setting['url'];
132140
$method = isset($setting['method']) ? $setting['method'] : 'POST';
133141
$xhr_url = isset($setting['xhr_url']) ? $setting['xhr_url'] : $url;
134-
$script.=<<<EOF
142+
$script .= <<<EOF
135143
$('.{$setting['document_class']}').click(function(){
136144
let url = '$url'.replace('{id}',$(this).attr('data-id'));
137145
let xhr_url = '$xhr_url'.replace('{id}',$(this).attr('data-id'));
@@ -140,25 +148,27 @@ public static function makeRowPlaneAction(Grid $grid,array $settings = [
140148
EOF;
141149
}
142150
Admin::script($script);
143-
$grid->actions(function ($actions)use($settings,$disable) {
151+
$grid->actions(function ($actions) use ($settings, $disable) {
144152
foreach ($settings as $setting) {
145153
$actions->add(new
146154
class($setting['document_class'], $setting['title']) extends RowAction {
147155
private $title;
148156
private $document_class;
157+
149158
public function __construct($document_class, $title)
150159
{
151160
parent::__construct();
152161
$this->document_class = $document_class;
153162
$this->title = $title;
154163
}
164+
155165
public function render()
156166
{
157167
return "<a href='javascript:void(0);' class='{$this->document_class}' data-id='{$this->getKey()}'>{$this->title}</a>";
158168
}
159169
});
160170
}
161-
foreach ($disable as $dis){
171+
foreach ($disable as $dis) {
162172
$dis == 'view' && $actions->disableView();
163173
$dis == 'edit' && $actions->disableEdit();
164174
$dis == 'delete' && $actions->disableDelete();
@@ -177,28 +187,28 @@ public function render()
177187
* setting.method ajax提交方法
178188
* @param array $disable ['view','edit','delete']
179189
*/
180-
public static function _makeRowPlaneAction(Grid $grid,array $settings = [
181-
['document_class'=>'','title'=>'','url'=>'','xhr_url'=>'','method'=>'POST']
182-
],array $disable=[])
190+
public static function _makeRowPlaneAction(Grid $grid, array $settings = [
191+
['document_class' => '', 'title' => '', 'url' => '', 'xhr_url' => '', 'method' => 'POST']
192+
], array $disable = [])
183193
{
184194
$script = '';
185-
foreach ($settings as $setting){
195+
foreach ($settings as $setting) {
186196
$url = $setting['url'];
187197
$method = isset($setting['method']) ? $setting['method'] : 'POST';
188198
$xhr_url = isset($setting['xhr_url']) ? $setting['xhr_url'] : $url;
189-
$script.=<<<EOF
199+
$script .= <<<EOF
190200
$('.{$setting['document_class']}').click(function(){
191201
let url = '$url'.replace('{id}',$(this).attr('data-id'));
192202
new ComponentPlane(url,'{$xhr_url}','{$method}');
193203
});
194204
EOF;
195205
}
196206
Admin::script($script);
197-
$grid->actions(function ($actions)use($settings,$disable) {
207+
$grid->actions(function ($actions) use ($settings, $disable) {
198208
foreach ($settings as $setting) {
199209
$actions->append("<a data-id='{$actions->getKey()}' href='javascript:void(0);' class='{$setting['document_class']}'><i class='fa {$setting['title']}'></i></a>");
200210
}
201-
foreach ($disable as $dis){
211+
foreach ($disable as $dis) {
202212
$dis == 'view' && $actions->disableView();
203213
$dis == 'edit' && $actions->disableEdit();
204214
$dis == 'delete' && $actions->disableDelete();

0 commit comments

Comments
 (0)