CustomBatchAction.php
2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
+-----------------------------------------------------------------------------------------------------------------------
* 管理端扩展 action : 自定义批量操作
+-----------------------------------------------------------------------------------------------------------------------
*
* PHP version 7
*
* @category App\Admin\Extensions\Actions
* @package App\Admin\Extensions\Actions
* @author Richer <yangzi1028@163.com>
* @date 2021年2月24日09:43:49
* @copyright 2020-2022 Richer (http://www.Richer.com/)
* @license http://www.Richer.com/ License
* @link http://www.Richer.com/
*/
namespace App\Admin\Extensions\Actions;
use Encore\Admin\Actions\BatchAction;
use Illuminate\Http\Request;
use Illuminate\Database\Eloquent\Collection;
use App\Admin\Rewrite\Facades\Admin;
/**
* Class CustomBatchAction
*
* @category App\Admin\Extensions\Actions
* @package App\Admin\Extensions\Actions
* @author Richer <yangzi1028@163.com>
* @date 2021年2月24日09:43:49
* @copyright 2020-2022 Richer (http://www.Richer.com/)
* @license http://www.Richer.com/ License
* @link http://www.Richer.com/
*/
class CustomBatchAction extends BatchAction
{
/**
* {@inheritdoc}
*/
public function actionScript()
{
$warning = $this->warning;//'请选择需要远程开锁的设备!';
return <<<SCRIPT
var key = $.admin.grid.selected();
if (key.length === 0) {
$.admin.toastr.error('{$warning}', '', {positionClass: 'toast-top-center'});
return ;
}
Object.assign(data, {_key:key});
SCRIPT;
}
/**
* @return string
*/
public function render()
{
$this->addScript();
$modalId = '';
if ($this->interactor instanceof Interactor\Form) {
$modalId = $this->interactor->getModalId();
if ($content = $this->html()) {
return $this->interactor->addElementAttr($content, $this->selector);
}
}
return sprintf(
"<a href='javascript:void(0);' class='%s btn btn-sm $this->style' %s>%s</a>",
$this->getElementClass(),
$modalId ? "modal='{$modalId}'" : '',
$this->name()
);
}
}