Skip to content

Commit 767c48b

Browse files
author
hikki
committed
v1 点线面
1 parent 2df6b41 commit 767c48b

File tree

1 file changed

+31
-68
lines changed

1 file changed

+31
-68
lines changed

src/DLPViewer.php

Lines changed: 31 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -166,78 +166,42 @@ public function render()
166166
}
167167

168168
/**
169-
* 新增表单-按钮
169+
* 列-多操作添加 (旧版图标按钮模式)
170170
* @param Grid $grid
171+
* @param array $settings [setting,...]
172+
* setting.document_class 自定义类名
173+
* setting.title 自定义按钮名 (图标css类 fa-edit fa-...)
174+
* setting.url 加载页地址
175+
* setting.xhr_url ajax提交地址
176+
* setting.method ajax提交方法
177+
* @param array $disable ['view','edit','delete']
171178
*/
172-
public static function makeAddFormAction(Grid $grid)
179+
public static function _makeRowPlaneAction(Grid $grid,array $settings = [
180+
['document_class'=>'','title'=>'','url'=>'','xhr_url'=>'','method'=>'POST']
181+
],array $disable=[])
173182
{
174-
$url = Request::capture()->getPathInfo();
175-
Admin::script(<<<EOF
176-
$('.CAForm').click(function(){
177-
componentPlane('{$url}/create','{$url}');
183+
$script = '';
184+
foreach ($settings as $setting){
185+
$url = $setting['url'];
186+
$method = isset($setting['method']) ? $setting['method'] : 'POST';
187+
$xhr_url = isset($setting['xhr_url']) ? $setting['xhr_url'] : $url;
188+
$script.=<<<EOF
189+
$('.{$setting['document_class']}').click(function(){
190+
let url = '$url'.replace('{id}',$(this).attr('data-id'));
191+
componentPlane(url,'{$xhr_url}','{$method}');
178192
});
179-
EOF
180-
);
181-
$grid->disableCreateButton();
182-
$grid->tools->append(new
183-
class extends RowAction {
184-
public function render()
185-
{
186-
return <<<EOF
187-
<div class="btn-group pull-right grid-create-btn" style="margin-right: 10px">
188-
<a href='javascript:void(0);' class="btn btn-sm btn-success CAForm" title="新增">
189-
<i class="fa fa-plus"></i><span class="hidden-xs">&nbsp;&nbsp;新增</span>
190-
</a>
191-
</div>
192193
EOF;
194+
}
195+
Admin::script($script);
196+
$grid->actions(function ($actions)use($settings,$disable) {
197+
foreach ($settings as $setting) {
198+
$actions->append("<a data-id='{$actions->getKey()}' href='javascript:void(0);' class='{$setting['document_class']}'><i class='fa {$setting['title']}'></i></a>");
199+
}
200+
foreach ($disable as $dis){
201+
$dis == 'view' && $actions->disableView();
202+
$dis == 'edit' && $actions->disableEdit();
203+
$dis == 'delete' && $actions->disableDelete();
193204
}
194-
});
195-
}
196-
197-
/**
198-
* 修改表单-按钮
199-
* @param Grid $grid
200-
*/
201-
public static function makeEditFormAction(Grid $grid)
202-
{
203-
$grid->actions(function ($actions) {
204-
$actions->disableEdit();
205-
$url = Request::capture()->getPathInfo();
206-
Admin::script(<<<EOF
207-
$('.CEForm').click(function(){
208-
let url = '{$url}' + '/'+this.getAttribute('data-id');
209-
componentPlane(url+'/edit',url);
210-
});
211-
EOF
212-
);
213-
214-
$actions->add(new
215-
class extends RowAction {
216-
public function render()
217-
{
218-
return "<a href='javascript:void(0);' class='CEForm' data-id='{$this->getKey()}'>修改</a>";
219-
}
220-
});
221-
});
222-
}
223-
224-
/**
225-
* 修改表单-按钮 (旧版图标模式)
226-
* @param Grid $grid
227-
*/
228-
public static function _makeEditFormAction(Grid &$grid)
229-
{
230-
$grid->actions(function ($actions) {
231-
$actions->disableEdit();
232-
$url = Request::capture()->getPathInfo();
233-
Admin::script(<<<EOF
234-
$('.CEForm').click(function(){
235-
let url = '{$url}' + '/'+this.getAttribute('data-id');
236-
componentPlane(url+'/edit',url);
237-
});
238-
EOF
239-
);
240-
$actions->append("<a data-id='{$actions->getKey()}' href='javascript:void(0);' class='CEForm'><i class='fa fa-edit'></i></a>");
241205
});
242206
}
243207

@@ -276,11 +240,10 @@ public static function result($success = true, $message = 'OK', $data = [])
276240
/**
277241
* 表单代码段插入js片段代码
278242
* @param $script
279-
* @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
280243
*/
281244
public static function script($script)
282245
{
283-
return Admin::script(<<<EOF
246+
Admin::script(<<<EOF
284247
new Promise((resolve, reject) => {
285248
while (true){
286249
if(document.getElementById('component') instanceof HTMLElement){

0 commit comments

Comments
 (0)